/[dynamips]/upstream/dynamips-0.2.7-RC2/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-RC2/vm.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (show annotations)
Sat Oct 6 16:24:54 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 9936 byte(s)
dynamips-0.2.7-RC2

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

  ViewVC Help
Powered by ViewVC 1.1.26