Commit | Line | Data |
---|---|---|
edd01519 | 1 | /* Remote debugging interface for Hitachi E7000 ICE, for GDB |
863099f4 | 2 | Copyright 1993 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 | |
21 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
22 | ||
23 | ||
24 | #include "defs.h" | |
25 | #include "gdbcore.h" | |
26 | #include "target.h" | |
27 | #include "wait.h" | |
28 | #include <varargs.h> | |
29 | #include <signal.h> | |
30 | #include <string.h> | |
31 | #include <sys/types.h> | |
32 | #include "serial.h" | |
33 | ||
34 | ||
35 | /* The E7000 is an in-circuit emulator for the Hitachi H8/300-H and | |
36 | Hitachi-SH processor. It has serial port and a lan port. | |
37 | ||
38 | The monitor command set makes it difficult to load large ammounts of | |
39 | data over the lan without using ftp - so try not to issue load | |
40 | commands when communicating over ethernet; use the ftpload command. | |
41 | ||
42 | The monitor pauses for a second when dumping srecords to the serial | |
43 | line too, so we use a slower per byte mechanism but without the | |
44 | startup overhead. Even so, it's pretty slow... */ | |
45 | ||
46 | int using_tcp; /* nonzero if using the tcp serial driver */ | |
47 | ||
48 | extern struct target_ops e7000_ops; /* Forward declaration */ | |
49 | #define CTRLC 0x03 | |
50 | #define ENQ 0x05 | |
51 | #define ACK 0x06 | |
52 | #define CTRLZ 0x1a | |
53 | ||
54 | char *ENQSTRING = "\005"; | |
55 | ||
56 | int echo; | |
edd01519 | 57 | int ctrl_c; |
863099f4 SC |
58 | static void e7000_close (); |
59 | static void e7000_fetch_register (); | |
60 | static void e7000_store_register (); | |
61 | ||
62 | static int timeout = 5; | |
63 | ||
64 | static void expect PARAMS ((char *)); | |
65 | static void expect_full_prompt PARAMS (()); | |
66 | static void expect_prompt PARAMS (()); | |
67 | static serial_t e7000_desc; | |
68 | ||
69 | ||
70 | /* Send data to e7000debug. Works just like printf. */ | |
edd01519 | 71 | #if 0 |
863099f4 SC |
72 | static void |
73 | printf_e7000debug (va_alist) | |
74 | va_dcl | |
75 | { | |
76 | va_list args; | |
77 | char *pattern; | |
78 | char buf[200]; | |
79 | ||
80 | va_start (args); | |
81 | ||
82 | pattern = va_arg (args, char *); | |
83 | ||
84 | vsprintf (buf, pattern, args); | |
edd01519 SC |
85 | #else |
86 | ||
87 | static void | |
88 | printf_e7000debug(a,b,c,d,e) | |
89 | { | |
90 | char buf[200]; | |
91 | sprintf(buf, a,b,c,d,e); | |
92 | #endif | |
863099f4 SC |
93 | if (SERIAL_WRITE (e7000_desc, buf, strlen (buf))) |
94 | fprintf (stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno)); | |
95 | ||
96 | /* And expect to see it echoed */ | |
97 | expect (buf); | |
98 | } | |
99 | ||
100 | static void | |
101 | putchar_e7000 (x) | |
102 | { | |
103 | char b[1]; | |
104 | b[0] = x; | |
105 | SERIAL_WRITE (e7000_desc, b, 1); | |
106 | } | |
107 | ||
108 | static void | |
109 | write_e7000 (s) | |
110 | char *s; | |
111 | { | |
112 | SERIAL_WRITE (e7000_desc, s, strlen (s)); | |
113 | } | |
114 | ||
115 | /* Read a character from the remote system, doing all the fancy timeout | |
116 | stuff. */ | |
117 | ||
118 | static int | |
119 | readchar (timeout) | |
120 | int timeout; | |
121 | { | |
122 | int c; | |
123 | do | |
124 | { | |
125 | c = SERIAL_READCHAR (e7000_desc, timeout); | |
126 | } | |
127 | while (c > 127); | |
128 | if (c == SERIAL_TIMEOUT) | |
129 | { | |
130 | if (timeout == 0) | |
131 | return c; /* Polls shouldn't generate timeout errors */ | |
132 | ||
133 | error ("Timeout reading from remote system."); | |
134 | } | |
135 | return c; | |
136 | } | |
137 | ||
edd01519 | 138 | |
863099f4 SC |
139 | /* Scan input from the remote system, until STRING is found. If DISCARD is |
140 | non-zero, then discard non-matching input, else print it out. | |
141 | Let the user break out immediately. */ | |
142 | static void | |
143 | expect (string) | |
144 | char *string; | |
145 | { | |
146 | char *p = string; | |
147 | int c; | |
148 | ||
863099f4 SC |
149 | while (1) |
150 | ||
151 | { | |
152 | c = readchar (timeout); | |
edd01519 SC |
153 | |
154 | notice_quit (); | |
155 | if (quit_flag == 1) | |
156 | { | |
157 | if (ctrl_c) { | |
158 | putchar_e7000(CTRLC); | |
159 | ctrl_c -- ; | |
160 | } | |
161 | else | |
162 | { | |
163 | quit(); | |
164 | } | |
165 | } | |
166 | ||
863099f4 SC |
167 | if (c == SERIAL_ERROR) |
168 | { | |
169 | error ("Serial communication error"); | |
170 | } | |
edd01519 | 171 | if (echo) |
863099f4 SC |
172 | { |
173 | if (c != '\r') | |
174 | putchar (c); | |
175 | fflush (stdout); | |
176 | } | |
177 | if (c == *p++) | |
178 | { | |
179 | if (*p == '\0') | |
180 | { | |
863099f4 SC |
181 | return; |
182 | } | |
183 | } | |
184 | else | |
185 | { | |
186 | p = string; | |
187 | } | |
188 | } | |
189 | } | |
190 | ||
191 | /* Keep discarding input until we see the e7000 prompt. | |
192 | ||
193 | The convention for dealing with the prompt is that you | |
194 | o give your command | |
195 | o *then* wait for the prompt. | |
196 | ||
197 | Thus the last thing that a procedure does with the serial line | |
198 | will be an expect_prompt(). Exception: e7000_resume does not | |
199 | wait for the prompt, because the terminal is being handed over | |
200 | to the inferior. However, the next thing which happens after that | |
201 | is a e7000_wait which does wait for the prompt. | |
202 | Note that this includes abnormal exit, e.g. error(). This is | |
203 | necessary to prevent getting into states from which we can't | |
204 | recover. */ | |
205 | static void | |
206 | expect_prompt () | |
207 | { | |
863099f4 SC |
208 | expect (":"); |
209 | } | |
210 | static void | |
211 | expect_full_prompt () | |
212 | { | |
863099f4 SC |
213 | expect ("\n:"); |
214 | } | |
215 | ||
216 | static int | |
217 | get_hex_digit (ch) | |
218 | { | |
219 | if (ch >= '0' && ch <= '9') | |
220 | return ch - '0'; | |
221 | else if (ch >= 'A' && ch <= 'F') | |
222 | return ch - 'A' + 10; | |
223 | else if (ch >= 'a' && ch <= 'f') | |
224 | return ch - 'a' + 10; | |
225 | return -1; | |
226 | ||
227 | } | |
228 | ||
229 | ||
230 | ||
231 | static int | |
232 | get_hex (start) | |
233 | int *start; | |
234 | { | |
235 | int value = get_hex_digit (*start); | |
236 | int try; | |
237 | ||
238 | *start = readchar (timeout); | |
239 | while ((try = get_hex_digit (*start)) >= 0) | |
240 | { | |
241 | value <<= 4; | |
242 | value += try; | |
243 | *start = readchar (timeout); | |
244 | } | |
245 | return value; | |
246 | } | |
247 | ||
248 | /* Get N 32-bit words from remote, each preceded by a space, | |
249 | and put them in registers starting at REGNO. */ | |
250 | ||
251 | static void | |
252 | get_hex_regs (n, regno) | |
253 | int n; | |
254 | int regno; | |
255 | { | |
256 | long val; | |
257 | int i; | |
258 | ||
259 | for (i = 0; i < n; i++) | |
260 | { | |
261 | int j; | |
262 | ||
263 | val = 0; | |
264 | for (j = 0; j < 8; j++) | |
265 | val = (val << 4) + get_hex_digit (j == 0); | |
266 | supply_register (regno++, (char *) &val); | |
267 | } | |
268 | } | |
269 | ||
270 | /* This is called not only when we first attach, but also when the | |
271 | user types "run" after having attached. */ | |
272 | static void | |
273 | e7000_create_inferior (execfile, args, env) | |
274 | char *execfile; | |
275 | char *args; | |
276 | char **env; | |
277 | { | |
278 | int entry_pt; | |
279 | ||
280 | if (args && *args) | |
281 | error ("Can't pass arguments to remote E7000DEBUG process"); | |
282 | ||
283 | if (execfile == 0 || exec_bfd == 0) | |
284 | error ("No exec file specified"); | |
285 | ||
286 | entry_pt = (int) bfd_get_start_address (exec_bfd); | |
287 | ||
288 | #ifdef CREATE_INFERIOR_HOOK | |
289 | CREATE_INFERIOR_HOOK (0); /* No process-ID */ | |
290 | #endif | |
291 | ||
292 | /* The "process" (board) is already stopped awaiting our commands, and | |
293 | the program is already downloaded. We just set its PC and go. */ | |
294 | ||
295 | clear_proceed_status (); | |
296 | ||
297 | /* Tell wait_for_inferior that we've started a new process. */ | |
298 | init_wait_for_inferior (); | |
299 | ||
300 | /* Set up the "saved terminal modes" of the inferior | |
301 | based on what modes we are starting it with. */ | |
302 | target_terminal_init (); | |
303 | ||
304 | /* Install inferior's terminal modes. */ | |
305 | target_terminal_inferior (); | |
306 | ||
307 | /* insert_step_breakpoint (); FIXME, do we need this? */ | |
308 | proceed ((CORE_ADDR) entry_pt, -1, 0); /* Let 'er rip... */ | |
309 | } | |
310 | ||
311 | /* Open a connection to a remote debugger. | |
312 | NAME is the filename used for communication. */ | |
313 | ||
314 | static int baudrate = 9600; | |
315 | static char dev_name[100]; | |
316 | ||
317 | static char *machine = ""; | |
318 | static char *user = ""; | |
319 | static char *passwd = ""; | |
320 | static char *dir = ""; | |
321 | ||
322 | /* Grab the next token and buy some space for it */ | |
323 | static char * | |
324 | next (ptr) | |
325 | char **ptr; | |
326 | { | |
327 | char *p = *ptr; | |
328 | char *s; | |
329 | char *r; | |
330 | int l = 0; | |
331 | while (*p && *p == ' ') | |
332 | { | |
333 | p++; | |
334 | } | |
335 | s = p; | |
336 | while (*p && (*p != ' ' && *p != '\t')) | |
337 | { | |
338 | l++; | |
339 | p++; | |
340 | } | |
341 | r = xmalloc (l + 1); | |
342 | memcpy (r, s, l); | |
343 | r[l] = 0; | |
344 | *ptr = p; | |
345 | return r; | |
346 | } | |
347 | ||
348 | static | |
349 | e7000_login (args, from_tty) | |
350 | char *args; | |
351 | int from_tty; | |
352 | { | |
353 | if (args) | |
354 | { | |
355 | machine = next (&args); | |
356 | user = next (&args); | |
357 | passwd = next (&args); | |
358 | dir = next (&args); | |
359 | if (from_tty) | |
360 | { | |
361 | printf ("Set info to %s %s %s %s\n", machine, user, passwd, dir); | |
362 | } | |
363 | } | |
364 | else | |
365 | { | |
366 | error ("Syntax is ftplogin <machine> <user> <passwd> <directory>"); | |
367 | } | |
368 | } | |
369 | ||
370 | /* Start an ftp transfer from the E7000 to a host */ | |
371 | ||
372 | static | |
373 | e7000_ftp (args, from_tty) | |
374 | char *args; | |
375 | int from_tty; | |
376 | { | |
377 | int oldtimeout = timeout; | |
378 | timeout = 10; | |
863099f4 SC |
379 | printf_e7000debug ("ftp %s\r", machine); |
380 | expect (" Username : "); | |
381 | printf_e7000debug ("%s\r", user); | |
382 | expect (" Password : "); | |
383 | write_e7000 (passwd); | |
384 | write_e7000 ("\r"); | |
385 | expect ("success\r"); | |
386 | expect ("FTP>"); | |
387 | printf_e7000debug ("cd %s\r", dir); | |
388 | expect ("FTP>"); | |
389 | printf_e7000debug ("ll 0;s:%s\r", args); | |
390 | expect ("FTP>"); | |
391 | printf_e7000debug ("bye\r"); | |
392 | expect (":"); | |
863099f4 SC |
393 | timeout = oldtimeout; |
394 | } | |
395 | ||
396 | static void | |
397 | e7000_open (args, from_tty) | |
398 | char *args; | |
399 | int from_tty; | |
400 | { | |
401 | int n; | |
402 | char junk[100]; | |
403 | int sync; | |
404 | target_preopen (from_tty); | |
405 | ||
406 | if (args) | |
407 | n = sscanf (args, " %s %d %s", dev_name, &baudrate, junk); | |
408 | else | |
409 | n = 0; | |
410 | if (n != 1 && n != 2) | |
411 | error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\ | |
412 | or \t\ttarget e7000 <host>[:<port>]\n"); | |
413 | ||
414 | if (n == 1 && strchr (dev_name, ':') == 0) | |
415 | { | |
416 | /* Default to normal telnet port */ | |
417 | strcat (dev_name, ":23"); | |
418 | } | |
419 | ||
420 | push_target (&e7000_ops); | |
421 | e7000_desc = SERIAL_OPEN (dev_name); | |
422 | ||
423 | ||
424 | if (!e7000_desc) | |
425 | perror_with_name (dev_name); | |
426 | ||
427 | using_tcp = strcmp (e7000_desc->ops->name, "tcp") == 0; | |
428 | ||
429 | SERIAL_SETBAUDRATE (e7000_desc, baudrate); | |
430 | SERIAL_RAW (e7000_desc); | |
431 | ||
432 | /* Hello? Are you there? */ | |
433 | sync = 0; | |
edd01519 | 434 | putchar_e7000 (CTRLC); |
863099f4 SC |
435 | while (!sync) |
436 | { | |
437 | int c; | |
438 | if (from_tty) | |
439 | printf_unfiltered ("[waiting for e7000...]\n"); | |
440 | write_e7000 ("\r\n"); | |
441 | c = SERIAL_READCHAR (e7000_desc, 3); | |
442 | while (c != SERIAL_TIMEOUT) | |
443 | { | |
444 | /* Dont echo cr's */ | |
445 | if (from_tty && c != '\r') | |
446 | { | |
447 | putchar (c); | |
448 | fflush (stdout); | |
449 | } | |
450 | if (c == ':') | |
451 | { | |
452 | sync = 1; | |
453 | } | |
454 | c = SERIAL_READCHAR (e7000_desc, 3); | |
455 | if (quit_flag) | |
456 | { | |
457 | putchar_e7000 (CTRLC); | |
458 | quit_flag = 0; | |
459 | } | |
460 | } | |
461 | } | |
462 | printf_e7000debug ("\r\n"); | |
463 | expect_prompt (); | |
464 | ||
465 | if (from_tty) | |
466 | printf_filtered ("Remote %s connected to %s\n", target_shortname, | |
467 | dev_name); | |
468 | ||
edd01519 SC |
469 | #ifdef GDB_TARGET_IS_H8300 |
470 | h8300hmode = 1; | |
471 | #endif | |
863099f4 SC |
472 | } |
473 | ||
474 | /* Close out all files and local state before this target loses control. */ | |
475 | ||
476 | static void | |
477 | e7000_close (quitting) | |
478 | int quitting; | |
479 | { | |
480 | if (e7000_desc) | |
481 | { | |
482 | SERIAL_CLOSE (e7000_desc); | |
483 | e7000_desc = 0; | |
484 | } | |
485 | } | |
486 | ||
487 | /* Terminate the open connection to the remote debugger. | |
488 | Use this when you want to detach and do something else | |
489 | with your gdb. */ | |
490 | static void | |
491 | e7000_detach (from_tty) | |
492 | int from_tty; | |
493 | { | |
494 | pop_target (); /* calls e7000_close to do the real work */ | |
495 | if (from_tty) | |
496 | printf ("Ending remote %s debugging\n", target_shortname); | |
497 | } | |
498 | ||
499 | /* Tell the remote machine to resume. */ | |
500 | ||
501 | static void | |
502 | e7000_resume (pid, step, sig) | |
503 | int pid, step, sig; | |
504 | { | |
505 | if (step) | |
506 | { | |
507 | printf_e7000debug ("S\r"); | |
508 | } | |
509 | else | |
510 | { | |
511 | printf_e7000debug ("G\r"); | |
512 | } | |
513 | } | |
514 | ||
515 | /* Read the remote registers into the block REGS. | |
516 | ||
edd01519 | 517 | For the H8/300 a register dump looks like: |
863099f4 | 518 | |
edd01519 SC |
519 | |
520 | PC=00021A CCR=80:I******* | |
521 | ER0 - ER3 0000000A 0000002E 0000002E 00000000 | |
522 | ER4 - ER7 00000000 00000000 00000000 00FFEFF6 | |
523 | 000218 MOV.B R1L,R2L | |
524 | STEP NORMAL END or | |
525 | BREAK POINT | |
863099f4 SC |
526 | */ |
527 | ||
528 | #ifdef GDB_TARGET_IS_H8300 | |
529 | char *want = "\n\ | |
530 | PC=%p CCR=%c\n\ | |
531 | ER0 - ER3 %0 %1 %2 %3\n\ | |
edd01519 SC |
532 | ER4 - ER7 %4 %5 %6 %7\n"; |
533 | ||
534 | char *want_nopc = "%p CCR=%c\n\ | |
535 | ER0 - ER3 %0 %1 %2 %3\n\ | |
536 | ER4 - ER7 %4 %5 %6 %7"; | |
537 | ||
863099f4 SC |
538 | |
539 | #endif | |
540 | #ifdef GDB_TARGET_IS_SH | |
edd01519 | 541 | char *want = "\n PC=%16 SR=%22\n\ |
863099f4 SC |
542 | PR=%17 GBR=%18 VBR=%19\n\ |
543 | MACH=%20 MACL=%21\n\ | |
544 | R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\ | |
edd01519 | 545 | R8-15 %8 %9 %10 %11 %12 %13 %14 %15\n"; |
863099f4 SC |
546 | |
547 | char *want_nopc = "%16 SR=%22\n\ | |
548 | PR=%17 GBR=%18 VBR=%19\n\ | |
549 | MACH=%20 MACL=%21\n\ | |
550 | R0-7 %0 %1 %2 %3 %4 %5 %6 %7\n\ | |
551 | R8-15 %8 %9 %10 %11 %12 %13 %14 %15"; | |
552 | ||
553 | ||
554 | #endif | |
555 | ||
556 | static | |
557 | int | |
558 | gch () | |
559 | { | |
560 | int c = readchar (timeout); | |
561 | if (echo) | |
562 | { | |
563 | if (c >= ' ') | |
564 | printf ("%c", c); | |
565 | else if (c == '\n') | |
566 | printf ("\n", c); | |
567 | } | |
568 | return c; | |
569 | } | |
570 | ||
571 | ||
572 | static | |
573 | unsigned int | |
574 | gbyte () | |
575 | { | |
576 | int high = get_hex_digit (gch ()); | |
577 | int low = get_hex_digit (gch ()); | |
578 | return (high << 4) + low; | |
579 | } | |
580 | ||
581 | void | |
582 | fetch_regs_from_dump (nextchar, want) | |
583 | int (*nextchar)(); | |
584 | char *want; | |
585 | { | |
586 | int regno; | |
587 | char buf[MAX_REGISTER_RAW_SIZE]; | |
588 | ||
589 | int thischar = nextchar(); | |
590 | ||
591 | while (*want) | |
592 | { | |
593 | switch (*want) | |
594 | { | |
595 | case '\n': | |
596 | while (thischar != '\n') | |
597 | thischar = nextchar(); | |
598 | thischar = nextchar(); | |
599 | while (thischar == '\r') | |
600 | thischar = nextchar(); | |
601 | want++; | |
602 | break; | |
603 | ||
604 | case ' ': | |
edd01519 | 605 | while (thischar == ' ' || thischar == '\t' || thischar == '\r' || thischar == '\n') |
863099f4 SC |
606 | thischar = nextchar(); |
607 | want++; | |
608 | break; | |
609 | ||
610 | default: | |
611 | if (*want == thischar) | |
612 | { | |
613 | want++; | |
614 | if (*want) | |
615 | thischar = nextchar(); | |
616 | ||
617 | } | |
618 | else if (thischar == ' ') | |
619 | { | |
620 | thischar = nextchar(); | |
621 | } | |
622 | else { | |
623 | error("out of sync in fetch registers"); | |
624 | } | |
625 | ||
626 | break; | |
627 | case '%': | |
628 | /* Got a register command */ | |
629 | want++; | |
630 | switch (*want) | |
631 | { | |
632 | #ifdef PC_REGNUM | |
633 | case 'p': | |
634 | regno = PC_REGNUM; | |
635 | want++; | |
636 | break; | |
637 | #endif | |
638 | #ifdef CCR_REGNUM | |
639 | case 'c': | |
640 | regno = CCR_REGNUM; | |
641 | want++; | |
642 | break; | |
643 | #endif | |
644 | #ifdef SP_REGNUM | |
645 | case 's': | |
646 | regno = SP_REGNUM; | |
647 | want++; | |
648 | break; | |
649 | #endif | |
650 | #ifdef FP_REGNUM | |
651 | case 'f': | |
652 | regno = FP_REGNUM; | |
653 | want++; | |
654 | break; | |
655 | #endif | |
656 | ||
657 | ||
658 | default: | |
659 | if (isdigit(want[0])) | |
660 | { | |
661 | if (isdigit(want[1])) | |
662 | { | |
663 | regno = (want[0] - '0') * 10 + want[1] - '0'; | |
664 | want+=2; | |
665 | } | |
666 | else | |
667 | { | |
668 | regno = want[0] - '0'; | |
669 | want++; | |
670 | } | |
671 | } | |
672 | ||
673 | else | |
674 | abort(); | |
675 | } | |
676 | store_signed_integer (buf, | |
677 | REGISTER_RAW_SIZE(regno), | |
678 | (LONGEST)get_hex(&thischar, nextchar)); | |
679 | supply_register (regno, buf); | |
680 | break; | |
681 | } | |
682 | } | |
683 | } | |
684 | ||
685 | static void | |
686 | e7000_fetch_registers () | |
687 | { | |
688 | int regno; | |
689 | ||
690 | printf_e7000debug ("R\r"); | |
691 | fetch_regs_from_dump (gch, want); | |
692 | ||
693 | /* And supply the extra ones the simulator uses */ | |
694 | for (regno = NUM_REALREGS; regno < NUM_REGS; regno++) | |
695 | { | |
696 | int buf = 0; | |
697 | supply_register (regno, (char *) (&buf)); | |
698 | } | |
699 | } | |
700 | ||
701 | /* Fetch register REGNO, or all registers if REGNO is -1. | |
702 | Returns errno value. */ | |
703 | ||
704 | static | |
705 | void | |
706 | e7000_fetch_register (regno) | |
707 | int regno; | |
708 | { | |
709 | e7000_fetch_registers (); | |
710 | } | |
711 | ||
712 | /* Store the remote registers from the contents of the block REGS. */ | |
713 | ||
714 | static void | |
715 | e7000_store_registers () | |
716 | { | |
717 | int regno; | |
718 | ||
719 | for (regno = 0; regno < NUM_REALREGS; regno++) | |
720 | e7000_store_register (regno); | |
721 | ||
722 | registers_changed (); | |
723 | } | |
724 | ||
725 | /* Store register REGNO, or all if REGNO == 0. | |
726 | Return errno value. */ | |
727 | static void | |
728 | e7000_store_register (regno) | |
729 | int regno; | |
730 | { | |
731 | if (regno == -1) | |
732 | { | |
733 | e7000_store_registers (); | |
734 | return; | |
735 | } | |
736 | #ifdef GDB_TARGET_IS_H8300 | |
737 | if (regno <= 7) | |
738 | { | |
739 | printf_e7000debug (".ER%d %x\r", regno, | |
740 | read_register (regno)); | |
741 | ||
742 | } | |
743 | else if (regno == PC_REGNUM) | |
744 | { | |
745 | printf_e7000debug (".PC %x\r", | |
746 | read_register (regno)); | |
747 | } | |
748 | else if (regno == CCR_REGNUM) | |
749 | { | |
750 | printf_e7000debug (".CCR %x\r", | |
751 | read_register (regno)); | |
752 | } | |
753 | #endif | |
754 | ||
755 | #ifdef GDB_TARGET_IS_SH | |
756 | switch (regno) | |
757 | { | |
758 | default: | |
759 | printf_e7000debug (".R%d %x\r", regno, | |
760 | read_register (regno)); | |
761 | ||
762 | break; | |
763 | case PC_REGNUM: | |
764 | printf_e7000debug (".PC %x\r", | |
765 | read_register (regno)); | |
766 | break; | |
767 | case SR_REGNUM: | |
768 | printf_e7000debug (".SR %x\r", | |
769 | read_register (regno)); | |
770 | break; | |
771 | ||
772 | case PR_REGNUM: | |
773 | printf_e7000debug (".PR %x\r", | |
774 | read_register (regno)); | |
775 | break; | |
776 | ||
777 | case GBR_REGNUM: | |
778 | printf_e7000debug (".GBR %x\r", | |
779 | read_register (regno)); | |
780 | break; | |
781 | ||
782 | case VBR_REGNUM: | |
783 | printf_e7000debug (".VBR %x\r", | |
784 | read_register (regno)); | |
785 | break; | |
786 | ||
787 | case MACH_REGNUM: | |
788 | printf_e7000debug (".MACH %x\r", | |
789 | read_register (regno)); | |
790 | break; | |
791 | ||
792 | case MACL_REGNUM: | |
793 | printf_e7000debug (".MACL %x\r", | |
794 | read_register (regno)); | |
795 | break; | |
796 | } | |
797 | ||
798 | #endif | |
799 | expect_prompt (); | |
800 | } | |
801 | ||
802 | /* Get ready to modify the registers array. On machines which store | |
803 | individual registers, this doesn't need to do anything. On machines | |
804 | which store all the registers in one fell swoop, this makes sure | |
805 | that registers contains all the registers from the program being | |
806 | debugged. */ | |
807 | ||
808 | static void | |
809 | e7000_prepare_to_store () | |
810 | { | |
811 | /* Do nothing, since we can store individual regs */ | |
812 | } | |
813 | ||
814 | static void | |
815 | e7000_files_info () | |
816 | { | |
817 | printf ("\tAttached to %s at %d baud.\n", | |
818 | dev_name, baudrate); | |
819 | } | |
820 | ||
821 | static | |
822 | int | |
823 | stickbyte (where, what) | |
824 | char *where; | |
825 | unsigned int what; | |
826 | { | |
827 | static CONST char digs[] = "0123456789ABCDEF"; | |
828 | where[0] = digs[(what >> 4) & 0xf]; | |
829 | where[1] = digs[(what & 0xf) & 0xf]; | |
830 | return what; | |
831 | } | |
832 | ||
833 | /* Write a small ammount of memory */ | |
834 | static int | |
835 | write_small (memaddr, myaddr, len) | |
836 | CORE_ADDR memaddr; | |
837 | unsigned char *myaddr; | |
838 | int len; | |
839 | { | |
840 | int i; | |
841 | for (i = 0; i < len; i++) | |
842 | { | |
843 | if (((memaddr + i) & 3) == 0 | |
844 | && (i + 3 < len)) | |
845 | { | |
846 | /* Can be done with a long word */ | |
847 | printf_e7000debug ("m %x %x%02x%02x%02x;l\r", | |
848 | memaddr + i, | |
849 | myaddr[i], | |
850 | myaddr[i + 1], | |
851 | myaddr[i + 2], | |
852 | myaddr[i + 3]); | |
853 | i += 3; | |
854 | } | |
855 | else | |
856 | { | |
857 | printf_e7000debug ("m %x %x\r", memaddr + i, myaddr[i]); | |
858 | } | |
859 | } | |
860 | expect_prompt (); | |
861 | return len; | |
862 | } | |
863 | /* Write a large ammount of memory, this only works with the serial mode enabled. | |
864 | Command is sent as | |
865 | il ;s:s\r -> | |
866 | <- il ;s:s\r | |
867 | <- ENQ | |
868 | ACK -> | |
869 | <- LO s\r | |
870 | Srecords... | |
871 | ^Z -> | |
872 | <- ENQ | |
873 | ACK -> | |
874 | <- : | |
875 | */ | |
876 | ||
877 | static int | |
878 | write_large (memaddr, myaddr, len) | |
879 | CORE_ADDR memaddr; | |
880 | unsigned char *myaddr; | |
881 | int len; | |
882 | { | |
883 | int i; | |
edd01519 | 884 | int c; |
863099f4 SC |
885 | #define maxstride 128 |
886 | int stride; | |
887 | ||
edd01519 | 888 | printf_e7000debug ("IL ;S:FK\r"); |
863099f4 SC |
889 | expect (ENQSTRING); |
890 | putchar_e7000 (ACK); | |
edd01519 | 891 | expect ("LO FK\r"); |
863099f4 SC |
892 | for (i = 0; i < len; i += stride) |
893 | { | |
894 | char compose[maxstride * 2 + 50]; | |
895 | int address = i + memaddr; | |
896 | int j; | |
897 | int check_sum; | |
898 | int where = 0; | |
899 | int alen; | |
900 | stride = len - i; | |
901 | if (stride > maxstride) | |
902 | stride = maxstride; | |
903 | ||
904 | compose[where++] = 'S'; | |
905 | check_sum = 0; | |
906 | if (address >= 0xffffff) | |
907 | { | |
908 | alen = 4; | |
909 | } | |
910 | else if (address >= 0xffff) | |
911 | { | |
912 | alen = 3; | |
913 | } | |
914 | else | |
915 | alen = 2; | |
edd01519 SC |
916 | compose[where++] = alen - 1 + '0'; /* insert type */ |
917 | check_sum += stickbyte (compose + where, alen + stride + 1); /* Insert length */ | |
863099f4 SC |
918 | where += 2; |
919 | while (alen > 0) | |
920 | { | |
921 | alen--; | |
922 | check_sum += stickbyte (compose + where, address >> (8 * (alen))); | |
923 | where += 2; | |
924 | } | |
925 | ||
926 | for (j = 0; j < stride; j++) | |
927 | { | |
928 | check_sum += stickbyte (compose + where, myaddr[i + j]); | |
929 | where += 2; | |
930 | } | |
931 | ||
932 | stickbyte (compose + where, ~check_sum); | |
933 | ||
934 | where += 2; | |
935 | compose[where++] = '\r'; | |
edd01519 SC |
936 | compose[where++] = '\n'; |
937 | compose[where++] = 0; | |
938 | { | |
939 | char *z; | |
940 | for (z = compose; *z; z++) ; | |
863099f4 | 941 | { |
edd01519 SC |
942 | SERIAL_WRITE (e7000_desc, compose, where); |
943 | j = SERIAL_READCHAR (e7000_desc, 0); | |
944 | if (j == SERIAL_TIMEOUT) | |
945 | { | |
946 | /* This is ok - nothing there */ | |
947 | } | |
948 | else if (j == ENQ) | |
949 | { | |
950 | /* Hmm, it's trying to tell us something */ | |
951 | expect (":"); | |
952 | error ("Error writing memory"); | |
953 | } | |
954 | else | |
955 | { | |
956 | printf ("@%d}@", j); | |
957 | while ((j = SERIAL_READCHAR(e7000_desc,0)) > 0) | |
958 | { | |
959 | printf ("@{%d}@",j); | |
960 | } | |
961 | } | |
863099f4 | 962 | } |
edd01519 | 963 | } |
863099f4 SC |
964 | } |
965 | /* Send the trailer record */ | |
966 | write_e7000 ("S70500000000FA\r"); | |
967 | putchar_e7000 (CTRLZ); | |
968 | expect (ENQSTRING); | |
969 | putchar_e7000 (ACK); | |
970 | expect (":"); | |
971 | return len; | |
972 | } | |
973 | ||
974 | /* Copy LEN bytes of data from debugger memory at MYADDR | |
975 | to inferior's memory at MEMADDR. Returns length moved. | |
976 | ||
977 | Can't use the Srecord load over ethernet, so dont use | |
978 | fast method then. | |
979 | */ | |
980 | static int | |
981 | e7000_write_inferior_memory (memaddr, myaddr, len) | |
982 | CORE_ADDR memaddr; | |
983 | unsigned char *myaddr; | |
984 | int len; | |
985 | { | |
986 | if (len < 16 || using_tcp) | |
987 | { | |
988 | return write_small (memaddr, myaddr, len); | |
989 | } | |
990 | else | |
991 | { | |
992 | return write_large (memaddr, myaddr, len); | |
993 | } | |
994 | } | |
995 | ||
863099f4 SC |
996 | |
997 | /* Read LEN bytes from inferior memory at MEMADDR. Put the result | |
998 | at debugger address MYADDR. Returns length moved. | |
999 | ||
1000 | ||
1001 | Small transactions we send | |
1002 | m <addr>;l | |
1003 | and receive | |
1004 | 00000000 12345678 ? | |
1005 | ||
1006 | */ | |
1007 | ||
1008 | static int | |
1009 | e7000_read_inferior_memory (memaddr, myaddr, len) | |
1010 | CORE_ADDR memaddr; | |
1011 | unsigned char *myaddr; | |
1012 | int len; | |
1013 | { | |
1014 | int count; | |
1015 | int c; | |
1016 | int i; | |
1017 | /* Starting address of this pass. */ | |
1018 | ||
1019 | if (((memaddr - 1) + len) < memaddr) | |
1020 | { | |
1021 | errno = EIO; | |
1022 | return 0; | |
1023 | } | |
1024 | ||
1025 | printf_e7000debug ("m %x;l\r", memaddr); | |
1026 | ||
1027 | for (count = 0; count < len; count += 4) | |
1028 | { | |
1029 | /* Suck away the address */ | |
1030 | c = gch(); | |
1031 | while (c != ' ') | |
1032 | c = gch(); | |
1033 | c = gch(); | |
1034 | if (c == '*') | |
1035 | { /* Some kind of error */ | |
1036 | expect_prompt(); | |
1037 | return -1; | |
1038 | } | |
1039 | while (c != ' ') | |
1040 | c = gch(); | |
1041 | ||
1042 | /* Now read in the data */ | |
1043 | for (i = 0; i < 4; i++) | |
1044 | { | |
1045 | int b = gbyte(); | |
1046 | if (count + i < len) { | |
1047 | myaddr[count + i] = b; | |
1048 | } | |
1049 | } | |
1050 | ||
1051 | /* Skip the trailing ? and send a . to end and a cr for more */ | |
1052 | gch(); | |
1053 | gch(); | |
1054 | if (count + 4 >= len) | |
1055 | printf_e7000debug(".\r"); | |
1056 | else | |
1057 | printf_e7000debug("\r"); | |
1058 | } | |
1059 | expect_prompt(); | |
1060 | } | |
1061 | ||
1062 | ||
1063 | #if 0 | |
1064 | /* | |
1065 | For large transfers we used to send | |
1066 | ||
1067 | ||
1068 | d <addr> <endaddr>\r | |
1069 | ||
1070 | and receive | |
1071 | <ADDR> < D A T A > < ASCII CODE > | |
1072 | 000000 5F FD FD FF DF 7F DF FF 01 00 01 00 02 00 08 04 "_..............." | |
1073 | 000010 FF D7 FF 7F D7 F1 7F FF 00 05 00 00 08 00 40 00 "..............@." | |
1074 | 000020 7F FD FF F7 7F FF FF F7 00 00 00 00 00 00 00 00 "................" | |
1075 | ||
1076 | A cost in chars for each transaction of 80 + 5*n-bytes. | |
1077 | ||
1078 | ||
1079 | Large transactions could be done with the srecord load code, but | |
1080 | there is a pause for a second before dumping starts, which slows the | |
1081 | average rate down! | |
1082 | */ | |
1083 | ||
1084 | static int | |
1085 | e7000_read_inferior_memory (memaddr, myaddr, len) | |
1086 | CORE_ADDR memaddr; | |
1087 | unsigned char *myaddr; | |
1088 | int len; | |
1089 | { | |
1090 | int count; | |
1091 | int c; | |
1092 | ||
1093 | /* Starting address of this pass. */ | |
1094 | ||
1095 | if (((memaddr - 1) + len) < memaddr) | |
1096 | { | |
1097 | errno = EIO; | |
1098 | return 0; | |
1099 | } | |
1100 | ||
1101 | printf_e7000debug ("d %x %x\r", memaddr, memaddr + len - 1); | |
1102 | ||
1103 | count = 0; | |
1104 | c = gch (); | |
1105 | ||
1106 | /* First skip the command */ | |
1107 | while (c == '\n') | |
1108 | c = gch (); | |
1109 | ||
1110 | while (c == ' ') | |
1111 | c = gch (); | |
1112 | if (c == '*') | |
1113 | { | |
1114 | expect ("\r"); | |
1115 | return -1; | |
1116 | } | |
1117 | ||
1118 | /* Skip the title line */ | |
1119 | while (c != '\n') | |
1120 | c = gch (); | |
1121 | c = gch (); | |
1122 | while (count < len) | |
1123 | { | |
1124 | /* Skip the address */ | |
1125 | while (c <= ' ') | |
1126 | c = gch (); | |
1127 | ||
1128 | get_hex (&c); | |
1129 | ||
1130 | /* read in the bytes on the line */ | |
1131 | while (c != '"' && count < len) | |
1132 | { | |
1133 | if (c == ' ') | |
1134 | c = gch (); | |
1135 | else | |
1136 | { | |
1137 | myaddr[count++] = get_hex (&c); | |
1138 | } | |
1139 | } | |
1140 | ||
1141 | while (c != '\n') | |
1142 | c = gch (); | |
1143 | } | |
1144 | ||
1145 | while (c != ':') | |
1146 | c = gch (); | |
1147 | ||
1148 | return len; | |
1149 | } | |
1150 | ||
1151 | static int | |
1152 | fast_but_for_the_pause_e7000_read_inferior_memory (memaddr, myaddr, len) | |
1153 | CORE_ADDR memaddr; | |
1154 | char *myaddr; | |
1155 | int len; | |
1156 | { | |
1157 | int loop; | |
1158 | int c; | |
1159 | ||
1160 | if (((memaddr - 1) + len) < memaddr) | |
1161 | { | |
1162 | errno = EIO; | |
1163 | return 0; | |
1164 | } | |
1165 | ||
1166 | printf_e7000debug ("is %x@%x:s\r", memaddr, len); | |
1167 | gch (); | |
1168 | c = gch (); | |
1169 | if (c != ENQ) | |
1170 | { | |
1171 | /* Got an error */ | |
1172 | error ("Memory read error"); | |
1173 | } | |
1174 | putchar_e7000 (ACK); | |
1175 | expect ("SV s"); | |
1176 | loop = 1; | |
1177 | while (loop) | |
1178 | { | |
1179 | int type; | |
1180 | int length; | |
1181 | int addr; | |
1182 | int i; | |
1183 | c = gch (); | |
1184 | switch (c) | |
1185 | { | |
1186 | case ENQ: /* ENQ, at the end */ | |
1187 | loop = 0; | |
1188 | break; | |
1189 | case 'S': | |
1190 | /* Start of an Srecord */ | |
1191 | type = gch (); | |
1192 | length = gbyte (); | |
1193 | switch (type) | |
1194 | { | |
1195 | case '7': /* Termination record, ignore */ | |
1196 | case '0': | |
1197 | case '8': | |
1198 | case '9': | |
1199 | /* Header record - ignore it */ | |
1200 | while (length--) | |
1201 | { | |
1202 | gbyte (); | |
1203 | } | |
1204 | break; | |
1205 | case '1': | |
1206 | case '2': | |
1207 | case '3': | |
1208 | { | |
1209 | int alen; | |
1210 | alen = type - '0' + 1; | |
1211 | addr = 0; | |
1212 | while (alen--) | |
1213 | { | |
1214 | addr = (addr << 8) + gbyte (); | |
1215 | length--; | |
1216 | } | |
1217 | ||
1218 | for (i = 0; i < length - 1; i++) | |
1219 | { | |
1220 | myaddr[i + addr - memaddr] = gbyte (); | |
1221 | } | |
1222 | gbyte (); /* Ignore checksum */ | |
1223 | } | |
1224 | } | |
1225 | } | |
1226 | } | |
1227 | putchar_e7000 (ACK); | |
1228 | expect ("TOP ADDRESS ="); | |
1229 | expect ("END ADDRESS ="); | |
1230 | expect (":"); | |
1231 | ||
1232 | return len; | |
1233 | } | |
1234 | ||
1235 | #endif | |
1236 | ||
1237 | static int | |
1238 | e7000_xfer_inferior_memory (memaddr, myaddr, len, write, target) | |
1239 | CORE_ADDR memaddr; | |
1240 | unsigned char *myaddr; | |
1241 | int len; | |
1242 | int write; | |
1243 | struct target_ops *target; /* ignored */ | |
1244 | { | |
1245 | if (write) | |
1246 | { | |
1247 | return e7000_write_inferior_memory( memaddr, myaddr, len); | |
1248 | } | |
1249 | else | |
1250 | { | |
1251 | return e7000_read_inferior_memory( memaddr, myaddr, len); | |
1252 | } | |
1253 | } | |
1254 | ||
1255 | static void | |
1256 | e7000_kill (args, from_tty) | |
1257 | char *args; | |
1258 | int from_tty; | |
1259 | { | |
1260 | ||
1261 | } | |
1262 | ||
1263 | /* Clean up when a program exits. | |
1264 | ||
1265 | The program actually lives on in the remote processor's RAM, and may be | |
1266 | run again without a download. Don't leave it full of breakpoint | |
1267 | instructions. */ | |
1268 | ||
1269 | static void | |
1270 | e7000_mourn_inferior () | |
1271 | { | |
1272 | remove_breakpoints (); | |
1273 | unpush_target (&e7000_ops); | |
1274 | generic_mourn_inferior (); /* Do all the proper things now */ | |
1275 | } | |
1276 | ||
1277 | #define MAX_E7000DEBUG_BREAKPOINTS 200 | |
1278 | ||
1279 | extern int memory_breakpoint_size; | |
1280 | static CORE_ADDR breakaddr[MAX_E7000DEBUG_BREAKPOINTS] = | |
1281 | {0}; | |
1282 | ||
1283 | static int | |
1284 | e7000_insert_breakpoint (addr, shadow) | |
1285 | CORE_ADDR addr; | |
1286 | unsigned char *shadow; | |
1287 | { | |
1288 | int i; | |
edd01519 | 1289 | static char nop[2] = NOP; |
863099f4 SC |
1290 | |
1291 | for (i = 0; i <= MAX_E7000DEBUG_BREAKPOINTS; i++) | |
1292 | if (breakaddr[i] == 0) | |
1293 | { | |
1294 | breakaddr[i] = addr; | |
1295 | /* Save old contents, and insert a nop in the space */ | |
1296 | e7000_read_inferior_memory (addr, shadow, 2); | |
1297 | e7000_write_inferior_memory (addr, nop, 2); | |
1298 | printf_e7000debug ("B %x\r", addr); | |
1299 | expect_prompt (); | |
1300 | return 0; | |
1301 | } | |
1302 | ||
1303 | error("Too many breakpoints ( > %d) for the E7000\n", MAX_E7000DEBUG_BREAKPOINTS); | |
1304 | return 1; | |
1305 | } | |
1306 | ||
1307 | static int | |
1308 | e7000_remove_breakpoint (addr, shadow) | |
1309 | CORE_ADDR addr; | |
1310 | unsigned char *shadow; | |
1311 | { | |
1312 | int i; | |
1313 | ||
1314 | for (i = 0; i < MAX_E7000DEBUG_BREAKPOINTS; i++) | |
1315 | if (breakaddr[i] == addr) | |
1316 | { | |
1317 | breakaddr[i] = 0; | |
1318 | printf_e7000debug ("B - %x\r", addr); | |
1319 | expect_prompt (); | |
1320 | /* Replace the insn under the break */ | |
1321 | e7000_write_inferior_memory (addr, shadow, 2); | |
1322 | return 0; | |
1323 | } | |
1324 | ||
1325 | fprintf (stderr, "Can't find breakpoint associated with 0x%x\n", addr); | |
1326 | return 1; | |
1327 | } | |
1328 | ||
1329 | ||
1330 | /* Put a command string, in args, out to STDBUG. Output from STDBUG is placed | |
1331 | on the users terminal until the prompt is seen. */ | |
1332 | ||
1333 | static void | |
1334 | e7000_command (args, fromtty) | |
1335 | char *args; | |
1336 | int fromtty; | |
1337 | { | |
1338 | ||
1339 | if (!e7000_desc) | |
1340 | error ("e7000 target not open."); | |
1341 | if (!args) | |
1342 | { | |
1343 | printf_e7000debug ("\r"); | |
1344 | } | |
1345 | else | |
1346 | { | |
1347 | printf_e7000debug ("%s\r", args); | |
1348 | } | |
edd01519 SC |
1349 | echo++; |
1350 | ctrl_c = 2; | |
863099f4 | 1351 | expect_full_prompt (); |
edd01519 SC |
1352 | echo--; |
1353 | ctrl_c = 0; | |
863099f4 SC |
1354 | printf_unfiltered ("\n"); |
1355 | } | |
1356 | ||
1357 | static void | |
1358 | e7000_load (args, fromtty) | |
1359 | char *args; | |
1360 | int fromtty; | |
1361 | { | |
edd01519 | 1362 | gr_load_image (args, fromtty); |
863099f4 SC |
1363 | } |
1364 | ||
1365 | static void | |
1366 | e7000_drain (args, fromtty) | |
1367 | char *args; | |
1368 | int fromtty; | |
1369 | ||
1370 | { | |
1371 | int c; | |
edd01519 SC |
1372 | printf_e7000debug("end\r"); |
1373 | putchar_e7000 (CTRLC); | |
1374 | while ((c = SERIAL_READCHAR (e7000_desc, 1) != SERIAL_TIMEOUT)) | |
863099f4 | 1375 | { |
edd01519 SC |
1376 | if(quit_flag) |
1377 | { | |
1378 | putchar_e7000(CTRLC); | |
1379 | quit_flag = 0; | |
1380 | } | |
863099f4 SC |
1381 | if (c > ' ' && c < 127) |
1382 | printf ("%c", c & 0xff); | |
1383 | else | |
1384 | printf ("<%x>", c & 0xff); | |
1385 | } | |
1386 | } | |
1387 | ||
1388 | e7000_noecho () | |
1389 | { | |
1390 | echo = !echo; | |
edd01519 SC |
1391 | if (echo) |
1392 | printf_filtered ("Snoop enabled\n"); | |
1393 | else | |
1394 | printf_filtered ("Snoop disabled\n"); | |
1395 | ||
1396 | } | |
1397 | ||
1398 | #define NITEMS 3 | |
1399 | static int | |
1400 | why_stop () | |
1401 | { | |
1402 | static char *strings[NITEMS] = | |
1403 | { | |
1404 | "STEP NORMAL", | |
1405 | "BREAK POINT", | |
1406 | "BREAK KEY", | |
1407 | }; | |
1408 | char *p[NITEMS]; | |
1409 | int c; | |
1410 | p[0] = strings[0]; | |
1411 | p[1] = strings[1]; | |
1412 | p[2] = strings[2]; | |
1413 | ||
1414 | c = gch(); | |
1415 | while (1) | |
1416 | { | |
1417 | int i; | |
1418 | for (i = 0; i < NITEMS; i++) | |
1419 | { | |
1420 | if (c == *(p[i])) | |
1421 | { | |
1422 | p[i]++; | |
1423 | if (*(p[i]) == 0) | |
1424 | { | |
1425 | /* found one of the choices */ | |
1426 | return i; | |
1427 | } | |
1428 | } | |
1429 | else { | |
1430 | p[i] = strings[i]; | |
1431 | } | |
1432 | } | |
1433 | ||
1434 | c = gch(); | |
1435 | } | |
1436 | } | |
1437 | /* Suck characters, if a string match, then return the strings index | |
1438 | otherwise echo them */ | |
1439 | int | |
1440 | expect_n ( strings) | |
1441 | char **strings; | |
1442 | { | |
1443 | char *(ptr[10]); | |
1444 | int n; | |
1445 | int c; | |
1446 | char saveaway[100]; | |
1447 | char *buffer = saveaway; | |
1448 | /* Count number of expect strings */ | |
1449 | ||
1450 | for (n =0; strings[n]; n++) | |
1451 | { | |
1452 | ptr[n] = strings[n]; | |
1453 | } | |
1454 | ||
1455 | while (1) { | |
1456 | int i; | |
1457 | int gotone = 0; | |
1458 | ||
1459 | c = SERIAL_READCHAR (e7000_desc, 1); | |
1460 | if (c == SERIAL_TIMEOUT) { | |
1461 | printf_unfiltered ("[waiting for e7000...]\n"); | |
1462 | } | |
1463 | #ifdef __GO32__ | |
1464 | if (kbhit()) | |
1465 | { | |
1466 | int k = getkey(); | |
1467 | if (k == 1) | |
1468 | quit_flag = 1; | |
1469 | } | |
1470 | #endif | |
1471 | ||
1472 | if (quit_flag) | |
1473 | { | |
1474 | putchar_e7000 (CTRLC); /* interrupt the running program */ | |
1475 | quit_flag = 0; | |
1476 | } | |
1477 | ||
1478 | for (i = 0; i < n; i++) | |
1479 | { | |
1480 | if (c == ptr[i][0]) | |
1481 | { | |
1482 | ptr[i]++; | |
1483 | if (ptr[i][0] == 0) | |
1484 | { | |
1485 | /* Gone all the way */ | |
1486 | return i; | |
1487 | } | |
1488 | gotone = 1; | |
1489 | } | |
1490 | else | |
1491 | { | |
1492 | ptr[i] = strings[i]; | |
1493 | } | |
1494 | } | |
1495 | ||
1496 | ||
1497 | if (gotone) | |
1498 | { | |
1499 | /* Save it up incase we find that there was no match */ | |
1500 | *buffer ++ = c; | |
1501 | } | |
1502 | else | |
1503 | { | |
1504 | if (buffer != saveaway) | |
1505 | { | |
1506 | *buffer++ = 0; | |
1507 | printf(buffer); | |
1508 | buffer = saveaway; | |
1509 | } | |
1510 | if (c != SERIAL_TIMEOUT) { | |
1511 | putchar (c); | |
1512 | fflush(stdout); | |
1513 | } | |
1514 | } | |
1515 | } | |
863099f4 SC |
1516 | } |
1517 | ||
edd01519 SC |
1518 | /* We subtract two from the pc here rather than use DECR_PC_AFTER_BREAK |
1519 | since the e7000 doesn't always add two to the pc, and the simulators never do. */ | |
1520 | ||
1521 | static void | |
1522 | sub2_from_pc() | |
1523 | { | |
1524 | char buf[4]; | |
1525 | store_signed_integer (buf, | |
1526 | REGISTER_RAW_SIZE(PC_REGNUM), | |
1527 | read_register (PC_REGNUM) -2); | |
1528 | supply_register (PC_REGNUM, buf); | |
1529 | printf_e7000debug (".PC %x\r", read_register (PC_REGNUM)); | |
1530 | } | |
1531 | #define WAS_SLEEP 0 | |
1532 | #define WAS_INT 1 | |
1533 | #define WAS_RUNNING 2 | |
1534 | #define WAS_OTHER 3 | |
1535 | static char *estrings[] = { "** SLEEP", "BREAK !", "** PC", "PC", 0}; | |
1536 | ||
863099f4 SC |
1537 | /* Wait until the remote machine stops, then return, |
1538 | storing status in STATUS just as `wait' would. */ | |
1539 | ||
1540 | static int | |
1541 | e7000_wait (pid, status) | |
1542 | int pid; | |
1543 | WAITTYPE *status; | |
1544 | { | |
1545 | int c; | |
edd01519 | 1546 | int reset_pc; |
863099f4 | 1547 | int regno; |
edd01519 SC |
1548 | int running_count = 0; |
1549 | int had_sleep = 0; | |
863099f4 | 1550 | int loop = 1; |
edd01519 | 1551 | char *reg; |
863099f4 SC |
1552 | int time = 0; |
1553 | WSETSTOP ((*status), 0); | |
1554 | /* Then echo chars until PC= string seen */ | |
1555 | gch (); /* Drop cr */ | |
1556 | gch (); /* and space */ | |
1557 | while (loop) | |
1558 | { | |
edd01519 SC |
1559 | switch (expect_n(estrings)) |
1560 | { | |
1561 | case WAS_OTHER: | |
1562 | /* how did this happen ? */ | |
1563 | loop =0; | |
1564 | break; | |
1565 | case WAS_SLEEP: | |
1566 | had_sleep = 1; | |
1567 | putchar_e7000 (CTRLC); | |
1568 | loop = 0; | |
1569 | break; | |
1570 | case WAS_INT: | |
1571 | loop = 0; | |
1572 | break; | |
1573 | case WAS_RUNNING: | |
1574 | running_count++; | |
1575 | if (running_count == 20) | |
863099f4 | 1576 | { |
edd01519 SC |
1577 | printf_unfiltered ("[running...]\n"); |
1578 | running_count = 0; | |
863099f4 | 1579 | } |
edd01519 | 1580 | break; |
863099f4 SC |
1581 | } |
1582 | } | |
edd01519 SC |
1583 | /* Skip till the PC=*/ |
1584 | expect("="); | |
863099f4 SC |
1585 | fetch_regs_from_dump (gch, want_nopc); |
1586 | ||
1587 | /* And supply the extra ones the simulator uses */ | |
1588 | for (regno = NUM_REALREGS; regno < NUM_REGS; regno++) | |
1589 | { | |
1590 | int buf = 0; | |
1591 | supply_register (regno, (char *) &buf); | |
1592 | } | |
1593 | ||
edd01519 | 1594 | reset_pc = why_stop (); |
863099f4 | 1595 | expect_full_prompt (); |
863099f4 | 1596 | |
edd01519 SC |
1597 | switch (reset_pc) |
1598 | { | |
1599 | case 1: /* Breakpoint */ | |
1600 | ||
1601 | WSETSTOP ((*status), SIGTRAP); | |
1602 | break; | |
1603 | case 0: | |
1604 | /* Single step */ | |
1605 | WSETSTOP ((*status), SIGTRAP); | |
1606 | break; | |
1607 | case 2: | |
1608 | /* Interrupt */ | |
1609 | if (had_sleep) | |
1610 | { | |
1611 | sub2_from_pc(); | |
1612 | WSETSTOP ((*status), SIGTRAP); | |
1613 | } | |
1614 | else | |
1615 | { | |
1616 | WSETSTOP ((*status), SIGINT); | |
1617 | } | |
1618 | break; | |
1619 | } | |
863099f4 SC |
1620 | return 0; |
1621 | } | |
1622 | ||
1623 | /* Define the target subroutine names */ | |
1624 | ||
1625 | struct target_ops e7000_ops = | |
1626 | { | |
1627 | "e7000", | |
1628 | "Remote Hitachi e7000 target", | |
1629 | "Use a remote Hitachi e7000 ICE connected by a serial line,\n\ | |
1630 | or a network connection.\n\ | |
1631 | Arguments are the name of the device for the serial line,\n\ | |
1632 | the speed to connect at in bits per second.\n\ | |
1633 | eg\n\ | |
1634 | target e7000 /dev/ttya 9600\n\ | |
1635 | target e7000 foobar", | |
1636 | e7000_open, | |
1637 | e7000_close, | |
1638 | 0, | |
1639 | e7000_detach, | |
1640 | e7000_resume, | |
1641 | e7000_wait, | |
1642 | e7000_fetch_register, | |
1643 | e7000_store_register, | |
1644 | e7000_prepare_to_store, | |
1645 | e7000_xfer_inferior_memory, | |
1646 | e7000_files_info, | |
edd01519 | 1647 | 0,0,/* e7000_insert_breakpoint, |
863099f4 SC |
1648 | e7000_remove_breakpoint, /* Breakpoints */ |
1649 | 0, | |
1650 | 0, | |
1651 | 0, | |
1652 | 0, | |
1653 | 0, /* Terminal handling */ | |
1654 | e7000_kill, | |
1655 | e7000_load, /* load */ | |
1656 | 0, /* lookup_symbol */ | |
1657 | e7000_create_inferior, | |
1658 | e7000_mourn_inferior, | |
1659 | 0, /* can_run */ | |
1660 | 0, /* notice_signals */ | |
1661 | process_stratum, | |
1662 | 0, /* next */ | |
1663 | 1, | |
1664 | 1, | |
1665 | 1, | |
1666 | 1, | |
1667 | 1, /* all mem, mem, stack, regs, exec */ | |
1668 | 0, | |
1669 | 0, /* Section pointers */ | |
1670 | OPS_MAGIC, /* Always the last thing */ | |
1671 | }; | |
1672 | ||
1673 | void | |
1674 | _initialize_remote_e7000 () | |
1675 | { | |
1676 | add_target (&e7000_ops); | |
1677 | add_com ("e7000 <command>", class_obscure, e7000_command, | |
1678 | "Send a command to the e7000 monitor."); | |
1679 | ||
1680 | add_com ("ftplogin <machine> <name> <passwd> <dir>", class_obscure, e7000_login, | |
1681 | "Login to machine and change to directory."); | |
1682 | ||
1683 | add_com ("ftpload <file>", class_obscure, e7000_ftp, | |
1684 | "Fetch and load a file from previously described place."); | |
1685 | ||
1686 | add_com ("drain", class_obscure, e7000_drain, | |
1687 | "Drain pending e7000 text buffers."); | |
edd01519 | 1688 | add_com ("snoop", class_obscure, e7000_noecho, "Toggle monitor echo."); |
863099f4 | 1689 | } |