/[dynamips]/upstream/dynamips-0.2.7-RC1/vm.h
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/dynamips-0.2.7-RC1/vm.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (show annotations)
Sat Oct 6 16:23:47 2007 UTC (12 years, 2 months ago) by dpavlin
File MIME type: text/plain
File size: 9745 byte(s)
dynamips-0.2.7-RC1

1 /*
2 * Cisco router simulation platform.
3 * Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr)
4 *
5 * Virtual Machines.
6 */
7
8 #ifndef __VM_H__
9 #define __VM_H__
10
11 #include <pthread.h>
12
13 #include "dynamips.h"
14 #include "memory.h"
15 #include "cpu.h"
16 #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
50
51 /* VM instance status */
52 enum {
53 VM_STATUS_HALTED = 0, /* VM is halted and no HW resources are used */
54 VM_STATUS_SHUTDOWN, /* Shutdown procedure engaged */
55 VM_STATUS_RUNNING, /* VM is running */
56 VM_STATUS_SUSPENDED, /* VM is suspended */
57 };
58
59 /* VM types */
60 enum {
61 VM_TYPE_C7200 = 0,
62 VM_TYPE_C3600,
63 VM_TYPE_C2691,
64 VM_TYPE_C3725,
65 VM_TYPE_C3745,
66 VM_TYPE_C2600,
67 VM_TYPE_PPC32_TEST,
68 };
69
70 /* Ghost RAM status */
71 enum {
72 VM_GHOST_RAM_NONE = 0,
73 VM_GHOST_RAM_GENERATE,
74 VM_GHOST_RAM_USE,
75 };
76
77 /* Timer IRQ check interval */
78 #define VM_TIMER_IRQ_CHECK_ITV 1000
79
80 /* forward declarations */
81 typedef struct vm_obj vm_obj_t;
82
83 /* Shutdown function prototype for an object */
84 typedef void *(*vm_shutdown_t)(vm_instance_t *vm,void *data);
85
86 /* VM object, used to keep track of devices and various things */
87 struct vm_obj {
88 char *name;
89 void *data;
90 struct vm_obj *next,**pprev;
91 vm_shutdown_t shutdown;
92 };
93
94 /* VM instance */
95 struct vm_instance {
96 char *name;
97 int type; /* C7200, C3600, ... */
98 int status; /* Instance status */
99 int instance_id; /* Instance Identifier */
100 char *lock_file; /* Lock file */
101 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 */
104 u_int iomem_size; /* IOMEM size in Mb */
105 u_int nvram_size; /* NVRAM size in Kb */
106 u_int pcmcia_disk_size[2]; /* PCMCIA disk0 and disk1 sizes (in Mb) */
107 u_int conf_reg,conf_reg_setup; /* Config register */
108 u_int clock_divisor; /* Clock Divisor (see cp0.c) */
109 u_int ram_mmap; /* Memory-mapped RAM ? */
110 u_int restart_ios; /* Restart IOS on reload ? */
111 u_int elf_machine_id; /* ELF machine identifier */
112 u_int exec_area_size; /* Size of execution area for CPU */
113 m_uint32_t ios_entry_point; /* IOS entry point */
114 char *ios_image; /* IOS image filename */
115 char *ios_config; /* IOS configuration file */
116 char *rom_filename; /* ROM filename */
117 char *sym_filename; /* Symbol filename */
118 FILE *lock_fd,*log_fd; /* Lock/Log file descriptors */
119 int debug_level; /* Debugging Level */
120 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 */
127 cpu_group_t *cpu_group;
128 cpu_gen_t *boot_cpu;
129 struct pci_bus *pci_bus[2];
130 struct pci_bus *pci_bus_pool[VM_PCI_POOL_SIZE];
131 struct pci_io_data *pci_io_space;
132
133 /* Memory mapped devices */
134 struct vdevice *dev_list;
135 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 */
142 char *ghost_ram_filename;
143
144 /* Ghost RAM image handling */
145 int ghost_status;
146
147 /* "idling" pointer counter */
148 m_uint64_t idle_pc;
149
150 /* Timer IRQ interval check */
151 u_int timer_irq_check_itv;
152
153 /* Console and AUX port VTTY type and parameters */
154 int vtty_con_type,vtty_aux_type;
155 int vtty_con_tcp_port,vtty_aux_tcp_port;
156 vtty_serial_option_t vtty_con_serial_option,vtty_aux_serial_option;
157
158 /* Virtual TTY for Console and AUX ports */
159 vtty_t *vtty_con,*vtty_aux;
160
161 /* Space reserved in NVRAM by ROM monitor */
162 u_int nvram_rom_space;
163
164 /* Extract and push IOS configuration */
165 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);
167
168 /* Chassis cookie (for c2600 and maybe other routers */
169 m_uint16_t chassis_cookie[64];
170
171 /* Specific hardware data */
172 void *hw_data;
173
174 /* VM objects */
175 struct vm_obj *vm_object_list;
176 };
177
178 #define VM_C7200(vm) ((c7200_t *)vm->hw_data)
179 #define VM_C3600(vm) ((c3600_t *)vm->hw_data)
180 #define VM_C2691(vm) ((c2691_t *)vm->hw_data)
181 #define VM_C3725(vm) ((c3725_t *)vm->hw_data)
182 #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;
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 */
202 void vm_object_init(vm_obj_t *obj);
203
204 /* Add a VM object to an instance */
205 void vm_object_add(vm_instance_t *vm,vm_obj_t *obj);
206
207 /* Remove a VM object from an instance */
208 void vm_object_remove(vm_instance_t *vm,vm_obj_t *obj);
209
210 /* Find an object given its name */
211 vm_obj_t *vm_object_find(vm_instance_t *vm,char *name);
212
213 /* Check that a mandatory object is present */
214 int vm_object_check(vm_instance_t *vm,char *name);
215
216 /* Dump the object list of an instance */
217 void vm_object_dump(vm_instance_t *vm);
218
219 /* Get VM type */
220 char *vm_get_type(vm_instance_t *vm);
221
222 /* Get MAC address MSB */
223 u_int vm_get_mac_addr_msb(vm_instance_t *vm);
224
225 /* Generate a filename for use by the instance */
226 char *vm_build_filename(vm_instance_t *vm,char *name);
227
228 /* Check that an instance lock file doesn't already exist */
229 int vm_get_lock(vm_instance_t *vm);
230
231 /* Erase lock file */
232 void vm_release_lock(vm_instance_t *vm,int erase);
233
234 /* Log a message */
235 void vm_flog(vm_instance_t *vm,char *module,char *format,va_list ap);
236
237 /* Log a message */
238 void vm_log(vm_instance_t *vm,char *module,char *format,...);
239
240 /* Close the log file */
241 int vm_close_log(vm_instance_t *vm);
242
243 /* Create the log file */
244 int vm_create_log(vm_instance_t *vm);
245
246 /* Error message */
247 void vm_error(vm_instance_t *vm,char *format,...);
248
249 /* Create a new VM instance */
250 vm_instance_t *vm_create(char *name,int instance_id,int machine_type);
251
252 /* Shutdown hardware resources used by a VM */
253 int vm_hardware_shutdown(vm_instance_t *vm);
254
255 /* Free resources used by a VM */
256 void vm_free(vm_instance_t *vm);
257
258 /* Get an instance given a name */
259 vm_instance_t *vm_acquire(char *name);
260
261 /* Release a VM (decrement reference count) */
262 int vm_release(vm_instance_t *vm);
263
264 /* Initialize RAM */
265 int vm_ram_init(vm_instance_t *vm,m_uint64_t paddr);
266
267 /* Initialize VTTY */
268 int vm_init_vtty(vm_instance_t *vm);
269
270 /* Delete VTTY */
271 void vm_delete_vtty(vm_instance_t *vm);
272
273 /* Bind a device to a virtual machine */
274 int vm_bind_device(vm_instance_t *vm,struct vdevice *dev);
275
276 /* Unbind a device from a virtual machine */
277 int vm_unbind_device(vm_instance_t *vm,struct vdevice *dev);
278
279 /* Map a device at the specified physical address */
280 int vm_map_device(vm_instance_t *vm,struct vdevice *dev,m_uint64_t base_addr);
281
282 /* Set an IRQ for a VM */
283 void vm_set_irq(vm_instance_t *vm,u_int irq);
284
285 /* Clear an IRQ for a VM */
286 void vm_clear_irq(vm_instance_t *vm,u_int irq);
287
288 /* Suspend a VM instance */
289 int vm_suspend(vm_instance_t *vm);
290
291 /* Resume a VM instance */
292 int vm_resume(vm_instance_t *vm);
293
294 /* Stop an instance */
295 int vm_stop(vm_instance_t *vm);
296
297 /* Monitor an instance periodically */
298 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 */
313 int vm_mmap_open_file(vm_instance_t *vm,char *name,
314 u_char **ptr,off_t *fsize);
315
316 /* Open/Create a VM file and map it in memory */
317 int vm_mmap_create_file(vm_instance_t *vm,char *name,size_t len,u_char **ptr);
318
319 /* Close a memory mapped file */
320 int vm_mmap_close_file(int fd,u_char *ptr,size_t len);
321
322 /* Save the Cisco IOS configuration from NVRAM */
323 int vm_ios_save_config(vm_instance_t *vm);
324
325 /* Set Cisco IOS image to use */
326 int vm_ios_set_image(vm_instance_t *vm,char *ios_image);
327
328 /* Unset a Cisco IOS configuration file */
329 void vm_ios_unset_config(vm_instance_t *vm);
330
331 /* Set Cisco IOS configuration file to use */
332 int vm_ios_set_config(vm_instance_t *vm,char *ios_config);
333
334 /* Extract IOS configuration from NVRAM and write it to a file */
335 int vm_nvram_extract_config(vm_instance_t *vm,char *filename);
336
337 /* Read an IOS configuraton from a file and push it to NVRAM */
338 int vm_nvram_push_config(vm_instance_t *vm,char *filename);
339
340 /* Save general VM configuration into the specified file */
341 void vm_save_config(vm_instance_t *vm,FILE *fd);
342
343 #endif

  ViewVC Help
Powered by ViewVC 1.1.26