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