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