📄 monitor.c
字号:
static char _[] = "@(#)monitor.c 5.28 93/11/02 11:46:54, Srini, AMD.";/****************************************************************************** * Copyright 1991 Advanced Micro Devices, Inc. * * This software is the property of Advanced Micro Devices, Inc (AMD) which * specifically grants the user the right to modify, use and distribute this * software provided this notice is not removed or altered. All other rights * are reserved by AMD. * * AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS * SOFTWARE. IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL * DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR * USE OF THIS SOFTWARE. * * So that all may benefit from your experience, please report any problems * or suggestions about this software to the 29K Technical Support Center at * 800-29-29-AMD (800-292-9263) in the USA, or 0800-89-1131 in the UK, or * 0031-11-1129 in Japan, toll free. The direct dial number is 512-462-4118. * * Advanced Micro Devices, Inc. * 29K Support Products * Mail Stop 573 * 5900 E. Ben White Blvd. * Austin, TX 78741 * 800-292-9263 ***************************************************************************** * Engineer: Srini Subramanian. ***************************************************************************** * This module implements the monitor command interpreter. ***************************************************************************** */#include <stdio.h>#include <string.h>#include <ctype.h>#include <signal.h>#ifdef MSDOS#include <stdlib.h>#include <conio.h>#include <io.h>#else#include <fcntl.h>#include <termio.h>/* #include <sys/ioctl.h> */#endif#include "monitor.h"#include "main.h"#include "memspcs.h"#include "error.h"#include "miniint.h"/* Function declarations */extern void Mini_Ctrl_C_Handler PARAMS((int));extern void Mini_loop PARAMS((void));extern INT32 Mini_go_forever PARAMS((void));extern void Mini_poll_kbd PARAMS((char *cmd_buffer, int size, int mode));extern int Mini_cmdfile_input PARAMS((char *cmd_buffer, int size));extern int tokenize_cmd PARAMS((char *, char **));extern void lcase_tokens PARAMS((char **, int));extern int get_word PARAMS((char *, INT32 *));extern void PrintTrapMsg PARAMS((int trapnum));extern void display_msg PARAMS((void));extern void display_termuser PARAMS((void));extern void display_term29k PARAMS((void));extern INT32 get_pc_addrs PARAMS((ADDR32 *pc1, ADDR32 *cps));extern INT32 get_pc1_inst PARAMS((ADDR32 cps, ADDR32 pc1, BYTE *inst));extern void dasm_instr PARAMS((ADDR32, struct instr_t *));extern void convert32 PARAMS((BYTE *));extern INT32 Mini_send_init_info PARAMS((INIT_INFO *init));static int FindCmdIndx PARAMS((char *string));/* Globals */GLOBAL struct bkpt_t *bkpt_table;GLOBAL char cmd_buffer[BUFFER_SIZE];GLOBAL char tip_cmd_buffer[256];GLOBAL int GoCmdFlag=0;#define TOGGLE_CHAR (io_config.io_toggle_char)/* Following three vars to be used in stdin/stdout/stderr funcs */#define IO_BUFSIZE 1024static char io_buffer[IO_BUFSIZE]; static INT32 io_bufsize;static INT32 io_count_done;static INT32 ProcessorState;static int GrossState;static INT32 exit_loop;static int CtrlCHit=0;static int BlockMode;/* These modes are defined in montip, udi2mtip.c file */#define TIP_COOKED 0x0#define TIP_RAW 0x1#define TIP_CBREAK 0x2#define TIP_ECHO 0x4#define TIP_ASYNC 0x8#define TIP_NBLOCK 0x10static INT32 TipStdinMode = TIP_COOKED; /* initial */#ifndef MSDOSstruct termio OldTermbuf, NewTermbuf; /* STDIN, Channel0 */#endif /* MSDOS *//* Monitor command table */struct MonitorCommands_t { char *CmdString; /* Maximum length */ INT32 (*CmdFn) PARAMS((char **, int));};static struct MonitorCommands_t MonitorCommands[] = {"a", asm_cmd,"attach", set_sessionid_cmd,"b", bkpt_cmd,"bc", bkpt_cmd,"b050", bkpt_cmd,"b050v", bkpt_cmd,"b050p", bkpt_cmd,"c", config_cmd,"caps", capab_cmd,"cp", create_proc_cmd,"con", connect_cmd,"ch0", channel0_cmd,"d", dump_cmd,"ex", exit_conn_cmd,"dw", dump_cmd,"dh", dump_cmd,"db", dump_cmd,"df", dump_cmd,"dd", dump_cmd,"dp", destroy_proc_cmd,"disc", disconnect_cmd,"detach", disconnect_cmd,"esc", escape_cmd,"eon", echomode_on,"eoff", echomode_off,"f", fill_cmd,"fw", fill_cmd,"fh", fill_cmd,"fb", fill_cmd,"ff", fill_cmd,"fd", fill_cmd,"fs", fill_cmd,"g", go_cmd,"h", help_cmd,"ix", ix_cmd,"il", il_cmd,"init", init_proc_cmd,"k", kill_cmd,"l", dasm_cmd,"logon", logon_cmd,"logoff", logoff_cmd,"m", move_cmd,"pid", set_pid_cmd,"q", quit_cmd,"qoff", quietmode_off,"qon", quietmode_on,"r", reset_cmd,"s", set_cmd,"sw", set_cmd,"sh", set_cmd,"sb", set_cmd,"sf", set_cmd,"sd", set_cmd,"sid", set_sessionid_cmd,"t", trace_cmd,"target", connect_cmd,"tip", tip_cmd,"ver", version_cmd,"xp", xp_cmd,"xc", xc_cmd,"y", yank_cmd,"zc", cmdfile_cmd,"ze", echofile_cmd,"zl", set_logfile,"?", help_cmd,"|", dummy_cmd,"", dummy_cmd,NULL};/* Trap Messages */static char *TrapMsg[] = {"Illegal Opcode","Unaligned Access","Out of Range","Coprocessor Not Present","Coprocessor Exception","Protection Violation","Instruction Access Exception","Data Access Exception","User-Mode Instruction TLB Miss","User-Mode Data TLB Miss","Supervisor-Mode Instruction TLB Miss","Supervisor-Mode Data TLB Miss","Instruction TLB Protection Violation","Data TLB Protection Violation","Timer","Trace","INTR0","INTR1","INTR2","INTR3","TRAP0","TRAP1","Floating-Point Exception"};voidMini_monitor(){ /* Initialize breakpoint table */ bkpt_table = NULL; GrossState = NOTEXECUTING; /* * Start with the user being the terminal controller. */ io_config.io_control = TERM_USER; io_config.target_running = FALSE;#ifndef MSDOS ioctl (fileno(stdin), TCGETA, &OldTermbuf); /* Initial settings */#endif /* * Define Ctrl-U as the io_toggle_char as default. */ io_config.io_toggle_char = (BYTE) 21; /* ** Open cmd file (if necessary) */ if (io_config.cmd_file_io == TRUE) { /* TRUE if -c option given */ io_config.cmd_file = fopen(io_config.cmd_filename, "r"); if (io_config.cmd_file == NULL) { warning (EMCMDOPEN); io_config.cmd_file_io = FALSE; } else { /* MON_STDIN is command file */ MON_STDIN = fileno(io_config.cmd_file); /* set MON_STDIN */ }; } /* ** Open log file, if no command file given. */ if (io_config.log_mode == (INT32) TRUE) { /* -log option given */ if (io_config.log_filename) { io_config.log_file = fopen(io_config.log_filename, "w"); if (io_config.log_file == NULL) { io_config.log_mode = (INT32) FALSE; warning(EMLOGOPEN); } } else { io_config.log_mode = (INT32) FALSE; warning(EMLOGOPEN); } } /* Install ctrl-C handler */ if (signal (SIGINT, Mini_Ctrl_C_Handler) == SIG_ERR) { fprintf(stderr, "Ctrl-C handler not installed.\n"); /* warning */ if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "Ctrl-C handler not installed.\n"); /* warning */ } /* Get into monitor loop */ Mini_loop();}voidMini_loop(){ INT32 retval; int token_count; char *token[MAX_TOKENS]; int Indx; exit_loop = FALSE; CtrlCHit = 0; /* ** Enter command interpreter loop */ fprintf(stderr, "%s>", ProgramName); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "%s>", ProgramName); BlockMode = BLOCK; /* wait for a user command */ do { if (CtrlCHit) { CtrlCHit = 0; /* Print a prompt */ fprintf(stderr, "\n%s>", ProgramName); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "\n%s>", ProgramName); } /* ** If the target was set to run, get its current status. */ if (Mini_get_target_stats((INT32) udi_waittime, &ProcessorState) != SUCCESS) { Mini_TIP_DestroyProc(); Mini_TIP_exit(); fatal_error(EMFATAL); }; GrossState = (int) (ProcessorState & 0xFF); switch (GrossState) { case NOTEXECUTING: /* do nothing */ io_config.io_control=TERM_USER; io_config.target_running = FALSE; BlockMode = BLOCK; /* wait for a user command */ break; case EXITED: /* do nothing */ if (GoCmdFlag) { GoCmdFlag = 0;#ifndef MSDOS ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */#endif if (!QuietMode) { fprintf (stderr, "Process exited with 0x%lx\n", (ProcessorState >> 8)); if (io_config.echo_mode == (INT32) TRUE) fprintf (io_config.echo_file, "Process exited with 0x%lx\n", (ProcessorState >> 8)); } fprintf (stderr, "%s>", ProgramName); if (io_config.echo_mode == (INT32) TRUE) fprintf (io_config.echo_file, "%s> ", ProgramName); } io_config.io_control=TERM_USER; io_config.target_running = FALSE; BlockMode = BLOCK; /* wait for a user command */ break; case RUNNING: /* any request from target? */ io_config.target_running = TRUE; BlockMode = NONBLOCK; /* return immediately */ break; case STOPPED: io_config.io_control=TERM_USER; io_config.target_running = TRUE; if (GoCmdFlag) { GoCmdFlag = 0;#ifndef MSDOS ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */#endif fprintf(stderr, "Execution stopped at "); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "Execution stopped at "); display_msg(); } BlockMode = BLOCK; /* wait for next user command */ break; case BREAK: io_config.io_control=TERM_USER; io_config.target_running = FALSE; if (GoCmdFlag) { GoCmdFlag = 0;#ifndef MSDOS ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */#endif fprintf(stderr, "Breakpoint hit at "); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "Breakpoint hit at "); display_msg(); } BlockMode = BLOCK; /* wait for next user command */ break; case STEPPED: io_config.io_control=TERM_USER; io_config.target_running = FALSE; if (GoCmdFlag) { GoCmdFlag = 0;#ifndef MSDOS ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */#endif fprintf(stderr, "Stepping... Execution stopped at "); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "Stepping...Execution stopped at "); display_msg(); } BlockMode = BLOCK; /* wait for next user command */ break; case WAITING: io_config.io_control=TERM_USER; io_config.target_running = FALSE; break; case HALTED: io_config.io_control=TERM_USER; io_config.target_running = FALSE; if (GoCmdFlag) { GoCmdFlag = 0;#ifndef MSDOS ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */#endif fprintf(stderr, "Execution halted at "); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "Execution halted at "); display_msg(); } BlockMode = BLOCK; /* wait for next user command */ break; case WARNED: io_config.io_control=TERM_USER; io_config.target_running = FALSE; break; case TRAPPED: io_config.io_control=TERM_USER; io_config.target_running = FALSE; if (GoCmdFlag) { GoCmdFlag = 0;#ifndef MSDOS ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */#endif PrintTrapMsg((int) (ProcessorState >> 8)); display_msg(); } BlockMode = BLOCK; /* wait for next user command */ break; case STDOUT_READY: io_bufsize = 0; io_count_done = (INT32) 0; do { Mini_get_stdout(io_buffer, IO_BUFSIZE, &io_count_done); write(MON_STDOUT, &io_buffer[0], (int) io_count_done); if (io_config.echo_mode == (INT32) TRUE) { fflush (io_config.echo_file); write (fileno(io_config.echo_file), &io_buffer[0], (int) io_count_done); } } while (io_count_done == (INT32) IO_BUFSIZE); break; case STDERR_READY: io_bufsize = 0; io_count_done = (INT32) 0; do { Mini_get_stderr(io_buffer, IO_BUFSIZE, &io_count_done); write(MON_STDERR, &io_buffer[0], (int) io_count_done); if (io_config.echo_mode == (INT32) TRUE) { fflush (io_config.echo_file); write (fileno(io_config.echo_file), &io_buffer[0], (int) io_count_done); } } while (io_count_done == (INT32) IO_BUFSIZE); break; case STDIN_NEEDED: /* Line buffered reads only */ if (io_config.cmd_file_io == TRUE) { /* read from command file */ if (Mini_cmdfile_input(io_buffer, IO_BUFSIZE) == SUCCESS) { io_bufsize = strlen(io_buffer); fprintf(stderr, "%s", io_buffer); /* echo */ if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "%s", io_buffer); /* echo */ } else { /* read from terminal */ io_bufsize = read( fileno(stdin), io_buffer, IO_BUFSIZE ); } } else { io_bufsize = read( fileno(stdin), io_buffer, IO_BUFSIZE ); }; if (io_bufsize < 0) { fprintf(stderr, "fatal error reading from stdin\n"); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "fatal error reading from stdin\n"); } if (io_config.echo_mode == (INT32) TRUE) { write (fileno(io_config.echo_file), &io_buffer[0], (int) io_bufsize); fflush (io_config.echo_file); } Mini_put_stdin(io_buffer, io_bufsize, &io_count_done); break; case STDINMODEX: /* call TIP to get StdinMode */ Mini_stdin_mode_x((INT32 *)&TipStdinMode); if (TipStdinMode & TIP_NBLOCK) io_config.io_control = TERM_29K; else if (TipStdinMode & TIP_ASYNC) io_config.io_control = TERM_29K; else if (TipStdinMode == TIP_COOKED) io_config.io_control = TERM_USER; else { fprintf(stderr, "DFEWARNING: TIP Requested Stdin Mode Not Supported.\n"); fprintf(stderr, "DFEWARNING: Using default mode.\n"); TipStdinMode = TIP_COOKED; io_config.io_control = TERM_USER; } if (io_config.io_control == TERM_29K) display_term29k(); break; default: break; }; /* end switch */ /* ** Check for keyboard input from command file first, then keyboard. */ if (io_config.io_control == TERM_USER) { if (io_config.target_running == FALSE) { if (io_config.cmd_ready == FALSE) { /* Get a new user command */ if (io_config.cmd_file_io == TRUE) { /* try command file first*/ if (Mini_cmdfile_input(cmd_buffer, BUFFER_SIZE) == SUCCESS) { fprintf(stderr, "%s", cmd_buffer); io_config.cmd_ready = TRUE; } else { Mini_poll_kbd(cmd_buffer, BUFFER_SIZE, BlockMode); } } else { /* keyboard */ /* Mini_poll_kbd function sets io_config.cmd_ready */ Mini_poll_kbd(cmd_buffer, BUFFER_SIZE, BlockMode); } } } else { Mini_poll_kbd(cmd_buffer, BUFFER_SIZE, BlockMode); } } else if (io_config.io_control == TERM_29K) { if ((GrossState == RUNNING) || GoCmdFlag) Mini_poll_channel0(); /* non-blocking */ } else { fprintf(stderr, "fatal error: Don't know who is controlling the terminal!\n"); return; } if (io_config.cmd_ready == TRUE) { /* if there is a command in buffer */#ifdef MSDOS if (io_config.log_mode == (INT32) TRUE) /* make a log file */ fprintf(io_config.log_file, "%s\n", cmd_buffer); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "%s\n", cmd_buffer);#else if (io_config.log_mode == (INT32) TRUE) /* make a log file */ fprintf(io_config.log_file, "%s", cmd_buffer); if (io_config.echo_mode == (INT32) TRUE) fprintf(io_config.echo_file, "%s", cmd_buffer);#endif /* ** Parse command */ token_count = tokenize_cmd(cmd_buffer, token); /* Convert first character (command) to lcase */ if (isupper(*token[0])) (*token[0]) = (char) tolower(*token[0]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -