📄 dynamips.c
字号:
/* * Cisco 7200 (Predator) simulation platform. * Copyright (c) 2005,2006 Christophe Fillot (cf@utc.fr) * * Many thanks to Nicolas Szalay for his patch * for the command line parsing and virtual machine * settings (RAM, ROM, NVRAM, ...) */#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <errno.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/mman.h>#include <signal.h>#include <fcntl.h>#include <assert.h>#include <getopt.h>#include ARCH_INC_FILE#include "dynamips.h"#include "mips64.h"#include "mips64_exec.h"#include "dev_c7200.h"#include "dev_c3600.h"#include "dev_c2691.h"#include "dev_c3725.h"#include "dev_c3745.h"#include "dev_vtty.h"#include "ptask.h"#include "timer.h"#include "registry.h"#include "hypervisor.h"#include "net_io.h"#include "net_io_bridge.h"#include "net_io_filter.h"#include "crc.h"#include "atm.h"#include "frame_relay.h"#include "eth_switch.h"#ifdef GEN_ETH#include "gen_eth.h"#endif#ifdef PROFILE#include "profiler.h"#endif/* Default name for logfile */#define LOGFILE_DEFAULT_NAME "dynamips_log.txt"/* Software version */const char *sw_version = DYNAMIPS_VERSION"-"JIT_ARCH;/* Hypervisor */int hypervisor_mode = 0;int hypervisor_tcp_port = 0;/* Log file */char *log_file_name = NULL;FILE *log_file = NULL;/* VM flags */volatile int vm_save_state = 0;/* Generic signal handler */void signal_gen_handler(int sig){ switch(sig) { case SIGHUP: /* For future use */ break; case SIGQUIT: /* save VM context */ vm_save_state = TRUE; break; case SIGINT: /* CTRL+C has been pressed */ if (hypervisor_mode) hypervisor_stopsig(); else { /* In theory, this shouldn't happen thanks to VTTY settings */ vm_instance_t *vm; if ((vm = vm_acquire("default")) != NULL) { /* Only forward ctrl-c if user has requested local terminal */ if (vm->vtty_con_type == VTTY_TYPE_TERM) { vtty_store_ctrlc(vm->vtty_con); } else { vm_stop(vm); } vm_release(vm); } else { fprintf(stderr,"Error: Cannot acquire instance handle.\n"); } } break; default: fprintf(stderr,"Unhandled signal %d\n",sig); }}/* Setups signals */static void setup_signals(void){ struct sigaction act; memset(&act,0,sizeof(act)); act.sa_handler = signal_gen_handler; act.sa_flags = SA_RESTART; sigaction(SIGHUP,&act,NULL); sigaction(SIGQUIT,&act,NULL); sigaction(SIGINT,&act,NULL);}/* Create general log file */static void create_log_file(void){ /* Set the default value of the log file name */ if (!log_file_name) { if (!(log_file_name = strdup(LOGFILE_DEFAULT_NAME))) { fprintf(stderr,"Unable to set log file name.\n"); exit(EXIT_FAILURE); } } if (!(log_file = fopen(log_file_name,"w"))) { fprintf(stderr,"Unable to create log file (%s).\n",strerror(errno)); exit(EXIT_FAILURE); }}/* Close general log file */static void close_log_file(void){ if (log_file) fclose(log_file); free(log_file_name); log_file = NULL; log_file_name = NULL;}/* Display the command line use */static void show_usage(int argc,char *argv[],int platform){ 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; default: fprintf(stderr,"show_usage: invalid platform.\n"); return; } printf("Usage: %s [options] <ios_image>\n\n",argv[0]); printf("Available options:\n" " -H <tcp_port> : Run in hypervisor mode\n\n" " -P <platform> : Platform to emulate (7200, 3600, " "2691, 3725 or 3745) " "(default: 7200)\n\n" " -l <log_file> : Set logging file (default is %s)\n" " -j : Disable the JIT compiler, very slow\n" " --exec-area <size> : Set the exec area size (default: %d Mb)\n" " --idle-pc <pc> : Set the idle PC (default: disabled)\n" " --timer-itv <val> : Timer IRQ interval check (default: %u)\n" "\n" " -i <instance> : Set instance ID\n" " -r <ram_size> : Set the virtual RAM size (default: %u Mb)\n" " -o <rom_size> : Set the virtual ROM size (default: %u Mb)\n" " -n <nvram_size> : Set the NVRAM size (default: %d Kb)\n" " -c <conf_reg> : Set the configuration register " "(default: 0x%04x)\n" " -m <mac_addr> : Set the MAC address of the chassis\n" " (default: automatically generated)\n" " -C <cfg_file> : Import an IOS configuration file " "into NVRAM\n" " -X : Do not use a file to simulate RAM (faster)\n" " -G <ghost_file> : Use a ghost file to simulate RAM\n" " -g <ghost_file> : Generate a ghost RAM file\n" " -R <rom_file> : Load an alternate ROM (default: embedded)\n" " -k <clock_div> : Set the clock divisor (default: %d)\n" "\n" " -T <port> : Console is on TCP <port>\n" " -U <si_desc> : Console in on serial interface <si_desc>\n" " (default is on the terminal)\n" "\n" " -A <port> : AUX is on TCP <port>\n" " -B <si_desc> : AUX is on serial interface <si_desc>\n" " (default is no AUX port)\n" "\n" " --disk0 <size> : Set PCMCIA ATA disk0: size " "(default: %u Mb)\n" " --disk1 <size> : Set PCMCIA ATA disk1: size " "(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); switch(platform) { case VM_TYPE_C7200: printf(" -t <npe_type> : Select NPE type (default: \"%s\")\n" " -M <midplane> : Select Midplane (\"std\" or \"vxr\")\n" " -p <pa_desc> : Define a Port Adapter\n" " -s <pa_nio> : Bind a Network IO interface to a " "Port Adapter\n", C7200_DEFAULT_NPE_TYPE); break; case VM_TYPE_C3600: printf(" -t <chassis_type> : Select Chassis type " "(default: \"%s\")\n" " --iomem-size <val> : IO memory (in percents, default: %u)\n" " -p <nm_desc> : Define a Network Module\n" " -s <nm_nio> : 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 <val> : IO memory (in percents, default: %u)\n" " -p <nm_desc> : Define a Network Module\n" " -s <nm_nio> : Bind a Network IO interface to a " "Network Module\n", def_nm_iomem_size); break; case VM_TYPE_C3725: printf(" --iomem-size <val> : IO memory (in percents, default: %u)\n" " -p <nm_desc> : Define a Network Module\n" " -s <nm_nio> : Bind a Network IO interface to a " "Network Module\n", def_nm_iomem_size); break; case VM_TYPE_C3745: printf(" --iomem-size <val> : IO memory (in percents, default: %u)\n" " -p <nm_desc> : Define a Network Module\n" " -s <nm_nio> : Bind a Network IO interface to a " "Network Module\n", def_nm_iomem_size); break; } printf("\n"#if DEBUG_SYM_TREE " -S <sym_file> : Load a symbol file\n"#endif " -a <cfg_file> : Virtual ATM switch configuration file\n" " -f <cfg_file> : Virtual Frame-Relay switch configuration " "file\n" " -E <cfg_file> : Virtual Ethernet switch configuration file\n" " -b <cfg_file> : Virtual bridge configuration file\n" " -e : Show network device list of the " "host machine\n" "\n"); printf("<si_desc> format:\n" " \"device{:baudrate{:databits{:parity{:stopbits{:hwflow}}}}}}\"\n" "\n"); switch(platform) { case VM_TYPE_C7200: printf("<pa_desc> format:\n" " \"slot:pa_driver\"\n" "\n"); printf("<pa_nio> 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("<nm_desc> format:\n" " \"slot:nm_driver\"\n" "\n"); printf("<nm_nio> 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: printf("<nm_desc> format:\n" " \"slot:nm_driver\"\n" "\n"); printf("<nm_nio> 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("<nm_desc> format:\n" " \"slot:nm_driver\"\n" "\n"); printf("<nm_nio> 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("<nm_desc> format:\n"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -