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