1 |
/* |
/* |
2 |
* Cisco 7200 (Predator) simulation platform. |
* Cisco router simulation platform. |
3 |
* Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr) |
* Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr) |
4 |
* |
* |
5 |
* Virtual Machines. |
* Virtual Machines. |
10 |
|
|
11 |
#include <pthread.h> |
#include <pthread.h> |
12 |
|
|
|
#include "mips64.h" |
|
13 |
#include "dynamips.h" |
#include "dynamips.h" |
14 |
#include "memory.h" |
#include "memory.h" |
15 |
#include "cpu.h" |
#include "cpu.h" |
16 |
#include "dev_vtty.h" |
#include "dev_vtty.h" |
17 |
|
|
18 |
|
#define VM_PAGE_SHIFT 12 |
19 |
|
#define VM_PAGE_SIZE (1 << VM_PAGE_SHIFT) |
20 |
|
#define VM_PAGE_IMASK (VM_PAGE_SIZE - 1) |
21 |
|
#define VM_PAGE_MASK (~(VM_PAGE_IMASK)) |
22 |
|
|
23 |
|
/* Number of pages in chunk area */ |
24 |
|
#define VM_CHUNK_AREA_SIZE 256 |
25 |
|
|
26 |
|
/* VM memory chunk */ |
27 |
|
typedef struct vm_chunk vm_chunk_t; |
28 |
|
struct vm_chunk { |
29 |
|
void *area; |
30 |
|
u_int page_alloc,page_total; |
31 |
|
vm_chunk_t *next; |
32 |
|
}; |
33 |
|
|
34 |
|
/* VM ghost pool entry */ |
35 |
|
typedef struct vm_ghost_image vm_ghost_image_t; |
36 |
|
struct vm_ghost_image { |
37 |
|
char *filename; |
38 |
|
u_int ref_count; |
39 |
|
int fd; |
40 |
|
off_t file_size; |
41 |
|
u_char *area_ptr; |
42 |
|
vm_ghost_image_t *next; |
43 |
|
}; |
44 |
|
|
45 |
|
/* Maximum number of devices per VM */ |
46 |
|
#define VM_DEVICE_MAX (1 << 6) |
47 |
|
|
48 |
|
/* Size of the PCI bus pool */ |
49 |
#define VM_PCI_POOL_SIZE 32 |
#define VM_PCI_POOL_SIZE 32 |
50 |
|
|
51 |
/* VM instance status */ |
/* VM instance status */ |
63 |
VM_TYPE_C2691, |
VM_TYPE_C2691, |
64 |
VM_TYPE_C3725, |
VM_TYPE_C3725, |
65 |
VM_TYPE_C3745, |
VM_TYPE_C3745, |
66 |
|
VM_TYPE_C2600, |
67 |
|
VM_TYPE_MSFC1, |
68 |
|
VM_TYPE_PPC32_TEST, |
69 |
}; |
}; |
70 |
|
|
71 |
/* Ghost RAM status */ |
/* Ghost RAM status */ |
99 |
int status; /* Instance status */ |
int status; /* Instance status */ |
100 |
int instance_id; /* Instance Identifier */ |
int instance_id; /* Instance Identifier */ |
101 |
char *lock_file; /* Lock file */ |
char *lock_file; /* Lock file */ |
102 |
char *log_file; /* Log file */ |
char *log_file; /* Log filename */ |
103 |
|
int log_file_enabled; /* Logging enabled */ |
104 |
u_int ram_size,rom_size; /* RAM and ROM size in Mb */ |
u_int ram_size,rom_size; /* RAM and ROM size in Mb */ |
105 |
u_int iomem_size; /* IOMEM size in Mb */ |
u_int iomem_size; /* IOMEM size in Mb */ |
106 |
u_int nvram_size; /* NVRAM size in Kb */ |
u_int nvram_size; /* NVRAM size in Kb */ |
119 |
FILE *lock_fd,*log_fd; /* Lock/Log file descriptors */ |
FILE *lock_fd,*log_fd; /* Lock/Log file descriptors */ |
120 |
int debug_level; /* Debugging Level */ |
int debug_level; /* Debugging Level */ |
121 |
int jit_use; /* CPUs use JIT */ |
int jit_use; /* CPUs use JIT */ |
122 |
|
int sparse_mem; /* Use sparse virtual memory */ |
123 |
|
|
124 |
|
/* Memory chunks */ |
125 |
|
vm_chunk_t *chunks; |
126 |
|
|
127 |
/* Basic hardware: system CPU, PCI busses and PCI I/O space */ |
/* Basic hardware: system CPU, PCI busses and PCI I/O space */ |
128 |
cpu_group_t *cpu_group; |
cpu_group_t *cpu_group; |
129 |
cpu_mips_t *boot_cpu; |
cpu_gen_t *boot_cpu; |
130 |
struct pci_bus *pci_bus[2]; |
struct pci_bus *pci_bus[2]; |
131 |
struct pci_bus *pci_bus_pool[VM_PCI_POOL_SIZE]; |
struct pci_bus *pci_bus_pool[VM_PCI_POOL_SIZE]; |
132 |
struct pci_io_data *pci_io_space; |
struct pci_io_data *pci_io_space; |
133 |
|
|
134 |
/* Memory mapped devices */ |
/* Memory mapped devices */ |
135 |
struct vdevice *dev_list; |
struct vdevice *dev_list; |
136 |
struct vdevice *dev_array[MIPS64_DEVICE_MAX]; |
struct vdevice *dev_array[VM_DEVICE_MAX]; |
137 |
|
|
138 |
|
/* IRQ routing */ |
139 |
|
void (*set_irq)(vm_instance_t *vm,u_int irq); |
140 |
|
void (*clear_irq)(vm_instance_t *vm,u_int irq); |
141 |
|
|
142 |
/* Filename for ghosted RAM */ |
/* Filename for ghosted RAM */ |
143 |
char *ghost_ram_filename; |
char *ghost_ram_filename; |
145 |
/* Ghost RAM image handling */ |
/* Ghost RAM image handling */ |
146 |
int ghost_status; |
int ghost_status; |
147 |
|
|
148 |
|
/* Timer IRQ interval check */ |
149 |
|
u_int timer_irq_check_itv; |
150 |
|
|
151 |
/* "idling" pointer counter */ |
/* "idling" pointer counter */ |
152 |
m_uint64_t idle_pc; |
m_uint64_t idle_pc; |
153 |
|
|
154 |
/* Timer IRQ interval check */ |
/* JIT block direct jumps */ |
155 |
u_int timer_irq_check_itv; |
int exec_blk_direct_jump; |
156 |
|
|
157 |
|
/* IRQ idling preemption */ |
158 |
|
u_int irq_idle_preempt[256]; |
159 |
|
|
160 |
/* Console and AUX port VTTY type and parameters */ |
/* Console and AUX port VTTY type and parameters */ |
161 |
int vtty_con_type,vtty_aux_type; |
int vtty_con_type,vtty_aux_type; |
172 |
ssize_t (*nvram_extract_config)(vm_instance_t *vm,char **buffer); |
ssize_t (*nvram_extract_config)(vm_instance_t *vm,char **buffer); |
173 |
int (*nvram_push_config)(vm_instance_t *vm,char *buffer,size_t len); |
int (*nvram_push_config)(vm_instance_t *vm,char *buffer,size_t len); |
174 |
|
|
175 |
|
/* Chassis cookie (for c2600 and maybe other routers) */ |
176 |
|
m_uint16_t chassis_cookie[64]; |
177 |
|
|
178 |
/* Specific hardware data */ |
/* Specific hardware data */ |
179 |
void *hw_data; |
void *hw_data; |
180 |
|
|
187 |
#define VM_C2691(vm) ((c2691_t *)vm->hw_data) |
#define VM_C2691(vm) ((c2691_t *)vm->hw_data) |
188 |
#define VM_C3725(vm) ((c3725_t *)vm->hw_data) |
#define VM_C3725(vm) ((c3725_t *)vm->hw_data) |
189 |
#define VM_C3745(vm) ((c3745_t *)vm->hw_data) |
#define VM_C3745(vm) ((c3745_t *)vm->hw_data) |
190 |
|
#define VM_C2600(vm) ((c2600_t *)vm->hw_data) |
191 |
|
#define VM_MSFC1(vm) ((msfc1_t *)vm->hw_data) |
192 |
|
|
193 |
extern int vm_file_naming_type; |
extern int vm_file_naming_type; |
194 |
|
|
195 |
|
/* Set an IRQ for a VM */ |
196 |
|
static inline void vm_set_irq(vm_instance_t *vm,u_int irq) |
197 |
|
{ |
198 |
|
if (vm->set_irq != NULL) |
199 |
|
vm->set_irq(vm,irq); |
200 |
|
} |
201 |
|
|
202 |
|
/* Clear an IRQ for a VM */ |
203 |
|
static inline void vm_clear_irq(vm_instance_t *vm,u_int irq) |
204 |
|
{ |
205 |
|
if (vm->clear_irq != NULL) |
206 |
|
vm->clear_irq(vm,irq); |
207 |
|
} |
208 |
|
|
209 |
/* Initialize a VM object */ |
/* Initialize a VM object */ |
210 |
void vm_object_init(vm_obj_t *obj); |
void vm_object_init(vm_obj_t *obj); |
211 |
|
|
305 |
/* Monitor an instance periodically */ |
/* Monitor an instance periodically */ |
306 |
void vm_monitor(vm_instance_t *vm); |
void vm_monitor(vm_instance_t *vm); |
307 |
|
|
308 |
|
/* Allocate an host page */ |
309 |
|
void *vm_alloc_host_page(vm_instance_t *vm); |
310 |
|
|
311 |
|
/* Free an host page */ |
312 |
|
void vm_free_host_page(vm_instance_t *vm,void *ptr); |
313 |
|
|
314 |
|
/* Get a ghost image */ |
315 |
|
int vm_ghost_image_get(char *filename,u_char **ptr,int *fd); |
316 |
|
|
317 |
|
/* Release a ghost image */ |
318 |
|
int vm_ghost_image_release(int fd); |
319 |
|
|
320 |
/* Open a VM file and map it in memory */ |
/* Open a VM file and map it in memory */ |
321 |
int vm_mmap_open_file(vm_instance_t *vm,char *name, |
int vm_mmap_open_file(vm_instance_t *vm,char *name, |
322 |
u_char **ptr,off_t *fsize); |
u_char **ptr,off_t *fsize); |