Commit | Line | Data |
---|---|---|
85a453d5 | 1 | /* Remote debugging interface for Renesas E7000 ICE, for GDB |
0a65a603 | 2 | |
197e01b6 | 3 | Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
281b533b | 4 | 2002, 2003, 2004, 2006 Free Software Foundation, Inc. |
0a65a603 | 5 | |
c906108c SS |
6 | Contributed by Cygnus Support. |
7 | ||
8 | Written by Steve Chamberlain for Cygnus Support. | |
9 | ||
10 | This file is part of GDB. | |
11 | ||
12 | This program is free software; you can redistribute it and/or modify | |
13 | it under the terms of the GNU General Public License as published by | |
14 | the Free Software Foundation; either version 2 of the License, or | |
15 | (at your option) any later version. | |
16 | ||
17 | This program is distributed in the hope that it will be useful, | |
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | GNU General Public License for more details. | |
21 | ||
22 | You should have received a copy of the GNU General Public License | |
23 | along with this program; if not, write to the Free Software | |
197e01b6 EZ |
24 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 | Boston, MA 02110-1301, USA. */ | |
c906108c | 26 | |
85a453d5 KI |
27 | /* The E7000 is an in-circuit emulator for the Renesas H8/300-H and |
28 | Renesas-SH processor. It has serial port and a lan port. | |
c906108c SS |
29 | |
30 | The monitor command set makes it difficult to load large ammounts of | |
31 | data over the lan without using ftp - so try not to issue load | |
32 | commands when communicating over ethernet; use the ftpload command. | |
33 | ||
34 | The monitor pauses for a second when dumping srecords to the serial | |
35 | line too, so we use a slower per byte mechanism but without the | |
36 | startup overhead. Even so, it's pretty slow... */ | |
37 | ||
38 | #include "defs.h" | |
39 | #include "gdbcore.h" | |
40 | #include "gdbarch.h" | |
41 | #include "inferior.h" | |
42 | #include "target.h" | |
c906108c SS |
43 | #include "value.h" |
44 | #include "command.h" | |
c906108c | 45 | #include "gdb_string.h" |
60250e8b | 46 | #include "exceptions.h" |
c906108c SS |
47 | #include "gdbcmd.h" |
48 | #include <sys/types.h> | |
49 | #include "serial.h" | |
50 | #include "remote-utils.h" | |
51 | #include "symfile.h" | |
4e052eda | 52 | #include "regcache.h" |
c906108c SS |
53 | #include <time.h> |
54 | #include <ctype.h> | |
55 | ||
56 | ||
57 | #if 1 | |
58 | #define HARD_BREAKPOINTS /* Now handled by set option. */ | |
59 | #define BC_BREAKPOINTS use_hard_breakpoints | |
60 | #endif | |
61 | ||
62 | #define CTRLC 0x03 | |
63 | #define ENQ 0x05 | |
64 | #define ACK 0x06 | |
65 | #define CTRLZ 0x1a | |
66 | ||
cc17453a EZ |
67 | /* This file is used by 2 different targets, sh-elf and h8300. The |
68 | h8300 is not multiarched and doesn't use the registers defined in | |
69 | tm-sh.h. To avoid using a macro GDB_TARGET_IS_SH, we do runtime check | |
70 | of the target, which requires that these namse below are always | |
71 | defined also in the h8300 case. */ | |
72 | ||
73 | #if !defined (PR_REGNUM) | |
74 | #define PR_REGNUM -1 | |
75 | #endif | |
76 | #if !defined (GBR_REGNUM) | |
77 | #define GBR_REGNUM -1 | |
78 | #endif | |
79 | #if !defined (VBR_REGNUM) | |
80 | #define VBR_REGNUM -1 | |
81 | #endif | |
82 | #if !defined (MACH_REGNUM) | |
83 | #define MACH_REGNUM -1 | |
84 | #endif | |
85 | #if !defined (MACL_REGNUM) | |
86 | #define MACL_REGNUM -1 | |
87 | #endif | |
88 | #if !defined (SR_REGNUM) | |
89 | #define SR_REGNUM -1 | |
90 | #endif | |
91 | ||
a14ed312 | 92 | extern void report_transfer_performance (unsigned long, time_t, time_t); |
c906108c SS |
93 | |
94 | extern char *sh_processor_type; | |
95 | ||
96 | /* Local function declarations. */ | |
97 | ||
a14ed312 | 98 | static void e7000_close (int); |
c906108c | 99 | |
a14ed312 | 100 | static void e7000_fetch_register (int); |
c906108c | 101 | |
a14ed312 | 102 | static void e7000_store_register (int); |
c906108c | 103 | |
a14ed312 | 104 | static void e7000_command (char *, int); |
c906108c | 105 | |
a14ed312 | 106 | static void e7000_login_command (char *, int); |
c906108c | 107 | |
a14ed312 | 108 | static void e7000_ftp_command (char *, int); |
c906108c | 109 | |
a14ed312 | 110 | static void e7000_drain_command (char *, int); |
c906108c | 111 | |
a14ed312 | 112 | static void expect (char *); |
c906108c | 113 | |
a14ed312 | 114 | static void expect_full_prompt (void); |
c906108c | 115 | |
a14ed312 | 116 | static void expect_prompt (void); |
c906108c | 117 | |
a14ed312 | 118 | static int e7000_parse_device (char *args, char *dev_name, int baudrate); |
c906108c SS |
119 | /* Variables. */ |
120 | ||
819cc324 | 121 | static struct serial *e7000_desc; |
c906108c SS |
122 | |
123 | /* Allow user to chose between using hardware breakpoints or memory. */ | |
c5aa993b | 124 | static int use_hard_breakpoints = 0; /* use sw breakpoints by default */ |
c906108c SS |
125 | |
126 | /* Nonzero if using the tcp serial driver. */ | |
127 | ||
c5aa993b | 128 | static int using_tcp; /* direct tcp connection to target */ |
c906108c SS |
129 | static int using_tcp_remote; /* indirect connection to target |
130 | via tcp to controller */ | |
131 | ||
132 | /* Nonzero if using the pc isa card. */ | |
133 | ||
134 | static int using_pc; | |
135 | ||
136 | extern struct target_ops e7000_ops; /* Forward declaration */ | |
137 | ||
138 | char *ENQSTRING = "\005"; | |
139 | ||
140 | /* Nonzero if some routine (as opposed to the user) wants echoing. | |
141 | FIXME: Do this reentrantly with an extra parameter. */ | |
142 | ||
143 | static int echo; | |
144 | ||
145 | static int ctrl_c; | |
146 | ||
147 | static int timeout = 20; | |
148 | ||
149 | /* Send data to e7000debug. */ | |
150 | ||
151 | static void | |
fba45db2 | 152 | puts_e7000debug (char *buf) |
c906108c SS |
153 | { |
154 | if (!e7000_desc) | |
8a3fe4f8 | 155 | error (_("Use \"target e7000 ...\" first.")); |
c906108c SS |
156 | |
157 | if (remote_debug) | |
158 | printf_unfiltered ("Sending %s\n", buf); | |
159 | ||
2cd58942 AC |
160 | if (serial_write (e7000_desc, buf, strlen (buf))) |
161 | fprintf_unfiltered (gdb_stderr, "serial_write failed: %s\n", safe_strerror (errno)); | |
c906108c SS |
162 | |
163 | /* And expect to see it echoed, unless using the pc interface */ | |
164 | #if 0 | |
165 | if (!using_pc) | |
166 | #endif | |
167 | expect (buf); | |
168 | } | |
169 | ||
170 | static void | |
fba45db2 | 171 | putchar_e7000 (int x) |
c906108c SS |
172 | { |
173 | char b[1]; | |
174 | ||
175 | b[0] = x; | |
2cd58942 | 176 | serial_write (e7000_desc, b, 1); |
c906108c SS |
177 | } |
178 | ||
179 | static void | |
fba45db2 | 180 | write_e7000 (char *s) |
c906108c | 181 | { |
2cd58942 | 182 | serial_write (e7000_desc, s, strlen (s)); |
c906108c SS |
183 | } |
184 | ||
185 | static int | |
fba45db2 | 186 | normal (int x) |
c906108c SS |
187 | { |
188 | if (x == '\n') | |
189 | return '\r'; | |
190 | return x; | |
191 | } | |
192 | ||
193 | /* Read a character from the remote system, doing all the fancy timeout | |
194 | stuff. Handles serial errors and EOF. If TIMEOUT == 0, and no chars, | |
195 | returns -1, else returns next char. Discards chars > 127. */ | |
196 | ||
197 | static int | |
fba45db2 | 198 | readchar (int timeout) |
c906108c SS |
199 | { |
200 | int c; | |
201 | ||
202 | do | |
203 | { | |
2cd58942 | 204 | c = serial_readchar (e7000_desc, timeout); |
c906108c SS |
205 | } |
206 | while (c > 127); | |
207 | ||
208 | if (c == SERIAL_TIMEOUT) | |
209 | { | |
210 | if (timeout == 0) | |
211 | return -1; | |
212 | echo = 0; | |
8a3fe4f8 | 213 | error (_("Timeout reading from remote system.")); |
c906108c SS |
214 | } |
215 | else if (c < 0) | |
8a3fe4f8 | 216 | error (_("Serial communication error")); |
c906108c | 217 | |
c5aa993b | 218 | if (remote_debug) |
c906108c SS |
219 | { |
220 | putchar_unfiltered (c); | |
221 | gdb_flush (gdb_stdout); | |
222 | } | |
223 | ||
224 | return normal (c); | |
225 | } | |
226 | ||
227 | #if 0 | |
228 | char * | |
fba45db2 | 229 | tl (int x) |
c906108c SS |
230 | { |
231 | static char b[8][10]; | |
232 | static int p; | |
233 | ||
234 | p++; | |
235 | p &= 7; | |
c5aa993b JM |
236 | if (x >= ' ') |
237 | { | |
c906108c SS |
238 | b[p][0] = x; |
239 | b[p][1] = 0; | |
240 | } | |
241 | else | |
242 | { | |
c5aa993b | 243 | sprintf (b[p], "<%d>", x); |
c906108c SS |
244 | } |
245 | ||
246 | return b[p]; | |
247 | } | |
248 | #endif | |
249 | ||
250 | /* Scan input from the remote system, until STRING is found. If | |
251 | DISCARD is non-zero, then discard non-matching input, else print it | |
252 | out. Let the user break out immediately. */ | |
253 | ||
254 | static void | |
fba45db2 | 255 | expect (char *string) |
c906108c SS |
256 | { |
257 | char *p = string; | |
258 | int c; | |
259 | int nl = 0; | |
260 | ||
261 | while (1) | |
262 | { | |
263 | c = readchar (timeout); | |
c5aa993b | 264 | |
c906108c SS |
265 | if (echo) |
266 | { | |
267 | if (c == '\r' || c == '\n') | |
268 | { | |
269 | if (!nl) | |
270 | putchar_unfiltered ('\n'); | |
271 | nl = 1; | |
272 | } | |
273 | else | |
274 | { | |
275 | nl = 0; | |
276 | putchar_unfiltered (c); | |
277 | } | |
278 | gdb_flush (gdb_stdout); | |
279 | } | |
280 | if (normal (c) == normal (*p++)) | |
281 | { | |
282 | if (*p == '\0') | |
283 | return; | |
284 | } | |
285 | else | |
286 | { | |
287 | p = string; | |
288 | ||
289 | if (normal (c) == normal (string[0])) | |
290 | p++; | |
291 | } | |
292 | } | |
293 | } | |
294 | ||
295 | /* Keep discarding input until we see the e7000 prompt. | |
296 | ||
297 | The convention for dealing with the prompt is that you | |
298 | o give your command | |
299 | o *then* wait for the prompt. | |
300 | ||
301 | Thus the last thing that a procedure does with the serial line will | |
302 | be an expect_prompt(). Exception: e7000_resume does not wait for | |
303 | the prompt, because the terminal is being handed over to the | |
304 | inferior. However, the next thing which happens after that is a | |
305 | e7000_wait which does wait for the prompt. Note that this includes | |
306 | abnormal exit, e.g. error(). This is necessary to prevent getting | |
307 | into states from which we can't recover. */ | |
308 | ||
309 | static void | |
fba45db2 | 310 | expect_prompt (void) |
c906108c SS |
311 | { |
312 | expect (":"); | |
313 | } | |
314 | ||
315 | static void | |
fba45db2 | 316 | expect_full_prompt (void) |
c906108c SS |
317 | { |
318 | expect ("\r:"); | |
319 | } | |
320 | ||
321 | static int | |
fba45db2 | 322 | convert_hex_digit (int ch) |
c906108c SS |
323 | { |
324 | if (ch >= '0' && ch <= '9') | |
325 | return ch - '0'; | |
326 | else if (ch >= 'A' && ch <= 'F') | |
327 | return ch - 'A' + 10; | |
328 | else if (ch >= 'a' && ch <= 'f') | |
329 | return ch - 'a' + 10; | |
330 | return -1; | |
331 | } | |
332 | ||
333 | static int | |
fba45db2 | 334 | get_hex (int *start) |
c906108c SS |
335 | { |
336 | int value = convert_hex_digit (*start); | |
337 | int try; | |
338 | ||
339 | *start = readchar (timeout); | |
340 | while ((try = convert_hex_digit (*start)) >= 0) | |
341 | { | |
342 | value <<= 4; | |
343 | value += try; | |
344 | *start = readchar (timeout); | |
345 | } | |
346 | return value; | |
347 | } | |
348 | ||
349 | #if 0 | |
350 | /* Get N 32-bit words from remote, each preceded by a space, and put | |
351 | them in registers starting at REGNO. */ | |
352 | ||
353 | static void | |
fba45db2 | 354 | get_hex_regs (int n, int regno) |
c906108c SS |
355 | { |
356 | long val; | |
357 | int i; | |
358 | ||
359 | for (i = 0; i < n; i++) | |
360 | { | |
361 | int j; | |
362 | ||
363 | val = 0; | |
364 | for (j = 0; j < 8; j++) | |
365 | val = (val << 4) + get_hex_digit (j == 0); | |
23a6d369 | 366 | regcache_raw_supply (current_regcache, regno++, (char *) &val); |
c906108c SS |
367 | } |
368 | } | |
369 | #endif | |
370 | ||
371 | /* This is called not only when we first attach, but also when the | |
372 | user types "run" after having attached. */ | |
373 | ||
374 | static void | |
c27cda74 AC |
375 | e7000_create_inferior (char *execfile, char *args, char **env, |
376 | int from_tty) | |
c906108c SS |
377 | { |
378 | int entry_pt; | |
379 | ||
380 | if (args && *args) | |
8a3fe4f8 | 381 | error (_("Can't pass arguments to remote E7000DEBUG process")); |
c906108c SS |
382 | |
383 | if (execfile == 0 || exec_bfd == 0) | |
8a3fe4f8 | 384 | error (_("No executable file specified")); |
c906108c SS |
385 | |
386 | entry_pt = (int) bfd_get_start_address (exec_bfd); | |
387 | ||
388 | #ifdef CREATE_INFERIOR_HOOK | |
389 | CREATE_INFERIOR_HOOK (0); /* No process-ID */ | |
390 | #endif | |
391 | ||
392 | /* The "process" (board) is already stopped awaiting our commands, and | |
393 | the program is already downloaded. We just set its PC and go. */ | |
394 | ||
395 | clear_proceed_status (); | |
396 | ||
397 | /* Tell wait_for_inferior that we've started a new process. */ | |
398 | init_wait_for_inferior (); | |
399 | ||
400 | /* Set up the "saved terminal modes" of the inferior | |
401 | based on what modes we are starting it with. */ | |
402 | target_terminal_init (); | |
403 | ||
404 | /* Install inferior's terminal modes. */ | |
405 | target_terminal_inferior (); | |
406 | ||
407 | /* insert_step_breakpoint (); FIXME, do we need this? */ | |
281b533b | 408 | write_pc ((CORE_ADDR) entry_pt); |
c906108c SS |
409 | } |
410 | ||
411 | /* Open a connection to a remote debugger. NAME is the filename used | |
412 | for communication. */ | |
413 | ||
414 | static int baudrate = 9600; | |
415 | static char dev_name[100]; | |
416 | ||
417 | static char *machine = ""; | |
418 | static char *user = ""; | |
419 | static char *passwd = ""; | |
420 | static char *dir = ""; | |
421 | ||
422 | /* Grab the next token and buy some space for it */ | |
423 | ||
424 | static char * | |
fba45db2 | 425 | next (char **ptr) |
c906108c SS |
426 | { |
427 | char *p = *ptr; | |
428 | char *s; | |
429 | char *r; | |
430 | int l = 0; | |
431 | ||
432 | while (*p && *p == ' ') | |
433 | p++; | |
434 | s = p; | |
435 | while (*p && (*p != ' ' && *p != '\t')) | |
436 | { | |
437 | l++; | |
438 | p++; | |
439 | } | |
440 | r = xmalloc (l + 1); | |
441 | memcpy (r, s, l); | |
442 | r[l] = 0; | |
443 | *ptr = p; | |
444 | return r; | |
445 | } | |
446 | ||
447 | static void | |
fba45db2 | 448 | e7000_login_command (char *args, int from_tty) |
c906108c SS |
449 | { |
450 | if (args) | |
451 | { | |
452 | machine = next (&args); | |
453 | user = next (&args); | |
454 | passwd = next (&args); | |
455 | dir = next (&args); | |
456 | if (from_tty) | |
457 | { | |
458 | printf_unfiltered ("Set info to %s %s %s %s\n", machine, user, passwd, dir); | |
459 | } | |
460 | } | |
461 | else | |
462 | { | |
8a3fe4f8 | 463 | error (_("Syntax is ftplogin <machine> <user> <passwd> <directory>")); |
c906108c SS |
464 | } |
465 | } | |
466 | ||
467 | /* Start an ftp transfer from the E7000 to a host */ | |
468 | ||
469 | static void | |
fba45db2 | 470 | e7000_ftp_command (char *args, int from_tty) |
c906108c SS |
471 | { |
472 | /* FIXME: arbitrary limit on machine names and such. */ | |
473 | char buf[200]; | |
474 | ||
475 | int oldtimeout = timeout; | |
476 | timeout = remote_timeout; | |
477 | ||
478 | sprintf (buf, "ftp %s\r", machine); | |
479 | puts_e7000debug (buf); | |
480 | expect (" Username : "); | |
481 | sprintf (buf, "%s\r", user); | |
482 | puts_e7000debug (buf); | |
483 | expect (" Password : "); | |
484 | write_e7000 (passwd); | |
485 | write_e7000 ("\r"); | |
486 | expect ("success\r"); | |
487 | expect ("FTP>"); | |
488 | sprintf (buf, "cd %s\r", dir); | |
489 | puts_e7000debug (buf); | |
490 | expect ("FTP>"); | |
491 | sprintf (buf, "ll 0;s:%s\r", args); | |
492 | puts_e7000debug (buf); | |
493 | expect ("FTP>"); | |
494 | puts_e7000debug ("bye\r"); | |
495 | expect (":"); | |
496 | timeout = oldtimeout; | |
497 | } | |
498 | ||
c5aa993b | 499 | static int |
fba45db2 | 500 | e7000_parse_device (char *args, char *dev_name, int baudrate) |
c906108c SS |
501 | { |
502 | char junk[128]; | |
503 | int n = 0; | |
504 | if (args && strcasecmp (args, "pc") == 0) | |
505 | { | |
506 | strcpy (dev_name, args); | |
507 | using_pc = 1; | |
508 | } | |
c5aa993b | 509 | else |
c906108c SS |
510 | { |
511 | /* FIXME! temp hack to allow use with port master - | |
c5aa993b JM |
512 | target tcp_remote <device> */ |
513 | if (args && strncmp (args, "tcp", 10) == 0) | |
514 | { | |
c906108c SS |
515 | char com_type[128]; |
516 | n = sscanf (args, " %s %s %d %s", com_type, dev_name, &baudrate, junk); | |
c5aa993b | 517 | using_tcp_remote = 1; |
c906108c | 518 | n--; |
c5aa993b JM |
519 | } |
520 | else if (args) | |
c906108c SS |
521 | { |
522 | n = sscanf (args, " %s %d %s", dev_name, &baudrate, junk); | |
523 | } | |
524 | ||
525 | if (n != 1 && n != 2) | |
526 | { | |
8a3fe4f8 | 527 | error (_("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\ |
c906108c SS |
528 | or \t\ttarget e7000 <host>[:<port>]\n\ |
529 | or \t\ttarget e7000 tcp_remote <host>[:<port>]\n\ | |
8a3fe4f8 | 530 | or \t\ttarget e7000 pc\n")); |
c906108c SS |
531 | } |
532 | ||
608506ed | 533 | #if !defined(__GO32__) && !defined(_WIN32) && !defined(__CYGWIN__) |
c906108c SS |
534 | /* FIXME! test for ':' is ambiguous */ |
535 | if (n == 1 && strchr (dev_name, ':') == 0) | |
536 | { | |
537 | /* Default to normal telnet port */ | |
538 | /* serial_open will use this to determine tcp communication */ | |
539 | strcat (dev_name, ":23"); | |
540 | } | |
541 | #endif | |
542 | if (!using_tcp_remote && strchr (dev_name, ':')) | |
c5aa993b | 543 | using_tcp = 1; |
c906108c SS |
544 | } |
545 | ||
546 | return n; | |
547 | } | |
548 | ||
549 | /* Stub for catch_errors. */ | |
550 | ||
551 | static int | |
34e9d9bb | 552 | e7000_start_remote (void *dummy) |
c906108c SS |
553 | { |
554 | int loop; | |
555 | int sync; | |
556 | int try; | |
557 | int quit_trying; | |
558 | ||
8edbea78 | 559 | immediate_quit++; /* Allow user to interrupt it */ |
c906108c SS |
560 | |
561 | /* Hello? Are you there? */ | |
562 | sync = 0; | |
c5aa993b | 563 | loop = 0; |
c906108c SS |
564 | try = 0; |
565 | quit_trying = 20; | |
566 | putchar_e7000 (CTRLC); | |
567 | while (!sync && ++try <= quit_trying) | |
568 | { | |
569 | int c; | |
570 | ||
571 | printf_unfiltered ("[waiting for e7000...]\n"); | |
572 | ||
573 | write_e7000 ("\r"); | |
574 | c = readchar (1); | |
575 | ||
576 | /* FIXME! this didn't seem right-> while (c != SERIAL_TIMEOUT) | |
577 | * we get stuck in this loop ... | |
578 | * We may never timeout, and never sync up :-( | |
579 | */ | |
580 | while (!sync && c != -1) | |
581 | { | |
582 | /* Dont echo cr's */ | |
583 | if (c != '\r') | |
584 | { | |
585 | putchar_unfiltered (c); | |
586 | gdb_flush (gdb_stdout); | |
587 | } | |
588 | /* Shouldn't we either break here, or check for sync in inner loop? */ | |
589 | if (c == ':') | |
590 | sync = 1; | |
591 | ||
c5aa993b | 592 | if (loop++ == 20) |
c906108c SS |
593 | { |
594 | putchar_e7000 (CTRLC); | |
595 | loop = 0; | |
596 | } | |
597 | ||
c5aa993b | 598 | QUIT; |
c906108c SS |
599 | |
600 | if (quit_flag) | |
601 | { | |
602 | putchar_e7000 (CTRLC); | |
603 | /* Was-> quit_flag = 0; */ | |
604 | c = -1; | |
c5aa993b | 605 | quit_trying = try + 1; /* we don't want to try anymore */ |
c906108c SS |
606 | } |
607 | else | |
608 | { | |
609 | c = readchar (1); | |
610 | } | |
611 | } | |
612 | } | |
613 | ||
614 | if (!sync) | |
615 | { | |
c5aa993b | 616 | fprintf_unfiltered (gdb_stderr, "Giving up after %d tries...\n", try); |
8a3fe4f8 | 617 | error (_("Unable to synchronize with target.")); |
c906108c SS |
618 | } |
619 | ||
620 | puts_e7000debug ("\r"); | |
621 | expect_prompt (); | |
622 | puts_e7000debug ("b -\r"); /* Clear breakpoints */ | |
623 | expect_prompt (); | |
624 | ||
8edbea78 | 625 | immediate_quit--; |
c906108c SS |
626 | |
627 | /* This is really the job of start_remote however, that makes an assumption | |
628 | that the target is about to print out a status message of some sort. That | |
629 | doesn't happen here. */ | |
630 | ||
631 | flush_cached_frames (); | |
632 | registers_changed (); | |
633 | stop_pc = read_pc (); | |
b04f3ab4 | 634 | print_stack_frame (get_selected_frame (NULL), 0, SRC_AND_LOC); |
c906108c SS |
635 | |
636 | return 1; | |
637 | } | |
638 | ||
639 | static void | |
fba45db2 | 640 | e7000_open (char *args, int from_tty) |
c906108c SS |
641 | { |
642 | int n; | |
643 | ||
644 | target_preopen (from_tty); | |
645 | ||
646 | n = e7000_parse_device (args, dev_name, baudrate); | |
647 | ||
648 | push_target (&e7000_ops); | |
649 | ||
2cd58942 | 650 | e7000_desc = serial_open (dev_name); |
c906108c SS |
651 | |
652 | if (!e7000_desc) | |
653 | perror_with_name (dev_name); | |
654 | ||
2cd58942 | 655 | if (serial_setbaudrate (e7000_desc, baudrate)) |
67dd5ca6 | 656 | { |
2cd58942 | 657 | serial_close (e7000_desc); |
67dd5ca6 FN |
658 | perror_with_name (dev_name); |
659 | } | |
2cd58942 | 660 | serial_raw (e7000_desc); |
c906108c | 661 | |
c906108c SS |
662 | /* Start the remote connection; if error (0), discard this target. |
663 | In particular, if the user quits, be sure to discard it | |
664 | (we'd be in an inconsistent state otherwise). */ | |
c5aa993b JM |
665 | if (!catch_errors (e7000_start_remote, (char *) 0, |
666 | "Couldn't establish connection to remote target\n", RETURN_MASK_ALL)) | |
667 | if (from_tty) | |
668 | printf_filtered ("Remote target %s connected to %s\n", target_shortname, | |
669 | dev_name); | |
c906108c SS |
670 | } |
671 | ||
672 | /* Close out all files and local state before this target loses control. */ | |
673 | ||
674 | static void | |
fba45db2 | 675 | e7000_close (int quitting) |
c906108c SS |
676 | { |
677 | if (e7000_desc) | |
678 | { | |
2cd58942 | 679 | serial_close (e7000_desc); |
c906108c SS |
680 | e7000_desc = 0; |
681 | } | |
682 | } | |
683 | ||
684 | /* Terminate the open connection to the remote debugger. Use this | |
685 | when you want to detach and do something else with your gdb. */ | |
686 | ||
687 | static void | |
55d80160 | 688 | e7000_detach (char *arg, int from_tty) |
c906108c SS |
689 | { |
690 | pop_target (); /* calls e7000_close to do the real work */ | |
691 | if (from_tty) | |
692 | printf_unfiltered ("Ending remote %s debugging\n", target_shortname); | |
693 | } | |
694 | ||
695 | /* Tell the remote machine to resume. */ | |
696 | ||
697 | static void | |
39f77062 | 698 | e7000_resume (ptid_t ptid, int step, enum target_signal sigal) |
c906108c SS |
699 | { |
700 | if (step) | |
701 | puts_e7000debug ("S\r"); | |
702 | else | |
703 | puts_e7000debug ("G\r"); | |
704 | } | |
705 | ||
706 | /* Read the remote registers into the block REGS. | |
707 | ||
708 | For the H8/300 a register dump looks like: | |
709 | ||
710 | PC=00021A CCR=80:I******* | |
711 | ER0 - ER3 0000000A 0000002E 0000002E 00000000 | |
712 | ER4 - ER7 00000000 00000000 00000000 00FFEFF6 | |
713 | 000218 MOV.B R1L,R2L | |
714 | STEP NORMAL END or | |
715 | BREAK POINT | |
c5aa993b | 716 | */ |
c906108c | 717 | |
c906108c SS |
718 | char *want_h8300h = "PC=%p CCR=%c\n\ |
719 | ER0 - ER3 %0 %1 %2 %3\n\ | |
720 | ER4 - ER7 %4 %5 %6 %7\n"; | |
721 | ||
722 | char *want_nopc_h8300h = "%p CCR=%c\n\ | |
723 | ER0 - ER3 %0 %1 %2 %3\n\ | |
724 | ER4 - ER7 %4 %5 %6 %7"; | |
725 | ||
726 | char *want_h8300s = "PC=%p CCR=%c\n\ | |
727 | MACH=\n\ | |
728 | ER0 - ER3 %0 %1 %2 %3\n\ | |
729 | ER4 - ER7 %4 %5 %6 %7\n"; | |
730 | ||
731 | char *want_nopc_h8300s = "%p CCR=%c EXR=%9\n\ | |
732 | ER0 - ER3 %0 %1 %2 %3\n\ | |
733 | ER4 - ER7 %4 %5 %6 %7"; | |
734 | ||
cc17453a | 735 | char *want_sh = "PC=%16 SR=%22\n\ |
c906108c SS |
736 | PR=%17 GBR=%18 VBR=%19\n\ |
737 | MACH=%20 MACL=%21\n\ | |
738 | R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\ | |
739 | R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n"; | |
740 | ||
cc17453a | 741 | char *want_nopc_sh = "%16 SR=%22\n\ |
c906108c SS |
742 | PR=%17 GBR=%18 VBR=%19\n\ |
743 | MACH=%20 MACL=%21\n\ | |
744 | R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\ | |
745 | R8-15 %8 %9 %10 %11 %12 %13 %14 %15"; | |
746 | ||
747 | char *want_sh3 = "PC=%16 SR=%22\n\ | |
748 | PR=%17 GBR=%18 VBR=%19\n\ | |
749 | MACH=%20 MACL=%21 SSR=%23 SPC=%24\n\ | |
750 | R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\ | |
751 | R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\ | |
752 | R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\ | |
753 | R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\ | |
754 | R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\ | |
755 | R4_BANK1-R7_BANK1 %37 %38 %39 %40"; | |
756 | ||
cc17453a | 757 | char *want_nopc_sh3 = "%16 SR=%22\n\ |
c906108c SS |
758 | PR=%17 GBR=%18 VBR=%19\n\ |
759 | MACH=%20 MACL=%21 SSR=%22 SPC=%23\n\ | |
760 | R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\ | |
761 | R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n\ | |
762 | R0_BANK0-R3_BANK0 %25 %26 %27 %28\n\ | |
763 | R4_BANK0-R7_BANK0 %29 %30 %31 %32\n\ | |
764 | R0_BANK1-R3_BANK1 %33 %34 %35 %36\n\ | |
765 | R4_BANK1-R7_BANK1 %37 %38 %39 %40"; | |
766 | ||
c906108c | 767 | static int |
fba45db2 | 768 | gch (void) |
c906108c SS |
769 | { |
770 | return readchar (timeout); | |
771 | } | |
772 | ||
773 | static unsigned int | |
fba45db2 | 774 | gbyte (void) |
c906108c SS |
775 | { |
776 | int high = convert_hex_digit (gch ()); | |
777 | int low = convert_hex_digit (gch ()); | |
778 | ||
779 | return (high << 4) + low; | |
780 | } | |
781 | ||
a78f21af | 782 | static void |
69dc947a | 783 | fetch_regs_from_dump (int (*nextchar) (), char *want) |
c906108c SS |
784 | { |
785 | int regno; | |
123a958e | 786 | char buf[MAX_REGISTER_SIZE]; |
c906108c SS |
787 | |
788 | int thischar = nextchar (); | |
789 | ||
4902674b | 790 | if (want == NULL) |
e2e0b3e5 | 791 | internal_error (__FILE__, __LINE__, _("Register set not selected.")); |
4902674b | 792 | |
c906108c SS |
793 | while (*want) |
794 | { | |
795 | switch (*want) | |
796 | { | |
797 | case '\n': | |
798 | /* Skip to end of line and then eat all new line type stuff */ | |
c5aa993b | 799 | while (thischar != '\n' && thischar != '\r') |
c906108c | 800 | thischar = nextchar (); |
c5aa993b | 801 | while (thischar == '\n' || thischar == '\r') |
c906108c SS |
802 | thischar = nextchar (); |
803 | want++; | |
804 | break; | |
805 | ||
806 | case ' ': | |
807 | while (thischar == ' ' | |
808 | || thischar == '\t' | |
809 | || thischar == '\r' | |
810 | || thischar == '\n') | |
811 | thischar = nextchar (); | |
812 | want++; | |
813 | break; | |
c5aa993b | 814 | |
c906108c SS |
815 | default: |
816 | if (*want == thischar) | |
817 | { | |
818 | want++; | |
819 | if (*want) | |
820 | thischar = nextchar (); | |
c5aa993b | 821 | |
c906108c SS |
822 | } |
823 | else if (thischar == ' ' || thischar == '\n' || thischar == '\r') | |
824 | { | |
825 | thischar = nextchar (); | |
826 | } | |
c5aa993b JM |
827 | else |
828 | { | |
8a3fe4f8 | 829 | error (_("out of sync in fetch registers wanted <%s>, got <%c 0x%x>"), |
c5aa993b JM |
830 | want, thischar, thischar); |
831 | } | |
832 | ||
c906108c SS |
833 | break; |
834 | case '%': | |
835 | /* Got a register command */ | |
836 | want++; | |
837 | switch (*want) | |
838 | { | |
839 | #ifdef PC_REGNUM | |
840 | case 'p': | |
841 | regno = PC_REGNUM; | |
842 | want++; | |
843 | break; | |
844 | #endif | |
845 | #ifdef CCR_REGNUM | |
846 | case 'c': | |
847 | regno = CCR_REGNUM; | |
848 | want++; | |
849 | break; | |
850 | #endif | |
851 | #ifdef SP_REGNUM | |
852 | case 's': | |
853 | regno = SP_REGNUM; | |
854 | want++; | |
855 | break; | |
856 | #endif | |
0ba6dca9 | 857 | #ifdef DEPRECATED_FP_REGNUM |
c906108c | 858 | case 'f': |
0ba6dca9 | 859 | regno = DEPRECATED_FP_REGNUM; |
c906108c SS |
860 | want++; |
861 | break; | |
862 | #endif | |
863 | ||
864 | default: | |
c5aa993b | 865 | if (isdigit (want[0])) |
c906108c SS |
866 | { |
867 | if (isdigit (want[1])) | |
868 | { | |
869 | regno = (want[0] - '0') * 10 + want[1] - '0'; | |
870 | want += 2; | |
871 | } | |
c5aa993b | 872 | else |
c906108c SS |
873 | { |
874 | regno = want[0] - '0'; | |
875 | want++; | |
876 | } | |
877 | } | |
c5aa993b | 878 | |
c906108c | 879 | else |
e2e0b3e5 | 880 | internal_error (__FILE__, __LINE__, _("failed internal consistency check")); |
c906108c SS |
881 | } |
882 | store_signed_integer (buf, | |
3acba339 | 883 | register_size (current_gdbarch, regno), |
34e9d9bb | 884 | (LONGEST) get_hex (&thischar)); |
23a6d369 | 885 | regcache_raw_supply (current_regcache, regno, buf); |
c906108c SS |
886 | break; |
887 | } | |
888 | } | |
889 | } | |
890 | ||
891 | static void | |
fba45db2 | 892 | e7000_fetch_registers (void) |
c906108c SS |
893 | { |
894 | int regno; | |
4902674b | 895 | char *wanted = NULL; |
7124f6fb | 896 | int realregs = 0; |
c906108c SS |
897 | |
898 | puts_e7000debug ("R\r"); | |
899 | ||
c906108c | 900 | if (TARGET_ARCHITECTURE->arch == bfd_arch_sh) |
cc17453a EZ |
901 | { |
902 | wanted = want_sh; | |
7124f6fb | 903 | realregs = 59; |
cc17453a EZ |
904 | switch (TARGET_ARCHITECTURE->mach) |
905 | { | |
906 | case bfd_mach_sh3: | |
907 | case bfd_mach_sh3e: | |
908 | case bfd_mach_sh4: | |
909 | wanted = want_sh3; | |
910 | } | |
911 | } | |
cc17453a EZ |
912 | if (TARGET_ARCHITECTURE->arch == bfd_arch_h8300) |
913 | { | |
454d0511 | 914 | wanted = want_h8300h; |
7124f6fb | 915 | realregs = 10; |
454d0511 DD |
916 | switch (TARGET_ARCHITECTURE->mach) |
917 | { | |
918 | case bfd_mach_h8300s: | |
919 | case bfd_mach_h8300sn: | |
920 | case bfd_mach_h8300sx: | |
921 | case bfd_mach_h8300sxn: | |
922 | wanted = want_h8300s; | |
7124f6fb | 923 | realregs = 11; |
454d0511 | 924 | } |
cc17453a | 925 | } |
cc17453a | 926 | |
c906108c SS |
927 | fetch_regs_from_dump (gch, wanted); |
928 | ||
929 | /* And supply the extra ones the simulator uses */ | |
7124f6fb | 930 | for (regno = realregs; regno < NUM_REGS; regno++) |
c906108c SS |
931 | { |
932 | int buf = 0; | |
933 | ||
23a6d369 | 934 | regcache_raw_supply (current_regcache, regno, (char *) (&buf)); |
c906108c SS |
935 | } |
936 | } | |
937 | ||
938 | /* Fetch register REGNO, or all registers if REGNO is -1. Returns | |
939 | errno value. */ | |
940 | ||
941 | static void | |
fba45db2 | 942 | e7000_fetch_register (int regno) |
c906108c SS |
943 | { |
944 | e7000_fetch_registers (); | |
945 | } | |
946 | ||
947 | /* Store the remote registers from the contents of the block REGS. */ | |
948 | ||
949 | static void | |
fba45db2 | 950 | e7000_store_registers (void) |
c906108c SS |
951 | { |
952 | int regno; | |
7124f6fb | 953 | int realregs = 0; |
c906108c | 954 | |
7124f6fb YS |
955 | if (TARGET_ARCHITECTURE->arch == bfd_arch_sh) |
956 | realregs = 59; | |
957 | if (TARGET_ARCHITECTURE->arch == bfd_arch_h8300) { | |
958 | realregs = ((TARGET_ARCHITECTURE->mach == bfd_mach_h8300s || | |
959 | TARGET_ARCHITECTURE->mach == bfd_mach_h8300sn || | |
960 | TARGET_ARCHITECTURE->mach == bfd_mach_h8300sx || | |
961 | TARGET_ARCHITECTURE->mach == bfd_mach_h8300sxn) ? 11 : 10); | |
962 | } | |
963 | ||
964 | for (regno = 0; regno < realregs; regno++) | |
c906108c SS |
965 | e7000_store_register (regno); |
966 | ||
967 | registers_changed (); | |
968 | } | |
969 | ||
970 | /* Store register REGNO, or all if REGNO == 0. Return errno value. */ | |
971 | ||
972 | static void | |
fba45db2 | 973 | e7000_store_register (int regno) |
c906108c SS |
974 | { |
975 | char buf[200]; | |
976 | ||
977 | if (regno == -1) | |
978 | { | |
979 | e7000_store_registers (); | |
980 | return; | |
981 | } | |
982 | ||
cc17453a | 983 | if (TARGET_ARCHITECTURE->arch == bfd_arch_h8300) |
c906108c | 984 | { |
cc17453a EZ |
985 | if (regno <= 7) |
986 | { | |
4902674b | 987 | sprintf (buf, ".ER%d %s\r", regno, phex_nz (read_register (regno), 0)); |
cc17453a EZ |
988 | puts_e7000debug (buf); |
989 | } | |
990 | else if (regno == PC_REGNUM) | |
991 | { | |
4902674b | 992 | sprintf (buf, ".PC %s\r", phex_nz (read_register (regno), 0)); |
cc17453a EZ |
993 | puts_e7000debug (buf); |
994 | } | |
995 | #ifdef CCR_REGNUM | |
996 | else if (regno == CCR_REGNUM) | |
997 | { | |
4902674b | 998 | sprintf (buf, ".CCR %s\r", phex_nz (read_register (regno), 0)); |
cc17453a EZ |
999 | puts_e7000debug (buf); |
1000 | } | |
1001 | #endif | |
c906108c | 1002 | } |
c906108c | 1003 | |
cc17453a | 1004 | else if (TARGET_ARCHITECTURE->arch == bfd_arch_sh) |
c906108c | 1005 | { |
cc17453a EZ |
1006 | if (regno == PC_REGNUM) |
1007 | { | |
4902674b | 1008 | sprintf (buf, ".PC %s\r", phex_nz (read_register (regno), 0)); |
cc17453a EZ |
1009 | puts_e7000debug (buf); |
1010 | } | |
c906108c | 1011 | |
cc17453a EZ |
1012 | else if (regno == SR_REGNUM) |
1013 | { | |
4902674b | 1014 | sprintf (buf, ".SR %s\r", phex_nz (read_register (regno), 0)); |
cc17453a EZ |
1015 | puts_e7000debug (buf); |
1016 | } | |
c906108c | 1017 | |
cc17453a EZ |
1018 | else if (regno == PR_REGNUM) |
1019 | { | |
4902674b | 1020 | sprintf (buf, ".PR %s\r", phex_nz (read_register (regno), 0)); |
cc17453a EZ |
1021 | puts_e7000debug (buf); |
1022 | } | |
c906108c | 1023 | |
cc17453a EZ |
1024 | else if (regno == GBR_REGNUM) |
1025 | { | |
4902674b | 1026 | sprintf (buf, ".GBR %s\r", phex_nz (read_register (regno), 0)); |
cc17453a EZ |
1027 | puts_e7000debug (buf); |
1028 | } | |
c906108c | 1029 | |
cc17453a EZ |
1030 | else if (regno == VBR_REGNUM) |
1031 | { | |
4902674b | 1032 | sprintf (buf, ".VBR %s\r", phex_nz (read_register (regno), 0)); |
cc17453a EZ |
1033 | puts_e7000debug (buf); |
1034 | } | |
c906108c | 1035 | |
cc17453a EZ |
1036 | else if (regno == MACH_REGNUM) |
1037 | { | |
4902674b | 1038 | sprintf (buf, ".MACH %s\r", phex_nz (read_register (regno), 0)); |
cc17453a EZ |
1039 | puts_e7000debug (buf); |
1040 | } | |
c906108c | 1041 | |
cc17453a EZ |
1042 | else if (regno == MACL_REGNUM) |
1043 | { | |
4902674b | 1044 | sprintf (buf, ".MACL %s\r", phex_nz (read_register (regno), 0)); |
cc17453a EZ |
1045 | puts_e7000debug (buf); |
1046 | } | |
1047 | else | |
1048 | { | |
4902674b | 1049 | sprintf (buf, ".R%d %s\r", regno, phex_nz (read_register (regno), 0)); |
cc17453a EZ |
1050 | puts_e7000debug (buf); |
1051 | } | |
c906108c SS |
1052 | } |
1053 | ||
c906108c SS |
1054 | expect_prompt (); |
1055 | } | |
1056 | ||
1057 | /* Get ready to modify the registers array. On machines which store | |
1058 | individual registers, this doesn't need to do anything. On machines | |
1059 | which store all the registers in one fell swoop, this makes sure | |
1060 | that registers contains all the registers from the program being | |
1061 | debugged. */ | |
1062 | ||
1063 | static void | |
fba45db2 | 1064 | e7000_prepare_to_store (void) |
c906108c SS |
1065 | { |
1066 | /* Do nothing, since we can store individual regs */ | |
1067 | } | |
1068 | ||
1069 | static void | |
55d80160 | 1070 | e7000_files_info (struct target_ops *ops) |
c906108c SS |
1071 | { |
1072 | printf_unfiltered ("\tAttached to %s at %d baud.\n", dev_name, baudrate); | |
1073 | } | |
1074 | ||
1075 | static int | |
fba45db2 | 1076 | stickbyte (char *where, unsigned int what) |
c906108c SS |
1077 | { |
1078 | static CONST char digs[] = "0123456789ABCDEF"; | |
1079 | ||
1080 | where[0] = digs[(what >> 4) & 0xf]; | |
1081 | where[1] = digs[(what & 0xf) & 0xf]; | |
1082 | ||
1083 | return what; | |
1084 | } | |
1085 | ||
1086 | /* Write a small ammount of memory. */ | |
1087 | ||
1088 | static int | |
fba45db2 | 1089 | write_small (CORE_ADDR memaddr, unsigned char *myaddr, int len) |
c906108c SS |
1090 | { |
1091 | int i; | |
1092 | char buf[200]; | |
1093 | ||
1094 | for (i = 0; i < len; i++) | |
1095 | { | |
1096 | if (((memaddr + i) & 3) == 0 && (i + 3 < len)) | |
1097 | { | |
1098 | /* Can be done with a long word */ | |
7aa83cac EZ |
1099 | sprintf (buf, "m %s %x%02x%02x%02x;l\r", |
1100 | paddr_nz (memaddr + i), | |
c906108c SS |
1101 | myaddr[i], myaddr[i + 1], myaddr[i + 2], myaddr[i + 3]); |
1102 | puts_e7000debug (buf); | |
1103 | i += 3; | |
1104 | } | |
1105 | else | |
1106 | { | |
7aa83cac | 1107 | sprintf (buf, "m %s %x\r", paddr_nz (memaddr + i), myaddr[i]); |
c906108c SS |
1108 | puts_e7000debug (buf); |
1109 | } | |
1110 | } | |
1111 | ||
1112 | expect_prompt (); | |
1113 | ||
1114 | return len; | |
1115 | } | |
1116 | ||
1117 | /* Write a large ammount of memory, this only works with the serial | |
1118 | mode enabled. Command is sent as | |
1119 | ||
c5aa993b JM |
1120 | il ;s:s\r -> |
1121 | <- il ;s:s\r | |
1122 | <- ENQ | |
1123 | ACK -> | |
1124 | <- LO s\r | |
1125 | Srecords... | |
1126 | ^Z -> | |
1127 | <- ENQ | |
1128 | ACK -> | |
1129 | <- : | |
1130 | */ | |
c906108c SS |
1131 | |
1132 | static int | |
fba45db2 | 1133 | write_large (CORE_ADDR memaddr, unsigned char *myaddr, int len) |
c906108c SS |
1134 | { |
1135 | int i; | |
1136 | #define maxstride 128 | |
1137 | int stride; | |
1138 | ||
1139 | puts_e7000debug ("IL ;S:FK\r"); | |
1140 | expect (ENQSTRING); | |
1141 | putchar_e7000 (ACK); | |
1142 | expect ("LO FK\r"); | |
1143 | ||
1144 | for (i = 0; i < len; i += stride) | |
1145 | { | |
1146 | char compose[maxstride * 2 + 50]; | |
1147 | int address = i + memaddr; | |
1148 | int j; | |
1149 | int check_sum; | |
1150 | int where = 0; | |
1151 | int alen; | |
1152 | ||
1153 | stride = len - i; | |
1154 | if (stride > maxstride) | |
1155 | stride = maxstride; | |
1156 | ||
1157 | compose[where++] = 'S'; | |
1158 | check_sum = 0; | |
1159 | if (address >= 0xffffff) | |
1160 | alen = 4; | |
1161 | else if (address >= 0xffff) | |
1162 | alen = 3; | |
1163 | else | |
1164 | alen = 2; | |
1165 | /* Insert type. */ | |
1166 | compose[where++] = alen - 1 + '0'; | |
1167 | /* Insert length. */ | |
1168 | check_sum += stickbyte (compose + where, alen + stride + 1); | |
1169 | where += 2; | |
1170 | while (alen > 0) | |
1171 | { | |
1172 | alen--; | |
1173 | check_sum += stickbyte (compose + where, address >> (8 * (alen))); | |
1174 | where += 2; | |
1175 | } | |
1176 | ||
1177 | for (j = 0; j < stride; j++) | |
1178 | { | |
1179 | check_sum += stickbyte (compose + where, myaddr[i + j]); | |
1180 | where += 2; | |
1181 | } | |
1182 | stickbyte (compose + where, ~check_sum); | |
1183 | where += 2; | |
1184 | compose[where++] = '\r'; | |
1185 | compose[where++] = '\n'; | |
1186 | compose[where++] = 0; | |
1187 | ||
2cd58942 | 1188 | serial_write (e7000_desc, compose, where); |
c906108c SS |
1189 | j = readchar (0); |
1190 | if (j == -1) | |
1191 | { | |
1192 | /* This is ok - nothing there */ | |
1193 | } | |
1194 | else if (j == ENQ) | |
1195 | { | |
1196 | /* Hmm, it's trying to tell us something */ | |
1197 | expect (":"); | |
8a3fe4f8 | 1198 | error (_("Error writing memory")); |
c906108c SS |
1199 | } |
1200 | else | |
1201 | { | |
1202 | printf_unfiltered ("@%d}@", j); | |
c5aa993b | 1203 | while ((j = readchar (0)) > 0) |
c906108c | 1204 | { |
c5aa993b | 1205 | printf_unfiltered ("@{%d}@", j); |
c906108c SS |
1206 | } |
1207 | } | |
1208 | } | |
1209 | ||
1210 | /* Send the trailer record */ | |
1211 | write_e7000 ("S70500000000FA\r"); | |
1212 | putchar_e7000 (CTRLZ); | |
1213 | expect (ENQSTRING); | |
1214 | putchar_e7000 (ACK); | |
1215 | expect (":"); | |
1216 | ||
1217 | return len; | |
1218 | } | |
1219 | ||
1220 | /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's | |
1221 | memory at MEMADDR. Returns length moved. | |
1222 | ||
1223 | Can't use the Srecord load over ethernet, so don't use fast method | |
1224 | then. */ | |
1225 | ||
1226 | static int | |
fba45db2 | 1227 | e7000_write_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len) |
c906108c SS |
1228 | { |
1229 | if (len < 16 || using_tcp || using_pc) | |
1230 | return write_small (memaddr, myaddr, len); | |
1231 | else | |
1232 | return write_large (memaddr, myaddr, len); | |
1233 | } | |
1234 | ||
1235 | /* Read LEN bytes from inferior memory at MEMADDR. Put the result | |
1236 | at debugger address MYADDR. Returns length moved. | |
1237 | ||
c5aa993b JM |
1238 | Small transactions we send |
1239 | m <addr>;l | |
1240 | and receive | |
1241 | 00000000 12345678 ? | |
c906108c SS |
1242 | */ |
1243 | ||
1244 | static int | |
fba45db2 | 1245 | e7000_read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len) |
c906108c SS |
1246 | { |
1247 | int count; | |
1248 | int c; | |
1249 | int i; | |
1250 | char buf[200]; | |
1251 | /* Starting address of this pass. */ | |
1252 | ||
c5aa993b | 1253 | /* printf("READ INF %x %x %d\n", memaddr, myaddr, len); */ |
c906108c SS |
1254 | if (((memaddr - 1) + len) < memaddr) |
1255 | { | |
1256 | errno = EIO; | |
1257 | return 0; | |
1258 | } | |
1259 | ||
7aa83cac | 1260 | sprintf (buf, "m %s;l\r", paddr_nz (memaddr)); |
c906108c SS |
1261 | puts_e7000debug (buf); |
1262 | ||
c5aa993b | 1263 | for (count = 0; count < len; count += 4) |
c906108c SS |
1264 | { |
1265 | /* Suck away the address */ | |
c5aa993b | 1266 | c = gch (); |
c906108c | 1267 | while (c != ' ') |
c5aa993b | 1268 | c = gch (); |
c906108c | 1269 | c = gch (); |
c5aa993b | 1270 | if (c == '*') |
c906108c | 1271 | { /* Some kind of error */ |
c5aa993b JM |
1272 | puts_e7000debug (".\r"); /* Some errors leave us in memory input mode */ |
1273 | expect_full_prompt (); | |
c906108c SS |
1274 | return -1; |
1275 | } | |
1276 | while (c != ' ') | |
c5aa993b | 1277 | c = gch (); |
c906108c SS |
1278 | |
1279 | /* Now read in the data */ | |
c5aa993b | 1280 | for (i = 0; i < 4; i++) |
c906108c | 1281 | { |
c5aa993b JM |
1282 | int b = gbyte (); |
1283 | if (count + i < len) | |
1284 | { | |
1285 | myaddr[count + i] = b; | |
1286 | } | |
c906108c SS |
1287 | } |
1288 | ||
1289 | /* Skip the trailing ? and send a . to end and a cr for more */ | |
c5aa993b | 1290 | gch (); |
c906108c SS |
1291 | gch (); |
1292 | if (count + 4 >= len) | |
c5aa993b | 1293 | puts_e7000debug (".\r"); |
c906108c | 1294 | else |
c5aa993b | 1295 | puts_e7000debug ("\r"); |
c906108c SS |
1296 | |
1297 | } | |
c5aa993b | 1298 | expect_prompt (); |
c906108c SS |
1299 | return len; |
1300 | } | |
1301 | ||
1302 | ||
1303 | ||
1304 | /* | |
c5aa993b | 1305 | For large transfers we used to send |
c906108c SS |
1306 | |
1307 | ||
c5aa993b | 1308 | d <addr> <endaddr>\r |
c906108c | 1309 | |
c5aa993b | 1310 | and receive |
c906108c SS |
1311 | <ADDRESS> < D A T A > < ASCII CODE > |
1312 | 00000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............." | |
1313 | 00000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@." | |
1314 | 00000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................" | |
1315 | ||
c5aa993b | 1316 | A cost in chars for each transaction of 80 + 5*n-bytes. |
c906108c | 1317 | |
c5aa993b JM |
1318 | Large transactions could be done with the srecord load code, but |
1319 | there is a pause for a second before dumping starts, which slows the | |
1320 | average rate down! | |
1321 | */ | |
c906108c SS |
1322 | |
1323 | static int | |
fba45db2 KB |
1324 | e7000_read_inferior_memory_large (CORE_ADDR memaddr, unsigned char *myaddr, |
1325 | int len) | |
c906108c SS |
1326 | { |
1327 | int count; | |
1328 | int c; | |
1329 | char buf[200]; | |
1330 | ||
1331 | /* Starting address of this pass. */ | |
1332 | ||
1333 | if (((memaddr - 1) + len) < memaddr) | |
1334 | { | |
1335 | errno = EIO; | |
1336 | return 0; | |
1337 | } | |
1338 | ||
7aa83cac | 1339 | sprintf (buf, "d %s %s\r", paddr_nz (memaddr), paddr_nz (memaddr + len - 1)); |
c906108c SS |
1340 | puts_e7000debug (buf); |
1341 | ||
1342 | count = 0; | |
1343 | c = gch (); | |
c5aa993b | 1344 | |
c906108c | 1345 | /* skip down to the first ">" */ |
c5aa993b | 1346 | while (c != '>') |
c906108c SS |
1347 | c = gch (); |
1348 | /* now skip to the end of that line */ | |
c5aa993b | 1349 | while (c != '\r') |
c906108c SS |
1350 | c = gch (); |
1351 | c = gch (); | |
1352 | ||
1353 | while (count < len) | |
1354 | { | |
1355 | /* get rid of any white space before the address */ | |
1356 | while (c <= ' ') | |
1357 | c = gch (); | |
1358 | ||
1359 | /* Skip the address */ | |
1360 | get_hex (&c); | |
1361 | ||
1362 | /* read in the bytes on the line */ | |
1363 | while (c != '"' && count < len) | |
1364 | { | |
1365 | if (c == ' ') | |
1366 | c = gch (); | |
1367 | else | |
1368 | { | |
1369 | myaddr[count++] = get_hex (&c); | |
1370 | } | |
1371 | } | |
1372 | /* throw out the rest of the line */ | |
c5aa993b | 1373 | while (c != '\r') |
c906108c SS |
1374 | c = gch (); |
1375 | } | |
1376 | ||
1377 | /* wait for the ":" prompt */ | |
1378 | while (c != ':') | |
1379 | c = gch (); | |
1380 | ||
1381 | return len; | |
1382 | } | |
1383 | ||
1384 | #if 0 | |
1385 | ||
1386 | static int | |
fba45db2 KB |
1387 | fast_but_for_the_pause_e7000_read_inferior_memory (CORE_ADDR memaddr, |
1388 | char *myaddr, int len) | |
c906108c SS |
1389 | { |
1390 | int loop; | |
1391 | int c; | |
1392 | char buf[200]; | |
1393 | ||
1394 | if (((memaddr - 1) + len) < memaddr) | |
1395 | { | |
1396 | errno = EIO; | |
1397 | return 0; | |
1398 | } | |
1399 | ||
1400 | sprintf (buf, "is %x@%x:s\r", memaddr, len); | |
1401 | puts_e7000debug (buf); | |
1402 | gch (); | |
1403 | c = gch (); | |
1404 | if (c != ENQ) | |
1405 | { | |
1406 | /* Got an error */ | |
8a3fe4f8 | 1407 | error (_("Memory read error")); |
c906108c SS |
1408 | } |
1409 | putchar_e7000 (ACK); | |
1410 | expect ("SV s"); | |
1411 | loop = 1; | |
1412 | while (loop) | |
1413 | { | |
1414 | int type; | |
1415 | int length; | |
1416 | int addr; | |
1417 | int i; | |
1418 | ||
1419 | c = gch (); | |
1420 | switch (c) | |
1421 | { | |
1422 | case ENQ: /* ENQ, at the end */ | |
1423 | loop = 0; | |
1424 | break; | |
1425 | case 'S': | |
1426 | /* Start of an Srecord */ | |
1427 | type = gch (); | |
1428 | length = gbyte (); | |
1429 | switch (type) | |
1430 | { | |
1431 | case '7': /* Termination record, ignore */ | |
1432 | case '0': | |
1433 | case '8': | |
1434 | case '9': | |
1435 | /* Header record - ignore it */ | |
1436 | while (length--) | |
1437 | { | |
1438 | gbyte (); | |
1439 | } | |
1440 | break; | |
1441 | case '1': | |
1442 | case '2': | |
1443 | case '3': | |
1444 | { | |
1445 | int alen; | |
1446 | ||
1447 | alen = type - '0' + 1; | |
1448 | addr = 0; | |
1449 | while (alen--) | |
1450 | { | |
1451 | addr = (addr << 8) + gbyte (); | |
1452 | length--; | |
1453 | } | |
1454 | ||
1455 | for (i = 0; i < length - 1; i++) | |
1456 | myaddr[i + addr - memaddr] = gbyte (); | |
1457 | ||
1458 | gbyte (); /* Ignore checksum */ | |
1459 | } | |
1460 | } | |
1461 | } | |
1462 | } | |
1463 | ||
1464 | putchar_e7000 (ACK); | |
1465 | expect ("TOP ADDRESS ="); | |
1466 | expect ("END ADDRESS ="); | |
1467 | expect (":"); | |
1468 | ||
1469 | return len; | |
1470 | } | |
1471 | ||
1472 | #endif | |
1473 | ||
69dc947a KB |
1474 | /* Transfer LEN bytes between GDB address MYADDR and target address |
1475 | MEMADDR. If WRITE is non-zero, transfer them to the target, | |
1476 | otherwise transfer them from the target. TARGET is unused. | |
1477 | ||
1478 | Returns the number of bytes transferred. */ | |
1479 | ||
c906108c | 1480 | static int |
18cf8b5b | 1481 | e7000_xfer_inferior_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, |
0a65a603 AC |
1482 | int write, struct mem_attrib *attrib, |
1483 | struct target_ops *target) | |
c906108c SS |
1484 | { |
1485 | if (write) | |
c5aa993b JM |
1486 | return e7000_write_inferior_memory (memaddr, myaddr, len); |
1487 | else if (len < 16) | |
1488 | return e7000_read_inferior_memory (memaddr, myaddr, len); | |
1489 | else | |
1490 | return e7000_read_inferior_memory_large (memaddr, myaddr, len); | |
c906108c SS |
1491 | } |
1492 | ||
1493 | static void | |
55d80160 | 1494 | e7000_kill (void) |
c906108c SS |
1495 | { |
1496 | } | |
1497 | ||
1498 | static void | |
fba45db2 | 1499 | e7000_load (char *args, int from_tty) |
c906108c SS |
1500 | { |
1501 | struct cleanup *old_chain; | |
1502 | asection *section; | |
1503 | bfd *pbfd; | |
1504 | bfd_vma entry; | |
1505 | #define WRITESIZE 0x1000 | |
c5aa993b | 1506 | char buf[2 + 4 + 4 + WRITESIZE]; /* `DT' + <addr> + <len> + <data> */ |
c906108c SS |
1507 | char *filename; |
1508 | int quiet; | |
1509 | int nostart; | |
1510 | time_t start_time, end_time; /* Start and end times of download */ | |
1511 | unsigned long data_count; /* Number of bytes transferred to memory */ | |
c5aa993b | 1512 | int oldtimeout = timeout; |
c906108c SS |
1513 | |
1514 | timeout = remote_timeout; | |
1515 | ||
1516 | ||
1517 | /* FIXME! change test to test for type of download */ | |
1518 | if (!using_tcp) | |
1519 | { | |
1520 | generic_load (args, from_tty); | |
1521 | return; | |
1522 | } | |
1523 | ||
1524 | /* for direct tcp connections, we can do a fast binary download */ | |
1525 | buf[0] = 'D'; | |
1526 | buf[1] = 'T'; | |
1527 | quiet = 0; | |
1528 | nostart = 0; | |
1529 | filename = NULL; | |
1530 | ||
1531 | while (*args != '\000') | |
1532 | { | |
1533 | char *arg; | |
1534 | ||
c5aa993b JM |
1535 | while (isspace (*args)) |
1536 | args++; | |
c906108c SS |
1537 | |
1538 | arg = args; | |
1539 | ||
c5aa993b JM |
1540 | while ((*args != '\000') && !isspace (*args)) |
1541 | args++; | |
c906108c SS |
1542 | |
1543 | if (*args != '\000') | |
1544 | *args++ = '\000'; | |
1545 | ||
1546 | if (*arg != '-') | |
1547 | filename = arg; | |
1548 | else if (strncmp (arg, "-quiet", strlen (arg)) == 0) | |
1549 | quiet = 1; | |
1550 | else if (strncmp (arg, "-nostart", strlen (arg)) == 0) | |
1551 | nostart = 1; | |
1552 | else | |
8a3fe4f8 | 1553 | error (_("unknown option `%s'"), arg); |
c906108c SS |
1554 | } |
1555 | ||
1556 | if (!filename) | |
1557 | filename = get_exec_file (1); | |
1558 | ||
1559 | pbfd = bfd_openr (filename, gnutarget); | |
1560 | if (pbfd == NULL) | |
1561 | { | |
1562 | perror_with_name (filename); | |
1563 | return; | |
1564 | } | |
5c65bbb6 | 1565 | old_chain = make_cleanup_bfd_close (pbfd); |
c906108c | 1566 | |
c5aa993b | 1567 | if (!bfd_check_format (pbfd, bfd_object)) |
8a3fe4f8 | 1568 | error (_("\"%s\" is not an object file: %s"), filename, |
c906108c SS |
1569 | bfd_errmsg (bfd_get_error ())); |
1570 | ||
1571 | start_time = time (NULL); | |
1572 | data_count = 0; | |
1573 | ||
1574 | puts_e7000debug ("mw\r"); | |
1575 | ||
1576 | expect ("\nOK"); | |
1577 | ||
c5aa993b | 1578 | for (section = pbfd->sections; section; section = section->next) |
c906108c SS |
1579 | { |
1580 | if (bfd_get_section_flags (pbfd, section) & SEC_LOAD) | |
1581 | { | |
1582 | bfd_vma section_address; | |
1583 | bfd_size_type section_size; | |
1584 | file_ptr fptr; | |
1585 | ||
1586 | section_address = bfd_get_section_vma (pbfd, section); | |
2c500098 | 1587 | section_size = bfd_get_section_size (section); |
c906108c SS |
1588 | |
1589 | if (!quiet) | |
4902674b | 1590 | printf_filtered ("[Loading section %s at 0x%s (%s bytes)]\n", |
c906108c | 1591 | bfd_get_section_name (pbfd, section), |
4902674b EZ |
1592 | paddr_nz (section_address), |
1593 | paddr_u (section_size)); | |
c906108c SS |
1594 | |
1595 | fptr = 0; | |
c5aa993b | 1596 | |
c906108c SS |
1597 | data_count += section_size; |
1598 | ||
1599 | while (section_size > 0) | |
1600 | { | |
1601 | int count; | |
1602 | static char inds[] = "|/-\\"; | |
1603 | static int k = 0; | |
1604 | ||
1605 | QUIT; | |
1606 | ||
1607 | count = min (section_size, WRITESIZE); | |
1608 | ||
1609 | buf[2] = section_address >> 24; | |
1610 | buf[3] = section_address >> 16; | |
1611 | buf[4] = section_address >> 8; | |
1612 | buf[5] = section_address; | |
1613 | ||
1614 | buf[6] = count >> 24; | |
1615 | buf[7] = count >> 16; | |
1616 | buf[8] = count >> 8; | |
1617 | buf[9] = count; | |
1618 | ||
1619 | bfd_get_section_contents (pbfd, section, buf + 10, fptr, count); | |
1620 | ||
2cd58942 | 1621 | if (serial_write (e7000_desc, buf, count + 10)) |
c906108c | 1622 | fprintf_unfiltered (gdb_stderr, |
2cd58942 | 1623 | "e7000_load: serial_write failed: %s\n", |
c5aa993b | 1624 | safe_strerror (errno)); |
c906108c SS |
1625 | |
1626 | expect ("OK"); | |
1627 | ||
1628 | if (!quiet) | |
1629 | { | |
1630 | printf_unfiltered ("\r%c", inds[k++ % 4]); | |
1631 | gdb_flush (gdb_stdout); | |
1632 | } | |
1633 | ||
1634 | section_address += count; | |
1635 | fptr += count; | |
1636 | section_size -= count; | |
1637 | } | |
1638 | } | |
1639 | } | |
1640 | ||
1641 | write_e7000 ("ED"); | |
1642 | ||
1643 | expect_prompt (); | |
1644 | ||
1645 | end_time = time (NULL); | |
1646 | ||
1647 | /* Finally, make the PC point at the start address */ | |
1648 | ||
1649 | if (exec_bfd) | |
1650 | write_pc (bfd_get_start_address (exec_bfd)); | |
1651 | ||
39f77062 | 1652 | inferior_ptid = null_ptid; /* No process now */ |
c906108c SS |
1653 | |
1654 | /* This is necessary because many things were based on the PC at the time that | |
1655 | we attached to the monitor, which is no longer valid now that we have loaded | |
1656 | new code (and just changed the PC). Another way to do this might be to call | |
1657 | normal_stop, except that the stack may not be valid, and things would get | |
1658 | horribly confused... */ | |
1659 | ||
1660 | clear_symtab_users (); | |
1661 | ||
1662 | if (!nostart) | |
1663 | { | |
1664 | entry = bfd_get_start_address (pbfd); | |
1665 | ||
1666 | if (!quiet) | |
4902674b | 1667 | printf_unfiltered ("[Starting %s at 0x%s]\n", filename, paddr_nz (entry)); |
c906108c | 1668 | |
c5aa993b | 1669 | /* start_routine (entry); */ |
c906108c SS |
1670 | } |
1671 | ||
1672 | report_transfer_performance (data_count, start_time, end_time); | |
1673 | ||
1674 | do_cleanups (old_chain); | |
1675 | timeout = oldtimeout; | |
1676 | } | |
1677 | ||
1678 | /* Clean up when a program exits. | |
1679 | ||
1680 | The program actually lives on in the remote processor's RAM, and may be | |
1681 | run again without a download. Don't leave it full of breakpoint | |
1682 | instructions. */ | |
1683 | ||
1684 | static void | |
fba45db2 | 1685 | e7000_mourn_inferior (void) |
c906108c SS |
1686 | { |
1687 | remove_breakpoints (); | |
1688 | unpush_target (&e7000_ops); | |
1689 | generic_mourn_inferior (); /* Do all the proper things now */ | |
1690 | } | |
1691 | ||
1692 | #define MAX_BREAKPOINTS 200 | |
1693 | #ifdef HARD_BREAKPOINTS | |
1694 | #define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : MAX_BREAKPOINTS) | |
1695 | #else | |
1696 | #define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS | |
1697 | #endif | |
1698 | ||
1699 | /* Since we can change to soft breakpoints dynamically, we must define | |
1700 | more than enough. Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */ | |
c5aa993b JM |
1701 | static CORE_ADDR breakaddr[MAX_BREAKPOINTS] = |
1702 | {0}; | |
c906108c SS |
1703 | |
1704 | static int | |
8181d85f | 1705 | e7000_insert_breakpoint (struct bp_target_info *bp_tgt) |
c906108c | 1706 | { |
8181d85f | 1707 | CORE_ADDR addr = bp_tgt->placed_address; |
c906108c SS |
1708 | int i; |
1709 | char buf[200]; | |
1710 | #if 0 | |
1711 | static char nop[2] = NOP; | |
1712 | #endif | |
1713 | ||
1714 | for (i = 0; i <= MAX_E7000DEBUG_BREAKPOINTS; i++) | |
1715 | if (breakaddr[i] == 0) | |
1716 | { | |
1717 | breakaddr[i] = addr; | |
1718 | /* Save old contents, and insert a nop in the space */ | |
1719 | #ifdef HARD_BREAKPOINTS | |
c5aa993b | 1720 | if (BC_BREAKPOINTS) |
c906108c | 1721 | { |
7aa83cac | 1722 | sprintf (buf, "BC%d A=%s\r", i + 1, paddr_nz (addr)); |
c906108c SS |
1723 | puts_e7000debug (buf); |
1724 | } | |
c5aa993b | 1725 | else |
c906108c | 1726 | { |
7aa83cac | 1727 | sprintf (buf, "B %s\r", paddr_nz (addr)); |
c906108c SS |
1728 | puts_e7000debug (buf); |
1729 | } | |
1730 | #else | |
1731 | #if 0 | |
8181d85f DJ |
1732 | bp_tgt->shadow_len = 2; |
1733 | e7000_read_inferior_memory (addr, bp_tgt->shadow_contents, 2); | |
c906108c SS |
1734 | e7000_write_inferior_memory (addr, nop, 2); |
1735 | #endif | |
1736 | ||
1737 | sprintf (buf, "B %x\r", addr); | |
1738 | puts_e7000debug (buf); | |
1739 | #endif | |
1740 | expect_prompt (); | |
1741 | return 0; | |
1742 | } | |
1743 | ||
8a3fe4f8 | 1744 | error (_("Too many breakpoints ( > %d) for the E7000."), |
c906108c SS |
1745 | MAX_E7000DEBUG_BREAKPOINTS); |
1746 | return 1; | |
1747 | } | |
1748 | ||
1749 | static int | |
8181d85f | 1750 | e7000_remove_breakpoint (struct bp_target_info *bp_tgt) |
c906108c | 1751 | { |
8181d85f | 1752 | CORE_ADDR addr = bp_tgt->placed_address; |
c906108c SS |
1753 | int i; |
1754 | char buf[200]; | |
1755 | ||
1756 | for (i = 0; i < MAX_E7000DEBUG_BREAKPOINTS; i++) | |
1757 | if (breakaddr[i] == addr) | |
1758 | { | |
1759 | breakaddr[i] = 0; | |
1760 | #ifdef HARD_BREAKPOINTS | |
c5aa993b | 1761 | if (BC_BREAKPOINTS) |
c906108c | 1762 | { |
c5aa993b | 1763 | sprintf (buf, "BC%d - \r", i + 1); |
c906108c SS |
1764 | puts_e7000debug (buf); |
1765 | } | |
c5aa993b | 1766 | else |
c906108c | 1767 | { |
7aa83cac | 1768 | sprintf (buf, "B - %s\r", paddr_nz (addr)); |
c906108c SS |
1769 | puts_e7000debug (buf); |
1770 | } | |
1771 | expect_prompt (); | |
1772 | #else | |
7aa83cac | 1773 | sprintf (buf, "B - %s\r", paddr_nz (addr)); |
c906108c SS |
1774 | puts_e7000debug (buf); |
1775 | expect_prompt (); | |
1776 | ||
1777 | #if 0 | |
1778 | /* Replace the insn under the break */ | |
8181d85f DJ |
1779 | e7000_write_inferior_memory (addr, bp_tgt->shadow_contents, |
1780 | bp_tgt->shadow_len); | |
c906108c SS |
1781 | #endif |
1782 | #endif | |
1783 | ||
1784 | return 0; | |
1785 | } | |
7aa83cac | 1786 | |
8a3fe4f8 | 1787 | warning (_("Can't find breakpoint associated with 0x%s."), paddr_nz (addr)); |
c906108c SS |
1788 | return 1; |
1789 | } | |
1790 | ||
1791 | /* Put a command string, in args, out to STDBUG. Output from STDBUG | |
1792 | is placed on the users terminal until the prompt is seen. */ | |
1793 | ||
1794 | static void | |
fba45db2 | 1795 | e7000_command (char *args, int fromtty) |
c906108c SS |
1796 | { |
1797 | /* FIXME: arbitrary limit on length of args. */ | |
1798 | char buf[200]; | |
1799 | ||
1800 | echo = 0; | |
1801 | ||
1802 | if (!e7000_desc) | |
8a3fe4f8 | 1803 | error (_("e7000 target not open.")); |
c906108c SS |
1804 | if (!args) |
1805 | { | |
1806 | puts_e7000debug ("\r"); | |
1807 | } | |
1808 | else | |
1809 | { | |
1810 | sprintf (buf, "%s\r", args); | |
1811 | puts_e7000debug (buf); | |
1812 | } | |
1813 | ||
1814 | echo++; | |
1815 | ctrl_c = 2; | |
1816 | expect_full_prompt (); | |
1817 | echo--; | |
1818 | ctrl_c = 0; | |
1819 | printf_unfiltered ("\n"); | |
1820 | ||
1821 | /* Who knows what the command did... */ | |
1822 | registers_changed (); | |
1823 | } | |
1824 | ||
1825 | ||
1826 | static void | |
fba45db2 | 1827 | e7000_drain_command (char *args, int fromtty) |
c906108c SS |
1828 | { |
1829 | int c; | |
1830 | ||
c5aa993b | 1831 | puts_e7000debug ("end\r"); |
c906108c SS |
1832 | putchar_e7000 (CTRLC); |
1833 | ||
b871e4ec | 1834 | while ((c = readchar (1)) != -1) |
c906108c SS |
1835 | { |
1836 | if (quit_flag) | |
1837 | { | |
c5aa993b | 1838 | putchar_e7000 (CTRLC); |
c906108c SS |
1839 | quit_flag = 0; |
1840 | } | |
1841 | if (c > ' ' && c < 127) | |
1842 | printf_unfiltered ("%c", c & 0xff); | |
1843 | else | |
1844 | printf_unfiltered ("<%x>", c & 0xff); | |
1845 | } | |
1846 | } | |
1847 | ||
1848 | #define NITEMS 7 | |
1849 | ||
1850 | static int | |
fba45db2 | 1851 | why_stop (void) |
c906108c | 1852 | { |
c5aa993b JM |
1853 | static char *strings[NITEMS] = |
1854 | { | |
c906108c SS |
1855 | "STEP NORMAL", |
1856 | "BREAK POINT", | |
1857 | "BREAK KEY", | |
1858 | "BREAK CONDI", | |
1859 | "CYCLE ACCESS", | |
1860 | "ILLEGAL INSTRUCTION", | |
1861 | "WRITE PROTECT", | |
1862 | }; | |
1863 | char *p[NITEMS]; | |
1864 | int c; | |
1865 | int i; | |
1866 | ||
1867 | for (i = 0; i < NITEMS; ++i) | |
1868 | p[i] = strings[i]; | |
c5aa993b | 1869 | |
c906108c SS |
1870 | c = gch (); |
1871 | while (1) | |
1872 | { | |
1873 | for (i = 0; i < NITEMS; i++) | |
1874 | { | |
c5aa993b | 1875 | if (c == *(p[i])) |
c906108c SS |
1876 | { |
1877 | p[i]++; | |
c5aa993b JM |
1878 | if (*(p[i]) == 0) |
1879 | { | |
c906108c SS |
1880 | /* found one of the choices */ |
1881 | return i; | |
1882 | } | |
1883 | } | |
1884 | else | |
1885 | p[i] = strings[i]; | |
1886 | } | |
1887 | ||
1888 | c = gch (); | |
1889 | } | |
1890 | } | |
1891 | ||
1892 | /* Suck characters, if a string match, then return the strings index | |
1893 | otherwise echo them. */ | |
1894 | ||
a78f21af | 1895 | static int |
fba45db2 | 1896 | expect_n (char **strings) |
c906108c SS |
1897 | { |
1898 | char *(ptr[10]); | |
c5aa993b | 1899 | int n; |
c906108c SS |
1900 | int c; |
1901 | char saveaway[100]; | |
1902 | char *buffer = saveaway; | |
1903 | /* Count number of expect strings */ | |
1904 | ||
c5aa993b | 1905 | for (n = 0; strings[n]; n++) |
c906108c SS |
1906 | { |
1907 | ptr[n] = strings[n]; | |
1908 | } | |
1909 | ||
1910 | while (1) | |
1911 | { | |
1912 | int i; | |
1913 | int gotone = 0; | |
1914 | ||
1915 | c = readchar (1); | |
1916 | if (c == -1) | |
1917 | { | |
1918 | printf_unfiltered ("[waiting for e7000...]\n"); | |
1919 | } | |
1920 | #ifdef __GO32__ | |
1921 | if (kbhit ()) | |
1922 | { | |
c5aa993b | 1923 | int k = getkey (); |
c906108c SS |
1924 | |
1925 | if (k == 1) | |
1926 | quit_flag = 1; | |
1927 | } | |
1928 | #endif | |
1929 | if (quit_flag) | |
1930 | { | |
1931 | putchar_e7000 (CTRLC); /* interrupt the running program */ | |
1932 | quit_flag = 0; | |
1933 | } | |
1934 | ||
1935 | for (i = 0; i < n; i++) | |
1936 | { | |
c5aa993b | 1937 | if (c == ptr[i][0]) |
c906108c SS |
1938 | { |
1939 | ptr[i]++; | |
1940 | if (ptr[i][0] == 0) | |
1941 | { | |
1942 | /* Gone all the way */ | |
1943 | return i; | |
1944 | } | |
1945 | gotone = 1; | |
1946 | } | |
1947 | else | |
1948 | { | |
1949 | ptr[i] = strings[i]; | |
1950 | } | |
1951 | } | |
c5aa993b | 1952 | |
c906108c SS |
1953 | if (gotone) |
1954 | { | |
1955 | /* Save it up incase we find that there was no match */ | |
c5aa993b | 1956 | *buffer++ = c; |
c906108c SS |
1957 | } |
1958 | else | |
1959 | { | |
c5aa993b | 1960 | if (buffer != saveaway) |
c906108c SS |
1961 | { |
1962 | *buffer++ = 0; | |
1963 | printf_unfiltered ("%s", buffer); | |
1964 | buffer = saveaway; | |
1965 | } | |
1966 | if (c != -1) | |
1967 | { | |
1968 | putchar_unfiltered (c); | |
1969 | gdb_flush (gdb_stdout); | |
1970 | } | |
1971 | } | |
1972 | } | |
1973 | } | |
1974 | ||
1975 | /* We subtract two from the pc here rather than use | |
1976 | DECR_PC_AFTER_BREAK since the e7000 doesn't always add two to the | |
1977 | pc, and the simulators never do. */ | |
1978 | ||
1979 | static void | |
fba45db2 | 1980 | sub2_from_pc (void) |
c906108c SS |
1981 | { |
1982 | char buf[4]; | |
1983 | char buf2[200]; | |
1984 | ||
1985 | store_signed_integer (buf, | |
3acba339 | 1986 | register_size (current_gdbarch, PC_REGNUM), |
c5aa993b | 1987 | read_register (PC_REGNUM) - 2); |
23a6d369 | 1988 | regcache_raw_supply (current_regcache, PC_REGNUM, buf); |
4902674b | 1989 | sprintf (buf2, ".PC %s\r", phex_nz (read_register (PC_REGNUM), 0)); |
c906108c SS |
1990 | puts_e7000debug (buf2); |
1991 | } | |
1992 | ||
1993 | #define WAS_SLEEP 0 | |
1994 | #define WAS_INT 1 | |
1995 | #define WAS_RUNNING 2 | |
1996 | #define WAS_OTHER 3 | |
1997 | ||
c5aa993b JM |
1998 | static char *estrings[] = |
1999 | { | |
c906108c SS |
2000 | "** SLEEP", |
2001 | "BREAK !", | |
2002 | "** PC", | |
2003 | "PC", | |
2004 | NULL | |
2005 | }; | |
2006 | ||
2007 | /* Wait until the remote machine stops, then return, storing status in | |
2008 | STATUS just as `wait' would. */ | |
2009 | ||
39f77062 KB |
2010 | static ptid_t |
2011 | e7000_wait (ptid_t ptid, struct target_waitstatus *status) | |
c906108c SS |
2012 | { |
2013 | int stop_reason; | |
2014 | int regno; | |
2015 | int running_count = 0; | |
2016 | int had_sleep = 0; | |
2017 | int loop = 1; | |
4902674b | 2018 | char *wanted_nopc = NULL; |
7124f6fb | 2019 | int realregs = 0; |
c906108c SS |
2020 | |
2021 | /* Then echo chars until PC= string seen */ | |
2022 | gch (); /* Drop cr */ | |
2023 | gch (); /* and space */ | |
2024 | ||
2025 | while (loop) | |
2026 | { | |
2027 | switch (expect_n (estrings)) | |
c5aa993b | 2028 | { |
c906108c SS |
2029 | case WAS_OTHER: |
2030 | /* how did this happen ? */ | |
2031 | loop = 0; | |
2032 | break; | |
2033 | case WAS_SLEEP: | |
2034 | had_sleep = 1; | |
2035 | putchar_e7000 (CTRLC); | |
2036 | loop = 0; | |
2037 | break; | |
2038 | case WAS_INT: | |
2039 | loop = 0; | |
2040 | break; | |
2041 | case WAS_RUNNING: | |
2042 | running_count++; | |
2043 | if (running_count == 20) | |
2044 | { | |
2045 | printf_unfiltered ("[running...]\n"); | |
2046 | running_count = 0; | |
2047 | } | |
2048 | break; | |
2049 | default: | |
2050 | /* error? */ | |
2051 | break; | |
2052 | } | |
2053 | } | |
2054 | ||
2055 | /* Skip till the PC= */ | |
2056 | expect ("="); | |
2057 | ||
c906108c | 2058 | if (TARGET_ARCHITECTURE->arch == bfd_arch_sh) |
cc17453a EZ |
2059 | { |
2060 | wanted_nopc = want_nopc_sh; | |
7124f6fb | 2061 | realregs = 59; |
cc17453a EZ |
2062 | switch (TARGET_ARCHITECTURE->mach) |
2063 | { | |
2064 | case bfd_mach_sh3: | |
2065 | case bfd_mach_sh3e: | |
2066 | case bfd_mach_sh4: | |
2067 | wanted_nopc = want_nopc_sh3; | |
2068 | } | |
2069 | } | |
cc17453a EZ |
2070 | if (TARGET_ARCHITECTURE->arch == bfd_arch_h8300) |
2071 | { | |
454d0511 | 2072 | wanted_nopc = want_nopc_h8300h; |
7124f6fb | 2073 | realregs = 10; |
454d0511 DD |
2074 | switch (TARGET_ARCHITECTURE->mach) |
2075 | { | |
2076 | case bfd_mach_h8300s: | |
2077 | case bfd_mach_h8300sn: | |
2078 | case bfd_mach_h8300sx: | |
2079 | case bfd_mach_h8300sxn: | |
2080 | wanted_nopc = want_nopc_h8300s; | |
7124f6fb | 2081 | realregs = 11; |
454d0511 | 2082 | } |
cc17453a | 2083 | } |
c906108c SS |
2084 | fetch_regs_from_dump (gch, wanted_nopc); |
2085 | ||
2086 | /* And supply the extra ones the simulator uses */ | |
7124f6fb | 2087 | for (regno = realregs; regno < NUM_REGS; regno++) |
c906108c SS |
2088 | { |
2089 | int buf = 0; | |
23a6d369 | 2090 | regcache_raw_supply (current_regcache, regno, (char *) &buf); |
c906108c SS |
2091 | } |
2092 | ||
2093 | stop_reason = why_stop (); | |
2094 | expect_full_prompt (); | |
2095 | ||
2096 | status->kind = TARGET_WAITKIND_STOPPED; | |
2097 | status->value.sig = TARGET_SIGNAL_TRAP; | |
2098 | ||
2099 | switch (stop_reason) | |
2100 | { | |
2101 | case 1: /* Breakpoint */ | |
c5aa993b JM |
2102 | write_pc (read_pc ()); /* PC is always off by 2 for breakpoints */ |
2103 | status->value.sig = TARGET_SIGNAL_TRAP; | |
c906108c SS |
2104 | break; |
2105 | case 0: /* Single step */ | |
c5aa993b | 2106 | status->value.sig = TARGET_SIGNAL_TRAP; |
c906108c SS |
2107 | break; |
2108 | case 2: /* Interrupt */ | |
2109 | if (had_sleep) | |
2110 | { | |
c5aa993b | 2111 | status->value.sig = TARGET_SIGNAL_TRAP; |
c906108c SS |
2112 | sub2_from_pc (); |
2113 | } | |
2114 | else | |
2115 | { | |
c5aa993b | 2116 | status->value.sig = TARGET_SIGNAL_INT; |
c906108c SS |
2117 | } |
2118 | break; | |
2119 | case 3: | |
2120 | break; | |
2121 | case 4: | |
2122 | printf_unfiltered ("a cycle address error?\n"); | |
c5aa993b | 2123 | status->value.sig = TARGET_SIGNAL_UNKNOWN; |
c906108c SS |
2124 | break; |
2125 | case 5: | |
c5aa993b | 2126 | status->value.sig = TARGET_SIGNAL_ILL; |
c906108c SS |
2127 | break; |
2128 | case 6: | |
c5aa993b | 2129 | status->value.sig = TARGET_SIGNAL_SEGV; |
c906108c SS |
2130 | break; |
2131 | case 7: /* Anything else (NITEMS + 1) */ | |
2132 | printf_unfiltered ("a write protect error?\n"); | |
c5aa993b | 2133 | status->value.sig = TARGET_SIGNAL_UNKNOWN; |
c906108c SS |
2134 | break; |
2135 | default: | |
2136 | /* Get the user's attention - this should never happen. */ | |
e2e0b3e5 | 2137 | internal_error (__FILE__, __LINE__, _("failed internal consistency check")); |
c906108c SS |
2138 | } |
2139 | ||
39f77062 | 2140 | return inferior_ptid; |
c906108c SS |
2141 | } |
2142 | ||
2143 | /* Stop the running program. */ | |
2144 | ||
2145 | static void | |
fba45db2 | 2146 | e7000_stop (void) |
c906108c SS |
2147 | { |
2148 | /* Sending a ^C is supposed to stop the running program. */ | |
2149 | putchar_e7000 (CTRLC); | |
2150 | } | |
2151 | ||
2152 | /* Define the target subroutine names. */ | |
2153 | ||
c5aa993b | 2154 | struct target_ops e7000_ops; |
c906108c | 2155 | |
c5aa993b JM |
2156 | static void |
2157 | init_e7000_ops (void) | |
c906108c | 2158 | { |
c5aa993b | 2159 | e7000_ops.to_shortname = "e7000"; |
85a453d5 KI |
2160 | e7000_ops.to_longname = "Remote Renesas e7000 target"; |
2161 | e7000_ops.to_doc = "Use a remote Renesas e7000 ICE connected by a serial line;\n\ | |
c906108c SS |
2162 | or a network connection.\n\ |
2163 | Arguments are the name of the device for the serial line,\n\ | |
2164 | the speed to connect at in bits per second.\n\ | |
2165 | eg\n\ | |
2166 | target e7000 /dev/ttya 9600\n\ | |
c5aa993b JM |
2167 | target e7000 foobar"; |
2168 | e7000_ops.to_open = e7000_open; | |
2169 | e7000_ops.to_close = e7000_close; | |
c5aa993b | 2170 | e7000_ops.to_detach = e7000_detach; |
c5aa993b JM |
2171 | e7000_ops.to_resume = e7000_resume; |
2172 | e7000_ops.to_wait = e7000_wait; | |
c5aa993b JM |
2173 | e7000_ops.to_fetch_registers = e7000_fetch_register; |
2174 | e7000_ops.to_store_registers = e7000_store_register; | |
2175 | e7000_ops.to_prepare_to_store = e7000_prepare_to_store; | |
c8e73a31 | 2176 | e7000_ops.deprecated_xfer_memory = e7000_xfer_inferior_memory; |
c5aa993b JM |
2177 | e7000_ops.to_files_info = e7000_files_info; |
2178 | e7000_ops.to_insert_breakpoint = e7000_insert_breakpoint; | |
2179 | e7000_ops.to_remove_breakpoint = e7000_remove_breakpoint; | |
c5aa993b JM |
2180 | e7000_ops.to_kill = e7000_kill; |
2181 | e7000_ops.to_load = e7000_load; | |
c5aa993b | 2182 | e7000_ops.to_create_inferior = e7000_create_inferior; |
c5aa993b | 2183 | e7000_ops.to_mourn_inferior = e7000_mourn_inferior; |
c5aa993b | 2184 | e7000_ops.to_stop = e7000_stop; |
c5aa993b | 2185 | e7000_ops.to_stratum = process_stratum; |
c5aa993b JM |
2186 | e7000_ops.to_has_all_memory = 1; |
2187 | e7000_ops.to_has_memory = 1; | |
2188 | e7000_ops.to_has_stack = 1; | |
2189 | e7000_ops.to_has_registers = 1; | |
2190 | e7000_ops.to_has_execution = 1; | |
c5aa993b | 2191 | e7000_ops.to_magic = OPS_MAGIC; |
c906108c SS |
2192 | }; |
2193 | ||
a78f21af AC |
2194 | extern initialize_file_ftype _initialize_remote_e7000; /* -Wmissing-prototypes */ |
2195 | ||
c906108c | 2196 | void |
fba45db2 | 2197 | _initialize_remote_e7000 (void) |
c906108c | 2198 | { |
c5aa993b | 2199 | init_e7000_ops (); |
c906108c SS |
2200 | add_target (&e7000_ops); |
2201 | ||
2202 | add_com ("e7000", class_obscure, e7000_command, | |
1bedd215 | 2203 | _("Send a command to the e7000 monitor.")); |
c906108c SS |
2204 | |
2205 | add_com ("ftplogin", class_obscure, e7000_login_command, | |
1bedd215 | 2206 | _("Login to machine and change to directory.")); |
c906108c SS |
2207 | |
2208 | add_com ("ftpload", class_obscure, e7000_ftp_command, | |
1bedd215 | 2209 | _("Fetch and load a file from previously described place.")); |
c906108c SS |
2210 | |
2211 | add_com ("drain", class_obscure, e7000_drain_command, | |
1bedd215 | 2212 | _("Drain pending e7000 text buffers.")); |
c906108c | 2213 | |
4d28ad1e AC |
2214 | add_setshow_integer_cmd ("usehardbreakpoints", no_class, |
2215 | &use_hard_breakpoints, _("\ | |
2216 | Set use of hardware breakpoints for all breakpoints."), _("\ | |
2217 | Show use of hardware breakpoints for all breakpoints."), NULL, | |
2218 | NULL, | |
2219 | NULL, /* FIXME: i18n: */ | |
2220 | &setlist, &showlist); | |
c906108c | 2221 | } |