1 /* Remote debugging interface for Motorola's MVME187BUG monitor, an embedded
4 Copyright 1992, 1993 Free Software Foundation, Inc.
5 Contributed by Cygnus Support. Written by K. Richard Pixley.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
45 /* External data declarations */
46 extern int stop_soon_quietly
; /* for wait_for_inferior */
48 /* Forward data declarations */
49 extern struct target_ops bug_ops
; /* Forward declaration */
51 /* Forward function declarations */
52 static void bug_close ();
53 static int bug_clear_breakpoints ();
54 static void bug_write_cr();
58 static int bug_read_inferior_memory (CORE_ADDR memaddr
, char *myaddr
, int len
);
59 static int bug_write_inferior_memory (CORE_ADDR memaddr
, unsigned char *myaddr
, int len
);
63 static int bug_read_inferior_memory ();
64 static int bug_write_inferior_memory ();
66 #endif /* not __STDC__ */
68 /* This is the serial descriptor to our target. */
70 static serial_t desc
= NULL
;
72 /* This variable is somewhat arbitrary. It's here so that it can be
73 set from within a running gdb. */
75 static int srec_max_retries
= 3;
77 /* Each S-record download to the target consists of an S0 header
78 record, some number of S3 data records, and one S7 termination
79 record. I call this download a "frame". Srec_frame says how many
80 bytes will be represented in each frame. */
82 static int srec_frame
= 160;
84 /* This variable determines how many bytes will be represented in each
87 static int srec_bytes
= 40;
89 /* At one point it appeared to me as though the bug monitor could not
90 really be expected to receive two sequential characters at 9600
91 baud reliably. Echo-pacing is an attempt to force data across the
92 line even in this condition. Specifically, in echo-pace mode, each
93 character is sent one at a time and we look for the echo before
94 sending the next. This is excruciatingly slow. */
96 static int srec_echo_pace
= 0;
98 /* How long to wait after an srec for a possible error message.
99 Similar to the above, I tried sleeping after sending each S3 record
100 in hopes that I might actually see error messages from the bug
101 monitor. This might actually work if we were to use sleep
102 intervals smaller than 1 second. */
104 static int srec_sleep
= 0;
106 /* Every srec_noise records, flub the checksum. This is a debugging
107 feature. Set the variable to something other than 1 in order to
108 inject *deliberate* checksum errors. One might do this if one
109 wanted to test error handling and recovery. */
111 static int srec_noise
= 0;
113 /***********************************************************************/
114 /* Caching stuff stolen from remote-nindy.c */
116 /* The data cache records all the data read from the remote machine
117 since the last time it stopped.
119 Each cache block holds LINE_SIZE bytes of data
120 starting at a multiple-of-LINE_SIZE address. */
122 #define LINE_SIZE_POWER 4
123 #define LINE_SIZE (1<<LINE_SIZE_POWER) /* eg 1<<3 == 8 */
124 #define LINE_SIZE_MASK ((LINE_SIZE-1)) /* eg 7*2+1= 111*/
125 #define DCACHE_SIZE 64 /* Number of cache blocks */
126 #define XFORM(x) ((x&LINE_SIZE_MASK)>>2)
129 struct dcache_block
*next
, *last
;
130 unsigned int addr
; /* Address for which data is recorded. */
131 int data
[LINE_SIZE
/ sizeof (int)];
134 struct dcache_block dcache_free
, dcache_valid
;
136 /* Free all the data cache blocks, thus discarding all cached data. */
141 register struct dcache_block
*db
;
143 while ((db
= dcache_valid
.next
) != &dcache_valid
)
146 insque (db
, &dcache_free
);
151 * If addr is present in the dcache, return the address of the block
155 struct dcache_block
*
159 register struct dcache_block
*db
;
164 /* Search all cache blocks for one that is at this address. */
165 db
= dcache_valid
.next
;
166 while (db
!= &dcache_valid
)
168 if ((addr
& ~LINE_SIZE_MASK
) == db
->addr
)
175 /* Return the int data at address ADDR in dcache block DC. */
178 dcache_value (db
, addr
)
179 struct dcache_block
*db
;
184 return (db
->data
[XFORM (addr
)]);
187 /* Get a free cache block, put or keep it on the valid list,
188 and return its address. The caller should store into the block
189 the address and data that it describes, then remque it from the
190 free list and insert it into the valid list. This procedure
191 prevents errors from creeping in if a ninMemGet is interrupted
192 (which used to put garbage blocks in the valid list...). */
194 struct dcache_block
*
197 register struct dcache_block
*db
;
199 if ((db
= dcache_free
.next
) == &dcache_free
)
201 /* If we can't get one from the free list, take last valid and put
202 it on the free list. */
203 db
= dcache_valid
.last
;
205 insque (db
, &dcache_free
);
209 insque (db
, &dcache_valid
);
213 /* Return the contents of the word at address ADDR in the remote machine,
214 using the data cache. */
220 register struct dcache_block
*db
;
222 db
= dcache_hit (addr
);
225 db
= dcache_alloc ();
227 bug_read_inferior_memory (addr
& ~LINE_SIZE_MASK
, (unsigned char *) db
->data
, LINE_SIZE
);
229 db
->addr
= addr
& ~LINE_SIZE_MASK
;
230 remque (db
); /* Off the free list */
231 insque (db
, &dcache_valid
); /* On the valid list */
233 return (dcache_value (db
, addr
));
236 /* Write the word at ADDR both in the data cache and in the remote machine. */
238 dcache_poke (addr
, data
)
242 register struct dcache_block
*db
;
244 /* First make sure the word is IN the cache. DB is its cache block. */
245 db
= dcache_hit (addr
);
248 db
= dcache_alloc ();
250 bug_write_inferior_memory (addr
& ~LINE_SIZE_MASK
, (unsigned char *) db
->data
, LINE_SIZE
);
252 db
->addr
= addr
& ~LINE_SIZE_MASK
;
253 remque (db
); /* Off the free list */
254 insque (db
, &dcache_valid
); /* On the valid list */
257 /* Modify the word in the cache. */
258 db
->data
[XFORM (addr
)] = data
;
260 /* Send the changed word. */
262 bug_write_inferior_memory (addr
, (unsigned char *) &data
, 4);
266 /* The cache itself. */
267 struct dcache_block the_cache
[DCACHE_SIZE
];
269 /* Initialize the data cache. */
274 register struct dcache_block
*db
;
277 dcache_free
.next
= dcache_free
.last
= &dcache_free
;
278 dcache_valid
.next
= dcache_valid
.last
= &dcache_valid
;
279 for (i
= 0; i
< DCACHE_SIZE
; i
++, db
++)
280 insque (db
, &dcache_free
);
283 /***********************************************************************
284 * I/O stuff stolen from remote-eb.c
285 ***********************************************************************/
287 /* with a timeout of 2, we time out waiting for the prompt after an
289 static int timeout
= 4;
291 static const char *dev_name
;
293 /* Descriptor for I/O to remote machine. Initialize it to -1 so that
294 bug_open knows that we don't have a file open when the program
297 static int is_open
= 0;
303 error ("remote device not open");
312 /* Read a character from the remote system, doing all the fancy
319 buf
= SERIAL_READCHAR (desc
, timeout
);
321 if (buf
== SERIAL_TIMEOUT
)
322 error ("Timeout reading from remote system.");
335 buf
= SERIAL_READCHAR (desc
, timeout
);
336 if (buf
== SERIAL_TIMEOUT
)
342 printf ("<timeout>");
353 buf
= SERIAL_READCHAR (desc
, 0);
354 if (buf
== SERIAL_TIMEOUT
)
360 printf ("<empty poll>");
365 /* Keep discarding input from the remote system, until STRING is found.
366 Let the user break out immediately. */
376 if (readchar () == *p
)
390 /* Keep discarding input until we see the bug prompt.
392 The convention for dealing with the prompt is that you
394 o *then* wait for the prompt.
396 Thus the last thing that a procedure does with the serial line
397 will be an expect_prompt(). Exception: bug_resume does not
398 wait for the prompt, because the terminal is being handed over
399 to the inferior. However, the next thing which happens after that
400 is a bug_wait which does wait for the prompt.
401 Note that this includes abnormal exit, e.g. error(). This is
402 necessary to prevent getting into states from which we can't
410 /* Get a hex digit from the remote system & return its value.
411 If ignore_space is nonzero, ignore spaces (not newline, tab, etc). */
413 get_hex_digit (ignore_space
)
421 if (ch
>= '0' && ch
<= '9')
423 else if (ch
>= 'A' && ch
<= 'F')
424 return ch
- 'A' + 10;
425 else if (ch
>= 'a' && ch
<= 'f')
426 return ch
- 'a' + 10;
427 else if (ch
!= ' ' || !ignore_space
)
430 error ("Invalid hex digit from remote system.");
435 /* Get a byte from bug_desc and put it in *BYT. Accept any number
443 val
= get_hex_digit (1) << 4;
444 val
|= get_hex_digit (0);
448 /* Read a 32-bit hex word from the bug, preceded by a space */
456 for (j
= 0; j
< 8; j
++)
457 val
= (val
<< 4) + get_hex_digit (j
== 0);
461 /* Called when SIGALRM signal sent due to alarm() timeout. */
463 /* Number of SIGTRAPs we need to simulate. That is, the next
464 NEED_ARTIFICIAL_TRAP calls to bug_wait should just return
465 SIGTRAP without actually waiting for anything. */
467 static int need_artificial_trap
= 0;
470 bug_kill (arg
, from_tty
)
478 * Download a file specified in 'args', to the bug.
482 bug_load (args
, fromtty
)
494 abfd
= bfd_openr (args
, 0);
497 printf_filtered ("Unable to open file %s\n", args
);
501 if (bfd_check_format (abfd
, bfd_object
) == 0)
503 printf_filtered ("File is not an object file\n");
508 while (s
!= (asection
*) NULL
)
510 if (s
->flags
& SEC_LOAD
)
514 char *buffer
= xmalloc (srec_frame
);
516 printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s
->name
, s
->vma
, s
->vma
+ s
->_raw_size
);
518 for (i
= 0; i
< s
->_raw_size
; i
+= srec_frame
)
520 if (srec_frame
> s
->_raw_size
- i
)
521 srec_frame
= s
->_raw_size
- i
;
523 bfd_get_section_contents (abfd
, s
, buffer
, i
, srec_frame
);
524 bug_write_inferior_memory (s
->vma
+ i
, buffer
, srec_frame
);
525 printf_filtered ("*");
528 printf_filtered ("\n");
533 sprintf (buffer
, "rs ip %lx", (unsigned long) abfd
->start_address
);
534 bug_write_cr (buffer
);
538 /* This is called not only when we first attach, but also when the
539 user types "run" after having attached. */
541 bug_create_inferior (execfile
, args
, env
)
549 error ("Can't pass arguments to remote bug process.");
551 if (execfile
== 0 || exec_bfd
== 0)
552 error ("No exec file specified");
554 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
557 bug_kill (NULL
, NULL
);
558 bug_clear_breakpoints ();
559 init_wait_for_inferior ();
563 insert_breakpoints (); /* Needed to get correct instruction in cache */
564 proceed (entry_pt
, -1, 0);
583 while (*s
&& !isspace (*s
))
589 copy
= xmalloc (len
+ 1);
590 memcpy (copy
, word
, len
);
596 static int baudrate
= 9600;
599 bug_open (name
, from_tty
)
603 push_target (&bug_ops
);
611 dev_name
= strdup (name
);
613 if (!(desc
= SERIAL_OPEN (dev_name
)))
614 perror_with_name ((char *) dev_name
);
621 /* Hello? Are you there? */
622 SERIAL_WRITE (desc
, "\r", 1);
625 /* Clear any break points */
626 bug_clear_breakpoints ();
628 printf_filtered ("Connected to remote 187bug system.\n");
631 /* Close out all files and local state before this target loses control. */
637 /* Clear any break points */
638 bug_clear_breakpoints ();
646 /* Terminate the open connection to the remote debugger.
647 Use this when you want to detach and do something else
650 bug_detach (args
, from_tty
)
655 bug_clear_breakpoints ();
657 pop_target (); /* calls bug_close to do the real work */
660 printf_filtered ("Ending remote %s debugging\n", target_shortname
);
663 /* Tell the remote machine to resume. */
666 bug_resume (pid
, step
, sig
)
675 /* Force the next bug_wait to return a trap. Not doing anything
676 about I/O from the target means that the user has to type
677 "continue" to see any. FIXME, this should be fixed. */
678 need_artificial_trap
= 1;
686 /* Given a null terminated list of strings LIST, read the input until we find one of
687 them. Return the index of the string found or -1 on error. '?' means match
688 any single character. Note that with the algorithm we use, the initial
689 character of the string cannot recur in the string, or we will not find some
690 cases of the string in the input. If PASSTHROUGH is non-zero, then
691 pass non-matching data on. */
694 multi_scan (list
, passthrough
)
698 char *swallowed
= NULL
; /* holding area */
699 char *swallowed_p
= swallowed
; /* Current position in swallowed. */
707 /* Look through the strings. Count them. Find the largest one so we can
708 allocate a holding area. */
710 for (max_length
= string_count
= i
= 0;
714 int length
= strlen(list
[i
]);
716 if (length
> max_length
)
720 /* if we have no strings, then something is wrong. */
721 if (string_count
== 0)
724 /* otherwise, we will need a holding area big enough to hold almost two
725 copies of our largest string. */
726 swallowed_p
= swallowed
= alloca(max_length
<< 1);
728 /* and a list of pointers to current scan points. */
729 plist
= alloca(string_count
* sizeof(*plist
));
732 for (i
= 0; i
< string_count
; ++i
)
735 for (ch
= readchar(); /* loop forever */ ; ch
= readchar())
737 QUIT
; /* Let user quit and leave process running */
740 for (i
= 0; i
< string_count
; ++i
)
742 if (ch
== *plist
[i
] || *plist
[i
] == '?')
745 if (*plist
[i
] == '\0')
761 /* Print out any characters which have been swallowed. */
764 for (p
= swallowed
; p
< swallowed_p
; ++p
)
770 swallowed_p
= swallowed
;
777 /* Wait until the remote machine stops, then return,
778 storing status in STATUS just as `wait' would. */
780 static char *wait_strings
[] = {
782 "Exception: Data Access Fault (Local Bus Timeout)",
791 int old_timeout
= timeout
;
792 int old_immediate_quit
= immediate_quit
;
794 WSETEXIT ((*status
), 0);
796 /* read off leftovers from resume so that the rest can be passed
797 back out as stdout. */
798 if (need_artificial_trap
== 0)
800 expect("Effective address: ");
801 (void) get_hex_word();
805 timeout
= -1; /* Don't time out -- user program is running. */
806 immediate_quit
= 1; /* Helps ability to QUIT */
808 switch (multi_scan(wait_strings
, need_artificial_trap
== 0))
810 case 0: /* breakpoint case */
811 WSETSTOP ((*status
), SIGTRAP
);
812 /* user output from the target can be discarded here. (?) */
816 case 1: /* bus error */
817 WSETSTOP ((*status
), SIGBUS
);
818 /* user output from the target can be discarded here. (?) */
822 case 2: /* normal case */
823 if (need_artificial_trap
!= 0)
826 WSETSTOP ((*status
), SIGTRAP
);
827 need_artificial_trap
--;
833 WSETEXIT ((*status
), 0);
837 case -1: /* trouble */
839 fprintf_filtered (stderr
,
840 "Trouble reading target during wait\n");
844 timeout
= old_timeout
;
845 immediate_quit
= old_immediate_quit
;
849 /* Return the name of register number REGNO
850 in the form input and output by bug.
852 Returns a pointer to a static buffer containing the answer. */
857 static char *rn
[] = {
858 "r00", "r01", "r02", "r03", "r04", "r05", "r06", "r07",
859 "r08", "r09", "r10", "r11", "r12", "r13", "r14", "r15",
860 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
861 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
863 /* these get confusing because we omit a few and switch some ordering around. */
865 "cr01", /* 32 = psr */
866 "fcr62", /* 33 = fpsr*/
867 "fcr63", /* 34 = fpcr */
868 "ip", /* this is something of a cheat. */
870 "cr05", /* 36 = snip */
871 "cr06", /* 37 = sfip */
884 SERIAL_WRITE (desc
, a
, l
);
887 for (i
= 0; i
< l
; i
++)
899 bug_write (s
, strlen (s
));
904 #if 0 /* not currently used */
905 /* Read from remote while the input matches STRING. Return zero on
906 success, -1 on failure. */
920 printf("\nNext character is '%c' - %d and s is \"%s\".\n", c
, c
, --s
);
930 bug_srec_write_cr (s
)
942 SERIAL_WRITE(desc
, p
, 1);
943 while (readchar_nofail() != *p
);
948 /* return(bug_scan (s) || bug_scan ("\n")); */
954 /* Store register REGNO, or all if REGNO == -1. */
957 bug_fetch_register(regno
)
960 REGISTER_TYPE regval
;
967 for (i
= 0; i
< NUM_REGS
; ++i
)
968 bug_fetch_register(i
);
973 bug_write_cr(get_reg_name(regno
));
975 regval
= get_hex_word();
978 /* the following registers contain flag bits in the lower to bit slots.
980 if (regno
== PC_REGNUM
/* aka sxip */
981 || regno
== NPC_REGNUM
/* aka snip */
982 || regno
== SFIP_REGNUM
) /* aka sfip */
985 supply_register(regno
, (char *) ®val
);
991 /* Store register REGNO, or all if REGNO == -1. */
994 bug_store_register (regno
)
1004 for (i
= 0; i
< NUM_REGS
; ++i
)
1005 bug_store_register(i
);
1011 regname
= (get_reg_name(regno
));
1013 sprintf(buffer
, "rs %s %08x",
1015 read_register(regno
));
1017 bug_write_cr(buffer
);
1024 /* Get ready to modify the registers array. On machines which store
1025 individual registers, this doesn't need to do anything. On machines
1026 which store all the registers in one fell swoop, this makes sure
1027 that registers contains all the registers from the program being
1031 bug_prepare_to_store ()
1033 /* Do nothing, since we can store individual regs */
1036 /* Read a word from remote address ADDR and return it.
1037 * This goes through the data cache.
1040 bug_fetch_word (addr
)
1043 return dcache_fetch (addr
);
1046 /* Write a word WORD into remote address ADDR.
1047 This goes through the data cache. */
1050 bug_store_word (addr
, word
)
1054 dcache_poke (addr
, word
);
1058 bug_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
1063 struct target_ops
*target
; /* ignored */
1067 /* Round starting address down to longword boundary. */
1068 register CORE_ADDR addr
;
1070 /* Round ending address up; get number of longwords that makes. */
1073 /* Allocate buffer of that many longwords. */
1074 register int *buffer
;
1076 addr
= memaddr
& -sizeof (int);
1077 count
= (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
1079 buffer
= (int *) alloca (count
* sizeof (int));
1083 /* Fill start and end extra bytes of buffer with existing memory data. */
1085 if (addr
!= memaddr
|| len
< (int) sizeof (int))
1087 /* Need part of initial word -- fetch it. */
1088 buffer
[0] = bug_fetch_word (addr
);
1091 if (count
> 1) /* FIXME, avoid if even boundary */
1094 = bug_fetch_word (addr
+ (count
- 1) * sizeof (int));
1097 /* Copy data to be written over corresponding part of buffer */
1099 bcopy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
1101 /* Write the entire buffer. */
1103 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
1106 bug_store_word (addr
, buffer
[i
]);
1117 /* Read all the longwords */
1118 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
1121 buffer
[i
] = bug_fetch_word (addr
);
1129 /* Copy appropriate bytes out of the buffer. */
1130 bcopy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
1141 command
= (srec_echo_pace
? "lo 0 ;x" : "lo 0");
1143 bug_write_cr (command
);
1146 bug_srec_write_cr ("S0030000FC");
1150 /* This is an extremely vulnerable and fragile function. I've made
1151 considerable attempts to make this deterministic, but I've
1152 certainly forgotten something. The trouble is that S-records are
1153 only a partial file format, not a protocol. Worse, apparently the
1154 m88k bug monitor does not run in real time while receiving
1155 S-records. Hence, we must pay excruciating attention to when and
1156 where error messages are returned, and what has actually been sent.
1158 Each call represents a chunk of memory to be sent to the target.
1159 We break that chunk into an S0 header record, some number of S3
1160 data records each containing srec_bytes, and an S7 termination
1163 static char *srecord_strings
[] = {
1170 bug_write_inferior_memory (memaddr
, myaddr
, len
)
1172 unsigned char *myaddr
;
1179 char buffer
[(srec_bytes
+ 8) << 1];
1187 if (retries
> srec_max_retries
)
1193 printf("\n<retrying...>\n");
1195 /* This expect_prompt call is extremely important. Without
1196 it, we will tend to resend our packet so fast that it
1197 will arrive before the bug monitor is ready to receive
1198 it. This would lead to a very ugly resend loop. */
1213 thisgo
= len
- done
;
1214 if (thisgo
> srec_bytes
)
1215 thisgo
= srec_bytes
;
1217 address
= memaddr
+ done
;
1218 sprintf (buf
, "S3%02X%08X", thisgo
+ 4 + 1, address
);
1221 checksum
+= (thisgo
+ 4 + 1
1223 + ((address
>> 8) & 0xff)
1224 + ((address
>> 16) & 0xff)
1225 + ((address
>> 24) & 0xff));
1227 for (idx
= 0; idx
< thisgo
; idx
++)
1229 sprintf (buf
, "%02X", myaddr
[idx
+ done
]);
1230 checksum
+= myaddr
[idx
+ done
];
1236 /* FIXME-NOW: insert a deliberate error every now and then.
1237 This is intended for testing/debugging the error handling
1239 static int counter
= 0;
1240 if (++counter
> srec_noise
)
1247 sprintf(buf
, "%02X", ~checksum
& 0xff);
1248 bug_srec_write_cr (buffer
);
1250 if (srec_sleep
!= 0)
1253 /* This pollchar is probably redundant to the multi_scan
1254 below. Trouble is, we can't be sure when or where an
1255 error message will appear. Apparently, when running at
1256 full speed from a typical sun4, error messages tend to
1257 appear to arrive only *after* the s7 record. */
1259 if ((x
= pollchar()) != 0)
1262 printf("\n<retrying...>\n");
1266 /* flush any remaining input and verify that we are back
1267 at the prompt level. */
1269 /* start all over again. */
1278 bug_srec_write_cr("S7060000000000F9");
1281 /* Having finished the load, we need to figure out whether we
1283 } while (multi_scan(srecord_strings
, 0) == 0);;
1291 char *file
= "nothing";
1294 file
= bfd_get_filename (exec_bfd
);
1298 printf_filtered ("\tAttached to DOS asynctsr and running program %s\n", file
);
1300 printf_filtered ("\tAttached to %s at %d baud and running program %s\n", dev_name
, baudrate
, file
);
1302 printf_filtered ("\ton an m88k processor.\n");
1305 /* Copy LEN bytes of data from debugger memory at MYADDR
1306 to inferior's memory at MEMADDR. Returns errno value.
1307 * sb/sh instructions don't work on unaligned addresses, when TU=1.
1310 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1311 at debugger address MYADDR. Returns errno value. */
1313 bug_read_inferior_memory (memaddr
, myaddr
, len
)
1324 unsigned int inaddr
;
1325 unsigned int checksum
;
1327 sprintf(request
, "du 0 %x:&%d", memaddr
, len
);
1328 bug_write_cr(request
);
1330 p
= buffer
= alloca(len
);
1332 /* scan up through the header */
1333 expect("S0030000FC");
1335 while (p
< buffer
+ len
)
1337 /* scan off any white space. */
1338 while (readchar() != 'S') ;;
1340 /* what kind of s-rec? */
1343 /* scan record size */
1344 get_hex_byte(&size
);
1358 inaddr
= (inaddr
<< 8) + c
;
1361 /* intentional fall through */
1364 inaddr
= (inaddr
<< 8) + c
;
1367 /* intentional fall through */
1370 inaddr
= (inaddr
<< 8) + c
;
1374 inaddr
= (inaddr
<< 8) + c
;
1381 error("reading s-records.");
1384 if (inaddr
< memaddr
1385 || (memaddr
+ len
) < (inaddr
+ size
))
1386 error("srec out of memory range.");
1388 if (p
!= buffer
+ inaddr
- memaddr
)
1389 error("srec out of sequence.");
1391 for (; size
; --size
, ++p
)
1398 if (c
!= (~checksum
& 0xff))
1399 error("bad s-rec checksum");
1404 if (p
!= buffer
+ len
)
1407 memcpy(myaddr
, buffer
, len
);
1411 #define MAX_BREAKS 16
1412 static int num_brkpts
= 0;
1414 bug_insert_breakpoint (addr
, save
)
1416 char *save
; /* Throw away, let bug save instructions */
1420 if (num_brkpts
< MAX_BREAKS
)
1425 sprintf (buffer
, "br %x", addr
);
1426 bug_write_cr (buffer
);
1432 fprintf_filtered (stderr
,
1433 "Too many break points, break point not installed\n");
1439 bug_remove_breakpoint (addr
, save
)
1441 char *save
; /* Throw away, let bug save instructions */
1448 sprintf (buffer
, "nobr %x", addr
);
1449 bug_write_cr (buffer
);
1456 /* Clear the bugs notion of what the break points are */
1458 bug_clear_breakpoints ()
1463 bug_write_cr ("nobr");
1474 bug_clear_breakpoints ();
1475 generic_mourn_inferior ();
1478 /* Put a command string, in args, out to the bug. The bug is assumed to
1479 be in raw mode, all writing/reading done through desc.
1480 Ouput from the bug is placed on the users terminal until the
1481 prompt from the bug is seen.
1482 FIXME: Can't handle commands that take input. */
1485 bug_com (args
, fromtty
)
1494 /* Clear all input so only command relative output is displayed */
1496 bug_write_cr (args
);
1497 bug_write ("\030", 1);
1502 bug_device (args
, fromtty
)
1507 dev_name
= get_word (&args
);
1522 int newrate
= atoi (s
);
1525 if (SERIAL_SETBAUDRATE (desc
, newrate
))
1526 error ("Can't use %d baud\n", newrate
);
1528 printf_filtered ("Checking target is in sync\n");
1530 printf_filtered ("Sending commands to set target to %d\n",
1533 sprintf (buffer
, "tm %d. N 8 1", baudrate
);
1534 bug_write_cr (buffer
);
1539 struct target_ops bug_ops
=
1541 "bug", "Remote BUG monitor",
1542 "Use the mvme187 board running the BUG monitor connected\n\
1545 bug_open
, bug_close
,
1546 0, bug_detach
, bug_resume
, bug_wait
, /* attach */
1547 bug_fetch_register
, bug_store_register
,
1548 bug_prepare_to_store
,
1549 bug_xfer_inferior_memory
,
1551 bug_insert_breakpoint
, bug_remove_breakpoint
, /* Breakpoints */
1552 0, 0, 0, 0, 0, /* Terminal handling */
1553 bug_kill
, /* FIXME, kill */
1555 0, /* lookup_symbol */
1556 bug_create_inferior
, /* create_inferior */
1557 bug_mourn
, /* mourn_inferior FIXME */
1559 0, /* notice_signals */
1560 process_stratum
, 0, /* next */
1561 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
1562 0, 0, /* Section pointers */
1563 OPS_MAGIC
, /* Always the last thing */
1567 _initialize_remote_bug ()
1569 add_target (&bug_ops
);
1571 add_com ("bug <command>", class_obscure
, bug_com
,
1572 "Send a command to the BUG monitor.");
1574 add_com ("device", class_obscure
, bug_device
,
1575 "Set the terminal line for BUG communications");
1578 add_com ("speed", class_obscure
, bug_speed
,
1579 "Set the terminal line speed for BUG communications");
1583 (add_set_cmd ("srec-bytes", class_support
, var_uinteger
,
1584 (char *) &srec_bytes
,
1586 Set the number of bytes represented in each S-record.\n\
1587 This affects the communication protocol with the remote target.",
1592 (add_set_cmd ("srec-max-retries", class_support
, var_uinteger
,
1593 (char *) &srec_max_retries
,
1595 Set the number of retries for shipping S-records.\n\
1596 This affects the communication protocol with the remote target.",
1601 (add_set_cmd ("srec-frame", class_support
, var_uinteger
,
1602 (char *) &srec_frame
,
1604 Set the number of bytes in an S-record frame.\n\
1605 This affects the communication protocol with the remote target.",
1610 (add_set_cmd ("srec-noise", class_support
, var_zinteger
,
1611 (char *) &srec_noise
,
1613 Set number of S-record to send before deliberately flubbing a checksum.\n\
1614 Zero means flub none at all. This affects the communication protocol\n\
1615 with the remote target.",
1620 (add_set_cmd ("srec-sleep", class_support
, var_zinteger
,
1621 (char *) &srec_sleep
,
1623 Set number of seconds to sleep after an S-record for a possible error message to arrive.\n\
1624 This affects the communication protocol with the remote target.",
1629 (add_set_cmd ("srec-echo-pace", class_support
, var_boolean
,
1630 (char *) &srec_echo_pace
,
1632 Set echo-verification.\n\
1633 When on, use verification by echo when downloading S-records. This is\n\
1634 much slower, but generally more reliable.",