#include "remote-utils.h"
#include "symfile.h"
#include <time.h>
+#include <ctype.h>
#if 1
#define HARD_BREAKPOINTS /* Now handled by set option. */
static void expect_prompt PARAMS ((void));
+static int e7000_parse_device PARAMS ((char *args, char *dev_name,
+ int baudrate));
/* Variables. */
static serial_t e7000_desc;
error ("Use \"target e7000 ...\" first.");
if (remote_debug)
- printf("Sending %s\n", buf);
+ printf_unfiltered ("Sending %s\n", buf);
if (SERIAL_WRITE (e7000_desc, buf, strlen (buf)))
- fprintf (stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno));
+ fprintf_unfiltered (gdb_stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno));
/* And expect to see it echoed, unless using the pc interface */
#if 0
}
/* Read a character from the remote system, doing all the fancy timeout
- stuff. */
+ stuff. Handles serial errors and EOF. If TIMEOUT == 0, and no chars,
+ returns -1, else returns next char. Discards chars > 127. */
static int
readchar (timeout)
echo = 0;
error ("Timeout reading from remote system.");
}
+ else if (c < 0)
+ error ("Serial communication error");
+
if (remote_debug)
{
- putchar (c);
- fflush (stdout);
+ putchar_unfiltered (c);
+ gdb_flush (gdb_stdout);
}
return normal (c);
while (1)
{
c = readchar (timeout);
+#if 0
notice_quit ();
if (quit_flag == 1)
{
quit ();
}
}
+#endif
- if (c == SERIAL_ERROR)
- {
- error ("Serial communication error");
- }
- if (echo || remote_debug)
+ if (echo)
{
if (c == '\r' || c == '\n')
{
if (!nl)
- putchar ('\n');
+ putchar_unfiltered ('\n');
nl = 1;
}
else
{
nl = 0;
- putchar (c);
+ putchar_unfiltered (c);
}
- fflush (stdout);
+ gdb_flush (gdb_stdout);
}
if (normal (c) == normal (*p++))
{
dir = next (&args);
if (from_tty)
{
- printf ("Set info to %s %s %s %s\n", machine, user, passwd, dir);
+ printf_unfiltered ("Set info to %s %s %s %s\n", machine, user, passwd, dir);
}
}
else
}
static int
-e7000_parse_device(args,dev_name,serial_flag,baudrate)
+e7000_parse_device (args, dev_name, baudrate)
char *args;
char *dev_name;
- int serial_flag;
int baudrate;
{
char junk[128];
{
/* FIXME! temp hack to allow use with port master -
target tcp_remote <device> */
- if (args && strncmp (args, "tcp_remote", 10) == 0)
+ if (args && strncmp (args, "tcp", 10) == 0)
{
char com_type[128];
n = sscanf (args, " %s %s %d %s", com_type, dev_name, &baudrate, junk);
or \t\ttarget e7000 pc\n");
}
-#if !defined(__GO32__) && !defined(__WIN32__)
+#if !defined(__GO32__) && !defined(_WIN32)
/* FIXME! test for ':' is ambiguous */
if (n == 1 && strchr (dev_name, ':') == 0)
{
return n;
}
-static void
-e7000_open (args, from_tty)
- char *args;
- int from_tty;
+/* Stub for catch_errors. */
+
+static int
+e7000_start_remote (dummy)
+ char *dummy;
{
- int n;
int loop;
int sync;
- int serial_flag;
-
- target_preopen (from_tty);
-
- n = e7000_parse_device(args,dev_name,serial_flag,baudrate);
-
- push_target (&e7000_ops);
-
- e7000_desc = SERIAL_OPEN (dev_name);
-
- if (!e7000_desc)
- perror_with_name (dev_name);
+ int try;
+ int quit_trying;
- SERIAL_SETBAUDRATE (e7000_desc, baudrate);
- SERIAL_RAW (e7000_desc);
+ immediate_quit = 1; /* Allow user to interrupt it */
/* Hello? Are you there? */
sync = 0;
loop = 0;
+ try = 0;
+ quit_trying = 20;
putchar_e7000 (CTRLC);
- while (!sync)
+ while (!sync && ++try <= quit_trying)
{
int c;
- if (from_tty)
- printf_unfiltered ("[waiting for e7000...]\n");
+ printf_unfiltered ("[waiting for e7000...]\n");
write_e7000 ("\r");
- c = SERIAL_READCHAR (e7000_desc, 1);
- while (c != SERIAL_TIMEOUT)
+ c = readchar (1);
+
+ /* FIXME! this didn't seem right-> while (c != SERIAL_TIMEOUT)
+ * we get stuck in this loop ...
+ * We may never timeout, and never sync up :-(
+ */
+ while (!sync && c != -1)
{
/* Dont echo cr's */
- if (from_tty && c != '\r')
+ if (c != '\r')
{
- putchar (c);
- fflush (stdout);
+ putchar_unfiltered (c);
+ gdb_flush (gdb_stdout);
}
+ /* Shouldn't we either break here, or check for sync in inner loop? */
if (c == ':')
sync = 1;
QUIT ;
-
if (quit_flag)
{
putchar_e7000 (CTRLC);
- quit_flag = 0;
+ /* Was-> quit_flag = 0; */
+ c = -1;
+ quit_trying = try+1; /* we don't want to try anymore */
+ }
+ else
+ {
+ c = readchar (1);
}
- c = SERIAL_READCHAR (e7000_desc, 1);
}
}
- puts_e7000debug ("\r");
+ if (!sync)
+ {
+ fprintf_unfiltered (gdb_stderr, "Giving up after %d tries...\n",try);
+ error ("Unable to syncronize with target.\n");
+ }
+
+ puts_e7000debug ("\r");
+ expect_prompt ();
+ puts_e7000debug ("b -\r"); /* Clear breakpoints */
expect_prompt ();
- puts_e7000debug ("b -\r");
+ immediate_quit = 0;
- expect_prompt ();
+/* This is really the job of start_remote however, that makes an assumption
+ that the target is about to print out a status message of some sort. That
+ doesn't happen here. */
- if (from_tty)
- printf_filtered ("Remote target %s connected to %s\n", target_shortname,
- dev_name);
+ flush_cached_frames ();
+ registers_changed ();
+ stop_pc = read_pc ();
+ set_current_frame (create_new_frame (read_fp (), stop_pc));
+ select_frame (get_current_frame (), 0);
+ print_stack_frame (selected_frame, -1, 1);
+
+ return 1;
+}
+
+static void
+e7000_open (args, from_tty)
+ char *args;
+ int from_tty;
+{
+ int n;
+
+ target_preopen (from_tty);
+
+ n = e7000_parse_device (args, dev_name, baudrate);
+
+ push_target (&e7000_ops);
+
+ e7000_desc = SERIAL_OPEN (dev_name);
+
+ if (!e7000_desc)
+ perror_with_name (dev_name);
+
+ SERIAL_SETBAUDRATE (e7000_desc, baudrate);
+ SERIAL_RAW (e7000_desc);
#ifdef GDB_TARGET_IS_H8300
h8300hmode = 1;
#endif
+
+ /* Start the remote connection; if error (0), discard this target.
+ In particular, if the user quits, be sure to discard it
+ (we'd be in an inconsistent state otherwise). */
+ if (!catch_errors (e7000_start_remote, (char *)0,
+ "Couldn't establish connection to remote target\n", RETURN_MASK_ALL))
+ if (from_tty)
+ printf_filtered ("Remote target %s connected to %s\n", target_shortname,
+ dev_name);
}
/* Close out all files and local state before this target loses control. */
{
pop_target (); /* calls e7000_close to do the real work */
if (from_tty)
- printf ("Ending remote %s debugging\n", target_shortname);
+ printf_unfiltered ("Ending remote %s debugging\n", target_shortname);
}
/* Tell the remote machine to resume. */
#ifdef GDB_TARGET_IS_H8300
-char *want = "PC=%p CCR=%c\n\
+char *want_h8300h = "PC=%p CCR=%c\n\
ER0 - ER3 %0 %1 %2 %3\n\
ER4 - ER7 %4 %5 %6 %7\n";
-char *want_nopc = "%p CCR=%c\n\
+char *want_nopc_h8300h = "%p CCR=%c\n\
+ ER0 - ER3 %0 %1 %2 %3\n\
+ ER4 - ER7 %4 %5 %6 %7";
+
+char *want_h8300s = "PC=%p CCR=%c\n\
+ MACH=\n\
+ ER0 - ER3 %0 %1 %2 %3\n\
+ ER4 - ER7 %4 %5 %6 %7\n";
+
+char *want_nopc_h8300s = "%p CCR=%c EXR=%9\n\
ER0 - ER3 %0 %1 %2 %3\n\
ER4 - ER7 %4 %5 %6 %7";
static int
gch ()
{
- int c = readchar (timeout);
-
- if (remote_debug)
- {
- if (c >= ' ')
- printf ("%c", c);
- else if (c == '\n')
- printf ("\n");
- }
- return c;
+ return readchar (timeout);
}
static unsigned int
e7000_fetch_registers ()
{
int regno;
+ char *wanted;
puts_e7000debug ("R\r");
#ifdef GDB_TARGET_IS_SH
- if ((sh_processor_type != NULL) && (*(sh_processor_type+2) == '3'))
- fetch_regs_from_dump (gch, want_sh3);
- else
- fetch_regs_from_dump (gch, want);
+ wanted = want;
+ if (target_architecture->arch == bfd_arch_sh)
+ switch (target_architecture->mach)
+ {
+ case bfd_mach_sh3:
+ case bfd_mach_sh3e:
+ /* start-sanitize-sh4 */
+ case bfd_mach_sh4:
+ /* end-sanitize-sh4 */
+ wanted = want_sh3;
+ }
#else
- fetch_regs_from_dump (gch, want);
+ if (h8300smode)
+ wanted = want_h8300s;
+ else
+ wanted = want_h8300h);
#endif
-
+ fetch_regs_from_dump (gch, wanted);
/* And supply the extra ones the simulator uses */
for (regno = NUM_REALREGS; regno < NUM_REGS; regno++)
static void
e7000_files_info ()
{
- printf ("\tAttached to %s at %d baud.\n", dev_name, baudrate);
+ printf_unfiltered ("\tAttached to %s at %d baud.\n", dev_name, baudrate);
}
static int
compose[where++] = 0;
SERIAL_WRITE (e7000_desc, compose, where);
- j = SERIAL_READCHAR (e7000_desc, 0);
- if (j == SERIAL_TIMEOUT)
+ j = readchar (0);
+ if (j == -1)
{
/* This is ok - nothing there */
}
}
else
{
- printf ("@%d}@", j);
- while ((j = SERIAL_READCHAR(e7000_desc,0)) > 0)
+ printf_unfiltered ("@%d}@", j);
+ while ((j = readchar (0)) > 0)
{
- printf ("@{%d}@",j);
+ printf_unfiltered ("@{%d}@",j);
}
}
}
c = gch ();
if (c == '*')
{ /* Some kind of error */
- expect_prompt();
+ puts_e7000debug (".\r"); /* Some errors leave us in memory input mode */
+ expect_full_prompt();
return -1;
}
while (c != ' ')
asection *section;
bfd *pbfd;
bfd_vma entry;
- int i;
#define WRITESIZE 0x1000
char buf[2 + 4 + 4 + WRITESIZE]; /* `DT' + <addr> + <len> + <data> */
char *filename;
{
int i;
char buf[200];
+#if 0
static char nop[2] = NOP;
+#endif
for (i = 0; i <= MAX_E7000DEBUG_BREAKPOINTS; i++)
if (breakaddr[i] == 0)
puts_e7000debug("end\r");
putchar_e7000 (CTRLC);
- while ((c = SERIAL_READCHAR (e7000_desc, 1) != SERIAL_TIMEOUT))
+ while ((c = readchar (1) != -1))
{
if (quit_flag)
{
quit_flag = 0;
}
if (c > ' ' && c < 127)
- printf ("%c", c & 0xff);
+ printf_unfiltered ("%c", c & 0xff);
else
- printf ("<%x>", c & 0xff);
+ printf_unfiltered ("<%x>", c & 0xff);
}
}
int i;
int gotone = 0;
- c = SERIAL_READCHAR (e7000_desc, 1);
- if (c == SERIAL_TIMEOUT)
+ c = readchar (1);
+ if (c == -1)
{
printf_unfiltered ("[waiting for e7000...]\n");
}
if (buffer != saveaway)
{
*buffer++ = 0;
- printf ("%s", buffer);
+ printf_unfiltered ("%s", buffer);
buffer = saveaway;
}
- if (c != SERIAL_TIMEOUT)
+ if (c != -1)
{
- putchar (c);
- fflush (stdout);
+ putchar_unfiltered (c);
+ gdb_flush (gdb_stdout);
}
}
}
int running_count = 0;
int had_sleep = 0;
int loop = 1;
+ char *wanted_nopc;
/* Then echo chars until PC= string seen */
gch (); /* Drop cr */
expect ("=");
#ifdef GDB_TARGET_IS_SH
- if ((sh_processor_type != NULL) && (*(sh_processor_type+2) == '3'))
- fetch_regs_from_dump (gch, want_sh3_nopc);
- else
- fetch_regs_from_dump (gch, want_nopc);
+ wanted_nopc = want_nopc;
+ if (target_architecture->arch == bfd_arch_sh)
+ switch (target_architecture->mach)
+ {
+ case bfd_mach_sh3:
+ case bfd_mach_sh3e:
+ /* start-sanitize-sh4 */
+ case bfd_mach_sh4:
+ /* end-sanitize-sh4 */
+ wanted_nopc = want_sh3_nopc;
+ }
#else
- fetch_regs_from_dump (gch, want_nopc);
+ if (h8300smode)
+ wanted_nopc = want_nopc_h8300s;
+ else
+ wanted_nopc = want_nopc_h8300h);
#endif
+ fetch_regs_from_dump (gch, wanted_nopc);
/* And supply the extra ones the simulator uses */
for (regno = NUM_REALREGS; regno < NUM_REGS; regno++)
{
add_target (&e7000_ops);
- add_com ("e7000 <command>", class_obscure, e7000_command,
+ add_com ("e7000", class_obscure, e7000_command,
"Send a command to the e7000 monitor.");
- add_com ("ftplogin <machine> <name> <passwd> <dir>", class_obscure, e7000_login_command,
+ add_com ("ftplogin", class_obscure, e7000_login_command,
"Login to machine and change to directory.");
- add_com ("ftpload <file>", class_obscure, e7000_ftp_command,
+ add_com ("ftpload", class_obscure, e7000_ftp_command,
"Fetch and load a file from previously described place.");
add_com ("drain", class_obscure, e7000_drain_command,