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