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