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 |
|
#include "cisco_eeprom.h" |
18 |
|
#include "cisco_card.h" |
19 |
|
#include "rommon_var.h" |
20 |
|
|
21 |
|
#define VM_PAGE_SHIFT 12 |
22 |
|
#define VM_PAGE_SIZE (1 << VM_PAGE_SHIFT) |
23 |
|
#define VM_PAGE_IMASK (VM_PAGE_SIZE - 1) |
24 |
|
#define VM_PAGE_MASK (~(VM_PAGE_IMASK)) |
25 |
|
|
26 |
|
/* Number of pages in chunk area */ |
27 |
|
#define VM_CHUNK_AREA_SIZE 256 |
28 |
|
|
29 |
|
/* VM memory chunk */ |
30 |
|
typedef struct vm_chunk vm_chunk_t; |
31 |
|
struct vm_chunk { |
32 |
|
void *area; |
33 |
|
u_int page_alloc,page_total; |
34 |
|
vm_chunk_t *next; |
35 |
|
}; |
36 |
|
|
37 |
|
/* VM ghost pool entry */ |
38 |
|
typedef struct vm_ghost_image vm_ghost_image_t; |
39 |
|
struct vm_ghost_image { |
40 |
|
char *filename; |
41 |
|
u_int ref_count; |
42 |
|
int fd; |
43 |
|
off_t file_size; |
44 |
|
u_char *area_ptr; |
45 |
|
vm_ghost_image_t *next; |
46 |
|
}; |
47 |
|
|
48 |
|
/* Maximum number of devices per VM */ |
49 |
|
#define VM_DEVICE_MAX (1 << 6) |
50 |
|
|
51 |
|
/* Size of the PCI bus pool */ |
52 |
#define VM_PCI_POOL_SIZE 32 |
#define VM_PCI_POOL_SIZE 32 |
53 |
|
|
54 |
/* VM instance status */ |
/* VM instance status */ |
59 |
VM_STATUS_SUSPENDED, /* VM is suspended */ |
VM_STATUS_SUSPENDED, /* VM is suspended */ |
60 |
}; |
}; |
61 |
|
|
|
/* VM types */ |
|
|
enum { |
|
|
VM_TYPE_C7200 = 0, |
|
|
VM_TYPE_C3600, |
|
|
VM_TYPE_C2691, |
|
|
VM_TYPE_C3725, |
|
|
VM_TYPE_C3745, |
|
|
}; |
|
|
|
|
62 |
/* Ghost RAM status */ |
/* Ghost RAM status */ |
63 |
enum { |
enum { |
64 |
VM_GHOST_RAM_NONE = 0, |
VM_GHOST_RAM_NONE = 0, |
69 |
/* Timer IRQ check interval */ |
/* Timer IRQ check interval */ |
70 |
#define VM_TIMER_IRQ_CHECK_ITV 1000 |
#define VM_TIMER_IRQ_CHECK_ITV 1000 |
71 |
|
|
72 |
|
/* Max slots per VM */ |
73 |
|
#define VM_MAX_SLOTS 16 |
74 |
|
|
75 |
/* forward declarations */ |
/* forward declarations */ |
76 |
typedef struct vm_obj vm_obj_t; |
typedef struct vm_obj vm_obj_t; |
77 |
|
|
89 |
/* VM instance */ |
/* VM instance */ |
90 |
struct vm_instance { |
struct vm_instance { |
91 |
char *name; |
char *name; |
92 |
int type; /* C7200, C3600, ... */ |
vm_platform_t *platform; /* Platform specific helpers */ |
93 |
int status; /* Instance status */ |
int status; /* Instance status */ |
94 |
int instance_id; /* Instance Identifier */ |
int instance_id; /* Instance Identifier */ |
95 |
char *lock_file; /* Lock file */ |
char *lock_file; /* Lock file */ |
96 |
char *log_file; /* Log file */ |
char *log_file; /* Log filename */ |
97 |
u_int ram_size,rom_size; /* RAM and ROM size in Mb */ |
int log_file_enabled; /* Logging enabled */ |
98 |
u_int iomem_size; /* IOMEM size in Mb */ |
u_int ram_size,rom_size; /* RAM and ROM size in Mb */ |
99 |
u_int nvram_size; /* NVRAM size in Kb */ |
u_int iomem_size; /* IOMEM size in Mb */ |
100 |
u_int pcmcia_disk_size[2]; /* PCMCIA disk0 and disk1 sizes (in Mb) */ |
u_int nvram_size; /* NVRAM size in Kb */ |
101 |
u_int conf_reg,conf_reg_setup; /* Config register */ |
u_int pcmcia_disk_size[2]; /* PCMCIA disk0 and disk1 sizes (in Mb) */ |
102 |
u_int clock_divisor; /* Clock Divisor (see cp0.c) */ |
u_int conf_reg,conf_reg_setup; /* Config register */ |
103 |
u_int ram_mmap; /* Memory-mapped RAM ? */ |
u_int clock_divisor; /* Clock Divisor (see cp0.c) */ |
104 |
u_int restart_ios; /* Restart IOS on reload ? */ |
u_int ram_mmap; /* Memory-mapped RAM ? */ |
105 |
u_int elf_machine_id; /* ELF machine identifier */ |
u_int restart_ios; /* Restart IOS on reload ? */ |
106 |
u_int exec_area_size; /* Size of execution area for CPU */ |
u_int elf_machine_id; /* ELF machine identifier */ |
107 |
m_uint32_t ios_entry_point; /* IOS entry point */ |
u_int exec_area_size; /* Size of execution area for CPU */ |
108 |
char *ios_image; /* IOS image filename */ |
m_uint32_t ios_entry_point; /* IOS entry point */ |
109 |
char *ios_config; /* IOS configuration file */ |
char *ios_image; /* IOS image filename */ |
110 |
char *rom_filename; /* ROM filename */ |
char *ios_config; /* IOS configuration file */ |
111 |
char *sym_filename; /* Symbol filename */ |
char *rom_filename; /* ROM filename */ |
112 |
FILE *lock_fd,*log_fd; /* Lock/Log file descriptors */ |
char *sym_filename; /* Symbol filename */ |
113 |
int debug_level; /* Debugging Level */ |
FILE *lock_fd,*log_fd; /* Lock/Log file descriptors */ |
114 |
int jit_use; /* CPUs use JIT */ |
int debug_level; /* Debugging Level */ |
115 |
|
int jit_use; /* CPUs use JIT */ |
116 |
|
int sparse_mem; /* Use sparse virtual memory */ |
117 |
|
u_int nm_iomem_size; /* IO mem size to be passed to Smart Init */ |
118 |
|
|
119 |
|
/* ROMMON variables */ |
120 |
|
struct rommon_var_list rommon_vars; |
121 |
|
|
122 |
|
/* Memory chunks */ |
123 |
|
vm_chunk_t *chunks; |
124 |
|
|
125 |
/* Basic hardware: system CPU, PCI busses and PCI I/O space */ |
/* Basic hardware: system CPU, PCI busses and PCI I/O space */ |
126 |
cpu_group_t *cpu_group; |
cpu_group_t *cpu_group; |
127 |
cpu_mips_t *boot_cpu; |
cpu_gen_t *boot_cpu; |
128 |
struct pci_bus *pci_bus[2]; |
struct pci_bus *pci_bus[2]; |
129 |
struct pci_bus *pci_bus_pool[VM_PCI_POOL_SIZE]; |
struct pci_bus *pci_bus_pool[VM_PCI_POOL_SIZE]; |
130 |
struct pci_io_data *pci_io_space; |
struct pci_io_data *pci_io_space; |
131 |
|
|
132 |
/* Memory mapped devices */ |
/* Memory mapped devices */ |
133 |
struct vdevice *dev_list; |
struct vdevice *dev_list; |
134 |
struct vdevice *dev_array[MIPS64_DEVICE_MAX]; |
struct vdevice *dev_array[VM_DEVICE_MAX]; |
135 |
|
|
136 |
|
/* IRQ routing */ |
137 |
|
void (*set_irq)(vm_instance_t *vm,u_int irq); |
138 |
|
void (*clear_irq)(vm_instance_t *vm,u_int irq); |
139 |
|
|
140 |
|
/* Slots for PA/NM/... */ |
141 |
|
u_int nr_slots; |
142 |
|
u_int slots_type; |
143 |
|
struct cisco_card *slots[VM_MAX_SLOTS]; |
144 |
|
struct cisco_card_driver **slots_drivers; |
145 |
|
struct pci_bus *slots_pci_bus[VM_MAX_SLOTS]; |
146 |
|
|
147 |
/* Filename for ghosted RAM */ |
/* Filename for ghosted RAM */ |
148 |
char *ghost_ram_filename; |
char *ghost_ram_filename; |
150 |
/* Ghost RAM image handling */ |
/* Ghost RAM image handling */ |
151 |
int ghost_status; |
int ghost_status; |
152 |
|
|
153 |
|
/* Timer IRQ interval check */ |
154 |
|
u_int timer_irq_check_itv; |
155 |
|
|
156 |
/* "idling" pointer counter */ |
/* "idling" pointer counter */ |
157 |
m_uint64_t idle_pc; |
m_uint64_t idle_pc; |
158 |
|
|
159 |
/* Timer IRQ interval check */ |
/* JIT block direct jumps */ |
160 |
u_int timer_irq_check_itv; |
int exec_blk_direct_jump; |
161 |
|
|
162 |
|
/* IRQ idling preemption */ |
163 |
|
u_int irq_idle_preempt[256]; |
164 |
|
|
165 |
/* Console and AUX port VTTY type and parameters */ |
/* Console and AUX port VTTY type and parameters */ |
166 |
int vtty_con_type,vtty_aux_type; |
int vtty_con_type,vtty_aux_type; |
173 |
/* Space reserved in NVRAM by ROM monitor */ |
/* Space reserved in NVRAM by ROM monitor */ |
174 |
u_int nvram_rom_space; |
u_int nvram_rom_space; |
175 |
|
|
176 |
/* Extract and push IOS configuration */ |
/* Chassis cookie (for c2600 and maybe other routers) */ |
177 |
ssize_t (*nvram_extract_config)(vm_instance_t *vm,char **buffer); |
m_uint16_t chassis_cookie[64]; |
|
int (*nvram_push_config)(vm_instance_t *vm,char *buffer,size_t len); |
|
178 |
|
|
179 |
/* Specific hardware data */ |
/* Specific hardware data */ |
180 |
void *hw_data; |
void *hw_data; |
183 |
struct vm_obj *vm_object_list; |
struct vm_obj *vm_object_list; |
184 |
}; |
}; |
185 |
|
|
186 |
#define VM_C7200(vm) ((c7200_t *)vm->hw_data) |
/* VM Platform definition */ |
187 |
#define VM_C3600(vm) ((c3600_t *)vm->hw_data) |
struct vm_platform { |
188 |
#define VM_C2691(vm) ((c2691_t *)vm->hw_data) |
char *name; |
189 |
#define VM_C3725(vm) ((c3725_t *)vm->hw_data) |
char *log_name; |
190 |
#define VM_C3745(vm) ((c3745_t *)vm->hw_data) |
char *cli_name; |
191 |
|
int (*create_instance)(vm_instance_t *vm); |
192 |
|
int (*delete_instance)(vm_instance_t *vm); |
193 |
|
int (*init_instance)(vm_instance_t *vm); |
194 |
|
int (*stop_instance)(vm_instance_t *vm); |
195 |
|
ssize_t (*nvram_extract_config)(vm_instance_t *vm,u_char **buffer); |
196 |
|
int (*nvram_push_config)(vm_instance_t *vm,u_char *buffer,size_t len); |
197 |
|
u_int (*get_mac_addr_msb)(void); |
198 |
|
void (*save_config)(vm_instance_t *vm,FILE *fd); |
199 |
|
int (*cli_parse_options)(vm_instance_t *vm,int option); |
200 |
|
void (*cli_show_options)(vm_instance_t *vm); |
201 |
|
void (*show_spec_drivers)(void); |
202 |
|
}; |
203 |
|
|
204 |
|
/* VM platform list item */ |
205 |
|
struct vm_platform_list { |
206 |
|
struct vm_platform_list *next; |
207 |
|
struct vm_platform *platform; |
208 |
|
}; |
209 |
|
|
210 |
extern int vm_file_naming_type; |
extern int vm_file_naming_type; |
211 |
|
|
212 |
|
/* Set an IRQ for a VM */ |
213 |
|
static inline void vm_set_irq(vm_instance_t *vm,u_int irq) |
214 |
|
{ |
215 |
|
if (vm->set_irq != NULL) |
216 |
|
vm->set_irq(vm,irq); |
217 |
|
} |
218 |
|
|
219 |
|
/* Clear an IRQ for a VM */ |
220 |
|
static inline void vm_clear_irq(vm_instance_t *vm,u_int irq) |
221 |
|
{ |
222 |
|
if (vm->clear_irq != NULL) |
223 |
|
vm->clear_irq(vm,irq); |
224 |
|
} |
225 |
|
|
226 |
/* Initialize a VM object */ |
/* Initialize a VM object */ |
227 |
void vm_object_init(vm_obj_t *obj); |
void vm_object_init(vm_obj_t *obj); |
228 |
|
|
271 |
/* Error message */ |
/* Error message */ |
272 |
void vm_error(vm_instance_t *vm,char *format,...); |
void vm_error(vm_instance_t *vm,char *format,...); |
273 |
|
|
|
/* Create a new VM instance */ |
|
|
vm_instance_t *vm_create(char *name,int instance_id,int machine_type); |
|
|
|
|
274 |
/* Shutdown hardware resources used by a VM */ |
/* Shutdown hardware resources used by a VM */ |
275 |
int vm_hardware_shutdown(vm_instance_t *vm); |
int vm_hardware_shutdown(vm_instance_t *vm); |
276 |
|
|
319 |
/* Monitor an instance periodically */ |
/* Monitor an instance periodically */ |
320 |
void vm_monitor(vm_instance_t *vm); |
void vm_monitor(vm_instance_t *vm); |
321 |
|
|
322 |
|
/* Allocate an host page */ |
323 |
|
void *vm_alloc_host_page(vm_instance_t *vm); |
324 |
|
|
325 |
|
/* Free an host page */ |
326 |
|
void vm_free_host_page(vm_instance_t *vm,void *ptr); |
327 |
|
|
328 |
|
/* Get a ghost image */ |
329 |
|
int vm_ghost_image_get(char *filename,u_char **ptr,int *fd); |
330 |
|
|
331 |
|
/* Release a ghost image */ |
332 |
|
int vm_ghost_image_release(int fd); |
333 |
|
|
334 |
/* Open a VM file and map it in memory */ |
/* Open a VM file and map it in memory */ |
335 |
int vm_mmap_open_file(vm_instance_t *vm,char *name, |
int vm_mmap_open_file(vm_instance_t *vm,char *name, |
336 |
u_char **ptr,off_t *fsize); |
u_char **ptr,off_t *fsize); |
362 |
/* Save general VM configuration into the specified file */ |
/* Save general VM configuration into the specified file */ |
363 |
void vm_save_config(vm_instance_t *vm,FILE *fd); |
void vm_save_config(vm_instance_t *vm,FILE *fd); |
364 |
|
|
365 |
|
/* Find a platform */ |
366 |
|
vm_platform_t *vm_platform_find(char *name); |
367 |
|
|
368 |
|
/* Find a platform given its CLI name */ |
369 |
|
vm_platform_t *vm_platform_find_cli_name(char *name); |
370 |
|
|
371 |
|
/* Register a platform */ |
372 |
|
int vm_platform_register(vm_platform_t *platform); |
373 |
|
|
374 |
|
/* Create an instance of the specified type */ |
375 |
|
vm_instance_t *vm_create_instance(char *name,int instance_id,char *type); |
376 |
|
|
377 |
|
/* Delete a VM instance */ |
378 |
|
int vm_delete_instance(char *name); |
379 |
|
|
380 |
|
/* Initialize a VM instance */ |
381 |
|
int vm_init_instance(vm_instance_t *vm); |
382 |
|
|
383 |
|
/* Stop a VM instance */ |
384 |
|
int vm_stop_instance(vm_instance_t *vm); |
385 |
|
|
386 |
|
/* Delete all VM instances */ |
387 |
|
int vm_delete_all_instances(void); |
388 |
|
|
389 |
|
/* Save all VM configs */ |
390 |
|
int vm_save_config_all(FILE *fd); |
391 |
|
|
392 |
#endif |
#endif |