1 /* Remote debugging interface for EST-300 ICE, for GDB
2 Copyright 1994 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 Written by Steve Chamberlain for Cygnus Support.
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. */
32 #include <sys/types.h>
34 #include "remote-utils.h"
37 static void expect_char
PARAMS ((int));
52 int c
= sr_readchar ();
68 if (ch
>= '0' && ch
<= '9')
70 else if (ch
>= 'A' && ch
<= 'F')
72 else if (ch
>= 'a' && ch
<= 'f')
81 int value
= get_hex_digit (*start
);
84 *start
= sr_readchar ();
85 while ((try = get_hex_digit (*start
)) >= 0)
89 *start
= sr_readchar ();
94 /* Tell the remote machine to resume. */
97 est_resume (pid
, step
, sig
)
100 write_and_expect (step
? ".SI" : ".GO");
103 /* A reg dump looks like
104 D0 = 00000000 D1 = 00000000 D2 = 00000000 D3 = 00000000
105 D4 = 00000000 D5 = 00000000 D6 = 00000000 D7 = 00000000
106 A0 = 00000000 A1 = 00000000 A2 = 00000000 A3 = 00000000
107 A4 = 00000000 A5 = 00000000 A6 = 00000000 A7 = 001104FE
108 USP = 00110400 SSP*= 001104FE PC = 00229BBC SR = 2000
109 VBR = 00110000 SFC = 0005 DFC = 0005
113 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00001234 00000000 001104FE 00110400 001104FE 00229BBC 2000 00110000 0005 0005
117 target_to_gdb_rn (rn
)
130 static void est_fetch_register ();
132 est_fetch_registers ()
139 write_and_expect (".DR");
144 for (regno
= 0; regno
< NUM_REGS
; regno
++)
145 supply_register (regno
, buf
);
148 for (target_rn
= 0; target_rn
< 23; target_rn
++)
151 while (!isdigit (c
) && !isalpha (c
))
154 while (isdigit (c
) || (c
>= 'A' && c
<= 'F'))
160 val
= val
+ c
- 'A' + 10;
164 regno
= target_to_gdb_rn (target_rn
);
171 supply_register (regno
, buf
);
177 /* Fetch register REGNO, or all registers if REGNO is -1.
178 Returns errno value. */
182 est_fetch_register (regno
)
185 est_fetch_registers ();
188 /* Store the remote registers from the contents of the block REGS. */
190 static void est_store_register ();
192 est_store_registers ()
196 for (regno
= 0; regno
< 18; regno
++)
197 est_store_register (regno
);
198 registers_changed ();
201 /* Store register REGNO, or all if REGNO == 0.
202 Return errno value. */
204 est_store_register (regno
)
210 est_store_registers ();
215 sprintf (buf
, ".SR D%d %x", regno
, read_register (regno
));
217 sprintf (buf
, ".SR A%d %x", regno
- 8, read_register (regno
));
218 else if (regno
== PC_REGNUM
)
219 sprintf (buf
, ".SR PC %x", read_register (regno
));
220 else if (regno
== PS_REGNUM
)
221 sprintf (buf
, ".SR SR %x", read_register (regno
));
224 write_and_expect (buf
);
228 /* Get ready to modify the registers array. On machines which store
229 individual registers, this doesn't need to do anything. On machines
230 which store all the registers in one fell swoop, this makes sure
231 that registers contains all the registers from the program being
237 stickbyte (where
, what
)
241 static CONST
char digs
[] = "0123456789ABCDEF";
242 where
[0] = digs
[(what
>> 4) & 0xf];
243 where
[1] = digs
[(what
& 0xf) & 0xf];
247 /* Copy LEN bytes of data from debugger memory at MYADDR
248 to inferior's memory at MEMADDR. Returns length moved. */
251 est_write_memory (memaddr
, myaddr
, len
)
253 unsigned char *myaddr
;
257 #define maxstride 128
260 write_and_expect (".DL");
262 for (i
= 0; i
< len
; i
+= stride
)
264 char compose
[maxstride
* 2 + 50];
265 int address
= i
+ memaddr
;
271 if (stride
> maxstride
)
274 compose
[where
++] = 'S';
276 if (address
>= 0xffffff)
280 else if (address
>= 0xffff)
286 compose
[where
++] = alen
- 1 + '0'; /* insert type */
287 check_sum
+= stickbyte (compose
+ where
, alen
+ stride
+ 1); /* Insert length */
292 check_sum
+= stickbyte (compose
+ where
, address
>> (8 * (alen
)));
296 for (j
= 0; j
< stride
; j
++)
298 check_sum
+= stickbyte (compose
+ where
, myaddr
[i
+ j
]);
302 stickbyte (compose
+ where
, ~check_sum
);
305 compose
[where
++] = 0;
307 sr_write_cr (compose
);
308 while (sr_readchar () != '+')
309 sr_write_cr (compose
);
312 /* Send the trailer record */
313 sr_write_cr ("S70500000000FA");
322 The dump memory command generates output which looks like:
326 4E 56 FF FC 4E 71 42 AE FF FC 72 09 B2 AE FF FC NV..NqB...r.....
327 6C 02 60 12 2F 2E FF FC 4E B9 00 00 00 2A 58 4F l.`./...N....*XO
328 52 AE FF FC 60 E4 4E 5E 4E 75 4E 56 00 00 20 2E R...`.N^NuNV.. .
329 00 08 D1 B9 00 00 00 00 4E 5E 4E 75 06 46 40 54 ........N^Nu.F@T
330 04 45 44 4C 54 45 40 56 42 F4 04 64 24 45 05 05 .EDLTE@VB..d$E..
331 00 6D 04 46 00 45 4C 05 04 46 04 4C 44 CD 00 65 .m.F.EL..F.LD..e
332 40 45 44 55 45 45 45 46 04 44 44 40 05 4D 00 44 @EDUEEEF.DD@.M.D
337 est_read_memory (memaddr
, myaddr
, len
)
339 unsigned char *myaddr
;
345 /* Starting address of this pass. */
347 if (((memaddr
- 1) + len
) < memaddr
)
353 sprintf (buf
, ".dmb %x %x", memaddr
, len
);
354 write_and_expect (buf
);
361 while (!isdigit (c
) && !isalpha (c
)) {
371 myaddr
[count
++] = get_hex (&c
);
389 est_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
391 unsigned char *myaddr
;
394 struct target_ops
*target
; /* ignored */
398 return est_write_memory (memaddr
, myaddr
, len
);
402 return est_read_memory (memaddr
, myaddr
, len
);
407 #define MAX_DEBUG_BREAKPOINTS 100
409 extern int memory_breakpoint_size
;
410 static CORE_ADDR breakaddr
[MAX_DEBUG_BREAKPOINTS
] =
414 est_clear_all_breakpoints ()
417 for (i
= 0; i
< MAX_DEBUG_BREAKPOINTS
; i
++)
424 write_and_expect (".RB");
431 est_insert_breakpoint (addr
, shadow
)
433 unsigned char *shadow
;
437 for (i
= 0; i
<= MAX_DEBUG_BREAKPOINTS
; i
++)
438 if (breakaddr
[i
] == 0)
442 sprintf (buf
, ".SB %x", addr
);
443 write_and_expect (buf
);
447 error ("Too many breakpoints ( > %d) for the est\n", MAX_DEBUG_BREAKPOINTS
);
452 est_remove_breakpoint (addr
, shadow
)
454 unsigned char *shadow
;
458 for (i
= 0; i
< MAX_DEBUG_BREAKPOINTS
; i
++)
459 if (breakaddr
[i
] == addr
)
463 sprintf (buf
, ".RB %x", addr
);
464 write_and_expect (buf
);
469 error ("Can't find breakpoint associated with 0x%x\n", addr
);
474 /* Wait until the remote machine stops, then return,
475 storing status in STATUS just as `wait' would. */
478 est_wait (pid
, status
)
480 struct target_waitstatus
*status
;
482 int c
= sr_readchar ();
485 /* What sort of stop */
487 status
->kind
= TARGET_WAITKIND_STOPPED
;
491 status
->value
.sig
= TARGET_SIGNAL_BUS
;
495 status
->value
.sig
= TARGET_SIGNAL_BUS
;
499 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
509 write_and_expect (".in");
513 extern struct gr_settings est_settings
;
516 est_open (args
, from_tty
)
520 gr_open (args
, from_tty
, &est_settings
);
523 /* Define the target subroutine names */
525 struct target_ops est_ops
=
528 "Remote EST-300 target",
529 "Use a remote EST-300 ICE connected by a serial line,\n\
530 or a network connection.\n\
531 Arguments are the name of the device for the serial line,\n\
532 the speed to connect at in bits per second.\n\
534 target est /dev/ttya 9600\n\
545 est_xfer_inferior_memory
,
547 est_insert_breakpoint
,
548 est_remove_breakpoint
, /* Breakpoints */
553 0, /* Terminal handling */
555 gr_load_image
, /* load */
556 0, /* lookup_symbol */
560 0, /* notice_signals */
568 1, /* all mem, mem, stack, regs, exec */
570 0, /* Section pointers */
571 OPS_MAGIC
, /* Always the last thing */
574 static struct gr_settings est_settings
=
579 est_clear_all_breakpoints
,
580 est_read_memory
, /* readfunc */
581 est_write_memory
, /* writefunc */
582 est_checkin
, /* checkin */
586 _initialize_remote_est ()
588 add_target (&est_ops
);