/* Remote debugging interface for boot monitors, for GDB.
- Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+
+ Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999,
+ 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of GDB.
#include "defs.h"
#include "gdbcore.h"
#include "target.h"
-#include "wait.h"
-#include <signal.h>
#include "gdb_string.h"
#include <sys/types.h>
#include "command.h"
#include "symfile.h"
#include "objfiles.h"
#include "gdb-stabs.h"
+#include "regcache.h"
struct cmd_list_element *showlist;
extern struct target_ops rombug_ops; /* Forward declaration */
static int timeout = 10;
static int is_trace_mode = 0;
/* Descriptor for I/O to remote machine. Initialize it to NULL */
-static serial_t monitor_desc = NULL;
+static struct serial *monitor_desc = NULL;
static CORE_ADDR bufaddr = 0;
static int buflen = 0;
vsprintf (buf, pattern, args);
va_end (args);
- if (SERIAL_WRITE (monitor_desc, buf, strlen (buf)))
- fprintf (stderr, "SERIAL_WRITE failed: %s\n", safe_strerror (errno));
+ if (serial_write (monitor_desc, buf, strlen (buf)))
+ fprintf (stderr, "serial_write failed: %s\n", safe_strerror (errno));
}
/* Read a character from the remote system, doing all the fancy timeout stuff */
static int
-readchar (timeout)
- int timeout;
+readchar (int timeout)
{
int c;
- c = SERIAL_READCHAR (monitor_desc, timeout);
+ c = serial_readchar (monitor_desc, timeout);
if (sr_get_debug ())
putchar (c & 0x7f);
non-zero, then discard non-matching input, else print it out.
Let the user break out immediately. */
static void
-expect (string, discard)
- char *string;
- int discard;
+expect (char *string, int discard)
{
char *p = string;
int c;
if (sr_get_debug ())
printf ("Expecting \"%s\"\n", string);
- immediate_quit = 1;
+ immediate_quit++;
while (1)
{
c = readchar (timeout);
{
if (*p == '\0')
{
- immediate_quit = 0;
+ immediate_quit--;
if (sr_get_debug ())
printf ("\nMatched\n");
return;
necessary to prevent getting into states from which we can't
recover. */
static void
-expect_prompt (discard)
- int discard;
+expect_prompt (int discard)
{
if (monitor_log)
/* This is a convenient place to do this. The idea is to do it often
/* Get a hex digit from the remote system & return its value.
If ignore_space is nonzero, ignore spaces (not newline, tab, etc). */
static int
-get_hex_digit (ignore_space)
- int ignore_space;
+get_hex_digit (int ignore_space)
{
int ch;
while (1)
/* Get a byte from monitor and put it in *BYT. Accept any number
leading spaces. */
static void
-get_hex_byte (byt)
- char *byt;
+get_hex_byte (char *byt)
{
int val;
/* Get N 32-bit words from remote, each preceded by a space,
and put them in registers starting at REGNO. */
static void
-get_hex_regs (n, regno)
- int n;
- int regno;
+get_hex_regs (int n, int regno)
{
long val;
int i;
for (j = 0; j < 4; j++)
{
get_hex_byte (&b);
- if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+ if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
val = (val << 8) + b;
else
val = val + (b << (j * 8));
/* This is called not only when we first attach, but also when the
user types "run" after having attached. */
static void
-rombug_create_inferior (execfile, args, env)
- char *execfile;
- char *args;
- char **env;
+rombug_create_inferior (char *execfile, char *args, char **env)
{
int entry_pt;
static char dev_name[100];
static void
-rombug_open (args, from_tty)
- char *args;
- int from_tty;
+rombug_open (char *args, int from_tty)
{
if (args == NULL)
error ("Use `target RomBug DEVICE-NAME' to use a serial port, or \n\
unpush_target (&rombug_ops);
strcpy (dev_name, args);
- monitor_desc = SERIAL_OPEN (dev_name);
+ monitor_desc = serial_open (dev_name);
if (monitor_desc == NULL)
perror_with_name (dev_name);
/* if baud rate is set by 'set remotebaud' */
- if (SERIAL_SETBAUDRATE (monitor_desc, sr_get_baud_rate ()))
+ if (serial_setbaudrate (monitor_desc, sr_get_baud_rate ()))
{
- SERIAL_CLOSE (monitor_desc);
+ serial_close (monitor_desc);
perror_with_name ("RomBug");
}
- SERIAL_RAW (monitor_desc);
+ serial_raw (monitor_desc);
if (tty_xon || tty_xoff)
{
struct hardware_ttystate
}
*tty_s;
- tty_s = (struct hardware_ttystate *) SERIAL_GET_TTY_STATE (monitor_desc);
+ tty_s = (struct hardware_ttystate *) serial_get_tty_state (monitor_desc);
if (tty_xon)
tty_s->t.c_iflag |= IXON;
if (tty_xoff)
tty_s->t.c_iflag |= IXOFF;
- SERIAL_SET_TTY_STATE (monitor_desc, (serial_ttystate) tty_s);
+ serial_set_tty_state (monitor_desc, (serial_ttystate) tty_s);
}
rombug_is_open = 1;
*/
static void
-rombug_close (quitting)
- int quitting;
+rombug_close (int quitting)
{
if (rombug_is_open)
{
- SERIAL_CLOSE (monitor_desc);
+ serial_close (monitor_desc);
monitor_desc = NULL;
rombug_is_open = 0;
}
}
int
-rombug_link (mod_name, text_reloc)
- char *mod_name;
- CORE_ADDR *text_reloc;
+rombug_link (char *mod_name, CORE_ADDR *text_reloc)
{
int i, j;
unsigned long val;
Use this when you want to detach and do something else
with your gdb. */
static void
-rombug_detach (from_tty)
- int from_tty;
+rombug_detach (int from_tty)
{
if (attach_flag)
{
* Tell the remote machine to resume.
*/
static void
-rombug_resume (pid, step, sig)
- int pid, step;
- enum target_signal sig;
+rombug_resume (ptid_t ptid, int step, enum target_signal sig)
{
if (monitor_log)
fprintf (log_file, "\nIn Resume (step=%d, sig=%d)\n", step, sig);
* storing status in status just as `wait' would.
*/
-static int
-rombug_wait (pid, status)
- int pid;
- struct target_waitstatus *status;
+static ptid *
+rombug_wait (ptid_t ptid, struct target_waitstatus *status)
{
int old_timeout = timeout;
struct section_offsets *offs;
{
if (obj_sec->objfile != symfile_objfile)
new_symfile_objfile (obj_sec->objfile, 1, 0);
- offs = ((struct section_offsets *)
- alloca (sizeof (struct section_offsets)
- + (symfile_objfile->num_sections * sizeof (offs->offsets))));
- memcpy (offs, symfile_objfile->section_offsets,
- (sizeof (struct section_offsets) +
- (symfile_objfile->num_sections * sizeof (offs->offsets))));
- ANOFFSET (offs, SECT_OFF_DATA) = addr;
- ANOFFSET (offs, SECT_OFF_BSS) = addr;
+ offs = (struct section_offsets *) alloca (SIZEOF_SECTION_OFFSETS);
+ memcpy (offs, symfile_objfile->section_offsets, SIZEOF_SECTION_OFFSETS);
+ offs->offsets[SECT_OFF_DATA (symfile_objfile)] = addr;
+ offs->offsets[SECT_OFF_BSS (symfile_objfile)] = addr;
objfile_relocate (symfile_objfile, offs);
}
- return 0;
+ return inferior_ptid;
}
/* Return the name of register number regno in the form input and output by
monitor wants. Lets take advantage of that just as long as possible! */
static char *
-get_reg_name (regno)
- int regno;
+get_reg_name (int regno)
{
static char buf[50];
char *p;
/* read the remote registers into the block regs. */
static void
-rombug_fetch_registers ()
+rombug_fetch_registers (void)
{
int regno, j, i;
long val;
for (j = 0; j < 2; j++)
{
get_hex_byte (&b);
- if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+ if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
val = (val << 8) + b;
else
val = val + (b << (j * 8));
/* Fetch register REGNO, or all registers if REGNO is -1.
Returns errno value. */
static void
-rombug_fetch_register (regno)
- int regno;
+rombug_fetch_register (int regno)
{
int val, j;
unsigned char b;
for (j = 0; j < 2; j++)
{
get_hex_byte (&b);
- if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+ if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
val = (val << 8) + b;
else
val = val + (b << (j * 8));
/* Store the remote registers from the contents of the block REGS. */
static void
-rombug_store_registers ()
+rombug_store_registers (void)
{
int regno;
/* Store register REGNO, or all if REGNO == 0.
return errno value. */
static void
-rombug_store_register (regno)
- int regno;
+rombug_store_register (int regno)
{
char *name;
debugged. */
static void
-rombug_prepare_to_store ()
+rombug_prepare_to_store (void)
{
/* Do nothing, since we can store individual regs */
}
static void
-rombug_files_info ()
+rombug_files_info (void)
{
printf ("\tAttached to %s at %d baud.\n",
dev_name, sr_get_baud_rate ());
/* Copy LEN bytes of data from debugger memory at MYADDR
to inferior's memory at MEMADDR. Returns length moved. */
static int
-rombug_write_inferior_memory (memaddr, myaddr, len)
- CORE_ADDR memaddr;
- unsigned char *myaddr;
- int len;
+rombug_write_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
{
int i;
char buf[10];
/* Read LEN bytes from inferior memory at MEMADDR. Put the result
at debugger address MYADDR. Returns length moved. */
static int
-rombug_read_inferior_memory (memaddr, myaddr, len)
- CORE_ADDR memaddr;
- char *myaddr;
- int len;
+rombug_read_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len)
{
int i, j;
return len;
}
-/* FIXME-someday! merge these two. */
+/* Transfer LEN bytes between GDB address MYADDR and target address
+ MEMADDR. If WRITE is non-zero, transfer them to the target,
+ otherwise transfer them from the target. TARGET is unused.
+
+ Returns the number of bytes transferred. */
+
static int
-rombug_xfer_inferior_memory (memaddr, myaddr, len, write, target)
- CORE_ADDR memaddr;
- char *myaddr;
- int len;
- int write;
- struct target_ops *target; /* ignored */
+rombug_xfer_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len,
+ int write, struct mem_attrib *attrib,
+ struct target_ops *target)
{
if (write)
return rombug_write_inferior_memory (memaddr, myaddr, len);
}
static void
-rombug_kill (args, from_tty)
- char *args;
- int from_tty;
+rombug_kill (char *args, int from_tty)
{
return; /* ignore attempts to kill target system */
}
instructions. */
static void
-rombug_mourn_inferior ()
+rombug_mourn_inferior (void)
{
remove_breakpoints ();
generic_mourn_inferior (); /* Do all the proper things now */
{0};
static int
-rombug_insert_breakpoint (addr, shadow)
- CORE_ADDR addr;
- char *shadow;
+rombug_insert_breakpoint (CORE_ADDR addr, char *shadow)
{
int i;
CORE_ADDR bp_addr = addr;
* _remove_breakpoint -- Tell the monitor to remove a breakpoint
*/
static int
-rombug_remove_breakpoint (addr, shadow)
- CORE_ADDR addr;
- char *shadow;
+rombug_remove_breakpoint (CORE_ADDR addr, char *shadow)
{
int i;
#define DOWNLOAD_LINE_SIZE 100
static void
-rombug_load (arg)
- char *arg;
+rombug_load (char *arg)
{
/* this part comment out for os9* */
#if 0
fflush (stdout);
}
- if (SERIAL_WRITE (monitor_desc, buf, bytes_read))
+ if (serial_write (monitor_desc, buf, bytes_read))
{
- fprintf (stderr, "SERIAL_WRITE failed: (while downloading) %s\n", safe_strerror (errno));
+ fprintf (stderr, "serial_write failed: (while downloading) %s\n", safe_strerror (errno));
break;
}
i = 0;
is seen. */
static void
-rombug_command (args, fromtty)
- char *args;
- int fromtty;
+rombug_command (char *args, int fromtty)
{
if (monitor_desc == NULL)
error ("monitor target not open.");
static struct ttystate ttystate;
static void
-cleanup_tty ()
+cleanup_tty (void)
{
printf ("\r\n[Exiting connect mode]\r\n");
- /*SERIAL_RESTORE(0, &ttystate); */
+ /*serial_restore(0, &ttystate); */
}
static void
-connect_command (args, fromtty)
- char *args;
- int fromtty;
+connect_command (char *args, int fromtty)
{
fd_set readfds;
int numfds;
do
{
FD_SET (0, &readfds);
- FD_SET (monitor_desc, &readfds);
+ FD_SET (deprecated_serial_fd (monitor_desc), &readfds);
numfds = select (sizeof (readfds) * 8, &readfds, 0, 0, 0);
}
while (numfds == 0);
}
}
- if (FD_ISSET (monitor_desc, &readfds))
+ if (FD_ISSET (deprecated_serial_fd (monitor_desc), &readfds))
{
while (1)
{
rombug_ops.to_thread_alive = 0;
rombug_ops.to_stop = 0; /* to_stop */
rombug_ops.to_pid_to_exec_file = NULL;
- rombug_ops.to_core_file_to_sym_file = NULL;
rombug_ops.to_stratum = process_stratum;
rombug_ops.DONT_USE = 0; /* next */
rombug_ops.to_has_all_memory = 1;
}
void
-_initialize_remote_os9k ()
+_initialize_remote_os9k (void)
{
init_rombug_ops ();
add_target (&rombug_ops);