* dbxread.c (read_dbx_dynamic_symtab): Reinstall support for sun3,
[deliverable/binutils-gdb.git] / gdb / remote-os9k.c
1 /* Remote debugging interface for boot monitors, for GDB.
2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 /* This file was derived from remote-eb.c, which did a similar job, but for
21 an AMD-29K running EBMON. That file was in turn derived from remote.c
22 as mentioned in the following comment (left in for comic relief):
23
24 "This is like remote.c but is for a different situation--
25 having a PC running os9000 hook up with a unix machine with
26 a serial line, and running ctty com2 on the PC. os9000 has a debug
27 monitor called ROMBUG running. Not to mention that the PC
28 has PC/NFS, so it can access the same executables that gdb can,
29 over the net in real time."
30
31 In reality, this module talks to a debug monitor called 'ROMBUG', which
32 We communicate with ROMBUG via a direct serial line, the network version
33 of ROMBUG is not available yet.
34 */
35
36 #include "defs.h"
37 #include "gdbcore.h"
38 #include "target.h"
39 #include "wait.h"
40 #include <varargs.h>
41 #include <signal.h>
42 #include <string.h>
43 #include <sys/types.h>
44 #include "command.h"
45 #include "serial.h"
46 #include "monitor.h"
47 #include "remote-utils.h"
48 #include "symtab.h"
49 #include "symfile.h"
50 #include "objfiles.h"
51 #include "gdb-stabs.h"
52 #include <termio.h>
53
54 #ifdef HAVE_TERMIO
55 # define TERMINAL struct termios
56 #else
57 # define TERMINAL struct sgttyb
58 #endif
59
60 struct monitor_ops *current_monitor;
61 struct cmd_list_element *showlist;
62 extern struct target_ops rombug_ops; /* Forward declaration */
63 extern struct monitor_ops rombug_cmds; /* Forward declaration */
64 extern struct cmd_list_element *setlist;
65 extern struct cmd_list_element *unsetlist;
66 extern int attach_flag;
67
68 static void rombug_close();
69 static void rombug_fetch_register();
70 static void rombug_fetch_registers();
71 static void rombug_store_register();
72 #if 0
73 static int sr_get_debug(); /* flag set by "set remotedebug" */
74 #endif
75 static int hashmark; /* flag set by "set hash" */
76 static int rombug_is_open = 0;
77
78 /* FIXME: Replace with sr_get_debug (). */
79 #define LOG_FILE "monitor.log"
80 FILE *log_file;
81 static int monitor_log = 0;
82 static int tty_xon = 0;
83 static int tty_xoff = 0;
84
85 static int timeout = 5;
86 static int is_trace_mode = 0;
87 /* Descriptor for I/O to remote machine. Initialize it to NULL*/
88 static serial_t monitor_desc = NULL;
89
90 /* Send data to monitor. Works just like printf. */
91 static void
92 printf_monitor(va_alist)
93 va_dcl
94 {
95 va_list args;
96 char *pattern;
97 char buf[200];
98 int i;
99
100 va_start(args);
101
102 pattern = va_arg(args, char *);
103
104 vsprintf(buf, pattern, args);
105
106 if (SERIAL_WRITE(monitor_desc, buf, strlen(buf)))
107 fprintf(stderr, "SERIAL_WRITE failed: %s\n", safe_strerror(errno));
108 }
109
110 /* Read a character from the remote system, doing all the fancy timeout stuff*/
111 static int
112 readchar(timeout)
113 int timeout;
114 {
115 int c;
116
117 c = SERIAL_READCHAR(monitor_desc, timeout);
118
119 if (sr_get_debug())
120 putchar(c & 0x7f);
121
122 if (monitor_log && isascii(c))
123 putc(c & 0x7f, log_file);
124
125 if (c >= 0)
126 return c & 0x7f;
127
128 if (c == SERIAL_TIMEOUT)
129 {
130 if (timeout == 0)
131 return c; /* Polls shouldn't generate timeout errors */
132
133 error("Timeout reading from remote system.");
134 }
135
136 perror_with_name("remote-monitor");
137 }
138
139 /* Scan input from the remote system, until STRING is found. If DISCARD is
140 non-zero, then discard non-matching input, else print it out.
141 Let the user break out immediately. */
142 static void
143 expect(string, discard)
144 char *string;
145 int discard;
146 {
147 char *p = string;
148 int c;
149
150 if (sr_get_debug())
151 printf ("Expecting \"%s\"\n", string);
152
153 immediate_quit = 1;
154 while (1)
155 {
156 c = readchar(timeout);
157 if (!isascii (c))
158 continue;
159 if (c == *p++)
160 {
161 if (*p == '\0')
162 {
163 immediate_quit = 0;
164 if (sr_get_debug())
165 printf ("\nMatched\n");
166 return;
167 }
168 }
169 else
170 {
171 if (!discard)
172 {
173 fwrite(string, 1, (p - 1) - string, stdout);
174 putchar((char)c);
175 fflush(stdout);
176 }
177 p = string;
178 }
179 }
180 }
181
182 /* Keep discarding input until we see the ROMBUG prompt.
183
184 The convention for dealing with the prompt is that you
185 o give your command
186 o *then* wait for the prompt.
187
188 Thus the last thing that a procedure does with the serial line
189 will be an expect_prompt(). Exception: rombug_resume does not
190 wait for the prompt, because the terminal is being handed over
191 to the inferior. However, the next thing which happens after that
192 is a rombug_wait which does wait for the prompt.
193 Note that this includes abnormal exit, e.g. error(). This is
194 necessary to prevent getting into states from which we can't
195 recover. */
196 static void
197 expect_prompt(discard)
198 int discard;
199 {
200 if (monitor_log)
201 /* This is a convenient place to do this. The idea is to do it often
202 enough that we never lose much data if we terminate abnormally. */
203 fflush(log_file);
204
205 if (is_trace_mode) {
206 expect("trace", discard);
207 is_trace_mode = 0;
208 } else {
209 expect (PROMPT, discard);
210 }
211 }
212
213 /* Get a hex digit from the remote system & return its value.
214 If ignore_space is nonzero, ignore spaces (not newline, tab, etc). */
215 static int
216 get_hex_digit(ignore_space)
217 int ignore_space;
218 {
219 int ch;
220 while (1)
221 {
222 ch = readchar(timeout);
223 if (ch >= '0' && ch <= '9')
224 return ch - '0';
225 else if (ch >= 'A' && ch <= 'F')
226 return ch - 'A' + 10;
227 else if (ch >= 'a' && ch <= 'f')
228 return ch - 'a' + 10;
229 else if (ch == ' ' && ignore_space)
230 ;
231 else
232 {
233 expect_prompt(1);
234 error("Invalid hex digit from remote system.");
235 }
236 }
237 }
238
239 /* Get a byte from monitor and put it in *BYT. Accept any number
240 leading spaces. */
241 static void
242 get_hex_byte (byt)
243 char *byt;
244 {
245 int val;
246
247 val = get_hex_digit (1) << 4;
248 val |= get_hex_digit (0);
249 *byt = val;
250 }
251
252 /* Get N 32-bit words from remote, each preceded by a space,
253 and put them in registers starting at REGNO. */
254 static void
255 get_hex_regs (n, regno)
256 int n;
257 int regno;
258 {
259 long val;
260 int i;
261 unsigned char b;
262
263 for (i = 0; i < n; i++)
264 {
265 int j;
266
267 val = 0;
268 for (j = 0; j < 4; j++)
269 {
270 #if TARGET_BYTE_ORDER == BIG_ENDIAN
271 get_hex_byte(&b);
272 val = (val << 8) + b;
273 #else
274 get_hex_byte(&b);
275 val = val + (b << (j*8));
276 #endif
277 }
278 supply_register (regno++, (char *) &val);
279 }
280 }
281
282 /* This is called not only when we first attach, but also when the
283 user types "run" after having attached. */
284 static void
285 rombug_create_inferior (execfile, args, env)
286 char *execfile;
287 char *args;
288 char **env;
289 {
290 int entry_pt;
291
292 /* Nonzero value indicates that a process really is running. */
293 inferior_pid = 9000;
294
295 if (args && *args)
296 error("Can't pass arguments to remote ROMBUG process");
297
298 if (execfile == 0 || exec_bfd == 0)
299 error("No exec file specified");
300
301 entry_pt = (int) bfd_get_start_address (exec_bfd);
302
303 if (monitor_log)
304 fputs ("\nIn Create_inferior()", log_file);
305
306
307 /* The "process" (board) is already stopped awaiting our commands, and
308 the program is already downloaded. We just set its PC and go. */
309
310 init_wait_for_inferior ();
311 proceed ((CORE_ADDR)entry_pt, TARGET_SIGNAL_DEFAULT, 0);
312 }
313
314 /* Open a connection to a remote debugger.
315 NAME is the filename used for communication. */
316
317 static char dev_name[100];
318
319 static void
320 rombug_open(args, from_tty)
321 char *args;
322 int from_tty;
323 {
324 if (args == NULL)
325 error ("Use `target RomBug DEVICE-NAME' to use a serial port, or \n\
326 `target RomBug HOST-NAME:PORT-NUMBER' to use a network connection.");
327
328 target_preopen(from_tty);
329
330 if (rombug_is_open)
331 unpush_target(&rombug_ops);
332
333 strcpy(dev_name, args);
334 monitor_desc = SERIAL_OPEN(dev_name);
335 if (monitor_desc == NULL)
336 perror_with_name(dev_name);
337
338 /* if baud rate is set by 'set remotebaud' */
339 if (SERIAL_SETBAUDRATE (monitor_desc, sr_get_baud_rate()))
340 {
341 SERIAL_CLOSE (monitor_desc);
342 perror_with_name ("RomBug");
343 }
344 SERIAL_RAW(monitor_desc);
345 if (tty_xon || tty_xoff)
346 {
347 struct hardware_ttystate { struct termios t;} *tty_s;
348
349 tty_s =(struct hardware_ttystate *)SERIAL_GET_TTY_STATE(monitor_desc);
350 if (tty_xon) tty_s->t.c_iflag |= IXON;
351 if (tty_xoff) tty_s->t.c_iflag |= IXOFF;
352 SERIAL_SET_TTY_STATE(monitor_desc, (serial_ttystate) tty_s);
353 }
354
355 rombug_is_open = 1;
356
357 log_file = fopen (LOG_FILE, "w");
358 if (log_file == NULL)
359 perror_with_name (LOG_FILE);
360
361 push_monitor (&rombug_cmds);
362 printf_monitor("\r"); /* CR wakes up monitor */
363 expect_prompt(1);
364
365 push_target (&rombug_ops);
366 if (from_tty)
367 printf("Remote %s connected to %s\n", target_shortname,
368 dev_name);
369
370 attach_flag = 1;
371 inferior_pid = 9000;
372 rombug_fetch_registers();
373 }
374
375 /*
376 * Close out all files and local state before this target loses control.
377 */
378
379 static void
380 rombug_close (quitting)
381 int quitting;
382 {
383 if (rombug_is_open) {
384 SERIAL_CLOSE(monitor_desc);
385 monitor_desc = NULL;
386 rombug_is_open = 0;
387 }
388
389 if (log_file) {
390 if (ferror(log_file))
391 fprintf(stderr, "Error writing log file.\n");
392 if (fclose(log_file) != 0)
393 fprintf(stderr, "Error closing log file.\n");
394 log_file = 0;
395 }
396 }
397
398 int
399 rombug_link(mod_name, text_reloc)
400 char *mod_name;
401 CORE_ADDR *text_reloc;
402 {
403 int i, j;
404 unsigned long val;
405 unsigned char b;
406
407 printf_monitor("l %s \r", mod_name);
408 expect_prompt(1);
409 printf_monitor(".r \r");
410 expect(REG_DELIM, 1);
411 for (i=0; i <= 7; i++)
412 {
413 val = 0;
414 for (j = 0; j < 4; j++)
415 {
416 get_hex_byte(&b);
417 val = (val << 8) + b;
418 }
419 }
420 expect_prompt(1);
421 *text_reloc = val;
422 return 1;
423 }
424
425 /* Terminate the open connection to the remote debugger.
426 Use this when you want to detach and do something else
427 with your gdb. */
428 static void
429 rombug_detach (from_tty)
430 int from_tty;
431 {
432 if (attach_flag) {
433 printf_monitor (GO_CMD);
434 attach_flag = 0;
435 inferior_pid = 0;
436 }
437 pop_target(); /* calls rombug_close to do the real work */
438 if (from_tty)
439 printf ("Ending remote %s debugging\n", target_shortname);
440 }
441
442 /*
443 * Tell the remote machine to resume.
444 */
445 static void
446 rombug_resume (pid, step, sig)
447 int pid, step;
448 enum target_signal sig;
449 {
450 if (monitor_log)
451 fprintf (log_file, "\nIn Resume (step=%d, sig=%d)\n", step, sig);
452
453 if (step)
454 {
455 is_trace_mode = 1;
456 printf_monitor (STEP_CMD);
457 /* wait for the echo. */
458 expect (STEP_CMD, 1);
459 }
460 else
461 {
462 printf_monitor (GO_CMD);
463 /* swallow the echo. */
464 expect (GO_CMD, 1);
465 }
466 }
467
468 /*
469 * Wait until the remote machine stops, then return,
470 * storing status in status just as `wait' would.
471 */
472
473 static int
474 rombug_wait (pid, status)
475 int pid;
476 struct target_waitstatus *status;
477 {
478 int old_timeout = timeout;
479 struct section_offsets *offs;
480 CORE_ADDR addr, pc;
481 struct obj_section *obj_sec;
482
483 if (monitor_log)
484 fputs ("\nIn wait ()", log_file);
485
486 status->kind = TARGET_WAITKIND_EXITED;
487 status->value.integer = 0;
488
489 timeout = 0; /* Don't time out -- user program is running. */
490 expect_prompt(1); /* Wait for prompt, outputting extraneous text */
491
492 status->kind = TARGET_WAITKIND_STOPPED;
493 status->value.sig = TARGET_SIGNAL_TRAP;
494 timeout = old_timeout;
495 rombug_fetch_registers();
496 pc = read_register(PC_REGNUM);
497 addr = read_register(DATABASE_REG);
498 obj_sec = find_pc_section (pc);
499 if (obj_sec != NULL)
500 {
501 if (obj_sec->objfile != symfile_objfile)
502 new_symfile_objfile(obj_sec->objfile, 1, 0);
503 offs = ((struct section_offsets *)
504 alloca (sizeof (struct section_offsets)
505 + (symfile_objfile->num_sections * sizeof (offs->offsets))));
506 memcpy (offs, symfile_objfile->section_offsets,
507 (sizeof (struct section_offsets) +
508 (symfile_objfile->num_sections * sizeof (offs->offsets))));
509 ANOFFSET (offs, SECT_OFF_DATA) = addr;
510 ANOFFSET (offs, SECT_OFF_BSS) = addr;
511
512 objfile_relocate(symfile_objfile, offs);
513 }
514 return 0;
515 }
516
517 /* Return the name of register number regno in the form input and output by
518 monitor. Currently, register_names just happens to contain exactly what
519 monitor wants. Lets take advantage of that just as long as possible! */
520
521 static char *
522 get_reg_name (regno)
523 int regno;
524 {
525 static char buf[50];
526 char *p;
527 char *b;
528
529 b = buf;
530
531 if (regno < 0)
532 return ("");
533 /*
534 for (p = reg_names[regno]; *p; p++)
535 *b++ = toupper(*p);
536 *b = '\000';
537 */
538 p = (char *)reg_names[regno];
539 return p;
540 /*
541 return buf;
542 */
543 }
544
545 /* read the remote registers into the block regs. */
546
547 static void
548 rombug_fetch_registers ()
549 {
550 int regno, j, i;
551 long val;
552 unsigned char b;
553
554 printf_monitor (GET_REG);
555 expect("eax:", 1);
556 expect("\n", 1);
557 get_hex_regs(1, 0);
558 get_hex_regs(1, 3);
559 get_hex_regs(1, 1);
560 get_hex_regs(1, 2);
561 get_hex_regs(1, 6);
562 get_hex_regs(1, 7);
563 get_hex_regs(1, 5);
564 get_hex_regs(1, 4);
565 for (regno = 8; regno <= 15; regno++)
566 {
567 expect(REG_DELIM, 1);
568 if (regno >= 8 && regno <= 13)
569 {
570 val = 0;
571 for (j = 0; j < 2; j++)
572 {
573 #if TARGET_BYTE_ORDER == BIG_ENDIAN
574 get_hex_byte(&b);
575 val = (val << 8) + b;
576 #else
577 get_hex_byte(&b);
578 val = val + (b << (j*8));
579 #endif
580 }
581
582 if (regno == 8) i = 10;
583 if (regno >= 9 && regno <= 12) i = regno + 3;
584 if (regno == 13) i = 11;
585 supply_register (i, (char *) &val);
586 }
587 else if (regno == 14)
588 {
589 get_hex_regs(1, PC_REGNUM);
590 }
591 else if (regno == 15)
592 {
593 get_hex_regs(1, 9);
594 }
595 else
596 {
597 val = 0;
598 supply_register(regno, (char *) &val);
599 }
600 }
601 expect_prompt (1);
602 }
603
604 /* Fetch register REGNO, or all registers if REGNO is -1.
605 Returns errno value. */
606 static void
607 rombug_fetch_register (regno)
608 int regno;
609 {
610 int val, j;
611 unsigned char b;
612
613 if (monitor_log) {
614 fprintf (log_file, "\nIn Fetch Register (reg=%s)\n", get_reg_name (regno));
615 fflush (log_file);
616 }
617
618 if (regno < 0)
619 {
620 rombug_fetch_registers ();
621 }
622 else
623 {
624 char *name = get_reg_name (regno);
625 printf_monitor (GET_REG);
626 if (regno >= 10 && regno <= 15)
627 {
628 expect ("\n", 1);
629 expect ("\n", 1);
630 expect (name, 1);
631 expect (REG_DELIM, 1);
632 val = 0;
633 for (j = 0; j < 2; j++)
634 {
635 #if TARGET_BYTE_ORDER == BIG_ENDIAN
636 get_hex_byte(&b);
637 val = (val << 8) + b;
638 #else
639 get_hex_byte(&b);
640 val = val + (b << (j*8));
641 #endif
642 }
643 supply_register (regno, (char *) &val);
644 }
645 else if (regno == 8 || regno == 9)
646 {
647 expect ("\n", 1);
648 expect ("\n", 1);
649 expect ("\n", 1);
650 expect (name, 1);
651 expect (REG_DELIM, 1);
652 get_hex_regs (1, regno);
653 }
654 else
655 {
656 expect (name, 1);
657 expect (REG_DELIM, 1);
658 expect("\n", 1);
659 get_hex_regs(1, 0);
660 get_hex_regs(1, 3);
661 get_hex_regs(1, 1);
662 get_hex_regs(1, 2);
663 get_hex_regs(1, 6);
664 get_hex_regs(1, 7);
665 get_hex_regs(1, 5);
666 get_hex_regs(1, 4);
667 }
668 expect_prompt (1);
669 }
670 return;
671 }
672
673 /* Store the remote registers from the contents of the block REGS. */
674
675 static void
676 rombug_store_registers ()
677 {
678 int regno;
679
680 for (regno = 0; regno <= PC_REGNUM; regno++)
681 rombug_store_register(regno);
682
683 registers_changed ();
684 }
685
686 /* Store register REGNO, or all if REGNO == 0.
687 return errno value. */
688 static void
689 rombug_store_register (regno)
690 int regno;
691 {
692 char *name;
693
694 if (monitor_log)
695 fprintf (log_file, "\nIn Store_register (regno=%d)\n", regno);
696
697 if (regno == -1)
698 rombug_store_registers ();
699 else
700 {
701 if (sr_get_debug())
702 printf ("Setting register %s to 0x%x\n", get_reg_name (regno), read_register (regno));
703
704 name = get_reg_name(regno);
705 if (name == 0) return;
706 printf_monitor (SET_REG, name, read_register (regno));
707
708 expect_prompt (1);
709 }
710 }
711
712 /* Get ready to modify the registers array. On machines which store
713 individual registers, this doesn't need to do anything. On machines
714 which store all the registers in one fell swoop, this makes sure
715 that registers contains all the registers from the program being
716 debugged. */
717
718 static void
719 rombug_prepare_to_store ()
720 {
721 /* Do nothing, since we can store individual regs */
722 }
723
724 static void
725 rombug_files_info ()
726 {
727 printf ("\tAttached to %s at %d baud.\n",
728 dev_name, sr_get_baud_rate());
729 }
730
731 /* Copy LEN bytes of data from debugger memory at MYADDR
732 to inferior's memory at MEMADDR. Returns length moved. */
733 static int
734 rombug_write_inferior_memory (memaddr, myaddr, len)
735 CORE_ADDR memaddr;
736 unsigned char *myaddr;
737 int len;
738 {
739 int i;
740 char buf[10];
741
742 if (monitor_log)
743 fprintf (log_file, "\nIn Write_inferior_memory (memaddr=%x, len=%d)\n", memaddr, len);
744
745 printf_monitor (MEM_SET_CMD, memaddr);
746 for (i = 0; i < len; i++)
747 {
748 expect (CMD_DELIM, 1);
749 printf_monitor ("%x \r", myaddr[i]);
750 if (sr_get_debug())
751 printf ("\nSet 0x%x to 0x%x\n", memaddr + i, myaddr[i]);
752 }
753 expect (CMD_DELIM, 1);
754 if (CMD_END)
755 printf_monitor (CMD_END);
756 expect_prompt (1);
757
758 return len;
759 }
760
761 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
762 at debugger address MYADDR. Returns length moved. */
763 static int
764 rombug_read_inferior_memory(memaddr, myaddr, len)
765 CORE_ADDR memaddr;
766 char *myaddr;
767 int len;
768 {
769 int i, j;
770 char buf[20];
771
772 /* Number of bytes read so far. */
773 int count;
774
775 /* Starting address of this pass. */
776 unsigned long startaddr;
777
778 /* Number of bytes to read in this pass. */
779 int len_this_pass;
780
781 if (monitor_log)
782 fprintf (log_file, "\nIn Read_inferior_memory (memaddr=%x, len=%d)\n", memaddr, len);
783
784 /* Note that this code works correctly if startaddr is just less
785 than UINT_MAX (well, really CORE_ADDR_MAX if there was such a
786 thing). That is, something like
787 rombug_read_bytes (CORE_ADDR_MAX - 4, foo, 4)
788 works--it never adds len To memaddr and gets 0. */
789 /* However, something like
790 rombug_read_bytes (CORE_ADDR_MAX - 3, foo, 4)
791 doesn't need to work. Detect it and give up if there's an attempt
792 to do that. */
793 if (((memaddr - 1) + len) < memaddr) {
794 errno = EIO;
795 return 0;
796 }
797
798 startaddr = memaddr;
799 count = 0;
800 while (count < len)
801 {
802 len_this_pass = 16;
803 if ((startaddr % 16) != 0)
804 len_this_pass -= startaddr % 16;
805 if (len_this_pass > (len - count))
806 len_this_pass = (len - count);
807 if (sr_get_debug())
808 printf ("\nDisplay %d bytes at %x\n", len_this_pass, startaddr);
809
810 printf_monitor (MEM_DIS_CMD, startaddr, 16);
811 expect ("- ", 1);
812 for (i = 0; i < len_this_pass; i++)
813 {
814 get_hex_byte (&myaddr[count++]);
815 if (sr_get_debug())
816 printf ("\nRead a 0x%x from 0x%x\n", myaddr[count-1], startaddr);
817 startaddr += 1;
818 }
819 expect(CMD_DELIM, 1);
820 }
821 if (CMD_END)
822 printf_monitor (CMD_END);
823 expect_prompt (1);
824
825 return len;
826 }
827
828 /* FIXME-someday! merge these two. */
829 static int
830 rombug_xfer_inferior_memory (memaddr, myaddr, len, write, target)
831 CORE_ADDR memaddr;
832 char *myaddr;
833 int len;
834 int write;
835 struct target_ops *target; /* ignored */
836 {
837 if (write)
838 return rombug_write_inferior_memory (memaddr, myaddr, len);
839 else
840 return rombug_read_inferior_memory (memaddr, myaddr, len);
841 }
842
843 static void
844 rombug_kill (args, from_tty)
845 char *args;
846 int from_tty;
847 {
848 return; /* ignore attempts to kill target system */
849 }
850
851 /* Clean up when a program exits.
852 The program actually lives on in the remote processor's RAM, and may be
853 run again without a download. Don't leave it full of breakpoint
854 instructions. */
855
856 static void
857 rombug_mourn_inferior ()
858 {
859 remove_breakpoints ();
860 generic_mourn_inferior (); /* Do all the proper things now */
861 }
862
863 #define MAX_MONITOR_BREAKPOINTS 16
864
865 extern int memory_breakpoint_size;
866 static CORE_ADDR breakaddr[MAX_MONITOR_BREAKPOINTS] = {0};
867
868 static int
869 rombug_insert_breakpoint (addr, shadow)
870 CORE_ADDR addr;
871 char *shadow;
872 {
873 int i;
874
875 if (monitor_log)
876 fprintf (log_file, "\nIn Insert_breakpoint (addr=%x)\n", addr);
877
878 for (i = 0; i <= MAX_MONITOR_BREAKPOINTS; i++)
879 if (breakaddr[i] == 0)
880 {
881 breakaddr[i] = addr;
882 if (sr_get_debug())
883 printf ("Breakpoint at %x\n", addr);
884 rombug_read_inferior_memory(addr, shadow, memory_breakpoint_size);
885 printf_monitor(SET_BREAK_CMD, addr);
886 expect_prompt(1);
887 return 0;
888 }
889
890 fprintf(stderr, "Too many breakpoints (> 16) for monitor\n");
891 return 1;
892 }
893
894 /*
895 * _remove_breakpoint -- Tell the monitor to remove a breakpoint
896 */
897 static int
898 rombug_remove_breakpoint (addr, shadow)
899 CORE_ADDR addr;
900 char *shadow;
901 {
902 int i;
903
904 if (monitor_log)
905 fprintf (log_file, "\nIn Remove_breakpoint (addr=%x)\n", addr);
906
907 for (i = 0; i < MAX_MONITOR_BREAKPOINTS; i++)
908 if (breakaddr[i] == addr)
909 {
910 breakaddr[i] = 0;
911 printf_monitor(CLR_BREAK_CMD, addr);
912 expect_prompt(1);
913 return 0;
914 }
915
916 fprintf(stderr, "Can't find breakpoint associated with 0x%x\n", addr);
917 return 1;
918 }
919
920 /* Load a file. This is usually an srecord, which is ascii. No
921 protocol, just sent line by line. */
922
923 #define DOWNLOAD_LINE_SIZE 100
924 static void
925 rombug_load (arg)
926 char *arg;
927 {
928 /* this part comment out for os9* */
929 #if 0
930 FILE *download;
931 char buf[DOWNLOAD_LINE_SIZE];
932 int i, bytes_read;
933
934 if (sr_get_debug())
935 printf ("Loading %s to monitor\n", arg);
936
937 download = fopen (arg, "r");
938 if (download == NULL)
939 {
940 error (sprintf (buf, "%s Does not exist", arg));
941 return;
942 }
943
944 printf_monitor (LOAD_CMD);
945 /* expect ("Waiting for S-records from host... ", 1); */
946
947 while (!feof (download))
948 {
949 bytes_read = fread (buf, sizeof (char), DOWNLOAD_LINE_SIZE, download);
950 if (hashmark)
951 {
952 putchar ('.');
953 fflush (stdout);
954 }
955
956 if (SERIAL_WRITE(monitor_desc, buf, bytes_read)) {
957 fprintf(stderr, "SERIAL_WRITE failed: (while downloading) %s\n", safe_strerror(errno));
958 break;
959 }
960 i = 0;
961 while (i++ <=200000) {} ; /* Ugly HACK, probably needs flow control */
962 if (bytes_read < DOWNLOAD_LINE_SIZE)
963 {
964 if (!feof (download))
965 error ("Only read %d bytes\n", bytes_read);
966 break;
967 }
968 }
969
970 if (hashmark)
971 {
972 putchar ('\n');
973 }
974 if (!feof (download))
975 error ("Never got EOF while downloading");
976 fclose (download);
977 #endif 0
978 }
979
980 /* Put a command string, in args, out to MONITOR.
981 Output from MONITOR is placed on the users terminal until the prompt
982 is seen. */
983
984 static void
985 rombug_command (args, fromtty)
986 char *args;
987 int fromtty;
988 {
989 if (monitor_desc == NULL)
990 error("monitor target not open.");
991
992 if (monitor_log)
993 fprintf (log_file, "\nIn command (args=%s)\n", args);
994
995 if (!args)
996 error("Missing command.");
997
998 printf_monitor("%s\r", args);
999 expect(CMD_DELIM, 0);
1000 }
1001
1002 #if 0
1003 /* Connect the user directly to MONITOR. This command acts just like the
1004 'cu' or 'tip' command. Use <CR>~. or <CR>~^D to break out. */
1005
1006 static struct ttystate ttystate;
1007
1008 static void
1009 cleanup_tty()
1010 { printf("\r\n[Exiting connect mode]\r\n");
1011 /*SERIAL_RESTORE(0, &ttystate);*/
1012 }
1013
1014 static void
1015 connect_command (args, fromtty)
1016 char *args;
1017 int fromtty;
1018 {
1019 fd_set readfds;
1020 int numfds;
1021 int c;
1022 char cur_esc = 0;
1023
1024 dont_repeat();
1025
1026 if (monitor_desc == NULL)
1027 error("monitor target not open.");
1028
1029 if (args)
1030 fprintf("This command takes no args. They have been ignored.\n");
1031
1032 printf("[Entering connect mode. Use ~. or ~^D to escape]\n");
1033
1034 serial_raw(0, &ttystate);
1035
1036 make_cleanup(cleanup_tty, 0);
1037
1038 FD_ZERO(&readfds);
1039
1040 while (1)
1041 {
1042 do
1043 {
1044 FD_SET(0, &readfds);
1045 FD_SET(monitor_desc, &readfds);
1046 numfds = select(sizeof(readfds)*8, &readfds, 0, 0, 0);
1047 }
1048 while (numfds == 0);
1049
1050 if (numfds < 0)
1051 perror_with_name("select");
1052
1053 if (FD_ISSET(0, &readfds))
1054 { /* tty input, send to monitor */
1055 c = getchar();
1056 if (c < 0)
1057 perror_with_name("connect");
1058
1059 printf_monitor("%c", c);
1060 switch (cur_esc)
1061 {
1062 case 0:
1063 if (c == '\r')
1064 cur_esc = c;
1065 break;
1066 case '\r':
1067 if (c == '~')
1068 cur_esc = c;
1069 else
1070 cur_esc = 0;
1071 break;
1072 case '~':
1073 if (c == '.' || c == '\004')
1074 return;
1075 else
1076 cur_esc = 0;
1077 }
1078 }
1079
1080 if (FD_ISSET(monitor_desc, &readfds))
1081 {
1082 while (1)
1083 {
1084 c = readchar(0);
1085 if (c < 0)
1086 break;
1087 putchar(c);
1088 }
1089 fflush(stdout);
1090 }
1091 }
1092 }
1093 #endif
1094
1095 /*
1096 * Define the monitor command strings. Since these are passed directly
1097 * through to a printf style function, we need can include formatting
1098 * strings. We also need a CR or LF on the end.
1099 */
1100 struct monitor_ops rombug_cmds = {
1101 "g \r", /* execute or usually GO command */
1102 "g \r", /* continue command */
1103 "t \r", /* single step */
1104 "b %x\r", /* set a breakpoint */
1105 "k %x\r", /* clear a breakpoint */
1106 "c %x\r", /* set memory to a value */
1107 "d %x %d\r", /* display memory */
1108 "$%08X", /* prompt memory commands use */
1109 ".%s %x\r", /* set a register */
1110 ":", /* delimiter between registers */
1111 ". \r", /* read a register */
1112 "mf \r", /* download command */
1113 "RomBug: ", /* monitor command prompt */
1114 ": ", /* end-of-command delimitor */
1115 ".\r" /* optional command terminator */
1116 };
1117
1118 struct target_ops rombug_ops = {
1119 "rombug",
1120 "Microware's ROMBUG debug monitor",
1121 "Use a remote computer running the ROMBUG debug monitor.\n\
1122 Specify the serial device it is connected to (e.g. /dev/ttya).",
1123 rombug_open,
1124 rombug_close,
1125 0,
1126 rombug_detach,
1127 rombug_resume,
1128 rombug_wait,
1129 rombug_fetch_register,
1130 rombug_store_register,
1131 rombug_prepare_to_store,
1132 rombug_xfer_inferior_memory,
1133 rombug_files_info,
1134 rombug_insert_breakpoint,
1135 rombug_remove_breakpoint, /* Breakpoints */
1136 0,
1137 0,
1138 0,
1139 0,
1140 0, /* Terminal handling */
1141 rombug_kill,
1142 rombug_load, /* load */
1143 rombug_link, /* lookup_symbol */
1144 rombug_create_inferior,
1145 rombug_mourn_inferior,
1146 0, /* can_run */
1147 0, /* notice_signals */
1148 process_stratum,
1149 0, /* next */
1150 1,
1151 1,
1152 1,
1153 1,
1154 1, /* has execution */
1155 0,
1156 0, /* Section pointers */
1157 OPS_MAGIC, /* Always the last thing */
1158 };
1159
1160 void
1161 _initialize_remote_os9k ()
1162 {
1163 add_target (&rombug_ops);
1164
1165 add_show_from_set (
1166 add_set_cmd ("hash", no_class, var_boolean, (char *)&hashmark,
1167 "Set display of activity while downloading a file.\nWhen enabled, a period \'.\' is displayed.",
1168 &setlist),
1169 &showlist);
1170
1171 add_show_from_set (
1172 add_set_cmd ("timeout", no_class, var_zinteger,
1173 (char *) &timeout,
1174 "Set timeout in seconds for remote MIPS serial I/O.",
1175 &setlist),
1176 &showlist);
1177
1178 add_show_from_set (
1179 add_set_cmd ("remotelog", no_class, var_zinteger,
1180 (char *) &monitor_log,
1181 "Set monitor activity log on(=1) or off(=0).",
1182 &setlist),
1183 &showlist);
1184
1185 add_show_from_set (
1186 add_set_cmd ("remotexon", no_class, var_zinteger,
1187 (char *) &tty_xon,
1188 "Set remote tty line XON control",
1189 &setlist),
1190 &showlist);
1191
1192 add_show_from_set (
1193 add_set_cmd ("remotexoff", no_class, var_zinteger,
1194 (char *) &tty_xoff,
1195 "Set remote tty line XOFF control",
1196 &setlist),
1197 &showlist);
1198
1199 add_com ("rombug <command>", class_obscure, rombug_command,
1200 "Send a command to the debug monitor.");
1201 #if 0
1202 add_com ("connect", class_obscure, connect_command,
1203 "Connect the terminal directly up to a serial based command monitor.\nUse <CR>~. or <CR>~^D to break out.");
1204 #endif
1205 }
This page took 0.056335 seconds and 4 git commands to generate.