📄 xspim.c
字号:
/* SPIM S20 MIPS simulator. X interface to SPIM (Derived from an earlier work by Alan Siow.) Copyright (C) 1990-2004 by James Larus (larus@cs.wisc.edu). ALL RIGHTS RESERVED. SPIM is distributed under the following conditions: You may make copies of SPIM for your own use and modify those copies. All copies of SPIM must retain my name and copyright notice. You may not sell SPIM or distributed SPIM in conjunction with a commerical product or service without the expressed written consent of James Larus. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. *//* $Header: /Software/SPIM/src/xspim.c 26 11/26/04 8:47p Larus $ */#include <stdio.h>#include <setjmp.h>#include <stdarg.h>#include <X11/Intrinsic.h>#include <X11/StringDefs.h>#include <X11/Shell.h>#include <X11/Xlib.h>#include <X11/Xaw/Cardinals.h>#include <X11/Xaw/Paned.h>#include <X11/Xaw/AsciiText.h>#include <X11/Xaw/Text.h>#include <X11/Xaw/Dialog.h>#include <X11/keysym.h>#include "spim.h"#include "string-stream.h"#include "spim-utils.h"#include "inst.h"#include "reg.h"#include "mem.h"#include "y.tab.h"#include "buttons.h"#include "windows.h"#include "xspim.h"#include "sym-tbl.h"typedef struct _AppResources{ String textFont; Boolean bare; Boolean delayed_branches; Boolean delayed_loads; Boolean pseudo; Boolean asmm; Boolean exception; char *exception_file_name; Boolean quiet; Boolean mapped_io; char *filename; char *display2; Boolean hex_gpr; Boolean hex_fpr; char *initial_data_limit; char *initial_data_size; char *initial_k_data_limit; char *initial_k_data_size; char *initial_k_text_size; char *initial_stack_limit; char *initial_stack_size; char *initial_text_size;} AppResources;/* Exported variables: *//* Not local, but not export so all files don't need setjmp.h */jmp_buf spim_top_level_env; /* For ^C */int bare_machine; /* Non-Zero => simulate bare machine */int delayed_branches; /* Non-Zero => simulate delayed branches */int delayed_loads; /* Non-Zero => simulate delayed loads */int accept_pseudo_insts; /* Non-Zero => parse pseudo instructions */int quiet; /* Non-Zero => no warning messages */port message_out, console_out, console_in;int mapped_io; /* Non-zero => activate memory-mapped IO */int pipe_out;int spim_return_value; /* Value returned when spim exits */XtAppContext app_con;Widget message, console = NULL;XtAppContext app_context;XFontStruct *text_font;Dimension button_width;int load_exception_handler;char *exception_file_name = DEFAULT_EXCEPTION_HANDLER;Pixmap mark;/* Local functions: */static void center_text_at_PC ();static char *check_buf_limit (char *, int *, int *);static void create_console_display ();static void display_data_seg ();static char *display_values (mem_addr from, mem_addr to, char *buf, int *limit, int *n);static char *display_insts (mem_addr from, mem_addr to, char *buf, int *limit, int *n);static void display_registers ();static void initialize (AppResources app_res);static mem_addr print_partial_line (mem_addr, char *, int *, int *);static void show_running ();static void syntax (char *program_name);static void write_text_to_window (Widget w, char *s);static String fallback_resources[] ={ "*font: *-courier-medium-r-normal--12-*-75-*", "*Label*font: *-adobe-helvetica-bold-r-*-*-12-*-75-*", "*panel*font: *-adobe-helvetica-medium-r-*-*-12-*-75-*", "*ShapeStyle: Oval", "*dialog*value.translations: #override \\n <Key>Return: confirm()", "*.translations: #override \\n <Ctrl>C: control_c_seen()", "*Form*left: ChainLeft", "*Form*right: ChainLeft", "*Form*top: ChainTop", "*Form*bottom: ChainTop", "*console.label: SPIM Console", "*Shell1*iconName: SPIM Console", NULL,};static XtActionsRec actionTable[2] ={ {"confirm", (XtActionProc) confirm}, {"control_c_seen", (XtActionProc) control_c_seen},};static XtResource resources[] ={ {XtNfont, XtCFont, XtRString, sizeof (char *), XtOffset (AppResources *, textFont), XtRString, NULL}, {"bare", "Bare", XtRBoolean, sizeof (Boolean), XtOffset (AppResources *, bare), XtRImmediate, False}, {"delayed_branches", "Delayed_Branches", XtRBoolean, sizeof (Boolean), XtOffset (AppResources *, delayed_branches), XtRImmediate, False}, {"delayed_loads", "Delayed_Loads", XtRBoolean, sizeof (Boolean), XtOffset (AppResources *, delayed_loads), XtRImmediate, False}, {"pseudo", "Pseudo", XtRBoolean, sizeof (Boolean), XtOffset (AppResources *, pseudo), XtRImmediate, (XtPointer)True}, {"asm", "Asm", XtRBoolean, sizeof (Boolean), XtOffset (AppResources *, asmm), XtRImmediate, False}, {"exception", "Exception", XtRBoolean, sizeof (Boolean), XtOffset (AppResources *, exception), XtRImmediate, (XtPointer) True}, {"exception_file_name", "Exception_File_Name", XtRString, sizeof (char *), XtOffset (AppResources *, exception_file_name), XtRString, NULL}, {"quiet", "Quiet", XtRBoolean, sizeof (Boolean), XtOffset (AppResources *, quiet), XtRImmediate, False}, {"mapped_io", "Mapped_IO", XtRBoolean, sizeof (Boolean), XtOffset (AppResources *, mapped_io), XtRImmediate, False}, {"filename", "Filename", XtRString, sizeof (char *), XtOffset (AppResources *, filename), XtRString, NULL}, {"display2", "Display2", XtRString, sizeof (char *), XtOffset (AppResources *, display2), XtRString, NULL}, {"hexGpr", "DisplayHex", XtRBoolean, sizeof (Boolean), XtOffset (AppResources *, hex_gpr), XtRImmediate, (XtPointer) True}, {"hexFpr", "DisplayHex", XtRBoolean, sizeof (Boolean), XtOffset (AppResources *, hex_fpr), XtRImmediate, False}, {"stext", "Stext", XtRString, sizeof (char *), XtOffset (AppResources *, initial_text_size), XtRString, NULL}, {"sdata", "Sdata", XtRString, sizeof (char *), XtOffset (AppResources *, initial_data_size), XtRString, NULL}, {"ldata", "Ldata", XtRString, sizeof (char *), XtOffset (AppResources *, initial_data_limit), XtRString, NULL}, {"sstack", "Sstack", XtRString, sizeof (char *), XtOffset (AppResources *, initial_stack_size), XtRString, NULL}, {"lstack", "Lstack", XtRString, sizeof (char *), XtOffset (AppResources *, initial_stack_limit), XtRString, NULL}, {"sktext", "Sktext", XtRString, sizeof (char *), XtOffset (AppResources *, initial_k_text_size), XtRString, NULL}, {"skdata", "Skdata", XtRString, sizeof (char *), XtOffset (AppResources *, initial_k_data_size), XtRString, NULL}, {"lkdata", "Lkdata", XtRString, sizeof (char *), XtOffset (AppResources *, initial_k_data_limit), XtRString, NULL}};static XrmOptionDescRec options[] ={ {"-asm", "asmm", XrmoptionNoArg, "True"}, {"-a", "asmm", XrmoptionNoArg, "True"}, {"-bare", "bare", XrmoptionNoArg, "True"}, {"-b", "bare", XrmoptionNoArg, "True"}, {"-delayed_branches", "delayed_branches", XrmoptionNoArg, "True"}, {"-db", "delayed_branches", XrmoptionNoArg, "True"}, {"-delayed_loads", "delayed_loads", XrmoptionNoArg, "True"}, {"-dl", "delayed_loads", XrmoptionNoArg, "True"}, {"-exception", "exception", XrmoptionNoArg, "True"}, {"-e", "exception", XrmoptionNoArg, "True"}, {"-noexception", "exception", XrmoptionNoArg, "False"}, {"-ne", "exception", XrmoptionNoArg, "False"}, {"-exception_file_name", "exception_file_name", XrmoptionSepArg, NULL}, {"-ef", "exception_file_name", XrmoptionSepArg, NULL}, {"-mapped_io", "mapped_io", XrmoptionNoArg, "True"}, {"-mio", "mapped_io", XrmoptionNoArg, "True"}, {"-nomapped_io","mapped_io", XrmoptionNoArg, "False"}, {"-nmio","mapped_io", XrmoptionNoArg, "False"}, {"-pseudo", "pseudo", XrmoptionNoArg, "True"}, {"-p", "pseudo", XrmoptionNoArg, "True"}, {"-nopseudo", "pseudo", XrmoptionNoArg, "False"}, {"-np", "pseudo", XrmoptionNoArg, "False"}, {"-quiet", "quiet", XrmoptionNoArg, "True"}, {"-q", "quiet", XrmoptionNoArg, "True"}, {"-noquiet","quiet", XrmoptionNoArg, "False"}, {"-nq","quiet", XrmoptionNoArg, "False"}, {"-trap", "exception", XrmoptionNoArg, "True"}, {"-t", "exception", XrmoptionNoArg, "True"}, {"-notrap", "exception", XrmoptionNoArg, "False"}, {"-nt", "exception", XrmoptionNoArg, "False"}, {"-trap_file_name", "exception_file_name", XrmoptionSepArg, NULL}, {"-tf", "exception_file_name", XrmoptionSepArg, NULL}, {"-stext", "stext", XrmoptionSepArg, NULL}, {"-st", "stext", XrmoptionSepArg, NULL}, {"-sdata", "sdata", XrmoptionSepArg, NULL}, {"-sd", "sdata", XrmoptionSepArg, NULL}, {"-ldata", "ldata", XrmoptionSepArg, NULL}, {"-ld", "ldata", XrmoptionSepArg, NULL}, {"-sstack", "sstack", XrmoptionSepArg, NULL}, {"-ss", "sstack", XrmoptionSepArg, NULL}, {"-lstack", "lstack", XrmoptionSepArg, NULL}, {"-ls", "lstack", XrmoptionSepArg, NULL}, {"-sktext", "sktext", XrmoptionSepArg, NULL}, {"-skt", "sktext", XrmoptionSepArg, NULL}, {"-skdata", "skdata", XrmoptionSepArg, NULL}, {"-skd", "skdata", XrmoptionSepArg, NULL}, {"-lkdata", "lkdata", XrmoptionSepArg, NULL}, {"-lkd", "lkdata", XrmoptionSepArg, NULL}, {"-file", "filename", XrmoptionSepArg, NULL}, {"-f", "filename", XrmoptionSepArg, NULL}, {"-d2", "display2", XrmoptionSepArg, NULL}, {"-hexgpr", "hexGpr", XrmoptionNoArg, "True"}, {"-nohexgpr", "hexGpr", XrmoptionNoArg, "False"}, {"-hexfpr", "hexFpr", XrmoptionNoArg, "True"}, {"-nohexfpr", "hexFpr", XrmoptionNoArg, "False"},};#define TICK_WIDTH 10#define TICK_HEIGHT 10static unsigned char tick_bits[] = { 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x80, 0x01, 0xc1, 0x00, 0x63, 0x00, 0x36, 0x00, 0x1c, 0x00, 0x08, 0x00, 0x00, 0x00};/* Flags to control the way that registers are displayed. */static int print_gpr_hex; /* Print GPRs in hex/decimal */static int print_fpr_hex; /* Print FPRs in hex/floating point *//* Local variables: */static Dimension app_width;static Dimension button_height;static Dimension command_height;static Dimension command_hspace;static Dimension command_vspace;static int console_is_visible;static Dimension display_height;static char *file_name = NULL;static Dimension reg_min_height;static Dimension reg_max_height;static Dimension segment_height;static Widget shell1;static int spim_is_running = 0;static Widget toplevel;static Widget pane1;static voidinitialize (AppResources app_res){ bare_machine = 0; delayed_branches = 0; delayed_loads = 0; accept_pseudo_insts = 1; quiet = 0; if (app_res.bare) { bare_machine = 1; delayed_branches = 1; delayed_loads = 1; } if (app_res.asmm) { bare_machine = 0; delayed_branches = 0; delayed_loads = 0; } if (app_res.delayed_branches) delayed_branches = 1; if (app_res.delayed_loads) delayed_loads = 1; if (app_res.pseudo) accept_pseudo_insts = 1; else accept_pseudo_insts = 0; if (app_res.exception) load_exception_handler = 1; else load_exception_handler = 0; if (app_res.exception_file_name) { exception_file_name = app_res.exception_file_name; load_exception_handler = 1; } if (app_res.quiet) quiet = 1; else quiet = 0; if (app_res.mapped_io) mapped_io = 1; else mapped_io = 0; if (app_res.filename) file_name = app_res.filename; if (app_res.textFont == NULL) app_res.textFont = XtNewString ("8x13"); if (!(text_font = XLoadQueryFont (XtDisplay (toplevel), app_res.textFont))) fatal_error ("Cannot open font %s\n", app_res.textFont); mark = XCreateBitmapFromData (XtDisplay (toplevel), RootWindowOfScreen (XtScreen (toplevel)), (char*)tick_bits, TICK_WIDTH, TICK_HEIGHT); button_height = TEXTHEIGHT * 1.6; button_width = TEXTWIDTH * 12; app_width = 6 * (button_width + 16); if ((unsigned)app_width < TEXTWIDTH * 4 * 22) /* Register display width */ app_width = TEXTWIDTH * 4 * 22; command_hspace = 8; command_vspace = 8; command_height = (button_height * 2) + (command_vspace * 3); reg_min_height = 15 * TEXTHEIGHT + 4; reg_max_height = reg_min_height + 10 * TEXTHEIGHT + 4; segment_height = 8 * TEXTHEIGHT + 4; display_height = 8 * TEXTHEIGHT + 4; print_gpr_hex = app_res.hex_gpr; print_fpr_hex = app_res.hex_fpr;}static voidcreate_console_display (){ Arg args[10]; Cardinal n; n = 0; XtSetArg (args[n], XtNeditType, XawtextAppend); n++; XtSetArg (args[n], XtNscrollVertical, XawtextScrollWhenNeeded); n++; XtSetArg (args[n], XtNpreferredPaneSize, TEXTHEIGHT * 24); n++; XtSetArg (args[n], XtNwidth, TEXTWIDTH * 80); n++; console = XtCreateManagedWidget ("console", asciiTextWidgetClass, pane1, args, n); XawTextEnableRedisplay (console); console_out.f = (FILE*) console;}voidclear_console_display (){ Arg args[10]; Cardinal n; XtSetArg (args[0], XtNstring, ""); XtSetValues(console, args, 1);}intmain (int argc, char **argv){ Widget toplevel2; AppResources app_res; Display *display; spim_return_value = 0; if (getenv ("SPIM_EXCEPTION_HANDLER") != NULL) exception_file_name = getenv("SPIM_EXCEPTION_HANDLER"); toplevel = XtAppInitialize (&app_context, "Xspim", options, XtNumber (options), &argc, argv, fallback_resources, NULL, ZERO); if (argc >= 0 && argv[argc] != NULL && argv[argc][0] == '-') syntax (argv[0]); /* Bad command line argument */ XtGetApplicationResources (toplevel, (XtPointer) &app_res, resources, XtNumber (resources), NULL, ZERO); if (app_res.display2 == NULL) display = XtDisplay (toplevel); else display = XtOpenDisplay (app_context, app_res.display2, "xspim", "Xspim", NULL, ZERO, &argc, argv); toplevel2 = XtAppCreateShell ("xspim","Xspim",applicationShellWidgetClass, display, NULL, ZERO); XtAppAddActions (app_context, actionTable, XtNumber (actionTable)); initialize (app_res); /* Console window */ shell1 = XtCreatePopupShell ("Shell1", topLevelShellWidgetClass, toplevel, NULL, ZERO); pane1 = XtCreateManagedWidget ("pane1", panedWidgetClass, shell1, NULL, ZERO); create_console_display (); create_sub_windows (toplevel, app_width, reg_min_height, reg_max_height, command_height, command_hspace, command_vspace, button_height, segment_height, display_height); XtRealizeWidget (toplevel); if (app_res.initial_text_size != NULL) initial_text_size = atoi (app_res.initial_text_size); if (app_res.initial_data_size != NULL) initial_data_size = atoi (app_res.initial_data_size); if (app_res.initial_data_limit != NULL) initial_data_limit = atoi (app_res.initial_data_limit); if (app_res.initial_stack_size != NULL) initial_stack_size = atoi (app_res.initial_stack_size); if (app_res.initial_stack_limit != NULL) initial_stack_limit = atoi (app_res.initial_stack_limit); if (app_res.initial_k_text_size != NULL) initial_k_text_size = atoi (app_res.initial_k_text_size); if (app_res.initial_k_data_size != NULL) initial_k_data_size = atoi (app_res.initial_k_data_size); if (app_res.initial_k_data_limit != NULL) initial_k_data_limit = atoi (app_res.initial_k_data_limit); write_startup_message (); initialize_world (load_exception_handler ? exception_file_name : NULL); if (file_name == NULL && argc > 1 && argv[argc - 1] != NULL) { /* The first unprocessed argument (aside from program name) is taken as a filename containing input program. */ file_name = argv[argc - 1]; } if (file_name) { read_file (file_name); record_file_name_for_prompt (file_name); } else { PC = starting_address (); redisplay_text (); center_text_at_PC (); redisplay_data ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -