--- upstream/dynamips-0.2.6-RC5/vm.h 2007/10/06 16:09:07 6 +++ upstream/dynamips-0.2.8-RC1/vm.h 2007/10/06 16:33:40 11 @@ -1,5 +1,5 @@ /* - * Cisco 7200 (Predator) simulation platform. + * Cisco router simulation platform. * Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr) * * Virtual Machines. @@ -10,12 +10,45 @@ #include -#include "mips64.h" #include "dynamips.h" #include "memory.h" #include "cpu.h" #include "dev_vtty.h" +#include "cisco_eeprom.h" +#include "cisco_card.h" +#include "rommon_var.h" + +#define VM_PAGE_SHIFT 12 +#define VM_PAGE_SIZE (1 << VM_PAGE_SHIFT) +#define VM_PAGE_IMASK (VM_PAGE_SIZE - 1) +#define VM_PAGE_MASK (~(VM_PAGE_IMASK)) + +/* Number of pages in chunk area */ +#define VM_CHUNK_AREA_SIZE 256 + +/* VM memory chunk */ +typedef struct vm_chunk vm_chunk_t; +struct vm_chunk { + void *area; + u_int page_alloc,page_total; + vm_chunk_t *next; +}; + +/* VM ghost pool entry */ +typedef struct vm_ghost_image vm_ghost_image_t; +struct vm_ghost_image { + char *filename; + u_int ref_count; + int fd; + off_t file_size; + u_char *area_ptr; + vm_ghost_image_t *next; +}; +/* Maximum number of devices per VM */ +#define VM_DEVICE_MAX (1 << 6) + +/* Size of the PCI bus pool */ #define VM_PCI_POOL_SIZE 32 /* VM instance status */ @@ -26,15 +59,6 @@ VM_STATUS_SUSPENDED, /* VM is suspended */ }; -/* VM types */ -enum { - VM_TYPE_C7200 = 0, - VM_TYPE_C3600, - VM_TYPE_C2691, - VM_TYPE_C3725, - VM_TYPE_C3745, -}; - /* Ghost RAM status */ enum { VM_GHOST_RAM_NONE = 0, @@ -45,6 +69,9 @@ /* Timer IRQ check interval */ #define VM_TIMER_IRQ_CHECK_ITV 1000 +/* Max slots per VM */ +#define VM_MAX_SLOTS 16 + /* forward declarations */ typedef struct vm_obj vm_obj_t; @@ -62,40 +89,60 @@ /* VM instance */ struct vm_instance { char *name; - int type; /* C7200, C3600, ... */ - int status; /* Instance status */ - int instance_id; /* Instance Identifier */ - char *lock_file; /* Lock file */ - char *log_file; /* Log file */ - u_int ram_size,rom_size; /* RAM and ROM size in Mb */ - u_int iomem_size; /* IOMEM size in Mb */ - u_int nvram_size; /* NVRAM size in Kb */ - u_int pcmcia_disk_size[2]; /* PCMCIA disk0 and disk1 sizes (in Mb) */ - u_int conf_reg,conf_reg_setup; /* Config register */ - u_int clock_divisor; /* Clock Divisor (see cp0.c) */ - u_int ram_mmap; /* Memory-mapped RAM ? */ - u_int restart_ios; /* Restart IOS on reload ? */ - u_int elf_machine_id; /* ELF machine identifier */ - u_int exec_area_size; /* Size of execution area for CPU */ - m_uint32_t ios_entry_point; /* IOS entry point */ - char *ios_image; /* IOS image filename */ - char *ios_config; /* IOS configuration file */ - char *rom_filename; /* ROM filename */ - char *sym_filename; /* Symbol filename */ - FILE *lock_fd,*log_fd; /* Lock/Log file descriptors */ - int debug_level; /* Debugging Level */ - int jit_use; /* CPUs use JIT */ + vm_platform_t *platform; /* Platform specific helpers */ + int status; /* Instance status */ + int instance_id; /* Instance Identifier */ + char *lock_file; /* Lock file */ + char *log_file; /* Log filename */ + int log_file_enabled; /* Logging enabled */ + u_int ram_size,rom_size; /* RAM and ROM size in Mb */ + u_int iomem_size; /* IOMEM size in Mb */ + u_int nvram_size; /* NVRAM size in Kb */ + u_int pcmcia_disk_size[2]; /* PCMCIA disk0 and disk1 sizes (in Mb) */ + u_int conf_reg,conf_reg_setup; /* Config register */ + u_int clock_divisor; /* Clock Divisor (see cp0.c) */ + u_int ram_mmap; /* Memory-mapped RAM ? */ + u_int restart_ios; /* Restart IOS on reload ? */ + u_int elf_machine_id; /* ELF machine identifier */ + u_int exec_area_size; /* Size of execution area for CPU */ + m_uint32_t ios_entry_point; /* IOS entry point */ + char *ios_image; /* IOS image filename */ + char *ios_config; /* IOS configuration file */ + char *rom_filename; /* ROM filename */ + char *sym_filename; /* Symbol filename */ + FILE *lock_fd,*log_fd; /* Lock/Log file descriptors */ + int debug_level; /* Debugging Level */ + int jit_use; /* CPUs use JIT */ + int sparse_mem; /* Use sparse virtual memory */ + u_int nm_iomem_size; /* IO mem size to be passed to Smart Init */ + + /* ROMMON variables */ + struct rommon_var_list rommon_vars; + + /* Memory chunks */ + vm_chunk_t *chunks; /* Basic hardware: system CPU, PCI busses and PCI I/O space */ cpu_group_t *cpu_group; - cpu_mips_t *boot_cpu; + cpu_gen_t *boot_cpu; struct pci_bus *pci_bus[2]; struct pci_bus *pci_bus_pool[VM_PCI_POOL_SIZE]; struct pci_io_data *pci_io_space; /* Memory mapped devices */ struct vdevice *dev_list; - struct vdevice *dev_array[MIPS64_DEVICE_MAX]; + struct vdevice *dev_array[VM_DEVICE_MAX]; + + /* IRQ routing */ + void (*set_irq)(vm_instance_t *vm,u_int irq); + void (*clear_irq)(vm_instance_t *vm,u_int irq); + + /* Slots for PA/NM/... */ + u_int nr_slots; + u_int slots_type; + struct cisco_card *slots[VM_MAX_SLOTS]; + struct cisco_card_driver **slots_drivers; + struct pci_bus *slots_pci_bus[VM_MAX_SLOTS]; /* Filename for ghosted RAM */ char *ghost_ram_filename; @@ -103,11 +150,17 @@ /* Ghost RAM image handling */ int ghost_status; + /* Timer IRQ interval check */ + u_int timer_irq_check_itv; + /* "idling" pointer counter */ m_uint64_t idle_pc; - /* Timer IRQ interval check */ - u_int timer_irq_check_itv; + /* JIT block direct jumps */ + int exec_blk_direct_jump; + + /* IRQ idling preemption */ + u_int irq_idle_preempt[256]; /* Console and AUX port VTTY type and parameters */ int vtty_con_type,vtty_aux_type; @@ -120,9 +173,8 @@ /* Space reserved in NVRAM by ROM monitor */ u_int nvram_rom_space; - /* Extract and push IOS configuration */ - ssize_t (*nvram_extract_config)(vm_instance_t *vm,char **buffer); - int (*nvram_push_config)(vm_instance_t *vm,char *buffer,size_t len); + /* Chassis cookie (for c2600 and maybe other routers) */ + m_uint16_t chassis_cookie[64]; /* Specific hardware data */ void *hw_data; @@ -131,14 +183,46 @@ struct vm_obj *vm_object_list; }; -#define VM_C7200(vm) ((c7200_t *)vm->hw_data) -#define VM_C3600(vm) ((c3600_t *)vm->hw_data) -#define VM_C2691(vm) ((c2691_t *)vm->hw_data) -#define VM_C3725(vm) ((c3725_t *)vm->hw_data) -#define VM_C3745(vm) ((c3745_t *)vm->hw_data) +/* VM Platform definition */ +struct vm_platform { + char *name; + char *log_name; + char *cli_name; + int (*create_instance)(vm_instance_t *vm); + int (*delete_instance)(vm_instance_t *vm); + int (*init_instance)(vm_instance_t *vm); + int (*stop_instance)(vm_instance_t *vm); + ssize_t (*nvram_extract_config)(vm_instance_t *vm,u_char **buffer); + int (*nvram_push_config)(vm_instance_t *vm,u_char *buffer,size_t len); + u_int (*get_mac_addr_msb)(void); + void (*save_config)(vm_instance_t *vm,FILE *fd); + int (*cli_parse_options)(vm_instance_t *vm,int option); + void (*cli_show_options)(vm_instance_t *vm); + void (*show_spec_drivers)(void); +}; + +/* VM platform list item */ +struct vm_platform_list { + struct vm_platform_list *next; + struct vm_platform *platform; +}; extern int vm_file_naming_type; +/* Set an IRQ for a VM */ +static inline void vm_set_irq(vm_instance_t *vm,u_int irq) +{ + if (vm->set_irq != NULL) + vm->set_irq(vm,irq); +} + +/* Clear an IRQ for a VM */ +static inline void vm_clear_irq(vm_instance_t *vm,u_int irq) +{ + if (vm->clear_irq != NULL) + vm->clear_irq(vm,irq); +} + /* Initialize a VM object */ void vm_object_init(vm_obj_t *obj); @@ -187,9 +271,6 @@ /* Error message */ void vm_error(vm_instance_t *vm,char *format,...); -/* Create a new VM instance */ -vm_instance_t *vm_create(char *name,int instance_id,int machine_type); - /* Shutdown hardware resources used by a VM */ int vm_hardware_shutdown(vm_instance_t *vm); @@ -238,6 +319,18 @@ /* Monitor an instance periodically */ void vm_monitor(vm_instance_t *vm); +/* Allocate an host page */ +void *vm_alloc_host_page(vm_instance_t *vm); + +/* Free an host page */ +void vm_free_host_page(vm_instance_t *vm,void *ptr); + +/* Get a ghost image */ +int vm_ghost_image_get(char *filename,u_char **ptr,int *fd); + +/* Release a ghost image */ +int vm_ghost_image_release(int fd); + /* Open a VM file and map it in memory */ int vm_mmap_open_file(vm_instance_t *vm,char *name, u_char **ptr,off_t *fsize); @@ -269,4 +362,31 @@ /* Save general VM configuration into the specified file */ void vm_save_config(vm_instance_t *vm,FILE *fd); +/* Find a platform */ +vm_platform_t *vm_platform_find(char *name); + +/* Find a platform given its CLI name */ +vm_platform_t *vm_platform_find_cli_name(char *name); + +/* Register a platform */ +int vm_platform_register(vm_platform_t *platform); + +/* Create an instance of the specified type */ +vm_instance_t *vm_create_instance(char *name,int instance_id,char *type); + +/* Delete a VM instance */ +int vm_delete_instance(char *name); + +/* Initialize a VM instance */ +int vm_init_instance(vm_instance_t *vm); + +/* Stop a VM instance */ +int vm_stop_instance(vm_instance_t *vm); + +/* Delete all VM instances */ +int vm_delete_all_instances(void); + +/* Save all VM configs */ +int vm_save_config_all(FILE *fd); + #endif