* solib.c (solib_add): New argument is the target_ops whose
[deliverable/binutils-gdb.git] / gdb / remote-eb.c
CommitLineData
dd3b648e
RP
1/* Remote debugging interface for AMD 29000 EBMON on IBM PC, for GDB.
2 Copyright 1990-1991 Free Software Foundation, Inc.
3 Contributed by Cygnus Support. Written by Jim Kingdon for Cygnus.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
99a7de40
JG
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
dd3b648e
RP
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
99a7de40
JG
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
dd3b648e
RP
20
21/* This is like remote.c but is for an esoteric situation--
22 having a 29k board in a PC hooked up to a unix machine with
23 a serial line, and running ctty com1 on the PC, through which
24 the unix machine can run ebmon. Not to mention that the PC
25 has PC/NFS, so it can access the same executables that gdb can,
26 over the net in real time. */
27
28#include <stdio.h>
29#include <string.h>
30#include "defs.h"
31#include "tm-29k.h"
32#include "param-no-tm.h"
33#include "inferior.h"
34#include "wait.h"
35#include "value.h"
36#include <ctype.h>
37#include <fcntl.h>
38#include <signal.h>
39#include <errno.h>
40#include "terminal.h"
41#include "target.h"
42
43extern void add_syms_addr_command ();
44extern struct value *call_function_by_hand();
45
46extern struct target_ops eb_ops; /* Forward declaration */
47
48#define LOG_FILE "eb.log"
49#if defined (LOG_FILE)
50FILE *log_file;
51#endif
52
53static int timeout = 5;
54
55/* Descriptor for I/O to remote machine. Initialize it to -1 so that
56 eb_open knows that we don't have a file open when the program
57 starts. */
58int eb_desc = -1;
59
60/* stream which is fdopen'd from eb_desc. Only valid when
61 eb_desc != -1. */
62FILE *eb_stream;
63
64/* Read a character from the remote system, doing all the fancy
65 timeout stuff. */
66static int
67readchar ()
68{
69 char buf;
70
71 buf = '\0';
72#ifdef HAVE_TERMIO
73 /* termio does the timeout for us. */
74 read (eb_desc, &buf, 1);
75#else
76 alarm (timeout);
77 if (read (eb_desc, &buf, 1) < 0)
78 {
79 if (errno == EINTR)
80 error ("Timeout reading from remote system.");
81 else
82 perror_with_name ("remote");
83 }
84 alarm (0);
85#endif
86
87 if (buf == '\0')
88 error ("Timeout reading from remote system.");
89#if defined (LOG_FILE)
90 putc (buf & 0x7f, log_file);
91#endif
92 return buf & 0x7f;
93}
94
95/* Keep discarding input from the remote system, until STRING is found.
96 Let the user break out immediately. */
97static void
98expect (string)
99 char *string;
100{
101 char *p = string;
102
103 immediate_quit = 1;
104 while (1)
105 {
106 if (readchar() == *p)
107 {
108 p++;
109 if (*p == '\0')
110 {
111 immediate_quit = 0;
112 return;
113 }
114 }
115 else
116 p = string;
117 }
118}
119
120/* Keep discarding input until we see the ebmon prompt.
121
122 The convention for dealing with the prompt is that you
123 o give your command
124 o *then* wait for the prompt.
125
126 Thus the last thing that a procedure does with the serial line
127 will be an expect_prompt(). Exception: eb_resume does not
128 wait for the prompt, because the terminal is being handed over
129 to the inferior. However, the next thing which happens after that
130 is a eb_wait which does wait for the prompt.
131 Note that this includes abnormal exit, e.g. error(). This is
132 necessary to prevent getting into states from which we can't
133 recover. */
134static void
135expect_prompt ()
136{
137#if defined (LOG_FILE)
138 /* This is a convenient place to do this. The idea is to do it often
139 enough that we never lose much data if we terminate abnormally. */
140 fflush (log_file);
141#endif
142 expect ("\n# ");
143}
144
145/* Get a hex digit from the remote system & return its value.
146 If ignore_space is nonzero, ignore spaces (not newline, tab, etc). */
147static int
148get_hex_digit (ignore_space)
149 int ignore_space;
150{
151 int ch;
152 while (1)
153 {
154 ch = readchar ();
155 if (ch >= '0' && ch <= '9')
156 return ch - '0';
157 else if (ch >= 'A' && ch <= 'F')
158 return ch - 'A' + 10;
159 else if (ch >= 'a' && ch <= 'f')
160 return ch - 'a' + 10;
161 else if (ch == ' ' && ignore_space)
162 ;
163 else
164 {
165 expect_prompt ();
166 error ("Invalid hex digit from remote system.");
167 }
168 }
169}
170
171/* Get a byte from eb_desc and put it in *BYT. Accept any number
172 leading spaces. */
173static void
174get_hex_byte (byt)
175 char *byt;
176{
177 int val;
178
179 val = get_hex_digit (1) << 4;
180 val |= get_hex_digit (0);
181 *byt = val;
182}
183
184/* Get N 32-bit words from remote, each preceded by a space,
185 and put them in registers starting at REGNO. */
186static void
187get_hex_regs (n, regno)
188 int n;
189 int regno;
190{
191 long val;
192 int i;
193
194 for (i = 0; i < n; i++)
195 {
196 int j;
197
198 val = 0;
199 for (j = 0; j < 8; j++)
200 val = (val << 4) + get_hex_digit (j == 0);
201 supply_register (regno++, &val);
202 }
203}
204
205/* Called when SIGALRM signal sent due to alarm() timeout. */
206#ifndef HAVE_TERMIO
207
208#ifndef __STDC__
209#define volatile /**/
210#endif
211volatile int n_alarms;
212
213void
214eb_timer ()
215{
216#if 0
217 if (kiodebug)
218 printf ("eb_timer called\n");
219#endif
220 n_alarms++;
221}
222#endif
223
224/* malloc'd name of the program on the remote system. */
225static char *prog_name = NULL;
226
227/* Nonzero if we have loaded the file ("yc") and not yet issued a "gi"
228 command. "gi" is supposed to happen exactly once for each "yc". */
229static int need_gi = 0;
230
231/* Number of SIGTRAPs we need to simulate. That is, the next
232 NEED_ARTIFICIAL_TRAP calls to eb_wait should just return
233 SIGTRAP without actually waiting for anything. */
234
235static int need_artificial_trap = 0;
236
237/* This is called not only when we first attach, but also when the
238 user types "run" after having attached. */
239void
240eb_start (inferior_args)
241char *inferior_args;
242{
243 /* OK, now read in the file. Y=read, C=COFF, D=no symbols
244 0=start address, %s=filename. */
245
246 fprintf (eb_stream, "YC D,0:%s", prog_name);
247
248 if (inferior_args != NULL)
249 fprintf(eb_stream, " %s", inferior_args);
250
251 fprintf (eb_stream, "\n");
252 fflush (eb_stream);
253
254 expect_prompt ();
255
256 need_gi = 1;
257}
258
259/* Translate baud rates from integers to damn B_codes. Unix should
260 have outgrown this crap years ago, but even POSIX wouldn't buck it. */
261
262#ifndef B19200
263#define B19200 EXTA
264#endif
265#ifndef B38400
266#define B38400 EXTB
267#endif
268
269struct {int rate, damn_b;} baudtab[] = {
270 {0, B0},
271 {50, B50},
272 {75, B75},
273 {110, B110},
274 {134, B134},
275 {150, B150},
276 {200, B200},
277 {300, B300},
278 {600, B600},
279 {1200, B1200},
280 {1800, B1800},
281 {2400, B2400},
282 {4800, B4800},
283 {9600, B9600},
284 {19200, B19200},
285 {38400, B38400},
286 {-1, -1},
287};
288
289int damn_b (rate)
290 int rate;
291{
292 int i;
293
294 for (i = 0; baudtab[i].rate != -1; i++)
295 if (rate == baudtab[i].rate) return baudtab[i].damn_b;
296 return B38400; /* Random */
297}
298
299
300/* Open a connection to a remote debugger.
301 NAME is the filename used for communication, then a space,
302 then the name of the program as we should name it to EBMON. */
303
304static int baudrate = 9600;
305static char *dev_name;
306void
307eb_open (name, from_tty)
308 char *name;
309 int from_tty;
310{
311 TERMINAL sg;
312
313 char *p;
314
f2fc6e7a
JK
315 target_preopen (from_tty);
316
dd3b648e
RP
317 /* Find the first whitespace character, it separates dev_name from
318 prog_name. */
319 if (name == 0)
320 goto erroid;
321
322 for (p = name;
323 *p != '\0' && !isspace (*p); p++)
324 ;
325 if (*p == '\0')
326erroid:
327 error ("\
328Please include the name of the device for the serial port,\n\
329the baud rate, and the name of the program to run on the remote system.");
330 dev_name = alloca (p - name + 1);
331 strncpy (dev_name, name, p - name);
332 dev_name[p - name] = '\0';
333
334 /* Skip over the whitespace after dev_name */
335 for (; isspace (*p); p++)
336 /*EMPTY*/;
337
338 if (1 != sscanf (p, "%d ", &baudrate))
339 goto erroid;
340
341 /* Skip the number and then the spaces */
342 for (; isdigit (*p); p++)
343 /*EMPTY*/;
344 for (; isspace (*p); p++)
345 /*EMPTY*/;
346
347 if (prog_name != NULL)
348 free (prog_name);
349 prog_name = savestring (p, strlen (p));
350
351 eb_close (0);
352
353 eb_desc = open (dev_name, O_RDWR);
354 if (eb_desc < 0)
355 perror_with_name (dev_name);
356 ioctl (eb_desc, TIOCGETP, &sg);
357#ifdef HAVE_TERMIO
358 sg.c_cc[VMIN] = 0; /* read with timeout. */
359 sg.c_cc[VTIME] = timeout * 10;
360 sg.c_lflag &= ~(ICANON | ECHO);
361 sg.c_cflag = (sg.c_cflag & ~CBAUD) | damn_b (baudrate);
362#else
363 sg.sg_ispeed = damn_b (baudrate);
364 sg.sg_ospeed = damn_b (baudrate);
365 sg.sg_flags |= RAW | ANYP;
366 sg.sg_flags &= ~ECHO;
367#endif
368
369 ioctl (eb_desc, TIOCSETP, &sg);
370 eb_stream = fdopen (eb_desc, "r+");
371
372 push_target (&eb_ops);
373 if (from_tty)
374 printf ("Remote %s debugging %s using %s\n", target_shortname,
375 prog_name, dev_name);
376
377#ifndef HAVE_TERMIO
378#ifndef NO_SIGINTERRUPT
379 /* Cause SIGALRM's to make reads fail with EINTR instead of resuming
380 the read. */
381 if (siginterrupt (SIGALRM, 1) != 0)
382 perror ("eb_open: error in siginterrupt");
383#endif
384
385 /* Set up read timeout timer. */
386 if ((void (*)) signal (SIGALRM, eb_timer) == (void (*)) -1)
387 perror ("eb_open: error in signal");
388#endif
389
390#if defined (LOG_FILE)
391 log_file = fopen (LOG_FILE, "w");
392 if (log_file == NULL)
393 perror_with_name (LOG_FILE);
394#endif
395
396 /* Hello? Are you there? */
397 write (eb_desc, "\n", 1);
398
399 expect_prompt ();
400}
401
402/* Close out all files and local state before this target loses control. */
403
404void
405eb_close (quitting)
406 int quitting;
407{
408
409 /* Due to a bug in Unix, fclose closes not only the stdio stream,
410 but also the file descriptor. So we don't actually close
411 eb_desc. */
412 if (eb_stream)
413 fclose (eb_stream); /* This also closes eb_desc */
414 if (eb_desc >= 0)
415 /* close (eb_desc); */
416
417 /* Do not try to close eb_desc again, later in the program. */
418 eb_stream = NULL;
419 eb_desc = -1;
420
421#if defined (LOG_FILE)
422 if (ferror (log_file))
423 printf ("Error writing log file.\n");
424 if (fclose (log_file) != 0)
425 printf ("Error closing log file.\n");
426#endif
427}
428
429/* Terminate the open connection to the remote debugger.
430 Use this when you want to detach and do something else
431 with your gdb. */
432void
433eb_detach (from_tty)
434 int from_tty;
435{
436 pop_target(); /* calls eb_close to do the real work */
437 if (from_tty)
438 printf ("Ending remote %s debugging\n", target_shortname);
439}
440
441/* Tell the remote machine to resume. */
442
443void
444eb_resume (step, sig)
445 int step, sig;
446{
447 if (step)
448 {
449 write (eb_desc, "t 1,s\n", 6);
450 /* Wait for the echo. */
451 expect ("t 1,s\r");
452 /* Then comes a line containing the instruction we stepped to. */
453 expect ("\n@");
454 /* Then we get the prompt. */
455 expect_prompt ();
456
457 /* Force the next eb_wait to return a trap. Not doing anything
458 about I/O from the target means that the user has to type
459 "continue" to see any. This should be fixed. */
460 need_artificial_trap = 1;
461 }
462 else
463 {
464 if (need_gi)
465 {
466 need_gi = 0;
467 write (eb_desc, "gi\n", 3);
468
469 /* Swallow the echo of "gi". */
470 expect ("gi\r");
471 }
472 else
473 {
474 write (eb_desc, "GR\n", 3);
475 /* Swallow the echo. */
476 expect ("GR\r");
477 }
478 }
479}
480
481/* Wait until the remote machine stops, then return,
482 storing status in STATUS just as `wait' would. */
483
484int
485eb_wait (status)
486 WAITTYPE *status;
487{
488 /* Strings to look for. '?' means match any single character.
489 Note that with the algorithm we use, the initial character
490 of the string cannot recur in the string, or we will not
491 find some cases of the string in the input. */
492
493 static char bpt[] = "Invalid interrupt taken - #0x50 - ";
494 /* It would be tempting to look for "\n[__exit + 0x8]\n"
495 but that requires loading symbols with "yc i" and even if
496 we did do that we don't know that the file has symbols. */
497 static char exitmsg[] = "\n@????????I JMPTI GR121,LR0";
498 char *bp = bpt;
499 char *ep = exitmsg;
500
501 /* Large enough for either sizeof (bpt) or sizeof (exitmsg) chars. */
502 char swallowed[50];
503 /* Current position in swallowed. */
504 char *swallowed_p = swallowed;
505
506 int ch;
507 int ch_handled;
508
509 int old_timeout = timeout;
510
511 WSETEXIT ((*status), 0);
512
513 if (need_artificial_trap != 0)
514 {
515 WSETSTOP ((*status), SIGTRAP);
516 need_artificial_trap--;
517 return 0;
518 }
519
520 timeout = 0; /* Don't time out -- user program is running. */
521 while (1)
522 {
523 ch_handled = 0;
524 ch = readchar ();
525 if (ch == *bp)
526 {
527 bp++;
528 if (*bp == '\0')
529 break;
530 ch_handled = 1;
531
532 *swallowed_p++ = ch;
533 }
534 else
535 bp = bpt;
536
537 if (ch == *ep || *ep == '?')
538 {
539 ep++;
540 if (*ep == '\0')
541 break;
542
543 if (!ch_handled)
544 *swallowed_p++ = ch;
545 ch_handled = 1;
546 }
547 else
548 ep = exitmsg;
549
550 if (!ch_handled)
551 {
552 char *p;
553
554 /* Print out any characters which have been swallowed. */
555 for (p = swallowed; p < swallowed_p; ++p)
556 putc (*p, stdout);
557 swallowed_p = swallowed;
558
559 putc (ch, stdout);
560 }
561 }
562 expect_prompt ();
563 if (*bp== '\0')
564 WSETSTOP ((*status), SIGTRAP);
565 else
566 WSETEXIT ((*status), 0);
567 timeout = old_timeout;
568
569 return 0;
570}
571
572/* Return the name of register number REGNO
573 in the form input and output by EBMON.
574
575 Returns a pointer to a static buffer containing the answer. */
576static char *
577get_reg_name (regno)
578 int regno;
579{
580 static char buf[80];
581 if (regno >= GR96_REGNUM && regno < GR96_REGNUM + 32)
582 sprintf (buf, "GR%03d", regno - GR96_REGNUM + 96);
583 else if (regno >= LR0_REGNUM && regno < LR0_REGNUM + 128)
584 sprintf (buf, "LR%03d", regno - LR0_REGNUM);
585 else if (regno == Q_REGNUM)
586 strcpy (buf, "SR131");
587 else if (regno >= BP_REGNUM && regno <= CR_REGNUM)
588 sprintf (buf, "SR%03d", regno - BP_REGNUM + 133);
589 else if (regno == ALU_REGNUM)
590 strcpy (buf, "SR132");
591 else if (regno >= IPC_REGNUM && regno <= IPB_REGNUM)
592 sprintf (buf, "SR%03d", regno - IPC_REGNUM + 128);
593 else if (regno >= VAB_REGNUM && regno <= LRU_REGNUM)
594 sprintf (buf, "SR%03d", regno - VAB_REGNUM);
595 else if (regno == GR1_REGNUM)
596 strcpy (buf, "GR001");
597 return buf;
598}
599
600/* Read the remote registers into the block REGS. */
601
602static void
603eb_fetch_registers ()
604{
605 int reg_index;
606 int regnum_index;
607 char tempbuf[10];
608 int i;
609
610#if 0
611 /* This should not be necessary, because one is supposed to read the
612 registers only when the inferior is stopped (at least with
613 ptrace() and why not make it the same for remote?). */
614 /* ^A is the "normal character" used to make sure we are talking to EBMON
615 and not to the program being debugged. */
616 write (eb_desc, "\001\n");
617 expect_prompt ();
618#endif
619
620 write (eb_desc, "dw gr96,gr127\n", 14);
621 for (reg_index = 96, regnum_index = GR96_REGNUM;
622 reg_index < 128;
623 reg_index += 4, regnum_index += 4)
624 {
625 sprintf (tempbuf, "GR%03d ", reg_index);
626 expect (tempbuf);
627 get_hex_regs (4, regnum_index);
628 expect ("\n");
629 }
630
631 for (i = 0; i < 128; i += 32)
632 {
633 /* The PC has a tendency to hang if we get these
634 all in one fell swoop ("dw lr0,lr127"). */
635 sprintf (tempbuf, "dw lr%d\n", i);
636 write (eb_desc, tempbuf, strlen (tempbuf));
637 for (reg_index = i, regnum_index = LR0_REGNUM + i;
638 reg_index < i + 32;
639 reg_index += 4, regnum_index += 4)
640 {
641 sprintf (tempbuf, "LR%03d ", reg_index);
642 expect (tempbuf);
643 get_hex_regs (4, regnum_index);
644 expect ("\n");
645 }
646 }
647
648 write (eb_desc, "dw sr133,sr133\n", 15);
649 expect ("SR133 ");
650 get_hex_regs (1, BP_REGNUM);
651 expect ("\n");
652
653 write (eb_desc, "dw sr134,sr134\n", 15);
654 expect ("SR134 ");
655 get_hex_regs (1, FC_REGNUM);
656 expect ("\n");
657
658 write (eb_desc, "dw sr135,sr135\n", 15);
659 expect ("SR135 ");
660 get_hex_regs (1, CR_REGNUM);
661 expect ("\n");
662
663 write (eb_desc, "dw sr131,sr131\n", 15);
664 expect ("SR131 ");
665 get_hex_regs (1, Q_REGNUM);
666 expect ("\n");
667
668 write (eb_desc, "dw sr0,sr14\n", 12);
669 for (reg_index = 0, regnum_index = VAB_REGNUM;
670 regnum_index <= LRU_REGNUM;
671 regnum_index += 4, reg_index += 4)
672 {
673 sprintf (tempbuf, "SR%03d ", reg_index);
674 expect (tempbuf);
675 get_hex_regs (reg_index == 12 ? 3 : 4, regnum_index);
676 expect ("\n");
677 }
678
679 /* There doesn't seem to be any way to get these. */
680 {
681 int val = -1;
682 supply_register (FPE_REGNUM, &val);
683 supply_register (INT_REGNUM, &val);
684 supply_register (FPS_REGNUM, &val);
685 supply_register (EXO_REGNUM, &val);
686 }
687
688 write (eb_desc, "dw gr1,gr1\n", 11);
689 expect ("GR001 ");
690 get_hex_regs (1, GR1_REGNUM);
691 expect_prompt ();
692}
693
694/* Fetch register REGNO, or all registers if REGNO is -1.
695 Returns errno value. */
696int
697eb_fetch_register (regno)
698 int regno;
699{
700 if (regno == -1)
701 eb_fetch_registers ();
702 else
703 {
704 char *name = get_reg_name (regno);
705 fprintf (eb_stream, "dw %s,%s\n", name, name);
706 expect (name);
707 expect (" ");
708 get_hex_regs (1, regno);
709 expect_prompt ();
710 }
711 return 0;
712}
713
714/* Store the remote registers from the contents of the block REGS. */
715
716static void
717eb_store_registers ()
718{
719 int i, j;
720 fprintf (eb_stream, "s gr1,%x\n", read_register (GR1_REGNUM));
721 expect_prompt ();
722
723 for (j = 0; j < 32; j += 16)
724 {
725 fprintf (eb_stream, "s gr%d,", j + 96);
726 for (i = 0; i < 15; ++i)
727 fprintf (eb_stream, "%x,", read_register (GR96_REGNUM + j + i));
728 fprintf (eb_stream, "%x\n", read_register (GR96_REGNUM + j + 15));
729 expect_prompt ();
730 }
731
732 for (j = 0; j < 128; j += 16)
733 {
734 fprintf (eb_stream, "s lr%d,", j);
735 for (i = 0; i < 15; ++i)
736 fprintf (eb_stream, "%x,", read_register (LR0_REGNUM + j + i));
737 fprintf (eb_stream, "%x\n", read_register (LR0_REGNUM + j + 15));
738 expect_prompt ();
739 }
740
741 fprintf (eb_stream, "s sr133,%x,%x,%x\n", read_register (BP_REGNUM),
742 read_register (FC_REGNUM), read_register (CR_REGNUM));
743 expect_prompt ();
744 fprintf (eb_stream, "s sr131,%x\n", read_register (Q_REGNUM));
745 expect_prompt ();
746 fprintf (eb_stream, "s sr0,");
747 for (i = 0; i < 11; ++i)
748 fprintf (eb_stream, "%x,", read_register (VAB_REGNUM + i));
749 fprintf (eb_stream, "%x\n", read_register (VAB_REGNUM + 11));
750 expect_prompt ();
751}
752
753/* Store register REGNO, or all if REGNO == 0.
754 Return errno value. */
755int
756eb_store_register (regno)
757 int regno;
758{
759 if (regno == -1)
760 eb_store_registers ();
761 else
762 {
763 char *name = get_reg_name (regno);
764 fprintf (eb_stream, "s %s,%x\n", name, read_register (regno));
765 /* Setting GR1 changes the numbers of all the locals, so
766 invalidate the register cache. Do this *after* calling
767 read_register, because we want read_register to return the
768 value that write_register has just stuffed into the registers
769 array, not the value of the register fetched from the
770 inferior. */
771 if (regno == GR1_REGNUM)
772 registers_changed ();
773 expect_prompt ();
774 }
775 return 0;
776}
777
778/* Get ready to modify the registers array. On machines which store
779 individual registers, this doesn't need to do anything. On machines
780 which store all the registers in one fell swoop, this makes sure
781 that registers contains all the registers from the program being
782 debugged. */
783
784void
785eb_prepare_to_store ()
786{
787 /* Do nothing, since we can store individual regs */
788}
789
790/* FIXME! Merge these two. */
791int
792eb_xfer_inferior_memory (memaddr, myaddr, len, write)
793 CORE_ADDR memaddr;
794 char *myaddr;
795 int len;
796 int write;
797{
798 if (write)
799 return eb_write_inferior_memory (memaddr, myaddr, len);
800 else
801 return eb_write_inferior_memory (memaddr, myaddr, len);
802}
803
804void
805eb_files_info ()
806{
807 printf ("\tAttached to %s at %d baud and running program %s.\n",
808 dev_name, baudrate, prog_name);
809}
810
811/* Copy LEN bytes of data from debugger memory at MYADDR
812 to inferior's memory at MEMADDR. Returns errno value. */
813int
814eb_write_inferior_memory (memaddr, myaddr, len)
815 CORE_ADDR memaddr;
816 char *myaddr;
817 int len;
818{
819 int i;
820
821 for (i = 0; i < len; i++)
822 {
823 if ((i % 16) == 0)
824 fprintf (eb_stream, "sb %x,", memaddr + i);
825 if ((i % 16) == 15 || i == len - 1)
826 {
827 fprintf (eb_stream, "%x\n", ((unsigned char *)myaddr)[i]);
828 expect_prompt ();
829 }
830 else
831 fprintf (eb_stream, "%x,", ((unsigned char *)myaddr)[i]);
832 }
833 return 0;
834}
835
836/* Read LEN bytes from inferior memory at MEMADDR. Put the result
837 at debugger address MYADDR. Returns errno value. */
838int
839eb_read_inferior_memory(memaddr, myaddr, len)
840 CORE_ADDR memaddr;
841 char *myaddr;
842 int len;
843{
844 int i;
845
846 /* Number of bytes read so far. */
847 int count;
848
849 /* Starting address of this pass. */
850 unsigned long startaddr;
851
852 /* Number of bytes to read in this pass. */
853 int len_this_pass;
854
855 /* Note that this code works correctly if startaddr is just less
856 than UINT_MAX (well, really CORE_ADDR_MAX if there was such a
857 thing). That is, something like
858 eb_read_bytes (CORE_ADDR_MAX - 4, foo, 4)
859 works--it never adds len to memaddr and gets 0. */
860 /* However, something like
861 eb_read_bytes (CORE_ADDR_MAX - 3, foo, 4)
862 doesn't need to work. Detect it and give up if there's an attempt
863 to do that. */
864 if (((memaddr - 1) + len) < memaddr)
865 return EIO;
866
867 startaddr = memaddr;
868 count = 0;
869 while (count < len)
870 {
871 len_this_pass = 16;
872 if ((startaddr % 16) != 0)
873 len_this_pass -= startaddr % 16;
874 if (len_this_pass > (len - count))
875 len_this_pass = (len - count);
876
877 fprintf (eb_stream, "db %x,%x\n", startaddr,
878 (startaddr - 1) + len_this_pass);
879 expect ("\n");
880
881 /* Look for 8 hex digits. */
882 i = 0;
883 while (1)
884 {
885 if (isxdigit (readchar ()))
886 ++i;
887 else
888 {
889 expect_prompt ();
890 error ("Hex digit expected from remote system.");
891 }
892 if (i >= 8)
893 break;
894 }
895
896 expect (" ");
897
898 for (i = 0; i < len_this_pass; i++)
899 get_hex_byte (&myaddr[count++]);
900
901 expect_prompt ();
902
903 startaddr += len_this_pass;
904 }
905 return 0;
906}
907
908/* Define the target subroutine names */
909
910struct target_ops eb_ops = {
911 "amd-eb", "Remote serial AMD EBMON target",
f2fc6e7a
JK
912 "Use a remote computer running EBMON connected by a serial line.\n\
913Arguments are the name of the device for the serial line,\n\
914the speed to connect at in bits per second, and the filename of the\n\
915executable as it exists on the remote computer. For example,\n\
916 target amd-eb /dev/ttya 9600 demo",
dd3b648e
RP
917 eb_open, eb_close,
918 0, eb_detach, eb_resume, eb_wait,
919 eb_fetch_register, eb_store_register,
920 eb_prepare_to_store, 0, 0, /* conv_to, conv_from */
921 eb_xfer_inferior_memory, eb_files_info,
922 0, 0, /* Breakpoints */
923 0, 0, 0, 0, 0, /* Terminal handling */
924 0, /* FIXME, kill */
925 0, add_syms_addr_command, /* load */
926 call_function_by_hand,
927 0, /* lookup_symbol */
928 0, /* create_inferior FIXME, eb_start here or something? */
929 0, /* mourn_inferior FIXME */
930 process_stratum, 0, /* next */
931 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
932 OPS_MAGIC, /* Always the last thing */
933};
934
935void
936_initialize_remote_eb ()
937{
938 add_target (&eb_ops);
939}
This page took 0.062652 seconds and 4 git commands to generate.