1 static char _[] = "@(#)monitor.c 5.28 93/11/02 11:46:54, Srini, AMD.";
2 /******************************************************************************
3 * Copyright 1991 Advanced Micro Devices, Inc.
5 * This software is the property of Advanced Micro Devices, Inc (AMD) which
6 * specifically grants the user the right to modify, use and distribute this
7 * software provided this notice is not removed or altered. All other rights
10 * AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
11 * SOFTWARE. IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL
12 * DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR
13 * USE OF THIS SOFTWARE.
15 * So that all may benefit from your experience, please report any problems
16 * or suggestions about this software to the 29K Technical Support Center at
17 * 800-29-29-AMD (800-292-9263) in the USA, or 0800-89-1131 in the UK, or
18 * 0031-11-1129 in Japan, toll free. The direct dial number is 512-462-4118.
20 * Advanced Micro Devices, Inc.
21 * 29K Support Products
23 * 5900 E. Ben White Blvd.
26 *****************************************************************************
27 * Engineer: Srini Subramanian.
28 *****************************************************************************
29 * This module implements the monitor command interpreter.
30 *****************************************************************************
44 /* #include <sys/ioctl.h> */
52 /* Function declarations */
53 extern void Mini_Ctrl_C_Handler PARAMS((int));
54 extern void Mini_loop PARAMS((void));
55 extern INT32 Mini_go_forever PARAMS((void));
56 extern void Mini_poll_kbd PARAMS((char *cmd_buffer, int size, int mode));
57 extern int Mini_cmdfile_input PARAMS((char *cmd_buffer, int size));
58 extern int tokenize_cmd PARAMS((char *, char **));
59 extern void lcase_tokens PARAMS((char **, int));
60 extern int get_word PARAMS((char *, INT32 *));
61 extern void PrintTrapMsg PARAMS((int trapnum));
62 extern void display_msg PARAMS((void));
63 extern void display_termuser PARAMS((void));
64 extern void display_term29k PARAMS((void));
65 extern INT32 get_pc_addrs PARAMS((ADDR32 *pc1, ADDR32 *cps));
66 extern INT32 get_pc1_inst PARAMS((ADDR32 cps, ADDR32 pc1, BYTE *inst));
67 extern void dasm_instr PARAMS((ADDR32, struct instr_t *));
68 extern void convert32 PARAMS((BYTE *));
69 extern INT32 Mini_send_init_info PARAMS((INIT_INFO *init));
71 static int FindCmdIndx PARAMS((char *string));
74 GLOBAL struct bkpt_t *bkpt_table;
76 GLOBAL char cmd_buffer[BUFFER_SIZE];
77 GLOBAL char tip_cmd_buffer[256];
78 GLOBAL int GoCmdFlag=0;
80 #define TOGGLE_CHAR (io_config.io_toggle_char)
82 /* Following three vars to be used in stdin/stdout/stderr funcs */
83 #define IO_BUFSIZE 1024
84 static char io_buffer[IO_BUFSIZE];
85 static INT32 io_bufsize;
86 static INT32 io_count_done;
88 static INT32 ProcessorState;
89 static int GrossState;
90 static INT32 exit_loop;
91 static int CtrlCHit=0;
93 /* These modes are defined in montip, udi2mtip.c file */
94 #define TIP_COOKED 0x0
96 #define TIP_CBREAK 0x2
99 #define TIP_NBLOCK 0x10
100 static INT32 TipStdinMode = TIP_COOKED; /* initial */
102 struct termio OldTermbuf, NewTermbuf; /* STDIN, Channel0 */
105 /* Monitor command table */
106 struct MonitorCommands_t {
107 char *CmdString; /* Maximum length */
108 INT32 (*CmdFn) PARAMS((char **, int));
111 static struct MonitorCommands_t MonitorCommands[] = {
113 "attach", set_sessionid_cmd,
121 "cp", create_proc_cmd,
131 "dp", destroy_proc_cmd,
132 "disc", disconnect_cmd,
133 "detach", disconnect_cmd,
136 "eoff", echomode_off,
148 "init", init_proc_cmd,
152 "logoff", logoff_cmd,
156 "qoff", quietmode_off,
165 "sid", set_sessionid_cmd,
167 "target", connect_cmd,
183 static char *TrapMsg[] = {
187 "Coprocessor Not Present",
188 "Coprocessor Exception",
189 "Protection Violation",
190 "Instruction Access Exception",
191 "Data Access Exception",
192 "User-Mode Instruction TLB Miss",
193 "User-Mode Data TLB Miss",
194 "Supervisor-Mode Instruction TLB Miss",
195 "Supervisor-Mode Data TLB Miss",
196 "Instruction TLB Protection Violation",
197 "Data TLB Protection Violation",
206 "Floating-Point Exception"
213 /* Initialize breakpoint table */
216 GrossState = NOTEXECUTING;
219 * Start with the user being the terminal controller.
221 io_config.io_control = TERM_USER;
222 io_config.target_running = FALSE;
225 ioctl (fileno(stdin), TCGETA, &OldTermbuf); /* Initial settings */
229 * Define Ctrl-U as the io_toggle_char as default.
231 io_config.io_toggle_char = (BYTE) 21;
234 ** Open cmd file (if necessary)
237 if (io_config.cmd_file_io == TRUE) { /* TRUE if -c option given */
238 io_config.cmd_file = fopen(io_config.cmd_filename, "r");
239 if (io_config.cmd_file == NULL) {
241 io_config.cmd_file_io = FALSE;
243 /* MON_STDIN is command file */
244 MON_STDIN = fileno(io_config.cmd_file); /* set MON_STDIN */
249 ** Open log file, if no command file given.
252 if (io_config.log_mode == (INT32) TRUE) { /* -log option given */
253 if (io_config.log_filename) {
254 io_config.log_file = fopen(io_config.log_filename, "w");
255 if (io_config.log_file == NULL) {
256 io_config.log_mode = (INT32) FALSE;
260 io_config.log_mode = (INT32) FALSE;
265 /* Install ctrl-C handler */
267 if (signal (SIGINT, Mini_Ctrl_C_Handler) == SIG_ERR) {
268 fprintf(stderr, "Ctrl-C handler not installed.\n"); /* warning */
269 if (io_config.echo_mode == (INT32) TRUE)
270 fprintf(io_config.echo_file, "Ctrl-C handler not installed.\n"); /* warning */
272 /* Get into monitor loop */
283 char *token[MAX_TOKENS];
289 ** Enter command interpreter loop
292 fprintf(stderr, "%s>", ProgramName);
293 if (io_config.echo_mode == (INT32) TRUE)
294 fprintf(io_config.echo_file, "%s>", ProgramName);
296 BlockMode = BLOCK; /* wait for a user command */
302 fprintf(stderr, "\n%s>", ProgramName);
303 if (io_config.echo_mode == (INT32) TRUE)
304 fprintf(io_config.echo_file, "\n%s>", ProgramName);
307 ** If the target was set to run, get its current status.
309 if (Mini_get_target_stats((INT32) udi_waittime, &ProcessorState) != SUCCESS) {
310 Mini_TIP_DestroyProc();
312 fatal_error(EMFATAL);
314 GrossState = (int) (ProcessorState & 0xFF);
315 switch (GrossState) {
316 case NOTEXECUTING: /* do nothing */
317 io_config.io_control=TERM_USER;
318 io_config.target_running = FALSE;
319 BlockMode = BLOCK; /* wait for a user command */
321 case EXITED: /* do nothing */
325 ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */
328 fprintf (stderr, "Process exited with 0x%lx\n",
329 (ProcessorState >> 8));
330 if (io_config.echo_mode == (INT32) TRUE)
331 fprintf (io_config.echo_file, "Process exited with 0x%lx\n",
332 (ProcessorState >> 8));
334 fprintf (stderr, "%s>", ProgramName);
335 if (io_config.echo_mode == (INT32) TRUE)
336 fprintf (io_config.echo_file, "%s> ", ProgramName);
338 io_config.io_control=TERM_USER;
339 io_config.target_running = FALSE;
340 BlockMode = BLOCK; /* wait for a user command */
342 case RUNNING: /* any request from target? */
343 io_config.target_running = TRUE;
344 BlockMode = NONBLOCK; /* return immediately */
347 io_config.io_control=TERM_USER;
348 io_config.target_running = TRUE;
352 ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */
354 fprintf(stderr, "Execution stopped at ");
355 if (io_config.echo_mode == (INT32) TRUE)
356 fprintf(io_config.echo_file, "Execution stopped at ");
359 BlockMode = BLOCK; /* wait for next user command */
362 io_config.io_control=TERM_USER;
363 io_config.target_running = FALSE;
367 ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */
369 fprintf(stderr, "Breakpoint hit at ");
370 if (io_config.echo_mode == (INT32) TRUE)
371 fprintf(io_config.echo_file, "Breakpoint hit at ");
374 BlockMode = BLOCK; /* wait for next user command */
377 io_config.io_control=TERM_USER;
378 io_config.target_running = FALSE;
382 ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */
384 fprintf(stderr, "Stepping... Execution stopped at ");
385 if (io_config.echo_mode == (INT32) TRUE)
386 fprintf(io_config.echo_file, "Stepping...Execution stopped at ");
389 BlockMode = BLOCK; /* wait for next user command */
392 io_config.io_control=TERM_USER;
393 io_config.target_running = FALSE;
396 io_config.io_control=TERM_USER;
397 io_config.target_running = FALSE;
401 ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */
403 fprintf(stderr, "Execution halted at ");
404 if (io_config.echo_mode == (INT32) TRUE)
405 fprintf(io_config.echo_file, "Execution halted at ");
408 BlockMode = BLOCK; /* wait for next user command */
411 io_config.io_control=TERM_USER;
412 io_config.target_running = FALSE;
415 io_config.io_control=TERM_USER;
416 io_config.target_running = FALSE;
420 ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */
422 PrintTrapMsg((int) (ProcessorState >> 8));
425 BlockMode = BLOCK; /* wait for next user command */
429 io_count_done = (INT32) 0;
431 Mini_get_stdout(io_buffer, IO_BUFSIZE, &io_count_done);
432 write(MON_STDOUT, &io_buffer[0], (int) io_count_done);
433 if (io_config.echo_mode == (INT32) TRUE) {
434 fflush (io_config.echo_file);
435 write (fileno(io_config.echo_file), &io_buffer[0], (int) io_count_done);
437 } while (io_count_done == (INT32) IO_BUFSIZE);
441 io_count_done = (INT32) 0;
443 Mini_get_stderr(io_buffer, IO_BUFSIZE, &io_count_done);
444 write(MON_STDERR, &io_buffer[0], (int) io_count_done);
445 if (io_config.echo_mode == (INT32) TRUE) {
446 fflush (io_config.echo_file);
447 write (fileno(io_config.echo_file), &io_buffer[0], (int) io_count_done);
449 } while (io_count_done == (INT32) IO_BUFSIZE);
452 /* Line buffered reads only */
453 if (io_config.cmd_file_io == TRUE) { /* read from command file */
454 if (Mini_cmdfile_input(io_buffer, IO_BUFSIZE) == SUCCESS) {
455 io_bufsize = strlen(io_buffer);
456 fprintf(stderr, "%s", io_buffer); /* echo */
457 if (io_config.echo_mode == (INT32) TRUE)
458 fprintf(io_config.echo_file, "%s", io_buffer); /* echo */
459 } else { /* read from terminal */
460 io_bufsize = read( fileno(stdin), io_buffer, IO_BUFSIZE );
463 io_bufsize = read( fileno(stdin), io_buffer, IO_BUFSIZE );
467 fprintf(stderr, "fatal error reading from stdin\n");
468 if (io_config.echo_mode == (INT32) TRUE)
469 fprintf(io_config.echo_file, "fatal error reading from stdin\n");
471 if (io_config.echo_mode == (INT32) TRUE) {
472 write (fileno(io_config.echo_file), &io_buffer[0], (int) io_bufsize);
473 fflush (io_config.echo_file);
475 Mini_put_stdin(io_buffer, io_bufsize, &io_count_done);
478 /* call TIP to get StdinMode */
479 Mini_stdin_mode_x((INT32 *)&TipStdinMode);
480 if (TipStdinMode & TIP_NBLOCK)
481 io_config.io_control = TERM_29K;
482 else if (TipStdinMode & TIP_ASYNC)
483 io_config.io_control = TERM_29K;
484 else if (TipStdinMode == TIP_COOKED)
485 io_config.io_control = TERM_USER;
487 fprintf(stderr, "DFEWARNING: TIP Requested Stdin Mode Not Supported.\n");
488 fprintf(stderr, "DFEWARNING: Using default mode.\n");
489 TipStdinMode = TIP_COOKED;
490 io_config.io_control = TERM_USER;
493 if (io_config.io_control == TERM_29K)
503 ** Check for keyboard input from command file first, then keyboard.
505 if (io_config.io_control == TERM_USER) {
506 if (io_config.target_running == FALSE) {
507 if (io_config.cmd_ready == FALSE) { /* Get a new user command */
508 if (io_config.cmd_file_io == TRUE) { /* try command file first*/
509 if (Mini_cmdfile_input(cmd_buffer, BUFFER_SIZE) == SUCCESS) {
510 fprintf(stderr, "%s", cmd_buffer);
511 io_config.cmd_ready = TRUE;
513 Mini_poll_kbd(cmd_buffer, BUFFER_SIZE, BlockMode);
515 } else { /* keyboard */
516 /* Mini_poll_kbd function sets io_config.cmd_ready */
517 Mini_poll_kbd(cmd_buffer, BUFFER_SIZE, BlockMode);
521 Mini_poll_kbd(cmd_buffer, BUFFER_SIZE, BlockMode);
523 } else if (io_config.io_control == TERM_29K) {
524 if ((GrossState == RUNNING) || GoCmdFlag)
525 Mini_poll_channel0(); /* non-blocking */
527 fprintf(stderr, "fatal error: Don't know who is controlling the terminal!\n");
532 if (io_config.cmd_ready == TRUE) { /* if there is a command in buffer */
534 if (io_config.log_mode == (INT32) TRUE) /* make a log file */
535 fprintf(io_config.log_file, "%s\n", cmd_buffer);
536 if (io_config.echo_mode == (INT32) TRUE)
537 fprintf(io_config.echo_file, "%s\n", cmd_buffer);
539 if (io_config.log_mode == (INT32) TRUE) /* make a log file */
540 fprintf(io_config.log_file, "%s", cmd_buffer);
541 if (io_config.echo_mode == (INT32) TRUE)
542 fprintf(io_config.echo_file, "%s", cmd_buffer);
548 token_count = tokenize_cmd(cmd_buffer, token);
549 /* Convert first character (command) to lcase */
550 if (isupper(*token[0]))
551 (*token[0]) = (char) tolower(*token[0]);
553 /* If anything but a y or z command, convert to lower case */
554 if ( ((*token[0]) != 'y') &&
555 ((*token[0]) != 'z') )
556 lcase_tokens(token, token_count);
558 if ((Indx = FindCmdIndx(token[0])) != (int) FAILURE)
559 io_config.cmd_ready = TRUE;
561 warning(EMNOSUCHCMD);
563 fprintf(stderr, "\n%s>", ProgramName);
564 if (io_config.echo_mode == (INT32) TRUE)
565 fprintf(io_config.echo_file, "\n%s>", ProgramName);
566 io_config.cmd_ready = FALSE; /* nothing to execute */
574 if (io_config.cmd_ready == TRUE) {
575 retval = MonitorCommands[Indx].CmdFn(token, token_count);
576 io_config.cmd_ready = FALSE;
577 if (retval == FAILURE) {
578 fprintf(stderr, "Command failed\n");
579 if (io_config.echo_mode == (INT32) TRUE)
580 fprintf(io_config.echo_file, "Command failed\n");
581 } else if (retval != SUCCESS) {
585 if (io_config.io_control == TERM_USER) {
586 fprintf(stderr, "%s>", ProgramName);
587 if (io_config.echo_mode == (INT32) TRUE)
588 fprintf(io_config.echo_file, "%s>", ProgramName);
594 } while (exit_loop != TRUE); /* end of do-while */
597 if (io_config.log_mode == (INT32) TRUE)
598 (void) fclose(io_config.log_file);
600 if (bkpt_table != NULL)
601 (void) free((char *) bkpt_table);
605 ** This function takes in a string and produces a lower case,
606 ** " argv - argc" style array. Then number of elements in the
607 ** array is returned.
611 tokenize_cmd(cmd, token)
617 /* Break input into tokens */
621 if (cmd[0] != '\0') {
622 token[token_count] = strtok(cmd, " \t,;\n\r");
624 if (token[token_count] != NULL) {
626 token_count = token_count + 1;
627 token[token_count] = strtok((char *) NULL, " \t,;\n\r");
628 } while ((token[token_count] != NULL) &&
629 (token_count < MAX_TOKENS));
637 return (token_count);
639 } /* end tokenize_cmd() */
644 ** This function is used to convert a list of tokens
645 ** to all lower case letters.
649 lcase_tokens(token, token_count)
650 char *token[MAX_TOKENS];
656 for (i=0; i<token_count; i=i+1) {
658 while (*temp_str != '\0') {
659 if (isupper(*temp_str))
660 *temp_str = (char) tolower(*temp_str);
664 } /* end lcase_string() */
670 static int complete=0;
672 /* Terminal control initialization. */
673 io_config.io_control = TERM_USER; /* 3.1-7 */
674 io_config.target_running = TRUE;
677 ioctl (fileno(stdin), TCGETA, &OldTermbuf); /* Initial settings */
680 /* Install ctrl-C handler */
682 if (signal (SIGINT, Mini_Ctrl_C_Handler) == SIG_ERR) {
683 fprintf(stderr, "Ctrl-C handler not installed.\n"); /* warning */
684 if (io_config.echo_mode == (INT32) TRUE)
685 fprintf(io_config.echo_file, "Ctrl-C handler not installed.\n"); /* warning */
688 ** Open cmd file (if necessary)
691 if (io_config.cmd_file_io == TRUE) { /* TRUE if -c option given */
692 io_config.cmd_file = fopen(io_config.cmd_filename, "r");
693 if (io_config.cmd_file == NULL) {
695 io_config.cmd_file_io = FALSE;
697 /* MON_STDIN is command file */
698 MON_STDIN = fileno(io_config.cmd_file); /* set MON_STDIN */
702 Mini_go(); /* set target running */
707 ** If the target was set to run, get its current status.
709 if (Mini_get_target_stats((INT32) udi_waittime, &ProcessorState) != SUCCESS) {
710 Mini_TIP_DestroyProc();
712 fatal_error(EMFATAL);
714 GrossState = (int) (ProcessorState & 0xFF);
715 switch (GrossState) {
716 case NOTEXECUTING: /* do nothing */
717 io_config.io_control = TERM_USER;
718 io_config.target_running = FALSE;
720 case EXITED: /* do nothing */
722 fprintf (stderr, "Process exited with 0x%lx\n",
723 (ProcessorState >> 8));
724 if (io_config.echo_mode == (INT32) TRUE)
725 fprintf (io_config.echo_file, "Process exited with 0x%lx\n",
726 (ProcessorState >> 8));
728 io_config.io_control = TERM_USER;
729 io_config.target_running = FALSE;
732 case RUNNING: /* any request from target? */
736 io_config.io_control = TERM_USER;
737 io_config.target_running = FALSE;
738 fprintf(stderr, "Execution stopped at ");
739 if (io_config.echo_mode == (INT32) TRUE)
740 fprintf(io_config.echo_file, "Execution stopped at ");
745 io_config.io_control = TERM_USER;
746 io_config.target_running = FALSE;
747 fprintf(stderr, "Breakpoint hit at ");
748 if (io_config.echo_mode == (INT32) TRUE)
749 fprintf(io_config.echo_file, "Breakpoint hit at ");
754 io_config.io_control = TERM_USER;
755 io_config.target_running = FALSE;
756 fprintf(stderr, "Stepping...Execution stopped at ");
757 if (io_config.echo_mode == (INT32) TRUE)
758 fprintf(io_config.echo_file, "Stepping...Execution stopped at ");
763 io_config.io_control = TERM_USER;
764 io_config.target_running = FALSE;
768 io_config.io_control = TERM_USER;
769 io_config.target_running = FALSE;
770 fprintf(stderr, "Execution halted at ");
771 if (io_config.echo_mode == (INT32) TRUE)
772 fprintf(io_config.echo_file, "Execution halted at ");
777 io_config.io_control = TERM_USER;
778 io_config.target_running = FALSE;
782 io_config.io_control = TERM_USER;
783 io_config.target_running = FALSE;
784 PrintTrapMsg((int) (ProcessorState >> 8));
789 io_count_done = (INT32) 0;
791 Mini_get_stdout(io_buffer, IO_BUFSIZE, &io_count_done);
792 write(MON_STDOUT, &io_buffer[0], (int) io_count_done);
793 if (io_config.echo_mode == (INT32) TRUE) {
794 fflush (io_config.echo_file);
795 write (fileno(io_config.echo_file), &io_buffer[0], (int) io_count_done);
797 } while (io_count_done == (INT32) IO_BUFSIZE);
801 io_count_done = (INT32) 0;
803 Mini_get_stderr(io_buffer, IO_BUFSIZE, &io_count_done);
804 write(MON_STDERR, &io_buffer[0], (int) io_count_done);
805 if (io_config.echo_mode == (INT32) TRUE) {
806 fflush (io_config.echo_file);
807 write (fileno(io_config.echo_file), &io_buffer[0], (int) io_count_done);
809 } while (io_count_done == (INT32) IO_BUFSIZE);
812 /* Line buffered reads only */
813 if (io_config.cmd_file_io == TRUE) { /* read from command file */
814 if (Mini_cmdfile_input(io_buffer, IO_BUFSIZE) == SUCCESS) {
815 io_bufsize = strlen(io_buffer);
816 fprintf(stderr, "%s", io_buffer); /* echo */
817 if (io_config.echo_mode == (INT32) TRUE)
818 fprintf(io_config.echo_file, "%s", io_buffer); /* echo */
819 } else { /* read from terminal */
820 io_bufsize = read( fileno(stdin), io_buffer, IO_BUFSIZE );
823 io_bufsize = read( fileno(stdin), io_buffer, IO_BUFSIZE );
827 fprintf(stderr, "fatal error reading from stdin\n");
828 if (io_config.echo_mode == (INT32) TRUE)
829 fprintf(io_config.echo_file, "fatal error reading from stdin\n");
831 if (io_config.echo_mode == (INT32) TRUE) {
832 fflush (io_config.echo_file);
833 write (fileno(io_config.echo_file), &io_buffer[0], (int) io_bufsize);
835 Mini_put_stdin(io_buffer, io_bufsize, &io_count_done);
838 /* call TIP to get StdinMode */
839 Mini_stdin_mode_x((INT32 *)&TipStdinMode);
840 if (TipStdinMode & TIP_NBLOCK)
841 io_config.io_control = TERM_29K;
842 else if (TipStdinMode & TIP_ASYNC)
843 io_config.io_control = TERM_29K;
844 else if (TipStdinMode == TIP_COOKED)
845 io_config.io_control = TERM_USER;
847 fprintf(stderr, "DFEWARNING: TIP Requested Stdin Mode Not Supported.\n");
848 fprintf(stderr, "DFEWARNING: Using default mode.\n");
849 TipStdinMode = TIP_COOKED;
850 io_config.io_control = TERM_USER;
852 if (io_config.io_control == TERM_29K)
858 io_config.io_control = TERM_USER;
859 io_config.target_running = FALSE;
864 kbhit(); /* Poll for Ctrl-C */
871 if (io_config.io_control == TERM_29K)
872 if (GrossState == RUNNING)
873 Mini_poll_channel0(); /* non-blocking */
875 TipStdinMode = TIP_COOKED;
879 ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */
885 Mini_TIP_DestroyProc();
888 NumberOfConnections=0;
894 get_pc_addrs(pc1, cps)
905 if ((retval = Mini_read_req (PC_SPACE,
906 (ADDR32) 0, /* doesn't matter */
908 (INT16) 4, /* size */
911 hostendian)) != SUCCESS) {
915 *pc1 = (ADDR32) pc_1;
916 if (host_config.host_endian != host_config.target_endian) {
917 convert32((BYTE *)pc1);
922 if ((retval = Mini_read_req (SPECIAL_REG,
925 (INT16) 4, /* size */
928 hostendian)) != SUCCESS) {
931 *cps = (ADDR32) cps_b;
932 if (host_config.host_endian != host_config.target_endian) {
933 convert32((BYTE *)cps);
940 get_pc1_inst(cps, pc1, inst)
952 if (cps & 0x100L) /* RE bit */
953 memory_space = I_ROM;
955 memory_space = I_MEM;
957 if ((retval = Mini_read_req(memory_space,
960 (INT16) sizeof(INST32), /* size */
963 hostendian)) != SUCCESS) {
975 union instruction_t {
976 BYTE buf[sizeof(struct instr_t)];
977 struct instr_t instr;
979 union instruction_t instruction;
982 (void) get_pc_addrs(&c_pc1, &c_cps);
983 (void) get_pc1_inst(c_cps, c_pc1, instruction.buf);
984 fprintf(stderr, " %08lx\n", c_pc1);
985 if (io_config.echo_mode == (INT32) TRUE)
986 fprintf(io_config.echo_file, " %08lx\n", c_pc1);
987 if (host_config.target_endian == LITTLE) {
988 temp.op = instruction.instr.b;
989 temp.c = instruction.instr.a;
990 temp.a = instruction.instr.c;
991 temp.b = instruction.instr.op;
992 } else { /* default BIG endian */
993 temp.op = instruction.instr.op;
994 temp.c = instruction.instr.c;
995 temp.a = instruction.instr.a;
996 temp.b = instruction.instr.b;
998 fprintf(stderr, "%08lx\t %02x%02x%02x%02x\t", c_pc1,
1003 if (io_config.echo_mode == (INT32) TRUE)
1004 fprintf(io_config.echo_file, "%08lx\t %02x%02x%02x%02x\t", c_pc1,
1009 (void) dasm_instr(c_pc1, &(temp));
1010 if (io_config.io_control == TERM_USER) {
1011 fprintf(stderr, "\n%s>", ProgramName);
1013 if (io_config.echo_mode == (INT32) TRUE)
1014 fprintf(io_config.echo_file, "\n%s>", ProgramName);
1019 Mini_cmdfile_input(cmd_buffer, size)
1023 if (fgets(cmd_buffer, size, io_config.cmd_file) == NULL) {
1024 io_config.cmd_file_io = FALSE;
1025 (void) fclose(io_config.cmd_file);
1026 MON_STDIN = fileno (stdin); /* reset to terminal after EOF */
1034 Mini_Ctrl_C_Handler(num)
1037 CtrlCHit = 1; /* used for run-only mode, no debugging */
1038 if (io_config.io_control == TERM_29K) {
1040 ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */
1043 if (io_config.target_running == TRUE)
1045 io_config.cmd_ready == FALSE;
1047 if (signal (SIGINT, Mini_Ctrl_C_Handler) == SIG_ERR) {
1048 fprintf(stderr, "Ctrl-C handler not installed.\n"); /* warning */
1049 if (io_config.echo_mode == (INT32) TRUE)
1050 fprintf(io_config.echo_file, "Ctrl-C handler not installed.\n"); /* warning */
1057 FindCmdIndx(CmdString)
1063 while (MonitorCommands[i].CmdString) {
1064 if (strcmp(CmdString, MonitorCommands[i].CmdString))
1073 escape_cmd(token, tokencnt)
1079 if ((retval = system ((char *) getenv("COMSPEC"))) != 0)
1080 return ((INT32) EMDOSERR);
1081 return ((INT32) SUCCESS);
1083 if ((retval = system ((char *) getenv("SHELL"))) != 0)
1084 return ((INT32) EMSYSERR);
1085 return ((INT32) SUCCESS);
1090 dummy_cmd(token, tokencnt)
1098 quit_cmd(token, tokencnt)
1104 for (i =0; i < NumberOfConnections; i++) {
1105 Mini_TIP_SetCurrSession(Session_ids[i]);
1106 Mini_TIP_DestroyProc();
1112 NumberOfConnections=0;
1117 connect_cmd(token, tokencnt)
1126 if ((retval = Mini_TIP_init(token[1], &Session_ids[NumberOfConnections]))
1128 NumberOfConnections=NumberOfConnections+1;
1131 return ((INT32) retval);
1135 disconnect_cmd(token, tokencnt)
1142 if ((retval = Mini_TIP_disc()) != SUCCESS)
1143 return ((INT32) retval);
1144 else { /* find some other session */
1145 NumberOfConnections=NumberOfConnections - 1;
1146 for (i = 0; i < NumberOfConnections; i++) {
1147 if ((retval = Mini_TIP_SetCurrSession(Session_ids[i])) == SUCCESS)
1150 if (i >= NumberOfConnections) { /* exit DFE */
1155 return ((INT32) retval);
1159 create_proc_cmd(token, tokencnt)
1165 retval = Mini_TIP_CreateProc();
1167 return ((INT32) retval);
1171 capab_cmd(token, tokencnt)
1177 retval = Mini_TIP_Capabilities();
1179 return ((INT32) retval);
1183 exit_conn_cmd(token, tokencnt)
1190 if ((retval = Mini_TIP_exit()) != SUCCESS) {;
1192 } else { /* find some other session */
1193 NumberOfConnections=NumberOfConnections - 1;
1194 for (i = 0; i < NumberOfConnections; i++) {
1195 if ((retval = Mini_TIP_SetCurrSession(Session_ids[i])) == SUCCESS)
1198 if (i >= NumberOfConnections) { /* exit DFE */
1204 return ((INT32) retval);
1208 init_proc_cmd(token, tokencnt)
1214 retval = Mini_send_init_info(&init_info);
1216 return ((INT32) retval);
1220 destroy_proc_cmd(token, tokencnt)
1226 retval = Mini_TIP_DestroyProc();
1228 return ((INT32) retval);
1232 set_sessionid_cmd(token, tokencnt)
1242 if (sscanf(token[1],"%d",&sid) != 1)
1245 retval = Mini_TIP_SetCurrSession(sid);
1247 return ((INT32) retval);
1251 set_pid_cmd(token, tokencnt)
1261 if (sscanf(token[1],"%d",&pid) != 1)
1264 retval = Mini_TIP_SetPID(pid);
1266 return ((INT32) retval);
1271 go_cmd(token, token_count)
1278 if ((retval = Mini_go()) != SUCCESS) {
1282 BlockMode = NONBLOCK;
1283 if (TipStdinMode & TIP_NBLOCK)
1284 io_config.io_control = TERM_29K;
1285 else if (TipStdinMode & TIP_ASYNC)
1286 io_config.io_control = TERM_29K;
1287 else if (TipStdinMode == TIP_COOKED)
1288 io_config.io_control = TERM_USER;
1290 TipStdinMode = TIP_COOKED;
1291 io_config.io_control = TERM_USER;
1293 io_config.target_running = TRUE;
1297 } /* end go_cmd() */
1300 ** This command is used to "trace" or step through code.
1301 ** A "t" command with no parameters defaults to a single.
1302 ** step. A "t" command with an integer value following
1303 ** steps for as many instructions as is specified by
1308 trace_cmd(token, token_count)
1316 if (token_count == 1) {
1320 if (token_count >= 2) {
1321 result = get_word(token[1], &count);
1326 if ((retval = Mini_step(count)) != SUCCESS) {
1330 BlockMode = NONBLOCK;
1331 if (TipStdinMode & TIP_NBLOCK)
1332 io_config.io_control = TERM_29K;
1333 else if (TipStdinMode & TIP_ASYNC)
1334 io_config.io_control = TERM_29K;
1335 else if (TipStdinMode == TIP_COOKED)
1336 io_config.io_control = TERM_USER;
1338 TipStdinMode = TIP_COOKED;
1339 io_config.io_control = TERM_USER;
1341 io_config.target_running = TRUE;
1345 } /* end trace_cmd() */
1348 * The "ch0" command is used to send characters (input) to the application
1349 * program asynchronously. This command deinstalls the control-C handler,
1350 * sets up input to raw mode, polls the keyboard, sends the bytes to the
1351 * TIP. The command is exited when Ctrl-U is typed.
1355 channel0_cmd(token, token_count)
1359 io_config.io_control = TERM_29K;
1361 ioctl (fileno(stdin), TCGETA, &NewTermbuf); /* New settings */
1362 NewTermbuf.c_lflag &= ~(ICANON);
1363 NewTermbuf.c_cc[4] = 0; /* MIN */
1364 NewTermbuf.c_cc[5] = 0; /* TIME */
1365 ioctl (fileno(stdin), TCSETA, &NewTermbuf); /* Set new settings */
1371 * Only for stdin, not for command file input
1374 Mini_poll_channel0()
1378 /* read from terminal */
1382 ch = (unsigned char) getche();
1383 if (io_config.echo_mode == (INT32) TRUE) {
1384 putc (ch, io_config.echo_file);
1385 fflush (io_config.echo_file);
1387 if (ch == (BYTE) TOGGLE_CHAR) { /* Ctrl-U typed, give control back to User */
1388 io_config.io_control = TERM_USER;
1392 if (ch == (unsigned char) 13) { /* \r, insert \n */
1393 putchar(10); /* line feed */
1394 if (io_config.echo_mode == (INT32) TRUE) {
1395 putc (ch, io_config.echo_file);
1396 fflush (io_config.echo_file);
1400 if (ch == (unsigned char) 10) { /* \n, ignore \n */
1404 Mini_put_stdin((char *)&ch, 1, &io_count_done);
1411 * Set STDIN to CBREAK mode. For each character read() send it
1412 * to TIP using Mini_put_stdin(). This is done only if the
1413 * terminal is controlled by the 29K Target System, i.e. when
1414 * io_config.io_control == TERM_29K. Otherwise, this function should
1415 * not be called as it would affect the command-line processing.
1417 /* while ((io_bufsize = read (fileno(stdin), &ch, 1)) == 1) { */
1418 if ((io_bufsize = read (fileno(stdin), &ch, 1)) == 1) {
1419 if (io_config.echo_mode == (INT32) TRUE) {
1420 putc (ch, io_config.echo_file);
1421 fflush (io_config.echo_file);
1423 if (ch == (BYTE) TOGGLE_CHAR) { /* process ctrl-U */
1424 ioctl (fileno(stdin), TCSETA, &OldTermbuf); /* reset old settings */
1425 io_config.io_control = TERM_USER;
1428 } else { /* send it to TIP */
1429 Mini_put_stdin((char *)&ch, 1, &io_count_done);
1434 } /* end Mini_poll_channel0() */
1440 if ((num >= 0) && (num <= 22)) {
1441 fprintf(stderr, "%s Trap occurred at ", TrapMsg[num]);
1442 if (io_config.echo_mode == (INT32) TRUE)
1443 fprintf(io_config.echo_file, "%s Trap occurred at ", TrapMsg[num]);
1445 fprintf(stderr, "Trap %d occurred at ");
1446 if (io_config.echo_mode == (INT32) TRUE)
1447 fprintf(io_config.echo_file, "Trap %d occurred at ");
1454 fprintf(stderr,"\nTerminal controlled 29K target...Type Ctrl-U <ret> for mondfe prompt\n");
1456 if (io_config.echo_mode == (INT32) TRUE)
1457 fprintf(stderr,"\nTerminal controlled 29K target...Type Ctrl-U <ret> for mondfe prompt\n");
1459 ioctl (fileno(stdin), TCGETA, &NewTermbuf); /* New settings */
1460 NewTermbuf.c_lflag &= ~(ICANON);
1461 NewTermbuf.c_cc[4] = 0; /* MIN */
1462 NewTermbuf.c_cc[5] = 0; /* TIME */
1463 ioctl (fileno(stdin), TCSETA, &NewTermbuf); /* Set new settings */
1471 ioctl (fileno(stdin), TCSETA, &OldTermbuf); /*reset settings */
1473 /* Print a prompt */
1474 fprintf(stderr, "\n%s>", ProgramName);
1475 if (io_config.echo_mode == (INT32) TRUE)
1476 fprintf(io_config.echo_file, "\n%s>", ProgramName);
1480 quietmode_off(token, token_count)
1489 quietmode_on(token, token_count)
1498 logoff_cmd(token, token_count)
1502 if (io_config.log_mode == (INT32) TRUE) {
1503 io_config.log_mode = (INT32) FALSE;
1504 (void) fclose(io_config.log_file);
1510 logon_cmd(token, token_count)
1514 if (io_config.log_mode == (INT32) FALSE) {
1515 if (strcmp(io_config.log_filename, "\0") != 0) {/* valid file */
1516 io_config.log_mode = (INT32) TRUE;
1517 if ((io_config.log_file = fopen(io_config.log_filename, "a")) == NULL)
1519 io_config.log_mode = (INT32) FALSE;
1530 set_logfile(token, token_count)
1534 if (token_count < 2) /* insufficient number of args */
1537 (void) strcpy ((char *)(&(io_config.log_filename[0])),token[1]);
1539 if (io_config.log_mode == (INT32) TRUE) { /* replace log file used */
1540 if ((io_config.log_file =
1541 fopen (io_config.log_filename, "w")) == NULL) {
1542 warning (EMLOGOPEN);
1543 io_config.log_mode = (INT32) FALSE;
1546 io_config.log_mode = (INT32) TRUE;
1547 if ((io_config.log_file =
1548 fopen (io_config.log_filename, "w")) == NULL) {
1549 warning (EMLOGOPEN);
1550 io_config.log_mode = (INT32) FALSE;
1558 echomode_on(token, token_count)
1562 if (io_config.echo_mode == (INT32) FALSE) {
1563 if (strcmp(io_config.echo_filename, "\0") != 0) { /* if valid file in effect */
1564 io_config.echo_mode = (INT32) TRUE;
1565 if ((io_config.echo_file = fopen (io_config.echo_filename, "a")) == NULL)
1567 warning (EMECHOPEN);
1568 io_config.echo_mode = (INT32) FALSE;
1571 warning(EMINVECHOFILE);
1577 echomode_off(token, token_count)
1581 if (io_config.echo_mode == (INT32) TRUE) {
1582 io_config.echo_mode = (INT32) FALSE;
1583 (void) fclose(io_config.echo_file);
1589 echofile_cmd(token, token_count)
1593 if (token_count < 2) /* insufficient number of args */
1596 (void) strcpy ((char *)(&(io_config.echo_filename[0])),token[1]);
1598 if (io_config.echo_mode == (INT32) TRUE) { /* replace echo file used */
1599 if ((io_config.echo_file =
1600 fopen (io_config.echo_filename, "w")) == NULL) {
1601 warning (EMECHOPEN);
1602 io_config.echo_mode = (INT32) FALSE;
1605 io_config.echo_mode = (INT32) TRUE;
1606 if ((io_config.echo_file =
1607 fopen (io_config.echo_filename, "w")) == NULL) {
1608 warning (EMECHOPEN);
1609 io_config.echo_mode = (INT32) FALSE;
1616 cmdfile_cmd(token, token_count)
1620 if (token_count < 2)
1623 (void) strcpy((char *)(&(io_config.cmd_filename[0])),token[1]);
1625 if (io_config.cmd_file_io == (INT32) TRUE) {
1626 warning (EMCMDFILENEST); /* command file nesting not allowed */
1628 io_config.cmd_file_io = (INT32) TRUE;
1629 if ((io_config.cmd_file = fopen (io_config.cmd_filename,"r")) == NULL) {
1630 warning (EMCMDOPEN);
1631 io_config.cmd_file_io = (INT32) FALSE;
1633 /* MON_STDIN is command file */
1634 MON_STDIN = fileno(io_config.cmd_file); /* set MON_STDIN */
1642 tip_cmd(token, token_count)
1646 if (token_count < 2)
1649 sprintf(tip_cmd_buffer, "%s %s\0", token[0], token[1]);
1651 Mini_put_trans(tip_cmd_buffer);