⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interp.c

📁 这个是LINUX下的GDB调度工具的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*> interp.c <*//* Simulator for the MIPS architecture.   This file is part of the MIPS sim		THIS SOFTWARE IS NOT COPYRIGHTED   Cygnus offers the following for use in the public domain.  Cygnus   makes no warranty with regard to the software or it's performance   and the user accepts the software "AS IS" with all faults.   CYGNUS DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO   THIS SOFTWARE INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.NOTEs:The IDT monitor (found on the VR4300 board), seems to lie aboutregister contents. It seems to treat the registers as sign-extended32-bit values. This cause *REAL* problems when single-stepping 64-bitcode on the hardware.*//* The TRACE manifests enable the provision of extra features. If they   are not defined then a simpler (quicker) simulator is constructed   without the required run-time checks, etc. */#if 1 /* 0 to allow user build selection, 1 to force inclusion */#define TRACE (1)#endif#include "bfd.h"#include "sim-main.h"#include "sim-utils.h"#include "sim-options.h"#include "sim-assert.h"#include "sim-hw.h"#include "itable.h"#include "config.h"#include <stdio.h>#include <stdarg.h>#include <ansidecl.h>#include <ctype.h>#include <limits.h>#include <math.h>#ifdef HAVE_STDLIB_H#include <stdlib.h>#endif#ifdef HAVE_STRING_H#include <string.h>#else#ifdef HAVE_STRINGS_H#include <strings.h>#endif#endif#include "getopt.h"#include "libiberty.h"#include "bfd.h"#include "gdb/callback.h"   /* GDB simulator callback interface */#include "gdb/remote-sim.h" /* GDB simulator interface */#include "sysdep.h"#ifndef PARAMS#define PARAMS(x) #endifchar* pr_addr PARAMS ((SIM_ADDR addr));char* pr_uword64 PARAMS ((uword64 addr));/* Within interp.c we refer to the sim_state and sim_cpu directly. */#define CPU cpu#define SD sd/* The following reserved instruction value is used when a simulator   trap is required. NOTE: Care must be taken, since this value may be   used in later revisions of the MIPS ISA. */#define RSVD_INSTRUCTION           (0x00000005)#define RSVD_INSTRUCTION_MASK      (0xFC00003F)#define RSVD_INSTRUCTION_ARG_SHIFT 6#define RSVD_INSTRUCTION_ARG_MASK  0xFFFFF  /* Bits in the Debug register */#define Debug_DBD 0x80000000   /* Debug Branch Delay */#define Debug_DM  0x40000000   /* Debug Mode         */#define Debug_DBp 0x00000002   /* Debug Breakpoint indicator *//*---------------------------------------------------------------------------*//*-- GDB simulator interface ------------------------------------------------*//*---------------------------------------------------------------------------*/static void ColdReset PARAMS((SIM_DESC sd));/*---------------------------------------------------------------------------*/#define DELAYSLOT()     {\                          if (STATE & simDELAYSLOT)\                            sim_io_eprintf(sd,"Delay slot already activated (branch in delay slot?)\n");\                          STATE |= simDELAYSLOT;\                        }#define JALDELAYSLOT()	{\			  DELAYSLOT ();\			  STATE |= simJALDELAYSLOT;\			}#define NULLIFY()       {\                          STATE &= ~simDELAYSLOT;\                          STATE |= simSKIPNEXT;\                        }#define CANCELDELAYSLOT() {\                            DSSTATE = 0;\                            STATE &= ~(simDELAYSLOT | simJALDELAYSLOT);\                          }#define INDELAYSLOT()	((STATE & simDELAYSLOT) != 0)#define INJALDELAYSLOT() ((STATE & simJALDELAYSLOT) != 0)/* Note that the monitor code essentially assumes this layout of memory.   If you change these, change the monitor code, too.  */#define K0BASE  (0x80000000)#define K0SIZE  (0x20000000)#define K1BASE  (0xA0000000)#define K1SIZE  (0x20000000)/* Simple run-time monitor support.      We emulate the monitor by placing magic reserved instructions at   the monitor's entry points; when we hit these instructions, instead   of raising an exception (as we would normally), we look at the   instruction and perform the appropriate monitory operation.      `*_monitor_base' are the physical addresses at which the corresponding         monitor vectors are located.  `0' means none.  By default,        install all three.    The RSVD_INSTRUCTION... macros specify the magic instructions we    use at the monitor entry points.  */static int firmware_option_p = 0;static SIM_ADDR idt_monitor_base =     0xBFC00000;static SIM_ADDR pmon_monitor_base =    0xBFC00500;static SIM_ADDR lsipmon_monitor_base = 0xBFC00200;static SIM_RC sim_firmware_command (SIM_DESC sd, char* arg);#define MEM_SIZE (2 << 20)#if defined(TRACE)static char *tracefile = "trace.din"; /* default filename for trace log */FILE *tracefh = NULL;static void open_trace PARAMS((SIM_DESC sd));#endif /* TRACE */static const char * get_insn_name (sim_cpu *, int);/* simulation target board.  NULL=canonical */static char* board = NULL;static DECLARE_OPTION_HANDLER (mips_option_handler);enum {  OPTION_DINERO_TRACE = OPTION_START,  OPTION_DINERO_FILE,  OPTION_FIRMWARE,  OPTION_BOARD};static SIM_RCmips_option_handler (sd, cpu, opt, arg, is_command)     SIM_DESC sd;     sim_cpu *cpu;     int opt;     char *arg;     int is_command;{  int cpu_nr;  switch (opt)    {    case OPTION_DINERO_TRACE: /* ??? */#if defined(TRACE)      /* Eventually the simTRACE flag could be treated as a toggle, to	 allow external control of the program points being traced	 (i.e. only from main onwards, excluding the run-time setup,	 etc.). */      for (cpu_nr = 0; cpu_nr < MAX_NR_PROCESSORS; cpu_nr++)	{	  sim_cpu *cpu = STATE_CPU (sd, cpu_nr);	  if (arg == NULL)	    STATE |= simTRACE;	  else if (strcmp (arg, "yes") == 0)	    STATE |= simTRACE;	  else if (strcmp (arg, "no") == 0)	    STATE &= ~simTRACE;	  else if (strcmp (arg, "on") == 0)	    STATE |= simTRACE;	  else if (strcmp (arg, "off") == 0)	    STATE &= ~simTRACE;	  else	    {	      fprintf (stderr, "Unrecognized dinero-trace option `%s'\n", arg);	      return SIM_RC_FAIL;	    }	}      return SIM_RC_OK;#else /* !TRACE */      fprintf(stderr,"\Simulator constructed without dinero tracing support (for performance).\n\Re-compile simulator with \"-DTRACE\" to enable this option.\n");      return SIM_RC_FAIL;#endif /* !TRACE */    case OPTION_DINERO_FILE:#if defined(TRACE)      if (optarg != NULL) {	char *tmp;	tmp = (char *)malloc(strlen(optarg) + 1);	if (tmp == NULL)	  {	    sim_io_printf(sd,"Failed to allocate buffer for tracefile name \"%s\"\n",optarg);	    return SIM_RC_FAIL;	  }	else {	  strcpy(tmp,optarg);	  tracefile = tmp;	  sim_io_printf(sd,"Placing trace information into file \"%s\"\n",tracefile);	}      }#endif /* TRACE */      return SIM_RC_OK;    case OPTION_FIRMWARE:      return sim_firmware_command (sd, arg);    case OPTION_BOARD:      {	if (arg)	  {	    board = zalloc(strlen(arg) + 1);	    strcpy(board, arg);	  }	return SIM_RC_OK;      }    }    return SIM_RC_OK;}static const OPTION mips_options[] ={  { {"dinero-trace", optional_argument, NULL, OPTION_DINERO_TRACE},      '\0', "on|off", "Enable dinero tracing",      mips_option_handler },  { {"dinero-file", required_argument, NULL, OPTION_DINERO_FILE},      '\0', "FILE", "Write dinero trace to FILE",      mips_option_handler },  { {"firmware", required_argument, NULL, OPTION_FIRMWARE},    '\0', "[idt|pmon|lsipmon|none][@ADDRESS]", "Emulate ROM monitor",    mips_option_handler },  { {"board", required_argument, NULL, OPTION_BOARD},     '\0', "none" /* rely on compile-time string concatenation for other options */#define BOARD_JMR3904 "jmr3904"           "|" BOARD_JMR3904#define BOARD_JMR3904_PAL "jmr3904pal"           "|" BOARD_JMR3904_PAL#define BOARD_JMR3904_DEBUG "jmr3904debug"           "|" BOARD_JMR3904_DEBUG#define BOARD_BSP "bsp"           "|" BOARD_BSP    , "Customize simulation for a particular board.", mips_option_handler },  { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL }};int interrupt_pending;voidinterrupt_event (SIM_DESC sd, void *data){  sim_cpu *cpu = STATE_CPU (sd, 0); /* FIXME */  address_word cia = CIA_GET (cpu);  if (SR & status_IE)    {      interrupt_pending = 0;      SignalExceptionInterrupt (1); /* interrupt "1" */    }  else if (!interrupt_pending)    sim_events_schedule (sd, 1, interrupt_event, data);}/*---------------------------------------------------------------------------*//*-- Device registration hook -----------------------------------------------*//*---------------------------------------------------------------------------*/static void device_init(SIM_DESC sd) {#ifdef DEVICE_INIT  extern void register_devices(SIM_DESC);  register_devices(sd);#endif}/*---------------------------------------------------------------------------*//*-- GDB simulator interface ------------------------------------------------*//*---------------------------------------------------------------------------*/SIM_DESCsim_open (kind, cb, abfd, argv)     SIM_OPEN_KIND kind;     host_callback *cb;     struct bfd *abfd;     char **argv;{  SIM_DESC sd = sim_state_alloc (kind, cb);  sim_cpu *cpu = STATE_CPU (sd, 0); /* FIXME */  SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);  /* FIXME: watchpoints code shouldn't need this */  STATE_WATCHPOINTS (sd)->pc = &(PC);  STATE_WATCHPOINTS (sd)->sizeof_pc = sizeof (PC);  STATE_WATCHPOINTS (sd)->interrupt_handler = interrupt_event;  /* Initialize the mechanism for doing insn profiling.  */  CPU_INSN_NAME (cpu) = get_insn_name;  CPU_MAX_INSNS (cpu) = nr_itable_entries;  STATE = 0;    if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK)    return 0;  sim_add_option_table (sd, NULL, mips_options);  /* getopt will print the error message so we just have to exit if this fails.     FIXME: Hmmm...  in the case of gdb we need getopt to call     print_filtered.  */  if (sim_parse_args (sd, argv) != SIM_RC_OK)    {      /* Uninstall the modules to avoid memory leaks,	 file descriptor leaks, etc.  */      sim_module_uninstall (sd);      return 0;    }  /* handle board-specific memory maps */  if (board == NULL)    {      /* Allocate core managed memory */            /* For compatibility with the old code - under this (at level one)	 are the kernel spaces K0 & K1.  Both of these map to a single	 smaller sub region */      sim_do_command(sd," memory region 0x7fff8000,0x8000") ; /* MTZ- 32 k stack */      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx%%0x%lx,0x%0x",		       K1BASE, K0SIZE,		       MEM_SIZE, /* actual size */		       K0BASE);            device_init(sd);    }  else if (board != NULL	   && (strcmp(board, BOARD_BSP) == 0))    {      int i;      STATE_ENVIRONMENT (sd) = OPERATING_ENVIRONMENT;      /* ROM: 0x9FC0_0000 - 0x9FFF_FFFF and 0xBFC0_0000 - 0xBFFF_FFFF */      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx,0x%0x",		       0x9FC00000, 		       4 * 1024 * 1024, /* 4 MB */		       0xBFC00000);      /* SRAM: 0x8000_0000 - 0x803F_FFFF and 0xA000_0000 - 0xA03F_FFFF */      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx,0x%0x",		       0x80000000, 		       4 * 1024 * 1024, /* 4 MB */		       0xA0000000);      /* DRAM: 0x8800_0000 - 0x89FF_FFFF and 0xA800_0000 - 0xA9FF_FFFF */      for (i=0; i<8; i++) /* 32 MB total */	{	  unsigned size = 4 * 1024 * 1024;  /* 4 MB */	  sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx,0x%0x",			   0x88000000 + (i * size), 			   size, 			   0xA8000000 + (i * size));	}    }#if (WITH_HW)  else if (board != NULL	   && (strcmp(board, BOARD_JMR3904) == 0 ||	       strcmp(board, BOARD_JMR3904_PAL) == 0 ||	       strcmp(board, BOARD_JMR3904_DEBUG) == 0))    {      /* match VIRTUAL memory layout of JMR-TX3904 board */      int i;      /* --- disable monitor unless forced on by user --- */      if (! firmware_option_p)	{	  idt_monitor_base = 0;	  pmon_monitor_base = 0;	  lsipmon_monitor_base = 0;	}      /* --- environment --- */      STATE_ENVIRONMENT (sd) = OPERATING_ENVIRONMENT;      /* --- memory --- */      /* ROM: 0x9FC0_0000 - 0x9FFF_FFFF and 0xBFC0_0000 - 0xBFFF_FFFF */      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx,0x%0x",		       0x9FC00000, 		       4 * 1024 * 1024, /* 4 MB */		       0xBFC00000);      /* SRAM: 0x8000_0000 - 0x803F_FFFF and 0xA000_0000 - 0xA03F_FFFF */      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx,0x%0x",		       0x80000000, 		       4 * 1024 * 1024, /* 4 MB */		       0xA0000000);      /* DRAM: 0x8800_0000 - 0x89FF_FFFF and 0xA800_0000 - 0xA9FF_FFFF */      for (i=0; i<8; i++) /* 32 MB total */	{	  unsigned size = 4 * 1024 * 1024;  /* 4 MB */	  sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx,0x%0x",			   0x88000000 + (i * size), 			   size, 			   0xA8000000 + (i * size));	}      /* Dummy memory regions for unsimulated devices - sorted by address */      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xB1000000, 0x400); /* ISA I/O */      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xB2100000, 0x004); /* ISA ctl */      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xB2500000, 0x004); /* LED/switch */      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xB2700000, 0x004); /* RTC */      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xB3C00000, 0x004); /* RTC */      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xFFFF8000, 0x900); /* DRAMC */      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xFFFF9000, 0x200); /* EBIF */      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xFFFFE000, 0x01c); /* EBIF */      sim_do_commandf (sd, "memory alias 0x%lx@1,0x%lx", 0xFFFFF500, 0x300); /* PIO */      /* --- simulated devices --- */      sim_hw_parse (sd, "/tx3904irc@0xffffc000/reg 0xffffc000 0x20");      sim_hw_parse (sd, "/tx3904cpu");      sim_hw_parse (sd, "/tx3904tmr@0xfffff000/reg 0xfffff000 0x100");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -