/[dynamips]/trunk/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

Annotation of /trunk/vm.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (hide annotations)
Sat Oct 6 16:45:40 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: text/plain
File size: 11085 byte(s)
make working copy

1 dpavlin 1 /*
2 dpavlin 7 * Cisco router simulation platform.
3 dpavlin 1 * 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 dpavlin 11 #include "cisco_eeprom.h"
18     #include "cisco_card.h"
19     #include "rommon_var.h"
20 dpavlin 1
21 dpavlin 7 #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 dpavlin 1 #define VM_PCI_POOL_SIZE 32
53    
54     /* VM instance status */
55     enum {
56     VM_STATUS_HALTED = 0, /* VM is halted and no HW resources are used */
57     VM_STATUS_SHUTDOWN, /* Shutdown procedure engaged */
58     VM_STATUS_RUNNING, /* VM is running */
59     VM_STATUS_SUSPENDED, /* VM is suspended */
60     };
61    
62 dpavlin 4 /* Ghost RAM status */
63     enum {
64     VM_GHOST_RAM_NONE = 0,
65     VM_GHOST_RAM_GENERATE,
66     VM_GHOST_RAM_USE,
67     };
68    
69 dpavlin 1 /* Timer IRQ check interval */
70     #define VM_TIMER_IRQ_CHECK_ITV 1000
71    
72 dpavlin 11 /* Max slots per VM */
73     #define VM_MAX_SLOTS 16
74    
75 dpavlin 1 /* forward declarations */
76     typedef struct vm_obj vm_obj_t;
77    
78     /* Shutdown function prototype for an object */
79     typedef void *(*vm_shutdown_t)(vm_instance_t *vm,void *data);
80    
81     /* VM object, used to keep track of devices and various things */
82     struct vm_obj {
83     char *name;
84     void *data;
85     struct vm_obj *next,**pprev;
86     vm_shutdown_t shutdown;
87     };
88    
89     /* VM instance */
90     struct vm_instance {
91     char *name;
92 dpavlin 11 vm_platform_t *platform; /* Platform specific helpers */
93     int status; /* Instance status */
94     int instance_id; /* Instance Identifier */
95     char *lock_file; /* Lock file */
96     char *log_file; /* Log filename */
97     int log_file_enabled; /* Logging enabled */
98     u_int ram_size,rom_size; /* RAM and ROM size in Mb */
99     u_int iomem_size; /* IOMEM size in Mb */
100     u_int nvram_size; /* NVRAM size in Kb */
101     u_int pcmcia_disk_size[2]; /* PCMCIA disk0 and disk1 sizes (in Mb) */
102     u_int conf_reg,conf_reg_setup; /* Config register */
103     u_int clock_divisor; /* Clock Divisor (see cp0.c) */
104     u_int ram_mmap; /* Memory-mapped RAM ? */
105     u_int restart_ios; /* Restart IOS on reload ? */
106     u_int elf_machine_id; /* ELF machine identifier */
107     u_int exec_area_size; /* Size of execution area for CPU */
108     m_uint32_t ios_entry_point; /* IOS entry point */
109     char *ios_image; /* IOS image filename */
110     char *ios_config; /* IOS configuration file */
111     char *rom_filename; /* ROM filename */
112     char *sym_filename; /* Symbol filename */
113     FILE *lock_fd,*log_fd; /* Lock/Log file descriptors */
114     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 dpavlin 1
119 dpavlin 11 /* ROMMON variables */
120     struct rommon_var_list rommon_vars;
121    
122 dpavlin 7 /* Memory chunks */
123     vm_chunk_t *chunks;
124    
125 dpavlin 1 /* Basic hardware: system CPU, PCI busses and PCI I/O space */
126     cpu_group_t *cpu_group;
127 dpavlin 7 cpu_gen_t *boot_cpu;
128 dpavlin 1 struct pci_bus *pci_bus[2];
129     struct pci_bus *pci_bus_pool[VM_PCI_POOL_SIZE];
130     struct pci_io_data *pci_io_space;
131    
132     /* Memory mapped devices */
133     struct vdevice *dev_list;
134 dpavlin 7 struct vdevice *dev_array[VM_DEVICE_MAX];
135 dpavlin 1
136 dpavlin 7 /* 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 dpavlin 11 /* 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 dpavlin 4 /* Filename for ghosted RAM */
148     char *ghost_ram_filename;
149    
150     /* Ghost RAM image handling */
151     int ghost_status;
152    
153 dpavlin 8 /* Timer IRQ interval check */
154     u_int timer_irq_check_itv;
155    
156 dpavlin 1 /* "idling" pointer counter */
157     m_uint64_t idle_pc;
158    
159 dpavlin 8 /* JIT block direct jumps */
160     int exec_blk_direct_jump;
161 dpavlin 1
162 dpavlin 8 /* IRQ idling preemption */
163     u_int irq_idle_preempt[256];
164    
165 dpavlin 1 /* Console and AUX port VTTY type and parameters */
166     int vtty_con_type,vtty_aux_type;
167     int vtty_con_tcp_port,vtty_aux_tcp_port;
168     vtty_serial_option_t vtty_con_serial_option,vtty_aux_serial_option;
169    
170     /* Virtual TTY for Console and AUX ports */
171     vtty_t *vtty_con,*vtty_aux;
172    
173     /* Space reserved in NVRAM by ROM monitor */
174     u_int nvram_rom_space;
175    
176 dpavlin 8 /* Chassis cookie (for c2600 and maybe other routers) */
177 dpavlin 7 m_uint16_t chassis_cookie[64];
178    
179 dpavlin 1 /* Specific hardware data */
180     void *hw_data;
181    
182     /* VM objects */
183     struct vm_obj *vm_object_list;
184     };
185    
186 dpavlin 11 /* VM Platform definition */
187     struct vm_platform {
188     char *name;
189     char *log_name;
190     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 dpavlin 1
204 dpavlin 11 /* VM platform list item */
205     struct vm_platform_list {
206     struct vm_platform_list *next;
207     struct vm_platform *platform;
208     };
209    
210 dpavlin 1 extern int vm_file_naming_type;
211    
212 dpavlin 7 /* 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 dpavlin 1 /* Initialize a VM object */
227     void vm_object_init(vm_obj_t *obj);
228    
229     /* Add a VM object to an instance */
230     void vm_object_add(vm_instance_t *vm,vm_obj_t *obj);
231    
232     /* Remove a VM object from an instance */
233     void vm_object_remove(vm_instance_t *vm,vm_obj_t *obj);
234    
235     /* Find an object given its name */
236     vm_obj_t *vm_object_find(vm_instance_t *vm,char *name);
237    
238     /* Check that a mandatory object is present */
239     int vm_object_check(vm_instance_t *vm,char *name);
240    
241     /* Dump the object list of an instance */
242     void vm_object_dump(vm_instance_t *vm);
243    
244     /* Get VM type */
245     char *vm_get_type(vm_instance_t *vm);
246    
247 dpavlin 4 /* Get MAC address MSB */
248     u_int vm_get_mac_addr_msb(vm_instance_t *vm);
249    
250 dpavlin 1 /* Generate a filename for use by the instance */
251     char *vm_build_filename(vm_instance_t *vm,char *name);
252    
253     /* Check that an instance lock file doesn't already exist */
254     int vm_get_lock(vm_instance_t *vm);
255    
256     /* Erase lock file */
257     void vm_release_lock(vm_instance_t *vm,int erase);
258    
259     /* Log a message */
260     void vm_flog(vm_instance_t *vm,char *module,char *format,va_list ap);
261    
262     /* Log a message */
263     void vm_log(vm_instance_t *vm,char *module,char *format,...);
264    
265     /* Close the log file */
266     int vm_close_log(vm_instance_t *vm);
267    
268     /* Create the log file */
269     int vm_create_log(vm_instance_t *vm);
270    
271     /* Error message */
272     void vm_error(vm_instance_t *vm,char *format,...);
273    
274     /* Shutdown hardware resources used by a VM */
275     int vm_hardware_shutdown(vm_instance_t *vm);
276    
277     /* Free resources used by a VM */
278     void vm_free(vm_instance_t *vm);
279    
280     /* Get an instance given a name */
281     vm_instance_t *vm_acquire(char *name);
282    
283     /* Release a VM (decrement reference count) */
284     int vm_release(vm_instance_t *vm);
285    
286 dpavlin 4 /* Initialize RAM */
287     int vm_ram_init(vm_instance_t *vm,m_uint64_t paddr);
288    
289 dpavlin 1 /* Initialize VTTY */
290     int vm_init_vtty(vm_instance_t *vm);
291    
292     /* Delete VTTY */
293     void vm_delete_vtty(vm_instance_t *vm);
294    
295     /* Bind a device to a virtual machine */
296     int vm_bind_device(vm_instance_t *vm,struct vdevice *dev);
297    
298     /* Unbind a device from a virtual machine */
299     int vm_unbind_device(vm_instance_t *vm,struct vdevice *dev);
300    
301     /* Map a device at the specified physical address */
302     int vm_map_device(vm_instance_t *vm,struct vdevice *dev,m_uint64_t base_addr);
303    
304     /* Set an IRQ for a VM */
305     void vm_set_irq(vm_instance_t *vm,u_int irq);
306    
307     /* Clear an IRQ for a VM */
308     void vm_clear_irq(vm_instance_t *vm,u_int irq);
309    
310     /* Suspend a VM instance */
311     int vm_suspend(vm_instance_t *vm);
312    
313     /* Resume a VM instance */
314     int vm_resume(vm_instance_t *vm);
315    
316     /* Stop an instance */
317     int vm_stop(vm_instance_t *vm);
318    
319     /* Monitor an instance periodically */
320     void vm_monitor(vm_instance_t *vm);
321    
322 dpavlin 7 /* 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 dpavlin 4 /* Open a VM file and map it in memory */
335     int vm_mmap_open_file(vm_instance_t *vm,char *name,
336     u_char **ptr,off_t *fsize);
337    
338     /* Open/Create a VM file and map it in memory */
339     int vm_mmap_create_file(vm_instance_t *vm,char *name,size_t len,u_char **ptr);
340    
341     /* Close a memory mapped file */
342     int vm_mmap_close_file(int fd,u_char *ptr,size_t len);
343    
344 dpavlin 1 /* Save the Cisco IOS configuration from NVRAM */
345     int vm_ios_save_config(vm_instance_t *vm);
346    
347     /* Set Cisco IOS image to use */
348     int vm_ios_set_image(vm_instance_t *vm,char *ios_image);
349    
350     /* Unset a Cisco IOS configuration file */
351     void vm_ios_unset_config(vm_instance_t *vm);
352    
353     /* Set Cisco IOS configuration file to use */
354     int vm_ios_set_config(vm_instance_t *vm,char *ios_config);
355    
356     /* Extract IOS configuration from NVRAM and write it to a file */
357     int vm_nvram_extract_config(vm_instance_t *vm,char *filename);
358    
359     /* Read an IOS configuraton from a file and push it to NVRAM */
360     int vm_nvram_push_config(vm_instance_t *vm,char *filename);
361    
362     /* Save general VM configuration into the specified file */
363     void vm_save_config(vm_instance_t *vm,FILE *fd);
364    
365 dpavlin 11 /* 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 dpavlin 1 #endif

  ViewVC Help
Powered by ViewVC 1.1.26