--- upstream/dynamips-0.2.7-RC1/dynamips.c 2007/10/06 16:23:47 7 +++ trunk/dynamips.c 2007/10/06 16:45:40 12 @@ -32,10 +32,14 @@ #include "dev_c3725.h" #include "dev_c3745.h" #include "dev_c2600.h" +#include "dev_c1700.h" +#include "dev_c6msfc1.h" +#include "dev_c6sup1.h" #include "ppc32_vmtest.h" #include "dev_vtty.h" #include "ptask.h" #include "timer.h" +#include "plugin.h" #include "registry.h" #include "hypervisor.h" #include "net_io.h" @@ -58,9 +62,13 @@ /* Software version */ const char *sw_version = DYNAMIPS_VERSION"-"JIT_ARCH; +/* Software version tag */ +const char *sw_version_tag = "2007050300"; + /* Hypervisor */ int hypervisor_mode = 0; int hypervisor_tcp_port = 0; +char *hypervisor_ip_address = NULL; /* Log file */ char *log_file_name = NULL; @@ -69,6 +77,9 @@ /* VM flags */ volatile int vm_save_state = 0; +/* Default platform */ +static char *default_platform = "7200"; + /* Generic signal handler */ void signal_gen_handler(int sig) { @@ -150,86 +161,14 @@ } /* Display the command line use */ -static void show_usage(int argc,char *argv[],int platform) +static void show_usage(vm_instance_t *vm,int argc,char *argv[]) { - u_int def_ram_size,def_rom_size,def_nvram_size; - u_int def_conf_reg,def_clock_div; - u_int def_disk0_size,def_disk1_size; - u_int def_nm_iomem_size = 0; - - switch(platform) { - case VM_TYPE_C7200: - def_ram_size = C7200_DEFAULT_RAM_SIZE; - def_rom_size = C7200_DEFAULT_ROM_SIZE; - def_nvram_size = C7200_DEFAULT_NVRAM_SIZE; - def_conf_reg = C7200_DEFAULT_CONF_REG; - def_clock_div = C7200_DEFAULT_CLOCK_DIV; - def_disk0_size = C7200_DEFAULT_DISK0_SIZE; - def_disk1_size = C7200_DEFAULT_DISK1_SIZE; - break; - case VM_TYPE_C3600: - def_ram_size = C3600_DEFAULT_RAM_SIZE; - def_rom_size = C3600_DEFAULT_ROM_SIZE; - def_nvram_size = C3600_DEFAULT_NVRAM_SIZE; - def_conf_reg = C3600_DEFAULT_CONF_REG; - def_clock_div = C3600_DEFAULT_CLOCK_DIV; - def_disk0_size = C3600_DEFAULT_DISK0_SIZE; - def_disk1_size = C3600_DEFAULT_DISK1_SIZE; - def_nm_iomem_size = C3600_DEFAULT_IOMEM_SIZE; - break; - case VM_TYPE_C2691: - def_ram_size = C2691_DEFAULT_RAM_SIZE; - def_rom_size = C2691_DEFAULT_ROM_SIZE; - def_nvram_size = C2691_DEFAULT_NVRAM_SIZE; - def_conf_reg = C2691_DEFAULT_CONF_REG; - def_clock_div = C2691_DEFAULT_CLOCK_DIV; - def_disk0_size = C2691_DEFAULT_DISK0_SIZE; - def_disk1_size = C2691_DEFAULT_DISK1_SIZE; - def_nm_iomem_size = C2691_DEFAULT_IOMEM_SIZE; - break; - case VM_TYPE_C3725: - def_ram_size = C3725_DEFAULT_RAM_SIZE; - def_rom_size = C3725_DEFAULT_ROM_SIZE; - def_nvram_size = C3725_DEFAULT_NVRAM_SIZE; - def_conf_reg = C3725_DEFAULT_CONF_REG; - def_clock_div = C3725_DEFAULT_CLOCK_DIV; - def_disk0_size = C3725_DEFAULT_DISK0_SIZE; - def_disk1_size = C3725_DEFAULT_DISK1_SIZE; - def_nm_iomem_size = C3725_DEFAULT_IOMEM_SIZE; - break; - case VM_TYPE_C3745: - def_ram_size = C3745_DEFAULT_RAM_SIZE; - def_rom_size = C3745_DEFAULT_ROM_SIZE; - def_nvram_size = C3745_DEFAULT_NVRAM_SIZE; - def_conf_reg = C3745_DEFAULT_CONF_REG; - def_clock_div = C3745_DEFAULT_CLOCK_DIV; - def_disk0_size = C3745_DEFAULT_DISK0_SIZE; - def_disk1_size = C3745_DEFAULT_DISK1_SIZE; - def_nm_iomem_size = C3745_DEFAULT_IOMEM_SIZE; - break; - case VM_TYPE_C2600: - def_ram_size = C2600_DEFAULT_RAM_SIZE; - def_rom_size = C2600_DEFAULT_ROM_SIZE; - def_nvram_size = C2600_DEFAULT_NVRAM_SIZE; - def_conf_reg = C2600_DEFAULT_CONF_REG; - def_clock_div = C2600_DEFAULT_CLOCK_DIV; - def_disk0_size = C2600_DEFAULT_DISK0_SIZE; - def_disk1_size = C2600_DEFAULT_DISK1_SIZE; - def_nm_iomem_size = C3745_DEFAULT_IOMEM_SIZE; - break; - case VM_TYPE_PPC32_TEST: - def_ram_size = PPC32_VMTEST_DEFAULT_RAM_SIZE; - default: - fprintf(stderr,"show_usage: invalid platform.\n"); - return; - } - printf("Usage: %s [options] \n\n",argv[0]); printf("Available options:\n" - " -H : Run in hypervisor mode\n\n" + " -H [:] : Run in hypervisor mode\n\n" " -P : Platform to emulate (7200, 3600, " - "2691, 3725 or 3745) " + "2691, 3725, 3745, 2600 or 1700) " "(default: 7200)\n\n" " -l : Set logging file (default is %s)\n" " -j : Disable the JIT compiler, very slow\n" @@ -268,61 +207,11 @@ "(default: %u Mb)\n" "\n", LOGFILE_DEFAULT_NAME,MIPS_EXEC_AREA_SIZE,VM_TIMER_IRQ_CHECK_ITV, - def_ram_size,def_rom_size,def_nvram_size,def_conf_reg, - def_clock_div,def_disk0_size,def_disk1_size); + vm->ram_size,vm->rom_size,vm->nvram_size,vm->conf_reg_setup, + vm->clock_divisor,vm->pcmcia_disk_size[0],vm->pcmcia_disk_size[1]); - switch(platform) { - case VM_TYPE_C7200: - printf(" -t : Select NPE type (default: \"%s\")\n" - " -M : Select Midplane (\"std\" or \"vxr\")\n" - " -p : Define a Port Adapter\n" - " -s : Bind a Network IO interface to a " - "Port Adapter\n", - C7200_DEFAULT_NPE_TYPE); - break; - - case VM_TYPE_C3600: - printf(" -t : Select Chassis type " - "(default: \"%s\")\n" - " --iomem-size : IO memory (in percents, default: %u)\n" - " -p : Define a Network Module\n" - " -s : Bind a Network IO interface to a " - "Network Module\n", - C3600_DEFAULT_CHASSIS,def_nm_iomem_size); - break; - - case VM_TYPE_C2691: - printf(" --iomem-size : IO memory (in percents, default: %u)\n" - " -p : Define a Network Module\n" - " -s : Bind a Network IO interface to a " - "Network Module\n", - def_nm_iomem_size); - break; - - case VM_TYPE_C3725: - printf(" --iomem-size : IO memory (in percents, default: %u)\n" - " -p : Define a Network Module\n" - " -s : Bind a Network IO interface to a " - "Network Module\n", - def_nm_iomem_size); - break; - - case VM_TYPE_C3745: - printf(" --iomem-size : IO memory (in percents, default: %u)\n" - " -p : Define a Network Module\n" - " -s : Bind a Network IO interface to a " - "Network Module\n", - def_nm_iomem_size); - break; - - case VM_TYPE_C2600: - printf(" --iomem-size : IO memory (in percents, default: %u)\n" - " -p : Define a Network Module\n" - " -s : Bind a Network IO interface to a " - "Network Module\n", - def_nm_iomem_size); - break; - } + if (vm->platform->cli_show_options != NULL) + vm->platform->cli_show_options(vm); printf("\n" #if DEBUG_SYM_TREE @@ -341,94 +230,43 @@ " \"device{:baudrate{:databits{:parity{:stopbits{:hwflow}}}}}}\"\n" "\n"); - switch(platform) { - case VM_TYPE_C7200: + switch(vm->slots_type) { + case CISCO_CARD_TYPE_PA: printf(" format:\n" - " \"slot:pa_driver\"\n" + " \"slot:sub_slot:pa_driver\"\n" "\n"); printf(" format:\n" " \"slot:port:netio_type{:netio_parameters}\"\n" "\n"); - - /* Show the possible NPE drivers */ - c7200_npe_show_drivers(); - - /* Show the possible PA drivers */ - c7200_pa_show_drivers(); - break; - - case VM_TYPE_C3600: - printf(" format:\n" - " \"slot:nm_driver\"\n" - "\n"); - - printf(" format:\n" - " \"slot:port:netio_type{:netio_parameters}\"\n" - "\n"); - - /* Show the possible chassis types for C3600 platform */ - c3600_chassis_show_drivers(); - - /* Show the possible NM drivers */ - c3600_nm_show_drivers(); break; - case VM_TYPE_C2691: + case CISCO_CARD_TYPE_NM: printf(" format:\n" - " \"slot:nm_driver\"\n" + " \"slot:sub_slot:nm_driver\"\n" "\n"); printf(" format:\n" " \"slot:port:netio_type{:netio_parameters}\"\n" "\n"); - - /* Show the possible NM drivers */ - c2691_nm_show_drivers(); break; - case VM_TYPE_C3725: - printf(" format:\n" - " \"slot:nm_driver\"\n" + case CISCO_CARD_TYPE_WIC: + printf(" format:\n" + " \"slot:wic_driver\"\n" "\n"); - printf(" format:\n" + printf(" format:\n" " \"slot:port:netio_type{:netio_parameters}\"\n" "\n"); - - /* Show the possible NM drivers */ - c3725_nm_show_drivers(); break; + } - case VM_TYPE_C3745: - printf(" format:\n" - " \"slot:nm_driver\"\n" - "\n"); - - printf(" format:\n" - " \"slot:port:netio_type{:netio_parameters}\"\n" - "\n"); - - /* Show the possible NM drivers */ - c3745_nm_show_drivers(); - break; - - case VM_TYPE_C2600: - printf(" format:\n" - " \"slot:nm_driver\"\n" - "\n"); - - printf(" format:\n" - " \"slot:port:netio_type{:netio_parameters}\"\n" - "\n"); - - /* Show the possible chassis types for C2600 platform */ - c2600_mainboard_show_drivers(); + if (vm->platform->show_spec_drivers != NULL) + vm->platform->show_spec_drivers(); - /* Show the possible NM drivers */ - c2600_nm_show_drivers(); - break; - } + /* Show possible slot drivers */ + vm_slot_show_drivers(vm); /* Show the possible NETIO types */ netio_show_types(); @@ -458,44 +296,46 @@ return NULL; } +/* Load plugins */ +static void cli_load_plugins(int argc,char *argv[]) +{ + char *str; + int i; + + for(i=1;inm_iomem_size = 0x8000 | atoi(optarg); - break; - - /* NM settings */ - case 'p': - return(c3600_cmd_nm_create(router,optarg)); - - /* NM NIO settings */ - case 's': - return(c3600_cmd_add_nio(router,optarg)); - - /* Unknown option */ - default: - return(-1); - } - - return(0); -} - -/* Parse specific options for the Cisco 2691 platform */ -static int cli_parse_c2691_options(vm_instance_t *vm,int option) -{ - c2691_t *router; - - router = VM_C2691(vm); - - switch(option) { - /* IO memory reserved for NMs (in percents!) */ - case OPT_IOMEM_SIZE: - router->nm_iomem_size = 0x8000 | atoi(optarg); - break; - - /* NM settings */ - case 'p': - return(c2691_cmd_nm_create(router,optarg)); - - /* NM NIO settings */ - case 's': - return(c2691_cmd_add_nio(router,optarg)); - - /* Unknown option */ - default: - return(-1); - } - - return(0); -} - -/* Parse specific options for the Cisco 3725 platform */ -static int cli_parse_c3725_options(vm_instance_t *vm,int option) -{ - c3725_t *router; - - router = VM_C3725(vm); - - switch(option) { - /* IO memory reserved for NMs (in percents!) */ - case OPT_IOMEM_SIZE: - router->nm_iomem_size = 0x8000 | atoi(optarg); - break; - - /* NM settings */ - case 'p': - return(c3725_cmd_nm_create(router,optarg)); - - /* NM NIO settings */ - case 's': - return(c3725_cmd_add_nio(router,optarg)); - - /* Unknown option */ - default: - return(-1); - } - - return(0); -} - -/* Parse specific options for the Cisco 3745 platform */ -static int cli_parse_c3745_options(vm_instance_t *vm,int option) -{ - c3745_t *router; - - router = VM_C3745(vm); - - switch(option) { - /* IO memory reserved for NMs (in percents!) */ - case OPT_IOMEM_SIZE: - router->nm_iomem_size = 0x8000 | atoi(optarg); - break; - - /* NM settings */ - case 'p': - return(c3745_cmd_nm_create(router,optarg)); - - /* NM NIO settings */ - case 's': - return(c3745_cmd_add_nio(router,optarg)); - - /* Unknown option */ - default: - return(-1); - } - - return(0); -} - -/* Parse specific options for the Cisco 2600 platform */ -static int cli_parse_c2600_options(vm_instance_t *vm,int option) -{ - c2600_t *router; - - router = VM_C2600(vm); - - switch(option) { - /* IO memory reserved for NMs (in percents!) */ - case OPT_IOMEM_SIZE: - router->nm_iomem_size = 0x8000 | atoi(optarg); - break; - - /* Mainboard type */ - case 't': - c2600_mainboard_set_type(router,optarg); - break; - - /* NM settings */ - case 'p': - return(c2600_cmd_nm_create(router,optarg)); - - /* NM NIO settings */ - case 's': - return(c2600_cmd_add_nio(router,optarg)); - - /* Unknown option */ - default: - return(-1); - } - - return(0); -} - /* Create a router instance */ -static vm_instance_t *cli_create_instance(char *name,int platform_type, +static vm_instance_t *cli_create_instance(char *name,char *platform_name, int instance_id) { vm_instance_t *vm; - c7200_t *c7200; - c3600_t *c3600; - c2691_t *c2691; - c3725_t *c3725; - c3745_t *c3745; - c2600_t *c2600; - - switch(platform_type) { - case VM_TYPE_C7200: - if (!(c7200 = c7200_create_instance(name,instance_id))) { - fprintf(stderr,"C7200: unable to create instance!\n"); - return NULL; - } - return(c7200->vm); - - case VM_TYPE_C3600: - if (!(c3600 = c3600_create_instance(name,instance_id))) { - fprintf(stderr,"C3600: unable to create instance!\n"); - return NULL; - } - return(c3600->vm); - case VM_TYPE_C2691: - if (!(c2691 = c2691_create_instance(name,instance_id))) { - fprintf(stderr,"C2691: unable to create instance!\n"); - return NULL; - } - return(c2691->vm); - - case VM_TYPE_C3725: - if (!(c3725 = c3725_create_instance(name,instance_id))) { - fprintf(stderr,"C3725: unable to create instance!\n"); - return NULL; - } - return(c3725->vm); - - case VM_TYPE_C3745: - if (!(c3745 = c3745_create_instance(name,instance_id))) { - fprintf(stderr,"C3745: unable to create instance!\n"); - return NULL; - } - return(c3745->vm); - - case VM_TYPE_C2600: - if (!(c2600 = c2600_create_instance(name,instance_id))) { - fprintf(stderr,"C2600: unable to create instance!\n"); - return NULL; - } - return(c2600->vm); - - case VM_TYPE_PPC32_TEST: - if (!(vm = ppc32_vmtest_create_instance(name,instance_id))) { - fprintf(stderr,"PPC32_TEST: unable to create instance!\n"); - return NULL; - } - return(vm); - - default: - fprintf(stderr,"Unknown platform type '%d'!\n",platform_type); - return NULL; + vm = vm_create_instance(name,instance_id,platform_name); + + if (vm == NULL) { + fprintf(stderr,"C7200: unable to create instance!\n"); + return NULL; } + + return vm; } /* Parse the command line */ -static int parse_std_cmd_line(int argc,char *argv[],int *platform) +static int parse_std_cmd_line(int argc,char *argv[]) { char *options_list = - "r:o:n:c:m:l:C:i:jt:p:s:k:T:U:A:B:a:f:E:b:S:R:M:eXP:N:G:g:"; + "r:o:n:c:m:l:C:i:jt:p:s:k:T:U:A:B:a:f:E:b:S:R:M:eXP:N:G:g:L:"; + vm_platform_t *platform; vm_instance_t *vm; int instance_id; - int res,option; + int option; char *str; /* Get the instance ID */ @@ -787,6 +381,8 @@ /* Use the old VM file naming type */ vm_file_naming_type = 1; + cli_load_plugins(argc,argv); + if ((str = cli_find_option(argc,argv,"-i"))) { instance_id = atoi(str); printf("Instance ID set to %d.\n",instance_id); @@ -796,10 +392,11 @@ vm_file_naming_type = atoi(str); /* Get the platform type */ - *platform = cli_get_platform_type(argc,argv); + if (!(platform = cli_get_platform_type(argc,argv))) + exit(EXIT_FAILURE); /* Create the default instance */ - if (!(vm = cli_create_instance("default",*platform,instance_id))) + if (!(vm = cli_create_instance("default",platform->name,instance_id))) exit(EXIT_FAILURE); opterr = 0; @@ -972,6 +569,16 @@ } break; + /* Port settings */ + case 'p': + vm_slot_cmd_create(vm,optarg); + break; + + /* NIO settings */ + case 's': + vm_slot_cmd_add_nio(vm,optarg); + break; + /* Virtual ATM switch */ case 'a': if (atmsw_start(optarg) == -1) @@ -1003,38 +610,20 @@ exit(EXIT_SUCCESS); #endif + /* Load plugin (already handled) */ + case 'L': + break; + /* Oops ! */ case '?': - show_usage(argc,argv,*platform); + show_usage(vm,argc,argv); exit(EXIT_FAILURE); /* Parse options specific to the platform */ default: - res = 0; - - switch(vm->type) { - case VM_TYPE_C7200: - res = cli_parse_c7200_options(vm,option); - break; - case VM_TYPE_C3600: - res = cli_parse_c3600_options(vm,option); - break; - case VM_TYPE_C2691: - res = cli_parse_c2691_options(vm,option); - break; - case VM_TYPE_C3725: - res = cli_parse_c3725_options(vm,option); - break; - case VM_TYPE_C3745: - res = cli_parse_c3745_options(vm,option); - break; - case VM_TYPE_C2600: - res = cli_parse_c2600_options(vm,option); - break; - } - - if (res == -1) - exit(EXIT_FAILURE); + if (vm->platform->cli_parse_options != NULL) + if (vm->platform->cli_parse_options(vm,option) == -1) + exit(EXIT_FAILURE); } } @@ -1046,7 +635,7 @@ } else { /* IOS missing */ fprintf(stderr,"Please specify an IOS image filename\n"); - show_usage(argc,argv,*platform); + show_usage(vm,argc,argv); exit(EXIT_FAILURE); } @@ -1060,8 +649,10 @@ */ static int run_hypervisor(int argc,char *argv[]) { - char *options_list = "H:l:hN:"; + char *options_list = "H:l:hN:L:"; int i,option; + char *index; + size_t len; for(i=1;iplatform->init_instance(vm) == -1) { fprintf(stderr,"Unable to initialize router instance.\n"); exit(EXIT_FAILURE); } #if (DEBUG_INSN_PERF_CNT > 0) || (DEBUG_BLOCK_PERF_CNT > 0) { - m_uint64_t counter,prev = 0,delta; + m_uint32_t counter,prev = 0,delta; while(vm->status == VM_STATUS_RUNNING) { counter = cpu_get_perf_counter(vm->boot_cpu); delta = counter - prev; prev = counter; - printf("delta = %llu\n",delta); + printf("delta = %u\n",delta); sleep(1); } } @@ -1244,7 +846,7 @@ /* Free resources used by instance */ vm_release(vm); } else { - hypervisor_tcp_server(hypervisor_tcp_port); + hypervisor_tcp_server(hypervisor_ip_address,hypervisor_tcp_port); } dynamips_reset();