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_PPC32_TEST, |
68 |
}; |
}; |
69 |
|
|
70 |
/* Ghost RAM status */ |
/* Ghost RAM status */ |
98 |
int status; /* Instance status */ |
int status; /* Instance status */ |
99 |
int instance_id; /* Instance Identifier */ |
int instance_id; /* Instance Identifier */ |
100 |
char *lock_file; /* Lock file */ |
char *lock_file; /* Lock file */ |
101 |
char *log_file; /* Log file */ |
char *log_file; /* Log filename */ |
102 |
|
int log_file_enabled; /* Logging enabled */ |
103 |
u_int ram_size,rom_size; /* RAM and ROM size in Mb */ |
u_int ram_size,rom_size; /* RAM and ROM size in Mb */ |
104 |
u_int iomem_size; /* IOMEM size in Mb */ |
u_int iomem_size; /* IOMEM size in Mb */ |
105 |
u_int nvram_size; /* NVRAM size in Kb */ |
u_int nvram_size; /* NVRAM size in Kb */ |
118 |
FILE *lock_fd,*log_fd; /* Lock/Log file descriptors */ |
FILE *lock_fd,*log_fd; /* Lock/Log file descriptors */ |
119 |
int debug_level; /* Debugging Level */ |
int debug_level; /* Debugging Level */ |
120 |
int jit_use; /* CPUs use JIT */ |
int jit_use; /* CPUs use JIT */ |
121 |
|
int sparse_mem; /* Use sparse virtual memory */ |
122 |
|
|
123 |
|
/* Memory chunks */ |
124 |
|
vm_chunk_t *chunks; |
125 |
|
|
126 |
/* Basic hardware: system CPU, PCI busses and PCI I/O space */ |
/* Basic hardware: system CPU, PCI busses and PCI I/O space */ |
127 |
cpu_group_t *cpu_group; |
cpu_group_t *cpu_group; |
128 |
cpu_mips_t *boot_cpu; |
cpu_gen_t *boot_cpu; |
129 |
struct pci_bus *pci_bus[2]; |
struct pci_bus *pci_bus[2]; |
130 |
struct pci_bus *pci_bus_pool[VM_PCI_POOL_SIZE]; |
struct pci_bus *pci_bus_pool[VM_PCI_POOL_SIZE]; |
131 |
struct pci_io_data *pci_io_space; |
struct pci_io_data *pci_io_space; |
132 |
|
|
133 |
/* Memory mapped devices */ |
/* Memory mapped devices */ |
134 |
struct vdevice *dev_list; |
struct vdevice *dev_list; |
135 |
struct vdevice *dev_array[MIPS64_DEVICE_MAX]; |
struct vdevice *dev_array[VM_DEVICE_MAX]; |
136 |
|
|
137 |
|
/* IRQ routing */ |
138 |
|
void (*set_irq)(vm_instance_t *vm,u_int irq); |
139 |
|
void (*clear_irq)(vm_instance_t *vm,u_int irq); |
140 |
|
|
141 |
/* Filename for ghosted RAM */ |
/* Filename for ghosted RAM */ |
142 |
char *ghost_ram_filename; |
char *ghost_ram_filename; |
165 |
ssize_t (*nvram_extract_config)(vm_instance_t *vm,char **buffer); |
ssize_t (*nvram_extract_config)(vm_instance_t *vm,char **buffer); |
166 |
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); |
167 |
|
|
168 |
|
/* Chassis cookie (for c2600 and maybe other routers */ |
169 |
|
m_uint16_t chassis_cookie[64]; |
170 |
|
|
171 |
/* Specific hardware data */ |
/* Specific hardware data */ |
172 |
void *hw_data; |
void *hw_data; |
173 |
|
|
180 |
#define VM_C2691(vm) ((c2691_t *)vm->hw_data) |
#define VM_C2691(vm) ((c2691_t *)vm->hw_data) |
181 |
#define VM_C3725(vm) ((c3725_t *)vm->hw_data) |
#define VM_C3725(vm) ((c3725_t *)vm->hw_data) |
182 |
#define VM_C3745(vm) ((c3745_t *)vm->hw_data) |
#define VM_C3745(vm) ((c3745_t *)vm->hw_data) |
183 |
|
#define VM_C2600(vm) ((c2600_t *)vm->hw_data) |
184 |
|
|
185 |
extern int vm_file_naming_type; |
extern int vm_file_naming_type; |
186 |
|
|
187 |
|
/* Set an IRQ for a VM */ |
188 |
|
static inline void vm_set_irq(vm_instance_t *vm,u_int irq) |
189 |
|
{ |
190 |
|
if (vm->set_irq != NULL) |
191 |
|
vm->set_irq(vm,irq); |
192 |
|
} |
193 |
|
|
194 |
|
/* Clear an IRQ for a VM */ |
195 |
|
static inline void vm_clear_irq(vm_instance_t *vm,u_int irq) |
196 |
|
{ |
197 |
|
if (vm->clear_irq != NULL) |
198 |
|
vm->clear_irq(vm,irq); |
199 |
|
} |
200 |
|
|
201 |
/* Initialize a VM object */ |
/* Initialize a VM object */ |
202 |
void vm_object_init(vm_obj_t *obj); |
void vm_object_init(vm_obj_t *obj); |
203 |
|
|
297 |
/* Monitor an instance periodically */ |
/* Monitor an instance periodically */ |
298 |
void vm_monitor(vm_instance_t *vm); |
void vm_monitor(vm_instance_t *vm); |
299 |
|
|
300 |
|
/* Allocate an host page */ |
301 |
|
void *vm_alloc_host_page(vm_instance_t *vm); |
302 |
|
|
303 |
|
/* Free an host page */ |
304 |
|
void vm_free_host_page(vm_instance_t *vm,void *ptr); |
305 |
|
|
306 |
|
/* Get a ghost image */ |
307 |
|
int vm_ghost_image_get(char *filename,u_char **ptr,int *fd); |
308 |
|
|
309 |
|
/* Release a ghost image */ |
310 |
|
int vm_ghost_image_release(int fd); |
311 |
|
|
312 |
/* Open a VM file and map it in memory */ |
/* Open a VM file and map it in memory */ |
313 |
int vm_mmap_open_file(vm_instance_t *vm,char *name, |
int vm_mmap_open_file(vm_instance_t *vm,char *name, |
314 |
u_char **ptr,off_t *fsize); |
u_char **ptr,off_t *fsize); |