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