1 /* Target communications support for Macraigor Systems' On-Chip Debugging
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Free Software
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
25 #include "gdb_string.h"
34 #include "gdb-stabs.h"
35 #include <sys/types.h>
41 /* Prototypes for local functions */
43 static int ocd_read_bytes (CORE_ADDR memaddr, char *myaddr, int len);
45 static int ocd_start_remote (PTR dummy);
47 static int readchar (int timeout);
49 static void reset_packet (void);
51 static void output_packet (void);
53 static int get_quoted_char (int timeout);
55 static void put_quoted_char (int c);
57 static void ocd_interrupt (int signo);
59 static void ocd_interrupt_twice (int signo);
61 static void interrupt_query (void);
63 static unsigned char *ocd_do_command (int cmd, int *statusp, int *lenp);
65 static void ocd_put_packet (unsigned char *packet, int pktlen);
67 static unsigned char *ocd_get_packet (int cmd, int *pktlen, int timeout);
69 static struct target_ops *current_ops = NULL;
71 static int last_run_status;
73 /* This was 5 seconds, which is a long time to sit and wait.
74 Unless this is going though some terminal server or multiplexer or
75 other form of hairy serial connection, I would think 2 seconds would
79 /* FIXME: Change to allow option to set timeout value on a per target
81 static int remote_timeout = 2;
84 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
85 ocd_open knows that we don't have a file open when the program
87 static struct serial *ocd_desc = NULL;
90 ocd_error (char *s, int error_code)
94 fputs_filtered (s, gdb_stderr);
95 fputs_filtered (" ", gdb_stderr);
106 s = "Cable disconnected";
109 s = "Couldn't enter OCD mode";
112 s = "Target stuck in reset";
115 s = "OCD hasn't been initialized";
118 s = "Write verify failed";
121 s = "Reg buff error (during MPC5xx fp reg read/write)";
124 s = "Invalid CPU register access attempt failed";
130 s = "Checksum error";
133 s = "Illegal command";
136 s = "Parameter error";
139 s = "Internal error";
142 s = "Flash erase error";
145 sprintf (buf, "Unknown error code %d", error_code);
152 /* Return nonzero if the thread TH is still alive on the remote system. */
155 ocd_thread_alive (ptid_t th)
160 /* Clean up connection to a remote debugger. */
164 ocd_close (int quitting)
167 serial_close (ocd_desc);
171 /* Stub for catch_errors. */
174 ocd_start_remote (PTR dummy)
176 unsigned char buf[10], *p;
181 enum ocd_target_type target_type;
183 target_type = *(enum ocd_target_type *) dummy;
185 immediate_quit++; /* Allow user to interrupt it */
187 serial_send_break (ocd_desc); /* Wake up the wiggler */
189 speed = 80; /* Divide clock by 4000 */
193 buf[2] = speed & 0xff;
194 buf[3] = target_type;
195 ocd_put_packet (buf, 4); /* Init OCD params */
196 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
199 error ("Truncated response packet from OCD device");
205 ocd_error ("OCD_INIT:", error_code);
207 ocd_do_command (OCD_AYT, &status, &pktlen);
209 p = ocd_do_command (OCD_GET_VERSION, &status, &pktlen);
211 printf_unfiltered ("[Wiggler version %x.%x, capability 0x%x]\n",
212 p[0], p[1], (p[2] << 16) | p[3]);
215 /* Reset the target */
217 ocd_do_command (OCD_RESET_RUN, &status, &pktlen);
218 /* ocd_do_command (OCD_RESET, &status, &pktlen); */
221 /* If processor is still running, stop it. */
223 if (!(status & OCD_FLAG_BDM))
227 /* When using a target box, we want to asynchronously return status when
228 target stops. The OCD_SET_CTL_FLAGS command is ignored by Wigglers.dll
229 when using a parallel Wiggler */
230 buf[0] = OCD_SET_CTL_FLAGS;
233 ocd_put_packet (buf, 3);
235 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
238 error ("Truncated response packet from OCD device");
244 ocd_error ("OCD_SET_CTL_FLAGS:", error_code);
249 /* This is really the job of start_remote however, that makes an assumption
250 that the target is about to print out a status message of some sort. That
251 doesn't happen here (in fact, it may not be possible to get the monitor to
252 send the appropriate packet). */
254 flush_cached_frames ();
255 registers_changed ();
256 stop_pc = read_pc ();
257 set_current_frame (create_new_frame (read_fp (), stop_pc));
258 select_frame (get_current_frame ());
259 print_stack_frame (selected_frame, -1, 1);
261 buf[0] = OCD_LOG_FILE;
262 buf[1] = 3; /* close existing WIGGLERS.LOG */
263 ocd_put_packet (buf, 2);
264 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
266 buf[0] = OCD_LOG_FILE;
267 buf[1] = 2; /* append to existing WIGGLERS.LOG */
268 ocd_put_packet (buf, 2);
269 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
274 /* Open a connection to a remote debugger.
275 NAME is the filename used for communication. */
278 ocd_open (char *name, int from_tty, enum ocd_target_type target_type,
279 struct target_ops *ops)
281 unsigned char buf[10], *p;
285 error ("To open an OCD connection, you need to specify the\n\
286 device the OCD device is attached to (e.g. /dev/ttya).");
288 target_preopen (from_tty);
292 unpush_target (current_ops);
294 ocd_desc = serial_open (name);
296 perror_with_name (name);
300 if (serial_setbaudrate (ocd_desc, baud_rate))
302 serial_close (ocd_desc);
303 perror_with_name (name);
307 serial_raw (ocd_desc);
309 /* If there is something sitting in the buffer we might take it as a
310 response to a command, which would be bad. */
311 serial_flush_input (ocd_desc);
315 puts_filtered ("Remote target wiggler connected to ");
316 puts_filtered (name);
317 puts_filtered ("\n");
319 push_target (current_ops); /* Switch to using remote target now */
321 /* Without this, some commands which require an active target (such as kill)
322 won't work. This variable serves (at least) double duty as both the pid
323 of the target process (if it has such), and as a flag indicating that a
324 target is active. These functions should be split out into seperate
325 variables, especially since GDB will someday have a notion of debugging
326 several processes. */
328 inferior_ptid = pid_to_ptid (42000);
329 /* Start the remote connection; if error (0), discard this target.
330 In particular, if the user quits, be sure to discard it
331 (we'd be in an inconsistent state otherwise). */
332 if (!catch_errors (ocd_start_remote, &target_type,
333 "Couldn't establish connection to remote target\n",
337 error ("Failed to connect to OCD.");
341 /* This takes a program previously attached to and detaches it. After
342 this is done, GDB can be used to debug some other program. We
343 better not have left any breakpoints in the target program or it'll
344 die when it hits one. */
347 ocd_detach (char *args, int from_tty)
350 error ("Argument given to \"detach\" when remotely debugging.");
354 puts_filtered ("Ending remote debugging.\n");
357 /* Tell the remote machine to resume. */
360 ocd_resume (ptid_t ptid, int step, enum target_signal siggnal)
365 ocd_do_command (OCD_STEP, &last_run_status, &pktlen);
367 ocd_do_command (OCD_RUN, &last_run_status, &pktlen);
376 ocd_do_command (OCD_STOP, &status, &pktlen);
378 if (!(status & OCD_FLAG_BDM))
379 error ("Can't stop target via BDM");
382 static volatile int ocd_interrupt_flag;
384 /* Send ^C to target to halt it. Target will respond, and send us a
388 ocd_interrupt (int signo)
390 /* If this doesn't work, try more severe steps. */
391 signal (signo, ocd_interrupt_twice);
394 printf_unfiltered ("ocd_interrupt called\n");
401 ocd_put_packet (buf, 1);
402 ocd_interrupt_flag = 1;
406 static void (*ofunc) ();
408 /* The user typed ^C twice. */
410 ocd_interrupt_twice (int signo)
412 signal (signo, ofunc);
416 signal (signo, ocd_interrupt);
419 /* Ask the user what to do when an interrupt is received. */
422 interrupt_query (void)
424 target_terminal_ours ();
426 if (query ("Interrupted while waiting for the program.\n\
427 Give up (and stop debugging it)? "))
429 target_mourn_inferior ();
430 throw_exception (RETURN_QUIT);
433 target_terminal_inferior ();
436 /* If nonzero, ignore the next kill. */
437 static int kill_kludge;
439 /* Wait until the remote machine stops, then return,
440 storing status in STATUS just as `wait' would.
441 Returns "pid" (though it's not clear what, if anything, that
442 means in the case of this target). */
452 ocd_interrupt_flag = 0;
454 /* Target might already be stopped by the time we get here. */
455 /* If we aren't already stopped, we need to loop until we've dropped
456 back into BDM mode */
458 while (!(last_run_status & OCD_FLAG_BDM))
461 ocd_put_packet (buf, 1);
462 p = ocd_get_packet (OCD_AYT, &pktlen, -1);
464 ofunc = (void (*)()) signal (SIGINT, ocd_interrupt);
465 signal (SIGINT, ofunc);
468 error ("Truncated response packet from OCD device");
470 last_run_status = p[1];
474 ocd_error ("target_wait:", error_code);
476 if (last_run_status & OCD_FLAG_PWF)
477 error ("OCD device lost VCC at BDM interface.");
478 else if (last_run_status & OCD_FLAG_CABLE_DISC)
479 error ("OCD device cable appears to have been disconnected.");
482 if (ocd_interrupt_flag)
488 /* Read registers from the OCD device. Specify the starting and ending
489 register number. Return the number of regs actually read in *NUMREGS.
490 Returns a pointer to a static array containing the register contents. */
493 ocd_read_bdm_registers (int first_bdm_regno, int last_bdm_regno, int *reglen)
495 unsigned char buf[10];
499 int error_code, status;
502 buf[0] = OCD_READ_REGS;
503 buf[1] = first_bdm_regno >> 8;
504 buf[2] = first_bdm_regno & 0xff;
505 buf[3] = last_bdm_regno >> 8;
506 buf[4] = last_bdm_regno & 0xff;
508 ocd_put_packet (buf, 5);
509 p = ocd_get_packet (OCD_READ_REGS, &pktlen, remote_timeout);
515 ocd_error ("read_bdm_registers:", error_code);
523 error ("Register block size bad: %d", i);
532 /* Read register BDM_REGNO and returns its value ala read_register() */
535 ocd_read_bdm_register (int bdm_regno)
541 p = ocd_read_bdm_registers (bdm_regno, bdm_regno, ®len);
542 regval = extract_unsigned_integer (p, reglen);
548 ocd_write_bdm_registers (int first_bdm_regno, unsigned char *regptr, int reglen)
552 int error_code, status;
555 buf = alloca (4 + reglen);
557 buf[0] = OCD_WRITE_REGS;
558 buf[1] = first_bdm_regno >> 8;
559 buf[2] = first_bdm_regno & 0xff;
561 memcpy (buf + 4, regptr, reglen);
563 ocd_put_packet (buf, 4 + reglen);
564 p = ocd_get_packet (OCD_WRITE_REGS, &pktlen, remote_timeout);
567 error ("Truncated response packet from OCD device");
573 ocd_error ("ocd_write_bdm_registers:", error_code);
577 ocd_write_bdm_register (int bdm_regno, CORE_ADDR reg)
579 unsigned char buf[4];
581 store_unsigned_integer (buf, 4, reg);
583 ocd_write_bdm_registers (bdm_regno, buf, 4);
587 ocd_prepare_to_store (void)
591 /* Write memory data directly to the remote machine.
592 This does not inform the data cache; the data cache uses this.
593 MEMADDR is the address in the remote memory space.
594 MYADDR is the address of the buffer in our space.
595 LEN is the number of bytes.
597 Returns number of bytes transferred, or 0 for error. */
599 static int write_mem_command = OCD_WRITE_MEM;
602 ocd_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
610 buf[0] = write_mem_command;
611 buf[5] = 1; /* Write as bytes */
612 buf[6] = 0; /* Don't verify */
618 int status, error_code;
620 numbytes = min (len, 256 - 8);
622 buf[1] = memaddr >> 24;
623 buf[2] = memaddr >> 16;
624 buf[3] = memaddr >> 8;
629 memcpy (&buf[8], myaddr, numbytes);
630 ocd_put_packet (buf, 8 + numbytes);
631 p = ocd_get_packet (OCD_WRITE_MEM, &pktlen, remote_timeout);
633 error ("Truncated response packet from OCD device");
638 if (error_code == 0x11) /* Got a bus error? */
640 CORE_ADDR error_address;
642 error_address = p[3] << 24;
643 error_address |= p[4] << 16;
644 error_address |= p[5] << 8;
645 error_address |= p[6];
646 numbytes = error_address - memaddr;
654 else if (error_code != 0)
655 ocd_error ("ocd_write_bytes:", error_code);
662 return origlen - len;
665 /* Read memory data directly from the remote machine.
666 This does not use the data cache; the data cache uses this.
667 MEMADDR is the address in the remote memory space.
668 MYADDR is the address of the buffer in our space.
669 LEN is the number of bytes.
671 Returns number of bytes transferred, or 0 for error. */
674 ocd_read_bytes (CORE_ADDR memaddr, char *myaddr, int len)
682 buf[0] = OCD_READ_MEM;
683 buf[5] = 1; /* Read as bytes */
689 int status, error_code;
691 numbytes = min (len, 256 - 7);
693 buf[1] = memaddr >> 24;
694 buf[2] = memaddr >> 16;
695 buf[3] = memaddr >> 8;
700 ocd_put_packet (buf, 7);
701 p = ocd_get_packet (OCD_READ_MEM, &pktlen, remote_timeout);
703 error ("Truncated response packet from OCD device");
708 if (error_code == 0x11) /* Got a bus error? */
710 CORE_ADDR error_address;
712 error_address = p[3] << 24;
713 error_address |= p[4] << 16;
714 error_address |= p[5] << 8;
715 error_address |= p[6];
716 numbytes = error_address - memaddr;
724 else if (error_code != 0)
725 ocd_error ("ocd_read_bytes:", error_code);
727 memcpy (myaddr, &p[4], numbytes);
734 return origlen - len;
737 /* Read or write LEN bytes from inferior memory at MEMADDR, transferring
738 to or from debugger address MYADDR. Write to inferior if SHOULD_WRITE is
739 nonzero. Returns length of data written or read; 0 for error. TARGET
744 ocd_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int should_write,
745 struct mem_attrib *attrib, struct target_ops *target)
750 res = ocd_write_bytes (memaddr, myaddr, len);
752 res = ocd_read_bytes (memaddr, myaddr, len);
758 ocd_files_info (struct target_ops *ignore)
760 puts_filtered ("Debugging a target over a serial line.\n");
763 /* Stuff for dealing with the packets which are part of this protocol.
764 See comment at top of file for details. */
766 /* Read a single character from the remote side, handling wierd errors. */
769 readchar (int timeout)
773 ch = serial_readchar (ocd_desc, timeout);
778 error ("Remote connection closed");
780 perror_with_name ("Remote communication error");
788 /* Read a character from the data stream, dequoting as necessary. SYN is
789 treated special. Any SYNs appearing in the data stream are returned as the
790 distinct value RAW_SYN (which has a value > 8 bits and therefore cannot be
791 mistaken for real data). */
794 get_quoted_char (int timeout)
798 ch = readchar (timeout);
803 error ("Timeout in mid-packet, aborting");
807 ch = readchar (timeout);
816 static unsigned char pkt[256 * 2 + 10], *pktp; /* Worst case */
827 if (serial_write (ocd_desc, pkt, pktp - pkt))
828 perror_with_name ("output_packet: write failed");
833 /* Output a quoted character. SYNs and DLEs are quoted. Everything else goes
834 through untouched. */
837 put_quoted_char (int c)
850 /* Send a packet to the OCD device. The packet framed by a SYN character,
851 a byte count and a checksum. The byte count only counts the number of
852 bytes between the count and the checksum. A count of zero actually
853 means 256. Any SYNs within the packet (including the checksum and
854 count) must be quoted. The quote character must be quoted as well.
855 Quoting is done by replacing the character with the two-character sequence
856 DLE, {char} | 0100. Note that the quoting mechanism has no effect on the
860 stu_put_packet (unsigned char *buf, int len)
862 unsigned char checksum;
865 if (len == 0 || len > 256)
866 internal_error (__FILE__, __LINE__, "failed internal consistency check"); /* Can't represent 0 length packet */
872 put_quoted_char (RAW_SYN);
886 put_quoted_char (-checksum & 0xff);
893 /* Send a packet to the OCD device. The packet framed by a SYN character,
894 a byte count and a checksum. The byte count only counts the number of
895 bytes between the count and the checksum. A count of zero actually
896 means 256. Any SYNs within the packet (including the checksum and
897 count) must be quoted. The quote character must be quoted as well.
898 Quoting is done by replacing the character with the two-character sequence
899 DLE, {char} | 0100. Note that the quoting mechanism has no effect on the
903 ocd_put_packet (unsigned char *buf, int len)
905 unsigned char checksum;
907 unsigned char *packet, *packet_ptr;
909 packet = alloca (len + 1 + 1); /* packet + SYN + checksum */
914 *packet_ptr++ = 0x55;
924 *packet_ptr++ = -checksum;
925 if (serial_write (ocd_desc, packet, packet_ptr - packet))
926 perror_with_name ("output_packet: write failed");
931 /* Get a packet from the OCD device. Timeout is only enforced for the
932 first byte of the packet. Subsequent bytes are expected to arrive in
933 time <= remote_timeout. Returns a pointer to a static buffer containing
934 the payload of the packet. *LENP contains the length of the packet.
937 static unsigned char *
938 stu_get_packet (unsigned char cmd, int *lenp, int timeout)
942 static unsigned char buf[256 + 10], *p;
943 unsigned char checksum;
947 ch = get_quoted_char (timeout);
950 error ("get_packet (readchar): %d", ch);
955 found_syn: /* Found the start of a packet */
960 len = get_quoted_char (remote_timeout);
970 len++; /* Include checksum */
974 ch = get_quoted_char (remote_timeout);
986 error ("Response phase error. Got 0x%x, expected 0x%x", buf[0], cmd);
994 /* Get a packet from the OCD device. Timeout is only enforced for the
995 first byte of the packet. Subsequent bytes are expected to arrive in
996 time <= remote_timeout. Returns a pointer to a static buffer containing
997 the payload of the packet. *LENP contains the length of the packet.
1000 static unsigned char *
1001 ocd_get_packet (int cmd, int *lenp, int timeout)
1005 static unsigned char packet[512];
1006 unsigned char *packet_ptr;
1007 unsigned char checksum;
1009 ch = readchar (timeout);
1012 error ("ocd_get_packet (readchar): %d", ch);
1015 error ("ocd_get_packet (readchar): %d", ch);
1017 /* Found the start of a packet */
1019 packet_ptr = packet;
1022 /* Read command char. That sort of tells us how long the packet is. */
1024 ch = readchar (timeout);
1027 error ("ocd_get_packet (readchar): %d", ch);
1034 ch = readchar (timeout);
1037 error ("ocd_get_packet (readchar): %d", ch);
1041 /* Get error code. */
1043 ch = readchar (timeout);
1046 error ("ocd_get_packet (readchar): %d", ch);
1050 switch (ch) /* Figure out length of packet */
1052 case 0x7: /* Write verify error? */
1053 len = 8; /* write address, value read back */
1055 case 0x11: /* Bus error? */
1056 /* write address, read flag */
1057 case 0x15: /* Internal error */
1058 len = 5; /* error code, vector */
1060 default: /* Error w/no params */
1063 case 0x0: /* Normal result */
1066 case OCD_AYT: /* Are You There? */
1067 case OCD_SET_BAUD_RATE: /* Set Baud Rate */
1068 case OCD_INIT: /* Initialize OCD device */
1069 case OCD_SET_SPEED: /* Set Speed */
1070 case OCD_SET_FUNC_CODE: /* Set Function Code */
1071 case OCD_SET_CTL_FLAGS: /* Set Control Flags */
1072 case OCD_SET_BUF_ADDR: /* Set Register Buffer Address */
1073 case OCD_RUN: /* Run Target from PC */
1074 case OCD_RUN_ADDR: /* Run Target from Specified Address */
1075 case OCD_STOP: /* Stop Target */
1076 case OCD_RESET_RUN: /* Reset Target and Run */
1077 case OCD_RESET: /* Reset Target and Halt */
1078 case OCD_STEP: /* Single Step */
1079 case OCD_WRITE_REGS: /* Write Register */
1080 case OCD_WRITE_MEM: /* Write Memory */
1081 case OCD_FILL_MEM: /* Fill Memory */
1082 case OCD_MOVE_MEM: /* Move Memory */
1083 case OCD_WRITE_INT_MEM: /* Write Internal Memory */
1084 case OCD_JUMP: /* Jump to Subroutine */
1085 case OCD_ERASE_FLASH: /* Erase flash memory */
1086 case OCD_PROGRAM_FLASH: /* Write flash memory */
1087 case OCD_EXIT_MON: /* Exit the flash programming monitor */
1088 case OCD_ENTER_MON: /* Enter the flash programming monitor */
1089 case OCD_LOG_FILE: /* Make Wigglers.dll save Wigglers.log */
1090 case OCD_SET_CONNECTION: /* Set type of connection in Wigglers.dll */
1093 case OCD_GET_VERSION: /* Get Version */
1096 case OCD_GET_STATUS_MASK: /* Get Status Mask */
1099 case OCD_GET_CTRS: /* Get Error Counters */
1100 case OCD_READ_REGS: /* Read Register */
1101 case OCD_READ_MEM: /* Read Memory */
1102 case OCD_READ_INT_MEM: /* Read Internal Memory */
1106 error ("ocd_get_packet: unknown packet type 0x%x\n", ch);
1110 if (len == 257) /* Byte stream? */
1111 { /* Yes, byte streams contain the length */
1112 ch = readchar (timeout);
1115 error ("ocd_get_packet (readchar): %d", ch);
1123 while (len-- >= 0) /* Do rest of packet and checksum */
1125 ch = readchar (timeout);
1128 error ("ocd_get_packet (readchar): %d", ch);
1134 error ("ocd_get_packet: bad packet checksum");
1136 if (cmd != -1 && cmd != packet[0])
1137 error ("Response phase error. Got 0x%x, expected 0x%x", packet[0], cmd);
1139 *lenp = packet_ptr - packet - 1; /* Subtract checksum byte */
1144 /* Execute a simple (one-byte) command. Returns a pointer to the data
1145 following the error code. */
1147 static unsigned char *
1148 ocd_do_command (int cmd, int *statusp, int *lenp)
1150 unsigned char buf[100], *p;
1151 int status, error_code;
1154 unsigned char logbuf[100];
1158 ocd_put_packet (buf, 1); /* Send command */
1159 p = ocd_get_packet (*buf, lenp, remote_timeout);
1162 error ("Truncated response packet from OCD device");
1167 if (error_code != 0)
1169 sprintf (errbuf, "ocd_do_command (0x%x):", cmd);
1170 ocd_error (errbuf, error_code);
1173 if (status & OCD_FLAG_PWF)
1174 error ("OCD device can't detect VCC at BDM interface.");
1175 else if (status & OCD_FLAG_CABLE_DISC)
1176 error ("BDM cable appears to be disconnected.");
1180 logbuf[0] = OCD_LOG_FILE;
1181 logbuf[1] = 3; /* close existing WIGGLERS.LOG */
1182 ocd_put_packet (logbuf, 2);
1183 ocd_get_packet (logbuf[0], &logpktlen, remote_timeout);
1185 logbuf[0] = OCD_LOG_FILE;
1186 logbuf[1] = 2; /* append to existing WIGGLERS.LOG */
1187 ocd_put_packet (logbuf, 2);
1188 ocd_get_packet (logbuf[0], &logpktlen, remote_timeout);
1196 /* For some mysterious reason, wait_for_inferior calls kill instead of
1197 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
1201 target_mourn_inferior ();
1205 /* Don't wait for it to die. I'm not really sure it matters whether
1207 target_mourn_inferior ();
1213 unpush_target (current_ops);
1214 generic_mourn_inferior ();
1217 /* All we actually do is set the PC to the start address of exec_bfd, and start
1218 the program at that point. */
1221 ocd_create_inferior (char *exec_file, char *args, char **env)
1223 if (args && (*args != '\000'))
1224 error ("Args are not supported by BDM.");
1226 clear_proceed_status ();
1227 proceed (bfd_get_start_address (exec_bfd), TARGET_SIGNAL_0, 0);
1231 ocd_load (char *args, int from_tty)
1233 generic_load (args, from_tty);
1235 inferior_ptid = null_ptid;
1237 /* This is necessary because many things were based on the PC at the time that
1238 we attached to the monitor, which is no longer valid now that we have loaded
1239 new code (and just changed the PC). Another way to do this might be to call
1240 normal_stop, except that the stack may not be valid, and things would get
1241 horribly confused... */
1243 clear_symtab_users ();
1246 /* This should be defined for each target */
1247 /* But we want to be able to compile this file for some configurations
1248 not yet supported fully */
1250 #define BDM_BREAKPOINT {0x0,0x0,0x0,0x0} /* For ppc 8xx */
1252 #define BDM_BREAKPOINT {0x4a,0xfa} /* BGND insn used for CPU32 */
1255 /* BDM (at least on CPU32) uses a different breakpoint */
1258 ocd_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
1260 static char break_insn[] = BDM_BREAKPOINT;
1263 val = target_read_memory (addr, contents_cache, sizeof (break_insn));
1266 val = target_write_memory (addr, break_insn, sizeof (break_insn));
1272 ocd_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
1274 static char break_insn[] = BDM_BREAKPOINT;
1277 val = target_write_memory (addr, contents_cache, sizeof (break_insn));
1283 bdm_command (char *args, int from_tty)
1285 error ("bdm command must be followed by `reset'");
1289 bdm_reset_command (char *args, int from_tty)
1294 error ("Not connected to OCD device.");
1296 ocd_do_command (OCD_RESET, &status, &pktlen);
1297 dcache_invalidate (target_dcache);
1298 registers_changed ();
1302 bdm_restart_command (char *args, int from_tty)
1307 error ("Not connected to OCD device.");
1309 ocd_do_command (OCD_RESET_RUN, &status, &pktlen);
1310 last_run_status = status;
1311 clear_proceed_status ();
1312 wait_for_inferior ();
1316 /* Temporary replacement for target_store_registers(). This prevents
1317 generic_load from trying to set the PC. */
1320 noop_store_registers (int regno)
1325 bdm_update_flash_command (char *args, int from_tty)
1328 struct cleanup *old_chain;
1329 void (*store_registers_tmp) (int);
1332 error ("Not connected to OCD device.");
1335 error ("Must specify file containing new OCD code.");
1337 /* old_chain = make_cleanup (flash_cleanup, 0); */
1339 ocd_do_command (OCD_ENTER_MON, &status, &pktlen);
1341 ocd_do_command (OCD_ERASE_FLASH, &status, &pktlen);
1343 write_mem_command = OCD_PROGRAM_FLASH;
1344 store_registers_tmp = current_target.to_store_registers;
1345 current_target.to_store_registers = noop_store_registers;
1347 generic_load (args, from_tty);
1349 current_target.to_store_registers = store_registers_tmp;
1350 write_mem_command = OCD_WRITE_MEM;
1352 ocd_do_command (OCD_EXIT_MON, &status, &pktlen);
1354 /* discard_cleanups (old_chain); */
1358 bdm_read_register_command (char *args, int from_tty)
1360 /* XXX repeat should go on to the next register */
1363 error ("Not connected to OCD device.");
1366 error ("Must specify BDM register number.");
1371 _initialize_remote_ocd (void)
1373 extern struct cmd_list_element *cmdlist;
1374 static struct cmd_list_element *ocd_cmd_list = NULL;
1376 add_show_from_set (add_set_cmd ("remotetimeout", no_class,
1377 var_integer, (char *) &remote_timeout,
1378 "Set timeout value for remote read.\n", &setlist),
1381 add_prefix_cmd ("ocd", class_obscure, bdm_command, "", &ocd_cmd_list, "ocd ",
1384 add_cmd ("reset", class_obscure, bdm_reset_command, "", &ocd_cmd_list);
1385 add_cmd ("restart", class_obscure, bdm_restart_command, "", &ocd_cmd_list);
1386 add_cmd ("update-flash", class_obscure, bdm_update_flash_command, "", &ocd_cmd_list);
1387 /* add_cmd ("read-register", class_obscure, bdm_read_register_command, "", &ocd_cmd_list); */