X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Focd.c;h=dffc176688ad0a0a605f8d29d3fa84c77ab7213c;hb=3e3ffd2b74c0321e887da2ca396070c6f61b0e1a;hp=3d054b7a0b9a771dac44fee57f9ffda1b457fffd;hpb=697ec6c4a5c1aa30f7fcb819398a4edad5e977c6;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/ocd.c b/gdb/ocd.c index 3d054b7a0b..dffc176688 100644 --- a/gdb/ocd.c +++ b/gdb/ocd.c @@ -1,5 +1,7 @@ /* Target communications support for Macraigor Systems' On-Chip Debugging - Copyright 1996, 1997 Free Software Foundation, Inc. + + Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004 Free + Software Foundation, Inc. This file is part of GDB. @@ -27,32 +29,23 @@ #include "bfd.h" #include "symfile.h" #include "target.h" -#include "gdb_wait.h" #include "gdbcmd.h" #include "objfiles.h" #include "gdb-stabs.h" -#include "dcache.h" #include #include #include "serial.h" #include "ocd.h" +#include "regcache.h" /* Prototypes for local functions */ static int ocd_read_bytes (CORE_ADDR memaddr, char *myaddr, int len); -static int ocd_start_remote (PTR dummy); +static int ocd_start_remote (void *dummy); static int readchar (int timeout); -static void reset_packet (void); - -static void output_packet (void); - -static int get_quoted_char (int timeout); - -static void put_quoted_char (int c); - static void ocd_interrupt (int signo); static void ocd_interrupt_twice (int signo); @@ -69,21 +62,10 @@ static struct target_ops *current_ops = NULL; static int last_run_status; -/* This was 5 seconds, which is a long time to sit and wait. - Unless this is going though some terminal server or multiplexer or - other form of hairy serial connection, I would think 2 seconds would - be plenty. */ - -#if 0 -/* FIXME: Change to allow option to set timeout value on a per target - basis. */ -static int remote_timeout = 2; -#endif - /* Descriptor for I/O to remote machine. Initialize it to NULL so that ocd_open knows that we don't have a file open when the program starts. */ -static serial_t ocd_desc = NULL; +static struct serial *ocd_desc = NULL; void ocd_error (char *s, int error_code) @@ -145,32 +127,31 @@ ocd_error (char *s, int error_code) s = buf; } - error (s); + error ("%s", s); } /* Return nonzero if the thread TH is still alive on the remote system. */ int -ocd_thread_alive (int th) +ocd_thread_alive (ptid_t th) { return 1; } /* Clean up connection to a remote debugger. */ -/* ARGSUSED */ void ocd_close (int quitting) { if (ocd_desc) - SERIAL_CLOSE (ocd_desc); + serial_close (ocd_desc); ocd_desc = NULL; } /* Stub for catch_errors. */ static int -ocd_start_remote (PTR dummy) +ocd_start_remote (void *dummy) { unsigned char buf[10], *p; int pktlen; @@ -183,7 +164,7 @@ ocd_start_remote (PTR dummy) immediate_quit++; /* Allow user to interrupt it */ - SERIAL_SEND_BREAK (ocd_desc); /* Wake up the wiggler */ + serial_send_break (ocd_desc); /* Wake up the wiggler */ speed = 80; /* Divide clock by 4000 */ @@ -210,19 +191,11 @@ ocd_start_remote (PTR dummy) printf_unfiltered ("[Wiggler version %x.%x, capability 0x%x]\n", p[0], p[1], (p[2] << 16) | p[3]); -#if 0 - /* Reset the target */ - - ocd_do_command (OCD_RESET_RUN, &status, &pktlen); -/* ocd_do_command (OCD_RESET, &status, &pktlen); */ -#endif - /* If processor is still running, stop it. */ if (!(status & OCD_FLAG_BDM)) ocd_stop (); -#if 1 /* When using a target box, we want to asynchronously return status when target stops. The OCD_SET_CTL_FLAGS command is ignored by Wigglers.dll when using a parallel Wiggler */ @@ -241,7 +214,6 @@ ocd_start_remote (PTR dummy) if (error_code != 0) ocd_error ("OCD_SET_CTL_FLAGS:", error_code); -#endif immediate_quit--; @@ -253,9 +225,7 @@ ocd_start_remote (PTR dummy) 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); + print_stack_frame (get_selected_frame (), 0, SRC_AND_LOC); buf[0] = OCD_LOG_FILE; buf[1] = 3; /* close existing WIGGLERS.LOG */ @@ -273,8 +243,6 @@ ocd_start_remote (PTR dummy) /* Open a connection to a remote debugger. NAME is the filename used for communication. */ -static DCACHE *ocd_dcache; - void ocd_open (char *name, int from_tty, enum ocd_target_type target_type, struct target_ops *ops) @@ -292,49 +260,24 @@ device the OCD device is attached to (e.g. /dev/ttya)."); unpush_target (current_ops); - if (!ocd_dcache) - ocd_dcache = dcache_init (ocd_read_bytes, ocd_write_bytes); - else - dcache_invd (ocd_dcache); - - if (strncmp (name, "wiggler", 7) == 0) - { - ocd_desc = SERIAL_OPEN ("ocd"); - if (!ocd_desc) - perror_with_name (name); - - buf[0] = OCD_LOG_FILE; - buf[1] = 1; /* open new or overwrite existing WIGGLERS.LOG */ - ocd_put_packet (buf, 2); - p = ocd_get_packet (buf[0], &pktlen, remote_timeout); - - buf[0] = OCD_SET_CONNECTION; - buf[1] = 0x01; /* atoi (name[11]); */ - ocd_put_packet (buf, 2); - p = ocd_get_packet (buf[0], &pktlen, remote_timeout); - } - else - /* not using Wigglers.dll */ - { - ocd_desc = SERIAL_OPEN (name); - if (!ocd_desc) - perror_with_name (name); - } + ocd_desc = serial_open (name); + if (!ocd_desc) + perror_with_name (name); if (baud_rate != -1) { - if (SERIAL_SETBAUDRATE (ocd_desc, baud_rate)) + if (serial_setbaudrate (ocd_desc, baud_rate)) { - SERIAL_CLOSE (ocd_desc); + serial_close (ocd_desc); perror_with_name (name); } } - SERIAL_RAW (ocd_desc); + serial_raw (ocd_desc); /* If there is something sitting in the buffer we might take it as a response to a command, which would be bad. */ - SERIAL_FLUSH_INPUT (ocd_desc); + serial_flush_input (ocd_desc); if (from_tty) { @@ -351,7 +294,7 @@ device the OCD device is attached to (e.g. /dev/ttya)."); variables, especially since GDB will someday have a notion of debugging several processes. */ - inferior_pid = 42000; + inferior_ptid = pid_to_ptid (42000); /* 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). */ @@ -383,12 +326,10 @@ ocd_detach (char *args, int from_tty) /* Tell the remote machine to resume. */ void -ocd_resume (int pid, int step, enum target_signal siggnal) +ocd_resume (ptid_t ptid, int step, enum target_signal siggnal) { int pktlen; - dcache_invd (ocd_dcache); - if (step) ocd_do_command (OCD_STEP, &last_run_status, &pktlen); else @@ -455,7 +396,7 @@ interrupt_query (void) Give up (and stop debugging it)? ")) { target_mourn_inferior (); - return_to_top_level (RETURN_QUIT); + throw_exception (RETURN_QUIT); } target_terminal_inferior (); @@ -767,12 +708,18 @@ ocd_read_bytes (CORE_ADDR memaddr, char *myaddr, int len) nonzero. Returns length of data written or read; 0 for error. TARGET is ignored. */ -/* ARGSUSED */ int ocd_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int should_write, - struct target_ops *target) + struct mem_attrib *attrib, struct target_ops *target) { - return dcache_xfer_memory (ocd_dcache, memaddr, myaddr, len, should_write); + int res; + + if (should_write) + res = ocd_write_bytes (memaddr, myaddr, len); + else + res = ocd_read_bytes (memaddr, myaddr, len); + + return res; } void @@ -791,7 +738,7 @@ readchar (int timeout) { int ch; - ch = SERIAL_READCHAR (ocd_desc, timeout); + ch = serial_readchar (ocd_desc, timeout); switch (ch) { @@ -805,112 +752,6 @@ readchar (int timeout) } } -#if 0 -/* Read a character from the data stream, dequoting as necessary. SYN is - treated special. Any SYNs appearing in the data stream are returned as the - distinct value RAW_SYN (which has a value > 8 bits and therefore cannot be - mistaken for real data). */ - -static int -get_quoted_char (int timeout) -{ - int ch; - - ch = readchar (timeout); - - switch (ch) - { - case SERIAL_TIMEOUT: - error ("Timeout in mid-packet, aborting"); - case SYN: - return RAW_SYN; - case DLE: - ch = readchar (timeout); - if (ch == SYN) - return RAW_SYN; - return ch & ~0100; - default: - return ch; - } -} - -static unsigned char pkt[256 * 2 + 10], *pktp; /* Worst case */ - -static void -reset_packet (void) -{ - pktp = pkt; -} - -static void -output_packet (void) -{ - if (SERIAL_WRITE (ocd_desc, pkt, pktp - pkt)) - perror_with_name ("output_packet: write failed"); - - reset_packet (); -} - -/* Output a quoted character. SYNs and DLEs are quoted. Everything else goes - through untouched. */ - -static void -put_quoted_char (int c) -{ - switch (c) - { - case SYN: - case DLE: - *pktp++ = DLE; - c |= 0100; - } - - *pktp++ = c; -} - -/* Send a packet to the OCD device. The packet framed by a SYN character, - a byte count and a checksum. The byte count only counts the number of - bytes between the count and the checksum. A count of zero actually - means 256. Any SYNs within the packet (including the checksum and - count) must be quoted. The quote character must be quoted as well. - Quoting is done by replacing the character with the two-character sequence - DLE, {char} | 0100. Note that the quoting mechanism has no effect on the - byte count. */ - -static void -stu_put_packet (unsigned char *buf, int len) -{ - unsigned char checksum; - unsigned char c; - - if (len == 0 || len > 256) - abort (); /* Can't represent 0 length packet */ - - reset_packet (); - - checksum = 0; - - put_quoted_char (RAW_SYN); - - c = len; - - do - { - checksum += c; - - put_quoted_char (c); - - c = *buf++; - } - while (len-- > 0); - - put_quoted_char (-checksum & 0xff); - - output_packet (); -} - -#else - /* Send a packet to the OCD device. The packet framed by a SYN character, a byte count and a checksum. The byte count only counts the number of bytes between the count and the checksum. A count of zero actually @@ -943,74 +784,9 @@ ocd_put_packet (unsigned char *buf, int len) } *packet_ptr++ = -checksum; - if (SERIAL_WRITE (ocd_desc, packet, packet_ptr - packet)) + if (serial_write (ocd_desc, packet, packet_ptr - packet)) perror_with_name ("output_packet: write failed"); } -#endif - -#if 0 -/* Get a packet from the OCD device. Timeout is only enforced for the - first byte of the packet. Subsequent bytes are expected to arrive in - time <= remote_timeout. Returns a pointer to a static buffer containing - the payload of the packet. *LENP contains the length of the packet. - */ - -static unsigned char * -stu_get_packet (unsigned char cmd, int *lenp, int timeout) -{ - int ch; - int len; - static unsigned char buf[256 + 10], *p; - unsigned char checksum; - -find_packet: - - ch = get_quoted_char (timeout); - - if (ch < 0) - error ("get_packet (readchar): %d", ch); - - if (ch != RAW_SYN) - goto find_packet; - -found_syn: /* Found the start of a packet */ - - p = buf; - checksum = 0; - - len = get_quoted_char (remote_timeout); - - if (len == RAW_SYN) - goto found_syn; - - checksum += len; - - if (len == 0) - len = 256; - - len++; /* Include checksum */ - - while (len-- > 0) - { - ch = get_quoted_char (remote_timeout); - if (ch == RAW_SYN) - goto found_syn; - - *p++ = ch; - checksum += ch; - } - - if (checksum != 0) - goto find_packet; - - if (cmd != buf[0]) - error ("Response phase error. Got 0x%x, expected 0x%x", buf[0], cmd); - - *lenp = p - buf - 1; - return buf; -} - -#else /* Get a packet from the OCD device. Timeout is only enforced for the first byte of the packet. Subsequent bytes are expected to arrive in @@ -1160,7 +936,6 @@ ocd_get_packet (int cmd, int *lenp, int timeout) *lenp = packet_ptr - packet - 1; /* Subtract checksum byte */ return packet; } -#endif /* Execute a simple (one-byte) command. Returns a pointer to the data following the error code. */ @@ -1239,7 +1014,7 @@ ocd_mourn (void) the program at that point. */ void -ocd_create_inferior (char *exec_file, char *args, char **env) +ocd_create_inferior (char *exec_file, char *args, char **env, int from_tty) { if (args && (*args != '\000')) error ("Args are not supported by BDM."); @@ -1253,7 +1028,7 @@ ocd_load (char *args, int from_tty) { generic_load (args, from_tty); - inferior_pid = 0; + inferior_ptid = null_ptid; /* This is necessary because many things were based on the PC at the time that we attached to the monitor, which is no longer valid now that we have loaded @@ -1269,9 +1044,6 @@ ocd_load (char *args, int from_tty) not yet supported fully */ #define BDM_BREAKPOINT {0x0,0x0,0x0,0x0} /* For ppc 8xx */ -#if 0 -#define BDM_BREAKPOINT {0x4a,0xfa} /* BGND insn used for CPU32 */ -#endif /* BDM (at least on CPU32) uses a different breakpoint */ @@ -1315,7 +1087,7 @@ bdm_reset_command (char *args, int from_tty) error ("Not connected to OCD device."); ocd_do_command (OCD_RESET, &status, &pktlen); - dcache_invd (ocd_dcache); + dcache_invalidate (target_dcache); registers_changed (); } @@ -1374,30 +1146,20 @@ bdm_update_flash_command (char *args, int from_tty) /* discard_cleanups (old_chain); */ } - -static void -bdm_read_register_command (char *args, int from_tty) -{ - /* XXX repeat should go on to the next register */ - - if (!ocd_desc) - error ("Not connected to OCD device."); - - if (!args) - error ("Must specify BDM register number."); - -} +extern initialize_file_ftype _initialize_remote_ocd; /* -Wmissing-prototypes */ + void _initialize_remote_ocd (void) { extern struct cmd_list_element *cmdlist; static struct cmd_list_element *ocd_cmd_list = NULL; - add_show_from_set (add_set_cmd ("remotetimeout", no_class, - var_integer, (char *) &remote_timeout, - "Set timeout value for remote read.\n", &setlist), - &showlist); + deprecated_add_show_from_set + (add_set_cmd ("remotetimeout", no_class, + var_integer, (char *) &remote_timeout, + "Set timeout value for remote read.\n", &setlist), + &showlist); add_prefix_cmd ("ocd", class_obscure, bdm_command, "", &ocd_cmd_list, "ocd ", 0, &cmdlist); @@ -1405,5 +1167,4 @@ _initialize_remote_ocd (void) add_cmd ("reset", class_obscure, bdm_reset_command, "", &ocd_cmd_list); add_cmd ("restart", class_obscure, bdm_restart_command, "", &ocd_cmd_list); add_cmd ("update-flash", class_obscure, bdm_update_flash_command, "", &ocd_cmd_list); - /* add_cmd ("read-register", class_obscure, bdm_read_register_command, "", &ocd_cmd_list); */ }