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 /* To be silent, or to loudly echo all input and output to and from
71 static int bug88k_snoop
= 0;
73 /* This is the serial descriptor to our target. */
75 static serial_t desc
= NULL
;
77 /* This variable is somewhat arbitrary. It's here so that it can be
78 set from within a running gdb. */
80 static int srec_max_retries
= 3;
82 /* Each S-record download to the target consists of an S0 header
83 record, some number of S3 data records, and one S7 termination
84 record. I call this download a "frame". Srec_frame says how many
85 bytes will be represented in each frame. */
87 static int srec_frame
= 160;
89 /* This variable determines how many bytes will be represented in each
92 static int srec_bytes
= 40;
94 /* At one point it appeared to me as though the bug monitor could not
95 really be expected to receive two sequential characters at 9600
96 baud reliably. Echo-pacing is an attempt to force data across the
97 line even in this condition. Specifically, in echo-pace mode, each
98 character is sent one at a time and we look for the echo before
99 sending the next. This is excruciatingly slow. */
101 static int srec_echo_pace
= 0;
103 /* How long to wait after an srec for a possible error message.
104 Similar to the above, I tried sleeping after sending each S3 record
105 in hopes that I might actually see error messages from the bug
106 monitor. This might actually work if we were to use sleep
107 intervals smaller than 1 second. */
109 static int srec_sleep
= 0;
111 /* Every srec_noise records, flub the checksum. This is a debugging
112 feature. Set the variable to something other than 1 in order to
113 inject *deliberate* checksum errors. One might do this if one
114 wanted to test error handling and recovery. */
116 static int srec_noise
= 0;
118 /***********************************************************************/
119 /* Caching stuff stolen from remote-nindy.c */
121 /* The data cache records all the data read from the remote machine
122 since the last time it stopped.
124 Each cache block holds LINE_SIZE bytes of data
125 starting at a multiple-of-LINE_SIZE address. */
127 #define LINE_SIZE_POWER 4
128 #define LINE_SIZE (1<<LINE_SIZE_POWER) /* eg 1<<3 == 8 */
129 #define LINE_SIZE_MASK ((LINE_SIZE-1)) /* eg 7*2+1= 111*/
130 #define DCACHE_SIZE 64 /* Number of cache blocks */
131 #define XFORM(x) ((x&LINE_SIZE_MASK)>>2)
134 struct dcache_block
*next
, *last
;
135 unsigned int addr
; /* Address for which data is recorded. */
136 int data
[LINE_SIZE
/ sizeof (int)];
139 struct dcache_block dcache_free
, dcache_valid
;
141 /* Free all the data cache blocks, thus discarding all cached data. */
146 register struct dcache_block
*db
;
148 while ((db
= dcache_valid
.next
) != &dcache_valid
)
151 insque (db
, &dcache_free
);
156 * If addr is present in the dcache, return the address of the block
160 struct dcache_block
*
164 register struct dcache_block
*db
;
169 /* Search all cache blocks for one that is at this address. */
170 db
= dcache_valid
.next
;
171 while (db
!= &dcache_valid
)
173 if ((addr
& ~LINE_SIZE_MASK
) == db
->addr
)
180 /* Return the int data at address ADDR in dcache block DC. */
183 dcache_value (db
, addr
)
184 struct dcache_block
*db
;
189 return (db
->data
[XFORM (addr
)]);
192 /* Get a free cache block, put or keep it on the valid list,
193 and return its address. The caller should store into the block
194 the address and data that it describes, then remque it from the
195 free list and insert it into the valid list. This procedure
196 prevents errors from creeping in if a ninMemGet is interrupted
197 (which used to put garbage blocks in the valid list...). */
199 struct dcache_block
*
202 register struct dcache_block
*db
;
204 if ((db
= dcache_free
.next
) == &dcache_free
)
206 /* If we can't get one from the free list, take last valid and put
207 it on the free list. */
208 db
= dcache_valid
.last
;
210 insque (db
, &dcache_free
);
214 insque (db
, &dcache_valid
);
218 /* Return the contents of the word at address ADDR in the remote machine,
219 using the data cache. */
225 register struct dcache_block
*db
;
227 db
= dcache_hit (addr
);
230 db
= dcache_alloc ();
232 bug_read_inferior_memory (addr
& ~LINE_SIZE_MASK
, (unsigned char *) db
->data
, LINE_SIZE
);
234 db
->addr
= addr
& ~LINE_SIZE_MASK
;
235 remque (db
); /* Off the free list */
236 insque (db
, &dcache_valid
); /* On the valid list */
238 return (dcache_value (db
, addr
));
241 /* Write the word at ADDR both in the data cache and in the remote machine. */
243 dcache_poke (addr
, data
)
247 register struct dcache_block
*db
;
249 /* First make sure the word is IN the cache. DB is its cache block. */
250 db
= dcache_hit (addr
);
253 db
= dcache_alloc ();
255 bug_write_inferior_memory (addr
& ~LINE_SIZE_MASK
, (unsigned char *) db
->data
, LINE_SIZE
);
257 db
->addr
= addr
& ~LINE_SIZE_MASK
;
258 remque (db
); /* Off the free list */
259 insque (db
, &dcache_valid
); /* On the valid list */
262 /* Modify the word in the cache. */
263 db
->data
[XFORM (addr
)] = data
;
265 /* Send the changed word. */
267 bug_write_inferior_memory (addr
, (unsigned char *) &data
, 4);
271 /* The cache itself. */
272 struct dcache_block the_cache
[DCACHE_SIZE
];
274 /* Initialize the data cache. */
279 register struct dcache_block
*db
;
282 dcache_free
.next
= dcache_free
.last
= &dcache_free
;
283 dcache_valid
.next
= dcache_valid
.last
= &dcache_valid
;
284 for (i
= 0; i
< DCACHE_SIZE
; i
++, db
++)
285 insque (db
, &dcache_free
);
288 /***********************************************************************
289 * I/O stuff stolen from remote-eb.c
290 ***********************************************************************/
292 /* with a timeout of 2, we time out waiting for the prompt after an
294 static int timeout
= 4;
296 static const char *dev_name
;
298 /* Descriptor for I/O to remote machine. Initialize it to -1 so that
299 bug_open knows that we don't have a file open when the program
302 static int is_open
= 0;
308 error ("remote device not open");
317 /* Read a character from the remote system, doing all the fancy
324 buf
= SERIAL_READCHAR (desc
, timeout
);
326 if (buf
== SERIAL_TIMEOUT
)
327 error ("Timeout reading from remote system.");
340 buf
= SERIAL_READCHAR (desc
, timeout
);
341 if (buf
== SERIAL_TIMEOUT
)
347 printf ("<timeout>");
358 buf
= SERIAL_READCHAR (desc
, 0);
359 if (buf
== SERIAL_TIMEOUT
)
365 printf ("<empty poll>");
370 /* Keep discarding input from the remote system, until STRING is found.
371 Let the user break out immediately. */
381 if (readchar () == *p
)
395 /* Keep discarding input until we see the bug prompt.
397 The convention for dealing with the prompt is that you
399 o *then* wait for the prompt.
401 Thus the last thing that a procedure does with the serial line
402 will be an expect_prompt(). Exception: bug_resume does not
403 wait for the prompt, because the terminal is being handed over
404 to the inferior. However, the next thing which happens after that
405 is a bug_wait which does wait for the prompt.
406 Note that this includes abnormal exit, e.g. error(). This is
407 necessary to prevent getting into states from which we can't
415 /* Get a hex digit from the remote system & return its value.
416 If ignore_space is nonzero, ignore spaces (not newline, tab, etc). */
418 get_hex_digit (ignore_space
)
426 if (ch
>= '0' && ch
<= '9')
428 else if (ch
>= 'A' && ch
<= 'F')
429 return ch
- 'A' + 10;
430 else if (ch
>= 'a' && ch
<= 'f')
431 return ch
- 'a' + 10;
432 else if (ch
!= ' ' || !ignore_space
)
435 error ("Invalid hex digit from remote system.");
440 /* Get a byte from bug_desc and put it in *BYT. Accept any number
448 val
= get_hex_digit (1) << 4;
449 val
|= get_hex_digit (0);
453 /* Read a 32-bit hex word from the bug, preceded by a space */
461 for (j
= 0; j
< 8; j
++)
462 val
= (val
<< 4) + get_hex_digit (j
== 0);
466 /* Called when SIGALRM signal sent due to alarm() timeout. */
468 /* Number of SIGTRAPs we need to simulate. That is, the next
469 NEED_ARTIFICIAL_TRAP calls to bug_wait should just return
470 SIGTRAP without actually waiting for anything. */
472 static int need_artificial_trap
= 0;
475 bug_kill (arg
, from_tty
)
483 * Download a file specified in 'args', to the bug.
487 bug_load (args
, fromtty
)
499 abfd
= bfd_openr (args
, 0);
502 printf_filtered ("Unable to open file %s\n", args
);
506 if (bfd_check_format (abfd
, bfd_object
) == 0)
508 printf_filtered ("File is not an object file\n");
513 while (s
!= (asection
*) NULL
)
515 if (s
->flags
& SEC_LOAD
)
519 char *buffer
= xmalloc (srec_frame
);
521 printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s
->name
, s
->vma
, s
->vma
+ s
->_raw_size
);
523 for (i
= 0; i
< s
->_raw_size
; i
+= srec_frame
)
525 if (srec_frame
> s
->_raw_size
- i
)
526 srec_frame
= s
->_raw_size
- i
;
528 bfd_get_section_contents (abfd
, s
, buffer
, i
, srec_frame
);
529 bug_write_inferior_memory (s
->vma
+ i
, buffer
, srec_frame
);
530 printf_filtered ("*");
533 printf_filtered ("\n");
538 sprintf (buffer
, "rs ip %lx", (unsigned long) abfd
->start_address
);
539 bug_write_cr (buffer
);
543 /* This is called not only when we first attach, but also when the
544 user types "run" after having attached. */
546 bug_create_inferior (execfile
, args
, env
)
554 error ("Can't pass arguments to remote bug process.");
556 if (execfile
== 0 || exec_bfd
== 0)
557 error ("No exec file specified");
559 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
562 bug_kill (NULL
, NULL
);
563 bug_clear_breakpoints ();
564 init_wait_for_inferior ();
568 insert_breakpoints (); /* Needed to get correct instruction in cache */
569 proceed (entry_pt
, -1, 0);
588 while (*s
&& !isspace (*s
))
594 copy
= xmalloc (len
+ 1);
595 memcpy (copy
, word
, len
);
601 static int baudrate
= 9600;
604 bug_open (name
, from_tty
)
608 push_target (&bug_ops
);
616 dev_name
= strdup (name
);
618 if (!(desc
= SERIAL_OPEN (dev_name
)))
619 perror_with_name ((char *) dev_name
);
626 /* Hello? Are you there? */
627 SERIAL_WRITE (desc
, "\r", 1);
630 /* Clear any break points */
631 bug_clear_breakpoints ();
633 printf_filtered ("Connected to remote 187bug system.\n");
636 /* Close out all files and local state before this target loses control. */
642 /* Clear any break points */
643 bug_clear_breakpoints ();
651 /* Terminate the open connection to the remote debugger.
652 Use this when you want to detach and do something else
655 bug_detach (args
, from_tty
)
660 bug_clear_breakpoints ();
662 pop_target (); /* calls bug_close to do the real work */
665 printf_filtered ("Ending remote %s debugging\n", target_shortname
);
668 /* Tell the remote machine to resume. */
671 bug_resume (pid
, step
, sig
)
680 /* Force the next bug_wait to return a trap. Not doing anything
681 about I/O from the target means that the user has to type
682 "continue" to see any. FIXME, this should be fixed. */
683 need_artificial_trap
= 1;
691 /* Given a null terminated list of strings LIST, read the input until we find one of
692 them. Return the index of the string found or -1 on error. '?' means match
693 any single character. Note that with the algorithm we use, the initial
694 character of the string cannot recur in the string, or we will not find some
695 cases of the string in the input. If PASSTHROUGH is non-zero, then
696 pass non-matching data on. */
699 multi_scan (list
, passthrough
)
703 char *swallowed
= NULL
; /* holding area */
704 char *swallowed_p
= swallowed
; /* Current position in swallowed. */
712 /* Look through the strings. Count them. Find the largest one so we can
713 allocate a holding area. */
715 for (max_length
= string_count
= i
= 0;
719 int length
= strlen(list
[i
]);
721 if (length
> max_length
)
725 /* if we have no strings, then something is wrong. */
726 if (string_count
== 0)
729 /* otherwise, we will need a holding area big enough to hold almost two
730 copies of our largest string. */
731 swallowed_p
= swallowed
= alloca(max_length
<< 1);
733 /* and a list of pointers to current scan points. */
734 plist
= alloca(string_count
* sizeof(*plist
));
737 for (i
= 0; i
< string_count
; ++i
)
740 for (ch
= readchar(); /* loop forever */ ; ch
= readchar())
742 QUIT
; /* Let user quit and leave process running */
745 for (i
= 0; i
< string_count
; ++i
)
747 if (ch
== *plist
[i
] || *plist
[i
] == '?')
750 if (*plist
[i
] == '\0')
766 /* Print out any characters which have been swallowed. */
769 for (p
= swallowed
; p
< swallowed_p
; ++p
)
775 swallowed_p
= swallowed
;
782 /* Wait until the remote machine stops, then return,
783 storing status in STATUS just as `wait' would. */
785 static char *wait_strings
[] = {
787 "Exception: Data Access Fault (Local Bus Timeout)",
796 int old_timeout
= timeout
;
797 int old_immediate_quit
= immediate_quit
;
799 WSETEXIT ((*status
), 0);
801 /* read off leftovers from resume so that the rest can be passed
802 back out as stdout. */
803 if (need_artificial_trap
== 0)
805 expect("Effective address: ");
806 (void) get_hex_word();
810 timeout
= -1; /* Don't time out -- user program is running. */
811 immediate_quit
= 1; /* Helps ability to QUIT */
813 switch (multi_scan(wait_strings
, need_artificial_trap
== 0))
815 case 0: /* breakpoint case */
816 WSETSTOP ((*status
), SIGTRAP
);
817 /* user output from the target can be discarded here. (?) */
821 case 1: /* bus error */
822 WSETSTOP ((*status
), SIGBUS
);
823 /* user output from the target can be discarded here. (?) */
827 case 2: /* normal case */
828 if (need_artificial_trap
!= 0)
831 WSETSTOP ((*status
), SIGTRAP
);
832 need_artificial_trap
--;
838 WSETEXIT ((*status
), 0);
842 case -1: /* trouble */
844 fprintf_filtered (stderr
,
845 "Trouble reading target during wait\n");
849 timeout
= old_timeout
;
850 immediate_quit
= old_immediate_quit
;
854 /* Return the name of register number REGNO
855 in the form input and output by bug.
857 Returns a pointer to a static buffer containing the answer. */
862 static char *rn
[] = {
863 "r00", "r01", "r02", "r03", "r04", "r05", "r06", "r07",
864 "r08", "r09", "r10", "r11", "r12", "r13", "r14", "r15",
865 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
866 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
868 /* these get confusing because we omit a few and switch some ordering around. */
870 "cr01", /* 32 = psr */
871 "fcr62", /* 33 = fpsr*/
872 "fcr63", /* 34 = fpcr */
873 "ip", /* this is something of a cheat. */
875 "cr05", /* 36 = snip */
876 "cr06", /* 37 = sfip */
889 SERIAL_WRITE (desc
, a
, l
);
892 for (i
= 0; i
< l
; i
++)
904 bug_write (s
, strlen (s
));
909 #if 0 /* not currently used */
910 /* Read from remote while the input matches STRING. Return zero on
911 success, -1 on failure. */
925 printf("\nNext character is '%c' - %d and s is \"%s\".\n", c
, c
, --s
);
935 bug_srec_write_cr (s
)
947 SERIAL_WRITE(desc
, p
, 1);
948 while (readchar_nofail() != *p
);
953 /* return(bug_scan (s) || bug_scan ("\n")); */
959 /* Store register REGNO, or all if REGNO == -1. */
962 bug_fetch_register(regno
)
965 REGISTER_TYPE regval
;
972 for (i
= 0; i
< NUM_REGS
; ++i
)
973 bug_fetch_register(i
);
978 bug_write_cr(get_reg_name(regno
));
980 regval
= get_hex_word();
983 /* the following registers contain flag bits in the lower to bit slots.
985 if (regno
== PC_REGNUM
/* aka sxip */
986 || regno
== NPC_REGNUM
/* aka snip */
987 || regno
== SFIP_REGNUM
) /* aka sfip */
990 supply_register(regno
, (char *) ®val
);
996 /* Store register REGNO, or all if REGNO == -1. */
999 bug_store_register (regno
)
1009 for (i
= 0; i
< NUM_REGS
; ++i
)
1010 bug_store_register(i
);
1016 regname
= (get_reg_name(regno
));
1018 sprintf(buffer
, "rs %s %08x",
1020 read_register(regno
));
1022 bug_write_cr(buffer
);
1029 /* Get ready to modify the registers array. On machines which store
1030 individual registers, this doesn't need to do anything. On machines
1031 which store all the registers in one fell swoop, this makes sure
1032 that registers contains all the registers from the program being
1036 bug_prepare_to_store ()
1038 /* Do nothing, since we can store individual regs */
1041 /* Read a word from remote address ADDR and return it.
1042 * This goes through the data cache.
1045 bug_fetch_word (addr
)
1048 return dcache_fetch (addr
);
1051 /* Write a word WORD into remote address ADDR.
1052 This goes through the data cache. */
1055 bug_store_word (addr
, word
)
1059 dcache_poke (addr
, word
);
1063 bug_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
1068 struct target_ops
*target
; /* ignored */
1072 /* Round starting address down to longword boundary. */
1073 register CORE_ADDR addr
;
1075 /* Round ending address up; get number of longwords that makes. */
1078 /* Allocate buffer of that many longwords. */
1079 register int *buffer
;
1081 addr
= memaddr
& -sizeof (int);
1082 count
= (((memaddr
+ len
) - addr
) + sizeof (int) - 1) / sizeof (int);
1084 buffer
= (int *) alloca (count
* sizeof (int));
1088 /* Fill start and end extra bytes of buffer with existing memory data. */
1090 if (addr
!= memaddr
|| len
< (int) sizeof (int))
1092 /* Need part of initial word -- fetch it. */
1093 buffer
[0] = bug_fetch_word (addr
);
1096 if (count
> 1) /* FIXME, avoid if even boundary */
1099 = bug_fetch_word (addr
+ (count
- 1) * sizeof (int));
1102 /* Copy data to be written over corresponding part of buffer */
1104 bcopy (myaddr
, (char *) buffer
+ (memaddr
& (sizeof (int) - 1)), len
);
1106 /* Write the entire buffer. */
1108 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
1111 bug_store_word (addr
, buffer
[i
]);
1122 /* Read all the longwords */
1123 for (i
= 0; i
< count
; i
++, addr
+= sizeof (int))
1126 buffer
[i
] = bug_fetch_word (addr
);
1134 /* Copy appropriate bytes out of the buffer. */
1135 bcopy ((char *) buffer
+ (memaddr
& (sizeof (int) - 1)), myaddr
, len
);
1146 command
= (srec_echo_pace
? "lo 0 ;x" : "lo 0");
1148 bug_write_cr (command
);
1151 bug_srec_write_cr ("S0030000FC");
1155 /* This is an extremely vulnerable and fragile function. I've made
1156 considerable attempts to make this deterministic, but I've
1157 certainly forgotten something. The trouble is that S-records are
1158 only a partial file format, not a protocol. Worse, apparently the
1159 m88k bug monitor does not run in real time while receiving
1160 S-records. Hence, we must pay excruciating attention to when and
1161 where error messages are returned, and what has actually been sent.
1163 Each call represents a chunk of memory to be sent to the target.
1164 We break that chunk into an S0 header record, some number of S3
1165 data records each containing srec_bytes, and an S7 termination
1168 static char *srecord_strings
[] = {
1175 bug_write_inferior_memory (memaddr
, myaddr
, len
)
1177 unsigned char *myaddr
;
1184 char buffer
[(srec_bytes
+ 8) << 1];
1192 if (retries
> srec_max_retries
)
1198 printf("\n<retrying...>\n");
1200 /* This expect_prompt call is extremely important. Without
1201 it, we will tend to resend our packet so fast that it
1202 will arrive before the bug monitor is ready to receive
1203 it. This would lead to a very ugly resend loop. */
1218 thisgo
= len
- done
;
1219 if (thisgo
> srec_bytes
)
1220 thisgo
= srec_bytes
;
1222 address
= memaddr
+ done
;
1223 sprintf (buf
, "S3%02X%08X", thisgo
+ 4 + 1, address
);
1226 checksum
+= (thisgo
+ 4 + 1
1228 + ((address
>> 8) & 0xff)
1229 + ((address
>> 16) & 0xff)
1230 + ((address
>> 24) & 0xff));
1232 for (idx
= 0; idx
< thisgo
; idx
++)
1234 sprintf (buf
, "%02X", myaddr
[idx
+ done
]);
1235 checksum
+= myaddr
[idx
+ done
];
1241 /* FIXME-NOW: insert a deliberate error every now and then.
1242 This is intended for testing/debugging the error handling
1244 static int counter
= 0;
1245 if (++counter
> srec_noise
)
1252 sprintf(buf
, "%02X", ~checksum
& 0xff);
1253 bug_srec_write_cr (buffer
);
1255 if (srec_sleep
!= 0)
1258 /* This pollchar is probably redundant to the multi_scan
1259 below. Trouble is, we can't be sure when or where an
1260 error message will appear. Apparently, when running at
1261 full speed from a typical sun4, error messages tend to
1262 appear to arrive only *after* the s7 record. */
1264 if ((x
= pollchar()) != 0)
1267 printf("\n<retrying...>\n");
1271 /* flush any remaining input and verify that we are back
1272 at the prompt level. */
1274 /* start all over again. */
1283 bug_srec_write_cr("S7060000000000F9");
1286 /* Having finished the load, we need to figure out whether we
1288 } while (multi_scan(srecord_strings
, 0) == 0);;
1296 char *file
= "nothing";
1299 file
= bfd_get_filename (exec_bfd
);
1303 printf_filtered ("\tAttached to DOS asynctsr and running program %s\n", file
);
1305 printf_filtered ("\tAttached to %s at %d baud and running program %s\n", dev_name
, baudrate
, file
);
1307 printf_filtered ("\ton an m88k processor.\n");
1310 /* Copy LEN bytes of data from debugger memory at MYADDR
1311 to inferior's memory at MEMADDR. Returns errno value.
1312 * sb/sh instructions don't work on unaligned addresses, when TU=1.
1315 /* Read LEN bytes from inferior memory at MEMADDR. Put the result
1316 at debugger address MYADDR. Returns errno value. */
1318 bug_read_inferior_memory (memaddr
, myaddr
, len
)
1329 unsigned int inaddr
;
1330 unsigned int checksum
;
1332 sprintf(request
, "du 0 %x:&%d", memaddr
, len
);
1333 bug_write_cr(request
);
1335 p
= buffer
= alloca(len
);
1337 /* scan up through the header */
1338 expect("S0030000FC");
1340 while (p
< buffer
+ len
)
1342 /* scan off any white space. */
1343 while (readchar() != 'S') ;;
1345 /* what kind of s-rec? */
1348 /* scan record size */
1349 get_hex_byte(&size
);
1363 inaddr
= (inaddr
<< 8) + c
;
1366 /* intentional fall through */
1369 inaddr
= (inaddr
<< 8) + c
;
1372 /* intentional fall through */
1375 inaddr
= (inaddr
<< 8) + c
;
1379 inaddr
= (inaddr
<< 8) + c
;
1386 error("reading s-records.");
1389 if (inaddr
< memaddr
1390 || (memaddr
+ len
) < (inaddr
+ size
))
1391 error("srec out of memory range.");
1393 if (p
!= buffer
+ inaddr
- memaddr
)
1394 error("srec out of sequence.");
1396 for (; size
; --size
, ++p
)
1403 if (c
!= (~checksum
& 0xff))
1404 error("bad s-rec checksum");
1409 if (p
!= buffer
+ len
)
1412 memcpy(myaddr
, buffer
, len
);
1416 #define MAX_BREAKS 16
1417 static int num_brkpts
= 0;
1419 bug_insert_breakpoint (addr
, save
)
1421 char *save
; /* Throw away, let bug save instructions */
1425 if (num_brkpts
< MAX_BREAKS
)
1430 sprintf (buffer
, "br %x", addr
);
1431 bug_write_cr (buffer
);
1437 fprintf_filtered (stderr
,
1438 "Too many break points, break point not installed\n");
1444 bug_remove_breakpoint (addr
, save
)
1446 char *save
; /* Throw away, let bug save instructions */
1453 sprintf (buffer
, "nobr %x", addr
);
1454 bug_write_cr (buffer
);
1461 /* Clear the bugs notion of what the break points are */
1463 bug_clear_breakpoints ()
1468 bug_write_cr ("nobr");
1479 bug_clear_breakpoints ();
1480 generic_mourn_inferior ();
1483 /* Put a command string, in args, out to the bug. The bug is assumed to
1484 be in raw mode, all writing/reading done through desc.
1485 Ouput from the bug is placed on the users terminal until the
1486 prompt from the bug is seen.
1487 FIXME: Can't handle commands that take input. */
1490 bug_com (args
, fromtty
)
1499 /* Clear all input so only command relative output is displayed */
1501 bug_write_cr (args
);
1502 bug_write ("\030", 1);
1507 bug_device (args
, fromtty
)
1512 dev_name
= get_word (&args
);
1527 int newrate
= atoi (s
);
1530 if (SERIAL_SETBAUDRATE (desc
, newrate
))
1531 error ("Can't use %d baud\n", newrate
);
1533 printf_filtered ("Checking target is in sync\n");
1535 printf_filtered ("Sending commands to set target to %d\n",
1538 sprintf (buffer
, "tm %d. N 8 1", baudrate
);
1539 bug_write_cr (buffer
);
1544 struct target_ops bug_ops
=
1546 "bug", "Remote BUG monitor",
1547 "Use the mvme187 board running the BUG monitor connected\n\
1550 bug_open
, bug_close
,
1551 0, bug_detach
, bug_resume
, bug_wait
, /* attach */
1552 bug_fetch_register
, bug_store_register
,
1553 bug_prepare_to_store
,
1554 bug_xfer_inferior_memory
,
1556 bug_insert_breakpoint
, bug_remove_breakpoint
, /* Breakpoints */
1557 0, 0, 0, 0, 0, /* Terminal handling */
1558 bug_kill
, /* FIXME, kill */
1560 0, /* lookup_symbol */
1561 bug_create_inferior
, /* create_inferior */
1562 bug_mourn
, /* mourn_inferior FIXME */
1564 0, /* notice_signals */
1565 process_stratum
, 0, /* next */
1566 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
1567 0, 0, /* Section pointers */
1568 OPS_MAGIC
, /* Always the last thing */
1572 _initialize_remote_bug ()
1574 add_target (&bug_ops
);
1576 add_com ("bug <command>", class_obscure
, bug_com
,
1577 "Send a command to the BUG monitor.");
1579 add_com ("device", class_obscure
, bug_device
,
1580 "Set the terminal line for BUG communications");
1583 add_com ("speed", class_obscure
, bug_speed
,
1584 "Set the terminal line speed for BUG communications");
1588 (add_set_cmd ("srec-bytes", class_support
, var_uinteger
,
1589 (char *) &srec_bytes
,
1591 Set the number of bytes represented in each S-record.\n\
1592 This affects the communication protocol with the remote target.",
1597 (add_set_cmd ("srec-max-retries", class_support
, var_uinteger
,
1598 (char *) &srec_max_retries
,
1600 Set the number of retries for shipping S-records.\n\
1601 This affects the communication protocol with the remote target.",
1606 (add_set_cmd ("srec-frame", class_support
, var_uinteger
,
1607 (char *) &srec_frame
,
1609 Set the number of bytes in an S-record frame.\n\
1610 This affects the communication protocol with the remote target.",
1615 (add_set_cmd ("srec-noise", class_support
, var_zinteger
,
1616 (char *) &srec_noise
,
1618 Set number of S-record to send before deliberately flubbing a checksum.\n\
1619 Zero means flub none at all. This affects the communication protocol\n\
1620 with the remote target.",
1625 (add_set_cmd ("srec-sleep", class_support
, var_zinteger
,
1626 (char *) &srec_sleep
,
1628 Set number of seconds to sleep after an S-record for a possible error message to arrive.\n\
1629 This affects the communication protocol with the remote target.",
1634 (add_set_cmd ("srec-echo-pace", class_support
, var_boolean
,
1635 (char *) &srec_echo_pace
,
1637 Set echo-verification.\n\
1638 When on, use verification by echo when downloading S-records. This is\n\
1639 much slower, but generally more reliable.",
1644 (add_set_cmd ("bug88k-snoop", class_support
, var_boolean
,
1645 (char *) &bug88k_snoop
,
1647 Set echoing of what's going to and from the monitor.\n\
1648 When on, echo data going out on and coming back from the serial line.",
This page took 0.064943 seconds and 4 git commands to generate.