#include "command.h"
#include <signal.h>
#include "gdb_string.h"
+#include "gdbcmd.h"
#include <sys/types.h>
#include "serial.h"
#include "remote-utils.h"
#include "symfile.h"
#include <time.h>
-#if 0
-#define HARD_BREAKPOINTS
-#define BC_BREAKPOINTS 0
+//#define DEBUGIFY
+#include "debugify.h"
+
+#if 1
+#define HARD_BREAKPOINTS /* Now handled by set option. */
+#define BC_BREAKPOINTS use_hard_breakpoints
#endif
#define CTRLC 0x03
static serial_t e7000_desc;
+/* Allow user to chose between using hardware breakpoints or memory. */
+static int use_hard_breakpoints = 0; /* use sw breakpoints by default */
+
/* Nonzero if using the tcp serial driver. */
-static int using_tcp;
+static int using_tcp; /* direct tcp connection to target */
+static int using_tcp_remote; /* indirect connection to target
+ via tcp to controller */
/* Nonzero if using the pc isa card. */
static int ctrl_c;
-static int timeout = 5;
+static int timeout = 20;
/* Send data to e7000debug. */
if (remote_debug)
printf("Sending %s\n", buf);
+ DBG(("Sending %s; waiting for echo...\n", buf));
if (SERIAL_WRITE (e7000_desc, buf, strlen (buf)))
fprintf (stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno));
if (!using_pc)
#endif
expect (buf);
+ DBG(("Got echo!n"));
}
static void
char buf[200];
int oldtimeout = timeout;
- timeout = 10;
+ timeout = remote_timeout;
sprintf (buf, "ftp %s\r", machine);
puts_e7000debug (buf);
timeout = oldtimeout;
}
-static void
-e7000_open (args, from_tty)
- char *args;
- int from_tty;
+static int
+e7000_parse_device(args,dev_name,serial_flag,baudrate)
+ char *args;
+ char *dev_name;
+ int serial_flag;
+ int baudrate;
{
- int n;
- int loop;
- char junk[100];
- int sync;
- target_preopen (from_tty);
-
- n = 0;
+ char junk[128];
+ int n = 0;
if (args && strcasecmp (args, "pc") == 0)
{
strcpy (dev_name, args);
+ using_pc = 1;
}
else
{
- if (args)
+ /* FIXME! temp hack to allow use with port master -
+ target tcp_remote <device> */
+ if (args && strncmp (args, "tcp_remote", 10) == 0)
+ {
+ char com_type[128];
+ n = sscanf (args, " %s %s %d %s", com_type, dev_name, &baudrate, junk);
+ using_tcp_remote=1;
+ n--;
+ }
+ else if (args)
{
n = sscanf (args, " %s %d %s", dev_name, &baudrate, junk);
}
{
error ("Bad arguments. Usage:\ttarget e7000 <device> <speed>\n\
or \t\ttarget e7000 <host>[:<port>]\n\
+or \t\ttarget e7000 tcp_remote <host>[:<port>]\n\
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)
{
/* Default to normal telnet port */
+ /* serial_open will use this to determine tcp communication */
strcat (dev_name, ":23");
}
#endif
+ if (!using_tcp_remote && strchr (dev_name, ':'))
+ using_tcp = 1;
}
+ return n;
+}
+
+static void
+e7000_open (args, from_tty)
+ char *args;
+ int from_tty;
+{
+ int n;
+ int loop;
+ int sync;
+ int serial_flag;
+ int try=0;
+ int quit_trying=20;
+
+ 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);
-
- using_tcp = strcmp (e7000_desc->ops->name, "tcp") == 0;
- using_pc = strcmp (e7000_desc->ops->name, "pc") == 0;
+ {
+ error ("Unable to open target or file not found: %s\n", dev_name);
+ }
SERIAL_SETBAUDRATE (e7000_desc, baudrate);
SERIAL_RAW (e7000_desc);
sync = 0;
loop = 0;
putchar_e7000 (CTRLC);
- while (!sync)
+ while (!sync && ++try <= quit_trying)
{
int c;
write_e7000 ("\r");
c = SERIAL_READCHAR (e7000_desc, 1);
- while (c != SERIAL_TIMEOUT)
+
+ /* 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 != SERIAL_TIMEOUT)
{
/* Dont echo cr's */
if (from_tty && c != '\r')
putchar (c);
fflush (stdout);
}
+ /* Shouldn't we either break here, or check for sync in inner loop? */
if (c == ':')
sync = 1;
QUIT ;
+ /* FIXME! with this logic, you might never break out of this loop!
+ * Changed to count tries and treat reads as TIMEOUTS
+ * In windows version, you never timeout cuz always read 1 char!
+ */
if (quit_flag)
{
putchar_e7000 (CTRLC);
- quit_flag = 0;
+ /* Was-> quit_flag = 0; */
+ c = SERIAL_TIMEOUT;
+ quit_trying = try+1; /* we don't want to try anymore */
}
- c = SERIAL_READCHAR (e7000_desc, 1);
+ else
+ c = SERIAL_READCHAR (e7000_desc, 1);
}
}
+
+ if (!sync)
+ {
+ if (from_tty)
+ printf_unfiltered ("Giving up after %d tries...\n",try);
+ error ("Unable to syncronize with target.\n");
+ return;
+ }
+
puts_e7000debug ("\r");
expect_prompt ();
#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_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 = "%p CCR=%c\n\
+char *want_nopc_h8300s = "%p CCR=%c EXR=%9\n\
ER0 - ER3 %0 %1 %2 %3\n\
ER4 - ER7 %4 %5 %6 %7";
else
fetch_regs_from_dump (gch, want);
#else
- fetch_regs_from_dump (gch, want);
+ fetch_regs_from_dump (gch, h8300smode ? want_h8300s : want_h8300h);
#endif
int nostart;
time_t start_time, end_time; /* Start and end times of download */
unsigned long data_count; /* Number of bytes transferred to memory */
+ int oldtimeout = timeout;
+
+ timeout = remote_timeout;
- if (!strchr (dev_name, ':'))
+
+ /* FIXME! change test to test for type of download */
+ if (!using_tcp)
{
generic_load (args, from_tty);
return;
}
+ /* for direct tcp connections, we can do a fast binary download */
buf[0] = 'D';
buf[1] = 'T';
quiet = 0;
report_transfer_performance (data_count, start_time, end_time);
do_cleanups (old_chain);
+ timeout = oldtimeout;
}
/* Clean up when a program exits.
generic_mourn_inferior (); /* Do all the proper things now */
}
+#define MAX_BREAKPOINTS 200
#ifdef HARD_BREAKPOINTS
-#define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : 200)
+#define MAX_E7000DEBUG_BREAKPOINTS (BC_BREAKPOINTS ? 5 : MAX_BREAKPOINTS)
#else
-#define MAX_E7000DEBUG_BREAKPOINTS 200
+#define MAX_E7000DEBUG_BREAKPOINTS MAX_BREAKPOINTS
#endif
extern int memory_breakpoint_size;
-static CORE_ADDR breakaddr[MAX_E7000DEBUG_BREAKPOINTS] = {0};
+/* Since we can change to soft breakpoints dynamically, we must define
+ more than enough. Was breakaddr[MAX_E7000DEBUG_BREAKPOINTS]. */
+static CORE_ADDR breakaddr[MAX_BREAKPOINTS] = {0};
static int
e7000_insert_breakpoint (addr, shadow)
else
fetch_regs_from_dump (gch, want_nopc);
#else
- fetch_regs_from_dump (gch, want_nopc);
+ fetch_regs_from_dump (gch, h8300smode ? want_nopc_h8300s : want_nopc_h8300h);
#endif
/* And supply the extra ones the simulator uses */
return 0;
}
+/* Stop the running program. */
+
+static void
+e7000_stop ()
+{
+ /* Sending a ^C is supposed to stop the running program. */
+ putchar_e7000 (CTRLC);
+}
+
/* Define the target subroutine names. */
struct target_ops e7000_ops =
0, /* to_can_run */
0, /* to_notice_signals */
0, /* to_thread_alive */
- 0, /* to_stop */
+ e7000_stop, /* to_stop */
process_stratum, /* to_stratum */
0, /* next (unused) */
1, /* to_has_all_memory */
add_com ("drain", class_obscure, e7000_drain_command,
"Drain pending e7000 text buffers.");
+
+ add_show_from_set (add_set_cmd ("usehardbreakpoints", no_class,
+ var_integer, (char *)&use_hard_breakpoints,
+ "Set use of hardware breakpoints for all breakpoints.\n", &setlist),
+ &showlist);
}