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

📄 xspim.c

📁 Spim软件的一些源码。其中有Xspim的
💻 C
📖 第 1 页 / 共 2 页
字号:
    }  XtAppMainLoop (app_context);  return (spim_return_value);}static voidsyntax (char *program_name){  XtDestroyApplicationContext (app_context);  fprintf (stderr, "Usage:\n %s", program_name);  fprintf (stderr, "-bare			Bare machine (no pseudo-ops, delayed branches and loads)\n");  fprintf (stderr, "-asm			Extended machine (pseudo-ops, no delayed branches and loads) (default)\n");  fprintf (stderr, "-delayed_branches	Execute delayed branches\n");  fprintf (stderr, "-delayed_loads		Execute delayed loads\n");  fprintf (stderr, "-exception		Load exception handler (default)\n");  fprintf (stderr, "-noexception		Do not load exception handler\n");  fprintf (stderr, "-exception_file <file>	Specify exception handler in place of default\n");  fprintf (stderr, "-quiet			Do not print warnings\n");  fprintf (stderr, "-noquiet		Print warnings (default)\n");  fprintf (stderr, "-mapped_io		Enable memory-mapped IO\n");  fprintf (stderr, "-nomapped_io		Do not enable memory-mapped IO (default)\n");  fprintf (stderr, "-file <file> <args>	Assembly code file and arguments to program\n");  exit (1);}voidcontrol_c_seen (int arg){  write_output (message_out, "\nExecution interrupted\n");  redisplay_data ();  continue_prompt (1);  if (spim_is_running)    longjmp (spim_top_level_env, 1);}voidpopup_console (Widget w, XtPointer client_data, XtPointer call_data){  if (console_is_visible)    {      console_is_visible = 0;      XtPopdown (shell1);    }  else    {      console_is_visible = 1;      XtPopup (shell1, XtGrabNone);    }}voidread_file (char *name){  int error_flag;  if (*name == '\0')    error_flag = 1;  else    error_flag = read_assembly_file (name);  if (!error_flag)    {      PC = find_symbol_address (DEFAULT_RUN_LOCATION);      redisplay_text ();      center_text_at_PC ();      redisplay_data ();    }}voidstart_program (mem_addr addr){  if (addr == 0)    addr = starting_address ();  if (addr != 0)    execute_program (addr, DEFAULT_RUN_STEPS, 0, 0);}voidexecute_program (mem_addr pc, int steps, int display, int cont_bkpt){  if (!setjmp (spim_top_level_env))    {      char *undefs = undefined_symbol_string ();      if (undefs != NULL)	{	  write_output (message_out, "The following symbols are undefined:\n");	  write_output (message_out, undefs);	  write_output (message_out, "\n");	  free (undefs);	}      spim_is_running = 1;      show_running ();      if (run_program (pc, steps, display, cont_bkpt))	continue_prompt (0);    }  redisplay_text ();  spim_is_running = 0;  center_text_at_PC ();  redisplay_data ();}static voidshow_running (){  Arg args[1];  XtSetArg (args[0], XtNstring, "Running.....");  XtSetValues (register_window, args, ONE);}/* Redisplay the contents of the registers and, if modified, the data   and stack segments. */voidredisplay_data (){  display_registers ();  display_data_seg ();}/* Redisplay the contents of the registers in a wide variety of   formats. */static voiddisplay_registers (){  Arg args [2];  static str_stream ss;  ss_clear (&ss);  format_registers (&ss, print_gpr_hex, print_fpr_hex);  XtSetArg (args[0], XtNstring, (String)ss_to_string (&ss));  XtSetArg (args[1], XtNlength, ss_length (&ss));  XtSetValues (register_window, args, TWO);}/* Redisplay the text segment and ktext segments if they have changed. */voidredisplay_text (){  Arg args [2];  static str_stream ss;  if (!text_modified)    return;  ss_clear (&ss);  format_insts (&ss, TEXT_BOT, text_top);  ss_printf (&ss, "\n\tKERNEL\n");  format_insts (&ss, K_TEXT_BOT, k_text_top);  XtSetArg (args[0], XtNstring, ss_to_string(&ss));  XtSetArg (args[1], XtNlength, ss_length (&ss));  XtSetValues (text_window, args, TWO);  text_modified = 0;}/* Center the text window at the instruction at the current PC and   highlight the instruction. */static voidcenter_text_at_PC (){  char buf[100];  XawTextBlock text;  XawTextPosition start, finish;  static mem_addr prev_PC = 0;  XawTextUnsetSelection(text_window);  if (PC < TEXT_BOT || (PC > text_top && (PC < K_TEXT_BOT || PC > k_text_top)))    return;  sprintf (buf, "\n[0x%08x]", PC);  text.firstPos = 0;  text.length = strlen (buf);  text.ptr = buf;  text.format = FMT8BIT;  /* Find start of line at PC: */  start = XawTextSearch (text_window, prev_PC <= PC ? XawsdRight : XawsdLeft,			 &text);  if (start == XawTextSearchError)    {      start = XawTextSearch (text_window,			     prev_PC > PC ? XawsdRight : XawsdLeft,			     &text);    }  if (start == XawTextSearchError)    {      if (PC != 0x00400000) return;      XawTextSetInsertionPoint (text_window, 0);    }  else    XawTextSetInsertionPoint (text_window, start + 1);  /* Find end of the line: */  text.length = 1;  finish = XawTextSearch (text_window, XawsdRight, &text);  if (finish == XawTextSearchError)    return;  /* Highlight the line: */  XawTextSetSelection(text_window, start + 1, finish);  prev_PC = PC;}/* Display the contents of the data and stack segments, if they have   been modified. */static voiddisplay_data_seg (){  Arg args [2];  static str_stream ss;  if (!data_modified)    return;  ss_clear (&ss);  format_data_segs(&ss);  XtSetArg (args[0], XtNstring, ss_to_string (&ss));  XtSetArg (args[1], XtNlength, ss_length (&ss));  XtSetValues (data_window, args, TWO);  data_modified = 0;}/* IO facilities: */voidwrite_output (port fp, char *fmt, ...){  va_list args;  Widget w;  char io_buffer [IO_BUFFSIZE];  va_start (args, fmt);  w = (Widget) fp.f;  if (w == console && !console_is_visible)    {      XtPopup (shell1, XtGrabNone);      console_is_visible = 1;    }  vsprintf (io_buffer, fmt, args);  va_end (args);  write_text_to_window (w, io_buffer);  /* Look for keyboard input (such as ^C) */  while (XtAppPending (app_context))    {      XEvent event;      XtAppNextEvent (app_context, &event);      XtDispatchEvent (&event);    }}/* Simulate the semantics of fgets, not gets, on an x-window. */voidread_input (char *str, int str_size){  char buffer[11];  KeySym key;  XComposeStatus compose;  XEvent event;  char *ptr;  if (!console_is_visible)    {      XtPopup (shell1, XtGrabNone);      console_is_visible = 1;    }  ptr = str;  while (1 < str_size)		/* Reserve space for null */    {      XtAppNextEvent (app_context, &event);      if (event.type == KeyPress)	{	  int chars = XLookupString (&event.xkey, buffer, 10, &key, &compose);	  if ((key == XK_Return) || (key == XK_KP_Enter))	    {	      *ptr++ = '\n';	      write_text_to_window (console, "\n");	      break;	    }	  else if (*buffer == 3) /* ^C */	    XtDispatchEvent (&event);	  else if (chars > 0)	    {	      /* Event is a character, not a modifier key */	      int n = (chars < str_size - 1 ? chars : str_size - 1);	      strncpy (ptr, buffer, n);	      ptr += n;	      str_size -= n;	      buffer[chars] = '\0';	      write_text_to_window (console, buffer);	    }	}      else	XtDispatchEvent (&event);    }  if (0 < str_size)    *ptr = '\0';}/* Checking for console input is messy with X windows. A key stroke appears   as an X event, which must be read to check its type. In addition, the   functions that read events all block.  So, when we check if console input   is available, we may see an event for a keystroke. If so, save the   keystroke for the next time the program reads a character. */static int previous_char = -1;intconsole_input_available (){  XEvent event;  if (!console_is_visible)    {      XtPopup (shell1, XtGrabNone);      console_is_visible = 1;    }  if (XtAppPending (app_context) != 0)    {      /* There is an event to process: */      XtAppNextEvent (app_context, &event);      if (event.type == KeyPress)	{	  /* Event is a key stroke: */	  char buffer[11];	  KeySym key;	  XComposeStatus compose;	  if (XLookupString (&event.xkey, buffer, 10, &key, &compose) > 0)	    {	      /* Event is a character, not a modifier key */	      if ((key == XK_Return) || (key == XK_KP_Enter))		previous_char = '\n';	      else if (buffer[0] == 3)	/* ^C */		XtDispatchEvent (&event);	      else if (buffer[0] != 0)		previous_char = (int)buffer[0];	      return (1);		/* There is a character */	    }	}      else	{	  XtDispatchEvent (&event);	}    }  return (0);    		/* There is no character */}charget_console_char (){  /* assert (previous_char != -1); */  return (char)previous_char;}voidput_console_char (char c){  char buf[4];  buf[0] = c;  buf[1] = '\0';  if (!console_is_visible)    {      XtPopup (shell1, XtGrabNone);      console_is_visible = 1;    }  write_text_to_window (console, buf);}/* Print an error message. */voiderror (char *fmt, ...){  va_list args;  char io_buffer [IO_BUFFSIZE];  va_start (args, fmt);  vsprintf (io_buffer, fmt, args);  va_end (args);  if (message != 0)    write_text_to_window (message, io_buffer);  else    fprintf (stderr, "%s", io_buffer);}/* Print the error message then exit. */voidfatal_error (char *fmt, ...){  va_list args;  va_start (args, fmt);  fmt = va_arg (args, char *);#ifdef NO_VFPRINTF  _doprnt (fmt, args, stderr);#else  vfprintf (stderr, fmt, args);#endif  exit (-1);}voidrun_error (char *fmt, ...){  va_list args;  char io_buffer [IO_BUFFSIZE];  va_start (args, fmt);  vsprintf (io_buffer, fmt, args);  va_end (args);  if (message != 0)    write_text_to_window (message, io_buffer);  else    fprintf (stderr, "%s", io_buffer);  if (spim_is_running)    longjmp (spim_top_level_env, 1);}static voidwrite_text_to_window (Widget w, char *s){  XawTextBlock textblock;  XawTextPosition ip = XawTextGetInsertionPoint (w);  if (!s || strlen (s) == 0) return;  textblock.firstPos = 0;  textblock.length = strlen (s);  textblock.ptr = s;  textblock.format = FMT8BIT;  XawTextReplace (w, ip, ip, &textblock);  XawTextSetInsertionPoint (w,			    XawTextGetInsertionPoint (w) + textblock.length);}

⌨️ 快捷键说明

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