1 |
/* |
/* |
2 |
* Cisco 7200 (Predator) simulation platform. |
* Cisco router simulation platform. |
3 |
* Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr) |
* Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr) |
4 |
* |
* |
5 |
* Many thanks to Nicolas Szalay for his patch |
* Many thanks to Nicolas Szalay for his patch |
20 |
#include <assert.h> |
#include <assert.h> |
21 |
#include <getopt.h> |
#include <getopt.h> |
22 |
|
|
|
#include ARCH_INC_FILE |
|
|
|
|
23 |
#include "dynamips.h" |
#include "dynamips.h" |
24 |
#include "mips64.h" |
#include "cpu.h" |
25 |
#include "mips64_exec.h" |
#include "mips64_exec.h" |
26 |
|
#include "mips64_jit.h" |
27 |
|
#include "ppc32_exec.h" |
28 |
|
#include "ppc32_jit.h" |
29 |
#include "dev_c7200.h" |
#include "dev_c7200.h" |
30 |
#include "dev_c3600.h" |
#include "dev_c3600.h" |
31 |
#include "dev_c2691.h" |
#include "dev_c2691.h" |
32 |
#include "dev_c3725.h" |
#include "dev_c3725.h" |
33 |
#include "dev_c3745.h" |
#include "dev_c3745.h" |
34 |
|
#include "dev_c2600.h" |
35 |
|
#include "ppc32_vmtest.h" |
36 |
#include "dev_vtty.h" |
#include "dev_vtty.h" |
37 |
#include "ptask.h" |
#include "ptask.h" |
38 |
#include "timer.h" |
#include "timer.h" |
207 |
def_disk1_size = C3745_DEFAULT_DISK1_SIZE; |
def_disk1_size = C3745_DEFAULT_DISK1_SIZE; |
208 |
def_nm_iomem_size = C3745_DEFAULT_IOMEM_SIZE; |
def_nm_iomem_size = C3745_DEFAULT_IOMEM_SIZE; |
209 |
break; |
break; |
210 |
|
case VM_TYPE_C2600: |
211 |
|
def_ram_size = C2600_DEFAULT_RAM_SIZE; |
212 |
|
def_rom_size = C2600_DEFAULT_ROM_SIZE; |
213 |
|
def_nvram_size = C2600_DEFAULT_NVRAM_SIZE; |
214 |
|
def_conf_reg = C2600_DEFAULT_CONF_REG; |
215 |
|
def_clock_div = C2600_DEFAULT_CLOCK_DIV; |
216 |
|
def_disk0_size = C2600_DEFAULT_DISK0_SIZE; |
217 |
|
def_disk1_size = C2600_DEFAULT_DISK1_SIZE; |
218 |
|
def_nm_iomem_size = C3745_DEFAULT_IOMEM_SIZE; |
219 |
|
break; |
220 |
|
case VM_TYPE_PPC32_TEST: |
221 |
|
def_ram_size = PPC32_VMTEST_DEFAULT_RAM_SIZE; |
222 |
default: |
default: |
223 |
fprintf(stderr,"show_usage: invalid platform.\n"); |
fprintf(stderr,"show_usage: invalid platform.\n"); |
224 |
return; |
return; |
250 |
" -X : Do not use a file to simulate RAM (faster)\n" |
" -X : Do not use a file to simulate RAM (faster)\n" |
251 |
" -G <ghost_file> : Use a ghost file to simulate RAM\n" |
" -G <ghost_file> : Use a ghost file to simulate RAM\n" |
252 |
" -g <ghost_file> : Generate a ghost RAM file\n" |
" -g <ghost_file> : Generate a ghost RAM file\n" |
253 |
|
" --sparse-mem : Use sparse memory\n" |
254 |
" -R <rom_file> : Load an alternate ROM (default: embedded)\n" |
" -R <rom_file> : Load an alternate ROM (default: embedded)\n" |
255 |
" -k <clock_div> : Set the clock divisor (default: %d)\n" |
" -k <clock_div> : Set the clock divisor (default: %d)\n" |
256 |
"\n" |
"\n" |
314 |
"Network Module\n", |
"Network Module\n", |
315 |
def_nm_iomem_size); |
def_nm_iomem_size); |
316 |
break; |
break; |
317 |
|
|
318 |
|
case VM_TYPE_C2600: |
319 |
|
printf(" --iomem-size <val> : IO memory (in percents, default: %u)\n" |
320 |
|
" -p <nm_desc> : Define a Network Module\n" |
321 |
|
" -s <nm_nio> : Bind a Network IO interface to a " |
322 |
|
"Network Module\n", |
323 |
|
def_nm_iomem_size); |
324 |
|
break; |
325 |
} |
} |
326 |
|
|
327 |
printf("\n" |
printf("\n" |
412 |
/* Show the possible NM drivers */ |
/* Show the possible NM drivers */ |
413 |
c3745_nm_show_drivers(); |
c3745_nm_show_drivers(); |
414 |
break; |
break; |
415 |
|
|
416 |
|
case VM_TYPE_C2600: |
417 |
|
printf("<nm_desc> format:\n" |
418 |
|
" \"slot:nm_driver\"\n" |
419 |
|
"\n"); |
420 |
|
|
421 |
|
printf("<nm_nio> format:\n" |
422 |
|
" \"slot:port:netio_type{:netio_parameters}\"\n" |
423 |
|
"\n"); |
424 |
|
|
425 |
|
/* Show the possible chassis types for C2600 platform */ |
426 |
|
c2600_mainboard_show_drivers(); |
427 |
|
|
428 |
|
/* Show the possible NM drivers */ |
429 |
|
c2600_nm_show_drivers(); |
430 |
|
break; |
431 |
} |
} |
432 |
|
|
433 |
/* Show the possible NETIO types */ |
/* Show the possible NETIO types */ |
475 |
vm_type = VM_TYPE_C3725; |
vm_type = VM_TYPE_C3725; |
476 |
else if (!strcmp(str,"3745")) |
else if (!strcmp(str,"3745")) |
477 |
vm_type = VM_TYPE_C3745; |
vm_type = VM_TYPE_C3745; |
478 |
|
else if (!strcmp(str,"2600")) |
479 |
|
vm_type = VM_TYPE_C2600; |
480 |
|
else if (!strcmp(str,"PPC32_TEST")) |
481 |
|
vm_type = VM_TYPE_PPC32_TEST; |
482 |
else |
else |
483 |
fprintf(stderr,"Invalid platform type '%s'\n",str); |
fprintf(stderr,"Invalid platform type '%s'\n",str); |
484 |
} |
} |
494 |
#define OPT_TIMER_ITV 0x104 |
#define OPT_TIMER_ITV 0x104 |
495 |
#define OPT_VM_DEBUG 0x105 |
#define OPT_VM_DEBUG 0x105 |
496 |
#define OPT_IOMEM_SIZE 0x106 |
#define OPT_IOMEM_SIZE 0x106 |
497 |
|
#define OPT_SPARSE_MEM 0x107 |
498 |
|
|
499 |
static struct option cmd_line_lopts[] = { |
static struct option cmd_line_lopts[] = { |
500 |
{ "disk0" , 1, NULL, OPT_DISK0_SIZE }, |
{ "disk0" , 1, NULL, OPT_DISK0_SIZE }, |
504 |
{ "timer-itv" , 1, NULL, OPT_TIMER_ITV }, |
{ "timer-itv" , 1, NULL, OPT_TIMER_ITV }, |
505 |
{ "vm-debug" , 1, NULL, OPT_VM_DEBUG }, |
{ "vm-debug" , 1, NULL, OPT_VM_DEBUG }, |
506 |
{ "iomem-size" , 1, NULL, OPT_IOMEM_SIZE }, |
{ "iomem-size" , 1, NULL, OPT_IOMEM_SIZE }, |
507 |
|
{ "sparse-mem" , 0, NULL, OPT_SPARSE_MEM }, |
508 |
{ NULL , 0, NULL, 0 }, |
{ NULL , 0, NULL, 0 }, |
509 |
}; |
}; |
510 |
|
|
669 |
return(0); |
return(0); |
670 |
} |
} |
671 |
|
|
672 |
|
/* Parse specific options for the Cisco 2600 platform */ |
673 |
|
static int cli_parse_c2600_options(vm_instance_t *vm,int option) |
674 |
|
{ |
675 |
|
c2600_t *router; |
676 |
|
|
677 |
|
router = VM_C2600(vm); |
678 |
|
|
679 |
|
switch(option) { |
680 |
|
/* IO memory reserved for NMs (in percents!) */ |
681 |
|
case OPT_IOMEM_SIZE: |
682 |
|
router->nm_iomem_size = 0x8000 | atoi(optarg); |
683 |
|
break; |
684 |
|
|
685 |
|
/* Mainboard type */ |
686 |
|
case 't': |
687 |
|
c2600_mainboard_set_type(router,optarg); |
688 |
|
break; |
689 |
|
|
690 |
|
/* NM settings */ |
691 |
|
case 'p': |
692 |
|
return(c2600_cmd_nm_create(router,optarg)); |
693 |
|
|
694 |
|
/* NM NIO settings */ |
695 |
|
case 's': |
696 |
|
return(c2600_cmd_add_nio(router,optarg)); |
697 |
|
|
698 |
|
/* Unknown option */ |
699 |
|
default: |
700 |
|
return(-1); |
701 |
|
} |
702 |
|
|
703 |
|
return(0); |
704 |
|
} |
705 |
|
|
706 |
/* Create a router instance */ |
/* Create a router instance */ |
707 |
static vm_instance_t *cli_create_instance(char *name,int platform_type, |
static vm_instance_t *cli_create_instance(char *name,int platform_type, |
708 |
int instance_id) |
int instance_id) |
709 |
{ |
{ |
710 |
|
vm_instance_t *vm; |
711 |
c7200_t *c7200; |
c7200_t *c7200; |
712 |
c3600_t *c3600; |
c3600_t *c3600; |
713 |
c2691_t *c2691; |
c2691_t *c2691; |
714 |
c3725_t *c3725; |
c3725_t *c3725; |
715 |
c3745_t *c3745; |
c3745_t *c3745; |
716 |
|
c2600_t *c2600; |
717 |
|
|
718 |
switch(platform_type) { |
switch(platform_type) { |
719 |
case VM_TYPE_C7200: |
case VM_TYPE_C7200: |
751 |
} |
} |
752 |
return(c3745->vm); |
return(c3745->vm); |
753 |
|
|
754 |
|
case VM_TYPE_C2600: |
755 |
|
if (!(c2600 = c2600_create_instance(name,instance_id))) { |
756 |
|
fprintf(stderr,"C2600: unable to create instance!\n"); |
757 |
|
return NULL; |
758 |
|
} |
759 |
|
return(c2600->vm); |
760 |
|
|
761 |
|
case VM_TYPE_PPC32_TEST: |
762 |
|
if (!(vm = ppc32_vmtest_create_instance(name,instance_id))) { |
763 |
|
fprintf(stderr,"PPC32_TEST: unable to create instance!\n"); |
764 |
|
return NULL; |
765 |
|
} |
766 |
|
return(vm); |
767 |
|
|
768 |
default: |
default: |
769 |
fprintf(stderr,"Unknown platform type '%d'!\n",platform_type); |
fprintf(stderr,"Unknown platform type '%d'!\n",platform_type); |
770 |
return NULL; |
return NULL; |
882 |
vm->ghost_status = VM_GHOST_RAM_GENERATE; |
vm->ghost_status = VM_GHOST_RAM_GENERATE; |
883 |
break; |
break; |
884 |
|
|
885 |
|
/* Use sparse memory */ |
886 |
|
case OPT_SPARSE_MEM: |
887 |
|
vm->sparse_mem = TRUE; |
888 |
|
break; |
889 |
|
|
890 |
/* Alternate ROM */ |
/* Alternate ROM */ |
891 |
case 'R': |
case 'R': |
892 |
vm->rom_filename = optarg; |
vm->rom_filename = optarg; |
1028 |
case VM_TYPE_C3745: |
case VM_TYPE_C3745: |
1029 |
res = cli_parse_c3745_options(vm,option); |
res = cli_parse_c3745_options(vm,option); |
1030 |
break; |
break; |
1031 |
|
case VM_TYPE_C2600: |
1032 |
|
res = cli_parse_c2600_options(vm,option); |
1033 |
|
break; |
1034 |
} |
} |
1035 |
|
|
1036 |
if (res == -1) |
if (res == -1) |
1118 |
c2691_delete_all_instances(); |
c2691_delete_all_instances(); |
1119 |
c3725_delete_all_instances(); |
c3725_delete_all_instances(); |
1120 |
c3745_delete_all_instances(); |
c3745_delete_all_instances(); |
1121 |
|
c2600_delete_all_instances(); |
1122 |
|
ppc32_vmtest_delete_all_instances(); |
1123 |
|
|
1124 |
/* Delete ATM and Frame-Relay switches + bridges */ |
/* Delete ATM and Frame-Relay switches + bridges */ |
1125 |
netio_bridge_delete_all(); |
netio_bridge_delete_all(); |
1145 |
atexit(profiler_savestat); |
atexit(profiler_savestat); |
1146 |
#endif |
#endif |
1147 |
|
|
1148 |
printf("Cisco 7200 Simulation Platform (version %s)\n",sw_version); |
printf("Cisco Router Simulation Platform (version %s)\n",sw_version); |
1149 |
printf("Copyright (c) 2005,2006 Christophe Fillot.\n"); |
printf("Copyright (c) 2005-2007 Christophe Fillot.\n"); |
1150 |
printf("Build date: %s %s\n\n",__DATE__,__TIME__); |
printf("Build date: %s %s\n\n",__DATE__,__TIME__); |
1151 |
|
|
1152 |
/* Initialize timers */ |
/* Initialize timers */ |
1184 |
/* Create instruction lookup tables */ |
/* Create instruction lookup tables */ |
1185 |
mips64_jit_create_ilt(); |
mips64_jit_create_ilt(); |
1186 |
mips64_exec_create_ilt(); |
mips64_exec_create_ilt(); |
1187 |
|
ppc32_jit_create_ilt(); |
1188 |
|
ppc32_exec_create_ilt(); |
1189 |
|
|
1190 |
setup_signals(); |
setup_signals(); |
1191 |
|
|
1210 |
case VM_TYPE_C3745: |
case VM_TYPE_C3745: |
1211 |
res = c3745_init_instance(VM_C3745(vm)); |
res = c3745_init_instance(VM_C3745(vm)); |
1212 |
break; |
break; |
1213 |
|
case VM_TYPE_C2600: |
1214 |
|
res = c2600_init_instance(VM_C2600(vm)); |
1215 |
|
break; |
1216 |
|
case VM_TYPE_PPC32_TEST: |
1217 |
|
res = ppc32_vmtest_init_instance(vm); |
1218 |
|
break; |
1219 |
default: |
default: |
1220 |
res = -1; |
res = -1; |
1221 |
} |
} |
1227 |
|
|
1228 |
#if (DEBUG_INSN_PERF_CNT > 0) || (DEBUG_BLOCK_PERF_CNT > 0) |
#if (DEBUG_INSN_PERF_CNT > 0) || (DEBUG_BLOCK_PERF_CNT > 0) |
1229 |
{ |
{ |
1230 |
m_uint64_t prev = 0,delta; |
m_uint64_t counter,prev = 0,delta; |
1231 |
while(vm->status == VM_STATUS_RUNNING) { |
while(vm->status == VM_STATUS_RUNNING) { |
1232 |
delta = vm->boot_cpu->perf_counter - prev; |
counter = cpu_get_perf_counter(vm->boot_cpu); |
1233 |
prev = vm->boot_cpu->perf_counter; |
delta = counter - prev; |
1234 |
|
prev = counter; |
1235 |
printf("delta = %llu\n",delta); |
printf("delta = %llu\n",delta); |
1236 |
sleep(1); |
sleep(1); |
1237 |
} |
} |