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