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

📄 psim.c

📁 这个是LINUX下的GDB调度工具的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*  This file is part of the program psim.    Copyright 1994, 1995, 1996, 1997, 2003 Andrew Cagney    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.     You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.     */#ifndef _PSIM_C_#define _PSIM_C_#include "cpu.h" /* includes psim.h */#include "idecode.h"#include "options.h"#include "tree.h"#include <signal.h>#include <stdio.h>#include <ctype.h>#ifdef HAVE_STDLIB_H#include <stdlib.h>#endif#include <setjmp.h>#ifdef HAVE_STRING_H#include <string.h>#else#ifdef HAVE_STRINGS_H#include <strings.h>#endif#endif#include "bfd.h"/* system structure, actual size of processor array determined at   runtime */struct _psim {  event_queue *events;  device *devices;  mon *monitor;  os_emul *os_emulation;  core *memory;  /* escape routine for inner functions */  void *path_to_halt;  void *path_to_restart;  /* status from last halt */  psim_status halt_status;  /* the processors proper */  int nr_cpus;  int last_cpu; /* CPU that last (tried to) execute an instruction */  cpu *processors[MAX_NR_PROCESSORS];};int current_target_byte_order;int current_host_byte_order;int current_environment;int current_alignment;int current_floating_point;int current_model_issue = MODEL_ISSUE_IGNORE;int current_stdio = DO_USE_STDIO;model_enum current_model = WITH_DEFAULT_MODEL;/* create the device tree */INLINE_PSIM\(device *)psim_tree(void){  device *root = tree_parse(NULL, "core");  tree_parse(root, "/aliases");  tree_parse(root, "/options");  tree_parse(root, "/chosen");  tree_parse(root, "/packages");  tree_parse(root, "/cpus");  tree_parse(root, "/openprom");  tree_parse(root, "/openprom/init");  tree_parse(root, "/openprom/trace");  tree_parse(root, "/openprom/options");  return root;}STATIC_INLINE_PSIM\(char *)find_arg(char *err_msg,	 int *ptr_to_argp,	 char **argv){  *ptr_to_argp += 1;  if (argv[*ptr_to_argp] == NULL)    error(err_msg);  return argv[*ptr_to_argp];}INLINE_PSIM\(void)psim_usage(int verbose){  printf_filtered("Usage:\n");  printf_filtered("\n");  printf_filtered("\tpsim [ <psim-option> ... ] <image> [ <image-arg> ... ]\n");  printf_filtered("\n");  printf_filtered("Where\n");  printf_filtered("\n");  printf_filtered("\t<image>         Name of the PowerPC program to run.\n");  if (verbose) {  printf_filtered("\t                This can either be a PowerPC binary or\n");  printf_filtered("\t                a text file containing a device tree\n");  printf_filtered("\t                specification.\n");  printf_filtered("\t                PSIM will attempt to determine from the\n");  printf_filtered("\t                specified <image> the intended emulation\n");  printf_filtered("\t                environment.\n");  printf_filtered("\t                If PSIM gets it wrong, the emulation\n");  printf_filtered("\t                environment can be specified using the\n");  printf_filtered("\t                `-e' option (described below).\n");  printf_filtered("\n"); }  printf_filtered("\t<image-arg>     Argument to be passed to <image>\n");  if (verbose) {  printf_filtered("\t                These arguments will be passed to\n");  printf_filtered("\t                <image> (as standard C argv, argc)\n");  printf_filtered("\t                when <image> is started.\n");  printf_filtered("\n"); }  printf_filtered("\t<psim-option>   See below\n");  printf_filtered("\n");  printf_filtered("The following are valid <psim-option>s:\n");  printf_filtered("\n");  printf_filtered("\t-c <count>      Limit the simulation to <count> iterations\n");  if (verbose) {   printf_filtered("\n");  }  printf_filtered("\t-i or -i2       Print instruction counting statistics\n");  if (verbose) {   printf_filtered("\t                Specify -i2 for a more detailed display\n");  printf_filtered("\n");  }  printf_filtered("\t-I              Print execution unit statistics\n");  if (verbose) { printf_filtered("\n"); }  printf_filtered("\t-e <os-emul>    specify an OS or platform to model\n");  if (verbose) {  printf_filtered("\t                Can be any of the following:\n");  printf_filtered("\t                bug - OEA + MOTO BUG ROM calls\n");  printf_filtered("\t                netbsd - UEA + NetBSD system calls\n");  printf_filtered("\t                solaris - UEA + Solaris system calls\n");  printf_filtered("\t                linux - UEA + Linux system calls\n");  printf_filtered("\t                chirp - OEA + a few OpenBoot calls\n");  printf_filtered("\n"); }  printf_filtered("\t-E <endian>     Specify the endianness of the target\n");  if (verbose) {   printf_filtered("\t                Can be any of the following:\n");  printf_filtered("\t                big - big endian target\n");  printf_filtered("\t                little - little endian target\n");  printf_filtered("\n"); }  printf_filtered("\t-f <file>       Merge <file> into the device tree\n");  if (verbose) { printf_filtered("\n"); }  printf_filtered("\t-h -? -H        give more detailed usage\n");  if (verbose) { printf_filtered("\n"); }  printf_filtered("\t-m <model>      Specify the processor to model (604)\n");  if (verbose) {  printf_filtered("\t                Selects the processor to use when\n");  printf_filtered("\t                modeling execution units.  Includes:\n");  printf_filtered("\t                604, 603 and 603e\n");  printf_filtered("\n"); }  printf_filtered("\t-n <nr-smp>     Specify the number of processors in SMP simulations\n");  if (verbose) {  printf_filtered("\t                Specifies the number of processors that are\n");  printf_filtered("\t                to be modeled in a symetric multi-processor (SMP)\n");  printf_filtered("\t                simulation\n");  printf_filtered("\n"); }  printf_filtered("\t-o <dev-spec>   Add device <dev-spec> to the device tree\n");  if (verbose) { printf_filtered("\n"); }  printf_filtered("\t-r <ram-size>   Set RAM size in bytes (OEA environments)\n");  if (verbose) { printf_filtered("\n"); }  printf_filtered("\t-t [!]<trace>   Enable (disable) <trace> option\n");  if (verbose) { printf_filtered("\n"); }  printf_filtered("\n");  trace_usage(verbose);  device_usage(verbose);  if (verbose > 1) {    printf_filtered("\n");    print_options();  }  error("");}/* Test "string" for containing a string of digits that form a numberbetween "min" and "max".  The return value is the number or "err". */staticint is_num( char *string, int min, int max, int err){  int result = 0;  for ( ; *string; ++string)  {    if (!isdigit(*string))    {      result = err;      break;    }    result = result * 10 + (*string - '0');  }  if (result < min || result > max)    result = err;  return result;}INLINE_PSIM\(char **)psim_options(device *root,	     char **argv){  device *current = root;  int argp;  if (argv == NULL)    return NULL;  argp = 0;  while (argv[argp] != NULL && argv[argp][0] == '-') {    char *p = argv[argp] + 1;    char *param;    while (*p != '\0') {      switch (*p) {      default:	psim_usage(0);	error ("");	break;      case 'c':	param = find_arg("Missing <count> option for -c (max-iterations)\n", &argp, argv);	tree_parse(root, "/openprom/options/max-iterations %s", param);	break;      case 'e':	param = find_arg("Missing <emul> option for -e (os-emul)\n", &argp, argv);	tree_parse(root, "/openprom/options/os-emul %s", param);	break;      case 'E':	/* endian spec, ignored for now */	param = find_arg("Missing <endian> option for -E (target-endian)\n", &argp, argv);	if (strcmp (param, "big") == 0)	  tree_parse (root, "/options/little-endian? false");	else if (strcmp (param, "little") == 0)	  tree_parse (root, "/options/little-endian? true");	else	  {	    printf_filtered ("Invalid <endian> option for -E (target-endian)\n");	    psim_usage (0);	  }	break;      case 'f':	param = find_arg("Missing <file> option for -f\n", &argp, argv);	psim_merge_device_file(root, param);	break;      case 'h':      case '?':	psim_usage(1);	break;      case 'H':	psim_usage(2);	break;      case 'i':	if (isdigit(p[1])) {	  tree_parse(root, "/openprom/trace/print-info %c", p[1]);	  p++;	}	else {	  tree_parse(root, "/openprom/trace/print-info 1");	}	break;      case 'I':	tree_parse(root, "/openprom/trace/print-info 2");	tree_parse(root, "/openprom/options/model-issue %d",		   MODEL_ISSUE_PROCESS);	break;      case 'm':	param = find_arg("Missing <model> option for -m (model)\n", &argp, argv);	tree_parse(root, "/openprom/options/model \"%s", param);	break;      case 'n':	param = find_arg("Missing <nr-smp> option for -n (smp)\n", &argp, argv);	tree_parse(root, "/openprom/options/smp %s", param);	break;      case 'o':	param = find_arg("Missing <dev-spec> option for -o\n", &argp, argv);	if (memcmp(param, "mpc860c0", 8) == 0)        {          if (param[8] == '\0')            tree_parse(root, "/options/mpc860c0 5");          else if (param[8] == '=' && is_num(param+9, 1, 10, 0))          {            tree_parse(root, "/options/mpc860c0 %s", param+9);          }          else error("Invalid mpc860c0 option for -o\n");        }	else          current = tree_parse(current, "%s", param);	break;      case 'r':	param = find_arg("Missing <ram-size> option for -r (oea-memory-size)\n", &argp, argv);	tree_parse(root, "/openprom/options/oea-memory-size %s",			       param);	break;      case 't':	param = find_arg("Missing <trace> option for -t (trace/*)\n", &argp, argv);	if (param[0] == '!')	  tree_parse(root, "/openprom/trace/%s 0", param+1);	else	  tree_parse(root, "/openprom/trace/%s 1", param);	break;      case '-':	/* it's a long option of the form --optionname=optionvalue.	   Such options can be passed through if we are invoked by	   gdb.  */	if (strstr(argv[argp], "architecture") != NULL) {          /* we must consume the argument here, so that we get out             of the loop.  */	  p = argv[argp] + strlen(argv[argp]) - 1;	  printf_filtered("Warning - architecture parameter ignored\n");        }	else	  error("Unrecognized option");	break;      }      p += 1;    }    argp += 1;  }  /* force the trace node to process its options now *before* the tree     initialization occures */  device_ioctl(tree_find_device(root, "/openprom/trace"),	       NULL, 0,	       device_ioctl_set_trace);  {    void semantic_init(device* root);    semantic_init(root);  }  /* return where the options end */  return argv + argp;}INLINE_PSIM\(void)psim_command(device *root,	     char **argv){  int argp = 0;  if (argv[argp] == NULL) {    return;  }  else if (strcmp(argv[argp], "trace") == 0) {    const char *opt = find_arg("Missing <trace> option", &argp, argv);    if (opt[0] == '!')      trace_option(opt + 1, 0);    else      trace_option(opt, 1);  }  else if (strcmp(*argv, "change-media") == 0) {    char *device = find_arg("Missing device name", &argp, argv);    char *media = argv[++argp];    device_ioctl(tree_find_device(root, device), NULL, 0,		 device_ioctl_change_media, media);  }  else {    printf_filtered("Unknown PSIM command %s, try\n", argv[argp]);    printf_filtered("    trace <trace-option>\n");

⌨️ 快捷键说明

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