1 /* Target communications support for Macraigor Systems' On-Chip Debugging
2 Copyright 1996, 1997 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
23 #include "gdb_string.h"
33 #include "gdb-stabs.h"
34 #include <sys/types.h>
39 /* Prototypes for local functions */
41 static int ocd_read_bytes (CORE_ADDR memaddr, char *myaddr, int len);
43 static int ocd_start_remote (PTR dummy);
45 static int readchar (int timeout);
47 static void reset_packet (void);
49 static void output_packet (void);
51 static int get_quoted_char (int timeout);
53 static void put_quoted_char (int c);
55 static void ocd_interrupt (int signo);
57 static void ocd_interrupt_twice (int signo);
59 static void interrupt_query (void);
61 static unsigned char *ocd_do_command (int cmd, int *statusp, int *lenp);
63 static void ocd_put_packet (unsigned char *packet, int pktlen);
65 static unsigned char *ocd_get_packet (int cmd, int *pktlen, int timeout);
67 static struct target_ops *current_ops = NULL;
69 static int last_run_status;
71 /* This was 5 seconds, which is a long time to sit and wait.
72 Unless this is going though some terminal server or multiplexer or
73 other form of hairy serial connection, I would think 2 seconds would
77 /* FIXME: Change to allow option to set timeout value on a per target
79 static int remote_timeout = 2;
82 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
83 ocd_open knows that we don't have a file open when the program
85 static serial_t ocd_desc = NULL;
88 ocd_error (char *s, int error_code)
92 fputs_filtered (s, gdb_stderr);
93 fputs_filtered (" ", gdb_stderr);
104 s = "Cable disconnected";
107 s = "Couldn't enter OCD mode";
110 s = "Target stuck in reset";
113 s = "OCD hasn't been initialized";
116 s = "Write verify failed";
119 s = "Reg buff error (during MPC5xx fp reg read/write)";
122 s = "Invalid CPU register access attempt failed";
128 s = "Checksum error";
131 s = "Illegal command";
134 s = "Parameter error";
137 s = "Internal error";
140 s = "Flash erase error";
143 sprintf (buf, "Unknown error code %d", error_code);
150 /* Return nonzero if the thread TH is still alive on the remote system. */
153 ocd_thread_alive (int th)
158 /* Clean up connection to a remote debugger. */
162 ocd_close (int quitting)
165 SERIAL_CLOSE (ocd_desc);
169 /* Stub for catch_errors. */
172 ocd_start_remote (PTR dummy)
174 unsigned char buf[10], *p;
179 enum ocd_target_type target_type;
181 target_type = *(enum ocd_target_type *) dummy;
183 immediate_quit++; /* Allow user to interrupt it */
185 SERIAL_SEND_BREAK (ocd_desc); /* Wake up the wiggler */
187 speed = 80; /* Divide clock by 4000 */
191 buf[2] = speed & 0xff;
192 buf[3] = target_type;
193 ocd_put_packet (buf, 4); /* Init OCD params */
194 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
197 error ("Truncated response packet from OCD device");
203 ocd_error ("OCD_INIT:", error_code);
205 ocd_do_command (OCD_AYT, &status, &pktlen);
207 p = ocd_do_command (OCD_GET_VERSION, &status, &pktlen);
209 printf_unfiltered ("[Wiggler version %x.%x, capability 0x%x]\n",
210 p[0], p[1], (p[2] << 16) | p[3]);
213 /* Reset the target */
215 ocd_do_command (OCD_RESET_RUN, &status, &pktlen);
216 /* ocd_do_command (OCD_RESET, &status, &pktlen); */
219 /* If processor is still running, stop it. */
221 if (!(status & OCD_FLAG_BDM))
225 /* When using a target box, we want to asynchronously return status when
226 target stops. The OCD_SET_CTL_FLAGS command is ignored by Wigglers.dll
227 when using a parallel Wiggler */
228 buf[0] = OCD_SET_CTL_FLAGS;
231 ocd_put_packet (buf, 3);
233 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
236 error ("Truncated response packet from OCD device");
242 ocd_error ("OCD_SET_CTL_FLAGS:", error_code);
247 /* This is really the job of start_remote however, that makes an assumption
248 that the target is about to print out a status message of some sort. That
249 doesn't happen here (in fact, it may not be possible to get the monitor to
250 send the appropriate packet). */
252 flush_cached_frames ();
253 registers_changed ();
254 stop_pc = read_pc ();
255 set_current_frame (create_new_frame (read_fp (), stop_pc));
256 select_frame (get_current_frame (), 0);
257 print_stack_frame (selected_frame, -1, 1);
259 buf[0] = OCD_LOG_FILE;
260 buf[1] = 3; /* close existing WIGGLERS.LOG */
261 ocd_put_packet (buf, 2);
262 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
264 buf[0] = OCD_LOG_FILE;
265 buf[1] = 2; /* append to existing WIGGLERS.LOG */
266 ocd_put_packet (buf, 2);
267 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
272 /* Open a connection to a remote debugger.
273 NAME is the filename used for communication. */
276 ocd_open (char *name, int from_tty, enum ocd_target_type target_type,
277 struct target_ops *ops)
279 unsigned char buf[10], *p;
283 error ("To open an OCD connection, you need to specify the\n\
284 device the OCD device is attached to (e.g. /dev/ttya).");
286 target_preopen (from_tty);
290 unpush_target (current_ops);
292 if (strncmp (name, "wiggler", 7) == 0)
294 ocd_desc = SERIAL_OPEN ("ocd");
296 perror_with_name (name);
298 buf[0] = OCD_LOG_FILE;
299 buf[1] = 1; /* open new or overwrite existing WIGGLERS.LOG */
300 ocd_put_packet (buf, 2);
301 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
303 buf[0] = OCD_SET_CONNECTION;
304 buf[1] = 0x01; /* atoi (name[11]); */
305 ocd_put_packet (buf, 2);
306 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
309 /* not using Wigglers.dll */
311 ocd_desc = SERIAL_OPEN (name);
313 perror_with_name (name);
318 if (SERIAL_SETBAUDRATE (ocd_desc, baud_rate))
320 SERIAL_CLOSE (ocd_desc);
321 perror_with_name (name);
325 SERIAL_RAW (ocd_desc);
327 /* If there is something sitting in the buffer we might take it as a
328 response to a command, which would be bad. */
329 SERIAL_FLUSH_INPUT (ocd_desc);
333 puts_filtered ("Remote target wiggler connected to ");
334 puts_filtered (name);
335 puts_filtered ("\n");
337 push_target (current_ops); /* Switch to using remote target now */
339 /* Without this, some commands which require an active target (such as kill)
340 won't work. This variable serves (at least) double duty as both the pid
341 of the target process (if it has such), and as a flag indicating that a
342 target is active. These functions should be split out into seperate
343 variables, especially since GDB will someday have a notion of debugging
344 several processes. */
346 inferior_pid = 42000;
347 /* Start the remote connection; if error (0), discard this target.
348 In particular, if the user quits, be sure to discard it
349 (we'd be in an inconsistent state otherwise). */
350 if (!catch_errors (ocd_start_remote, &target_type,
351 "Couldn't establish connection to remote target\n",
355 error ("Failed to connect to OCD.");
359 /* This takes a program previously attached to and detaches it. After
360 this is done, GDB can be used to debug some other program. We
361 better not have left any breakpoints in the target program or it'll
362 die when it hits one. */
365 ocd_detach (char *args, int from_tty)
368 error ("Argument given to \"detach\" when remotely debugging.");
372 puts_filtered ("Ending remote debugging.\n");
375 /* Tell the remote machine to resume. */
378 ocd_resume (int pid, int step, enum target_signal siggnal)
383 ocd_do_command (OCD_STEP, &last_run_status, &pktlen);
385 ocd_do_command (OCD_RUN, &last_run_status, &pktlen);
394 ocd_do_command (OCD_STOP, &status, &pktlen);
396 if (!(status & OCD_FLAG_BDM))
397 error ("Can't stop target via BDM");
400 static volatile int ocd_interrupt_flag;
402 /* Send ^C to target to halt it. Target will respond, and send us a
406 ocd_interrupt (int signo)
408 /* If this doesn't work, try more severe steps. */
409 signal (signo, ocd_interrupt_twice);
412 printf_unfiltered ("ocd_interrupt called\n");
419 ocd_put_packet (buf, 1);
420 ocd_interrupt_flag = 1;
424 static void (*ofunc) ();
426 /* The user typed ^C twice. */
428 ocd_interrupt_twice (int signo)
430 signal (signo, ofunc);
434 signal (signo, ocd_interrupt);
437 /* Ask the user what to do when an interrupt is received. */
440 interrupt_query (void)
442 target_terminal_ours ();
444 if (query ("Interrupted while waiting for the program.\n\
445 Give up (and stop debugging it)? "))
447 target_mourn_inferior ();
448 return_to_top_level (RETURN_QUIT);
451 target_terminal_inferior ();
454 /* If nonzero, ignore the next kill. */
455 static int kill_kludge;
457 /* Wait until the remote machine stops, then return,
458 storing status in STATUS just as `wait' would.
459 Returns "pid" (though it's not clear what, if anything, that
460 means in the case of this target). */
470 ocd_interrupt_flag = 0;
472 /* Target might already be stopped by the time we get here. */
473 /* If we aren't already stopped, we need to loop until we've dropped
474 back into BDM mode */
476 while (!(last_run_status & OCD_FLAG_BDM))
479 ocd_put_packet (buf, 1);
480 p = ocd_get_packet (OCD_AYT, &pktlen, -1);
482 ofunc = (void (*)()) signal (SIGINT, ocd_interrupt);
483 signal (SIGINT, ofunc);
486 error ("Truncated response packet from OCD device");
488 last_run_status = p[1];
492 ocd_error ("target_wait:", error_code);
494 if (last_run_status & OCD_FLAG_PWF)
495 error ("OCD device lost VCC at BDM interface.");
496 else if (last_run_status & OCD_FLAG_CABLE_DISC)
497 error ("OCD device cable appears to have been disconnected.");
500 if (ocd_interrupt_flag)
506 /* Read registers from the OCD device. Specify the starting and ending
507 register number. Return the number of regs actually read in *NUMREGS.
508 Returns a pointer to a static array containing the register contents. */
511 ocd_read_bdm_registers (int first_bdm_regno, int last_bdm_regno, int *reglen)
513 unsigned char buf[10];
517 int error_code, status;
520 buf[0] = OCD_READ_REGS;
521 buf[1] = first_bdm_regno >> 8;
522 buf[2] = first_bdm_regno & 0xff;
523 buf[3] = last_bdm_regno >> 8;
524 buf[4] = last_bdm_regno & 0xff;
526 ocd_put_packet (buf, 5);
527 p = ocd_get_packet (OCD_READ_REGS, &pktlen, remote_timeout);
533 ocd_error ("read_bdm_registers:", error_code);
541 error ("Register block size bad: %d", i);
550 /* Read register BDM_REGNO and returns its value ala read_register() */
553 ocd_read_bdm_register (int bdm_regno)
559 p = ocd_read_bdm_registers (bdm_regno, bdm_regno, ®len);
560 regval = extract_unsigned_integer (p, reglen);
566 ocd_write_bdm_registers (int first_bdm_regno, unsigned char *regptr, int reglen)
570 int error_code, status;
573 buf = alloca (4 + reglen);
575 buf[0] = OCD_WRITE_REGS;
576 buf[1] = first_bdm_regno >> 8;
577 buf[2] = first_bdm_regno & 0xff;
579 memcpy (buf + 4, regptr, reglen);
581 ocd_put_packet (buf, 4 + reglen);
582 p = ocd_get_packet (OCD_WRITE_REGS, &pktlen, remote_timeout);
585 error ("Truncated response packet from OCD device");
591 ocd_error ("ocd_write_bdm_registers:", error_code);
595 ocd_write_bdm_register (int bdm_regno, CORE_ADDR reg)
597 unsigned char buf[4];
599 store_unsigned_integer (buf, 4, reg);
601 ocd_write_bdm_registers (bdm_regno, buf, 4);
605 ocd_prepare_to_store (void)
609 /* Write memory data directly to the remote machine.
610 This does not inform the data cache; the data cache uses this.
611 MEMADDR is the address in the remote memory space.
612 MYADDR is the address of the buffer in our space.
613 LEN is the number of bytes.
615 Returns number of bytes transferred, or 0 for error. */
617 static int write_mem_command = OCD_WRITE_MEM;
620 ocd_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
628 buf[0] = write_mem_command;
629 buf[5] = 1; /* Write as bytes */
630 buf[6] = 0; /* Don't verify */
636 int status, error_code;
638 numbytes = min (len, 256 - 8);
640 buf[1] = memaddr >> 24;
641 buf[2] = memaddr >> 16;
642 buf[3] = memaddr >> 8;
647 memcpy (&buf[8], myaddr, numbytes);
648 ocd_put_packet (buf, 8 + numbytes);
649 p = ocd_get_packet (OCD_WRITE_MEM, &pktlen, remote_timeout);
651 error ("Truncated response packet from OCD device");
656 if (error_code == 0x11) /* Got a bus error? */
658 CORE_ADDR error_address;
660 error_address = p[3] << 24;
661 error_address |= p[4] << 16;
662 error_address |= p[5] << 8;
663 error_address |= p[6];
664 numbytes = error_address - memaddr;
672 else if (error_code != 0)
673 ocd_error ("ocd_write_bytes:", error_code);
680 return origlen - len;
683 /* Read memory data directly from the remote machine.
684 This does not use the data cache; the data cache uses this.
685 MEMADDR is the address in the remote memory space.
686 MYADDR is the address of the buffer in our space.
687 LEN is the number of bytes.
689 Returns number of bytes transferred, or 0 for error. */
692 ocd_read_bytes (CORE_ADDR memaddr, char *myaddr, int len)
700 buf[0] = OCD_READ_MEM;
701 buf[5] = 1; /* Read as bytes */
707 int status, error_code;
709 numbytes = min (len, 256 - 7);
711 buf[1] = memaddr >> 24;
712 buf[2] = memaddr >> 16;
713 buf[3] = memaddr >> 8;
718 ocd_put_packet (buf, 7);
719 p = ocd_get_packet (OCD_READ_MEM, &pktlen, remote_timeout);
721 error ("Truncated response packet from OCD device");
726 if (error_code == 0x11) /* Got a bus error? */
728 CORE_ADDR error_address;
730 error_address = p[3] << 24;
731 error_address |= p[4] << 16;
732 error_address |= p[5] << 8;
733 error_address |= p[6];
734 numbytes = error_address - memaddr;
742 else if (error_code != 0)
743 ocd_error ("ocd_read_bytes:", error_code);
745 memcpy (myaddr, &p[4], numbytes);
752 return origlen - len;
755 /* Read or write LEN bytes from inferior memory at MEMADDR, transferring
756 to or from debugger address MYADDR. Write to inferior if SHOULD_WRITE is
757 nonzero. Returns length of data written or read; 0 for error. TARGET
762 ocd_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int should_write,
763 struct target_ops *target)
768 res = ocd_write_bytes (memaddr, myaddr, len);
770 res = ocd_read_bytes (memaddr, myaddr, len);
776 ocd_files_info (struct target_ops *ignore)
778 puts_filtered ("Debugging a target over a serial line.\n");
781 /* Stuff for dealing with the packets which are part of this protocol.
782 See comment at top of file for details. */
784 /* Read a single character from the remote side, handling wierd errors. */
787 readchar (int timeout)
791 ch = SERIAL_READCHAR (ocd_desc, timeout);
796 error ("Remote connection closed");
798 perror_with_name ("Remote communication error");
806 /* Read a character from the data stream, dequoting as necessary. SYN is
807 treated special. Any SYNs appearing in the data stream are returned as the
808 distinct value RAW_SYN (which has a value > 8 bits and therefore cannot be
809 mistaken for real data). */
812 get_quoted_char (int timeout)
816 ch = readchar (timeout);
821 error ("Timeout in mid-packet, aborting");
825 ch = readchar (timeout);
834 static unsigned char pkt[256 * 2 + 10], *pktp; /* Worst case */
845 if (SERIAL_WRITE (ocd_desc, pkt, pktp - pkt))
846 perror_with_name ("output_packet: write failed");
851 /* Output a quoted character. SYNs and DLEs are quoted. Everything else goes
852 through untouched. */
855 put_quoted_char (int c)
868 /* Send a packet to the OCD device. The packet framed by a SYN character,
869 a byte count and a checksum. The byte count only counts the number of
870 bytes between the count and the checksum. A count of zero actually
871 means 256. Any SYNs within the packet (including the checksum and
872 count) must be quoted. The quote character must be quoted as well.
873 Quoting is done by replacing the character with the two-character sequence
874 DLE, {char} | 0100. Note that the quoting mechanism has no effect on the
878 stu_put_packet (unsigned char *buf, int len)
880 unsigned char checksum;
883 if (len == 0 || len > 256)
884 abort (); /* Can't represent 0 length packet */
890 put_quoted_char (RAW_SYN);
904 put_quoted_char (-checksum & 0xff);
911 /* Send a packet to the OCD device. The packet framed by a SYN character,
912 a byte count and a checksum. The byte count only counts the number of
913 bytes between the count and the checksum. A count of zero actually
914 means 256. Any SYNs within the packet (including the checksum and
915 count) must be quoted. The quote character must be quoted as well.
916 Quoting is done by replacing the character with the two-character sequence
917 DLE, {char} | 0100. Note that the quoting mechanism has no effect on the
921 ocd_put_packet (unsigned char *buf, int len)
923 unsigned char checksum;
925 unsigned char *packet, *packet_ptr;
927 packet = alloca (len + 1 + 1); /* packet + SYN + checksum */
932 *packet_ptr++ = 0x55;
942 *packet_ptr++ = -checksum;
943 if (SERIAL_WRITE (ocd_desc, packet, packet_ptr - packet))
944 perror_with_name ("output_packet: write failed");
949 /* Get a packet from the OCD device. Timeout is only enforced for the
950 first byte of the packet. Subsequent bytes are expected to arrive in
951 time <= remote_timeout. Returns a pointer to a static buffer containing
952 the payload of the packet. *LENP contains the length of the packet.
955 static unsigned char *
956 stu_get_packet (unsigned char cmd, int *lenp, int timeout)
960 static unsigned char buf[256 + 10], *p;
961 unsigned char checksum;
965 ch = get_quoted_char (timeout);
968 error ("get_packet (readchar): %d", ch);
973 found_syn: /* Found the start of a packet */
978 len = get_quoted_char (remote_timeout);
988 len++; /* Include checksum */
992 ch = get_quoted_char (remote_timeout);
1004 error ("Response phase error. Got 0x%x, expected 0x%x", buf[0], cmd);
1006 *lenp = p - buf - 1;
1012 /* Get a packet from the OCD device. Timeout is only enforced for the
1013 first byte of the packet. Subsequent bytes are expected to arrive in
1014 time <= remote_timeout. Returns a pointer to a static buffer containing
1015 the payload of the packet. *LENP contains the length of the packet.
1018 static unsigned char *
1019 ocd_get_packet (int cmd, int *lenp, int timeout)
1023 static unsigned char packet[512];
1024 unsigned char *packet_ptr;
1025 unsigned char checksum;
1027 ch = readchar (timeout);
1030 error ("ocd_get_packet (readchar): %d", ch);
1033 error ("ocd_get_packet (readchar): %d", ch);
1035 /* Found the start of a packet */
1037 packet_ptr = packet;
1040 /* Read command char. That sort of tells us how long the packet is. */
1042 ch = readchar (timeout);
1045 error ("ocd_get_packet (readchar): %d", ch);
1052 ch = readchar (timeout);
1055 error ("ocd_get_packet (readchar): %d", ch);
1059 /* Get error code. */
1061 ch = readchar (timeout);
1064 error ("ocd_get_packet (readchar): %d", ch);
1068 switch (ch) /* Figure out length of packet */
1070 case 0x7: /* Write verify error? */
1071 len = 8; /* write address, value read back */
1073 case 0x11: /* Bus error? */
1074 /* write address, read flag */
1075 case 0x15: /* Internal error */
1076 len = 5; /* error code, vector */
1078 default: /* Error w/no params */
1081 case 0x0: /* Normal result */
1084 case OCD_AYT: /* Are You There? */
1085 case OCD_SET_BAUD_RATE: /* Set Baud Rate */
1086 case OCD_INIT: /* Initialize OCD device */
1087 case OCD_SET_SPEED: /* Set Speed */
1088 case OCD_SET_FUNC_CODE: /* Set Function Code */
1089 case OCD_SET_CTL_FLAGS: /* Set Control Flags */
1090 case OCD_SET_BUF_ADDR: /* Set Register Buffer Address */
1091 case OCD_RUN: /* Run Target from PC */
1092 case OCD_RUN_ADDR: /* Run Target from Specified Address */
1093 case OCD_STOP: /* Stop Target */
1094 case OCD_RESET_RUN: /* Reset Target and Run */
1095 case OCD_RESET: /* Reset Target and Halt */
1096 case OCD_STEP: /* Single Step */
1097 case OCD_WRITE_REGS: /* Write Register */
1098 case OCD_WRITE_MEM: /* Write Memory */
1099 case OCD_FILL_MEM: /* Fill Memory */
1100 case OCD_MOVE_MEM: /* Move Memory */
1101 case OCD_WRITE_INT_MEM: /* Write Internal Memory */
1102 case OCD_JUMP: /* Jump to Subroutine */
1103 case OCD_ERASE_FLASH: /* Erase flash memory */
1104 case OCD_PROGRAM_FLASH: /* Write flash memory */
1105 case OCD_EXIT_MON: /* Exit the flash programming monitor */
1106 case OCD_ENTER_MON: /* Enter the flash programming monitor */
1107 case OCD_LOG_FILE: /* Make Wigglers.dll save Wigglers.log */
1108 case OCD_SET_CONNECTION: /* Set type of connection in Wigglers.dll */
1111 case OCD_GET_VERSION: /* Get Version */
1114 case OCD_GET_STATUS_MASK: /* Get Status Mask */
1117 case OCD_GET_CTRS: /* Get Error Counters */
1118 case OCD_READ_REGS: /* Read Register */
1119 case OCD_READ_MEM: /* Read Memory */
1120 case OCD_READ_INT_MEM: /* Read Internal Memory */
1124 error ("ocd_get_packet: unknown packet type 0x%x\n", ch);
1128 if (len == 257) /* Byte stream? */
1129 { /* Yes, byte streams contain the length */
1130 ch = readchar (timeout);
1133 error ("ocd_get_packet (readchar): %d", ch);
1141 while (len-- >= 0) /* Do rest of packet and checksum */
1143 ch = readchar (timeout);
1146 error ("ocd_get_packet (readchar): %d", ch);
1152 error ("ocd_get_packet: bad packet checksum");
1154 if (cmd != -1 && cmd != packet[0])
1155 error ("Response phase error. Got 0x%x, expected 0x%x", packet[0], cmd);
1157 *lenp = packet_ptr - packet - 1; /* Subtract checksum byte */
1162 /* Execute a simple (one-byte) command. Returns a pointer to the data
1163 following the error code. */
1165 static unsigned char *
1166 ocd_do_command (int cmd, int *statusp, int *lenp)
1168 unsigned char buf[100], *p;
1169 int status, error_code;
1172 unsigned char logbuf[100];
1176 ocd_put_packet (buf, 1); /* Send command */
1177 p = ocd_get_packet (*buf, lenp, remote_timeout);
1180 error ("Truncated response packet from OCD device");
1185 if (error_code != 0)
1187 sprintf (errbuf, "ocd_do_command (0x%x):", cmd);
1188 ocd_error (errbuf, error_code);
1191 if (status & OCD_FLAG_PWF)
1192 error ("OCD device can't detect VCC at BDM interface.");
1193 else if (status & OCD_FLAG_CABLE_DISC)
1194 error ("BDM cable appears to be disconnected.");
1198 logbuf[0] = OCD_LOG_FILE;
1199 logbuf[1] = 3; /* close existing WIGGLERS.LOG */
1200 ocd_put_packet (logbuf, 2);
1201 ocd_get_packet (logbuf[0], &logpktlen, remote_timeout);
1203 logbuf[0] = OCD_LOG_FILE;
1204 logbuf[1] = 2; /* append to existing WIGGLERS.LOG */
1205 ocd_put_packet (logbuf, 2);
1206 ocd_get_packet (logbuf[0], &logpktlen, remote_timeout);
1214 /* For some mysterious reason, wait_for_inferior calls kill instead of
1215 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
1219 target_mourn_inferior ();
1223 /* Don't wait for it to die. I'm not really sure it matters whether
1225 target_mourn_inferior ();
1231 unpush_target (current_ops);
1232 generic_mourn_inferior ();
1235 /* All we actually do is set the PC to the start address of exec_bfd, and start
1236 the program at that point. */
1239 ocd_create_inferior (char *exec_file, char *args, char **env)
1241 if (args && (*args != '\000'))
1242 error ("Args are not supported by BDM.");
1244 clear_proceed_status ();
1245 proceed (bfd_get_start_address (exec_bfd), TARGET_SIGNAL_0, 0);
1249 ocd_load (char *args, int from_tty)
1251 generic_load (args, from_tty);
1255 /* This is necessary because many things were based on the PC at the time that
1256 we attached to the monitor, which is no longer valid now that we have loaded
1257 new code (and just changed the PC). Another way to do this might be to call
1258 normal_stop, except that the stack may not be valid, and things would get
1259 horribly confused... */
1261 clear_symtab_users ();
1264 /* This should be defined for each target */
1265 /* But we want to be able to compile this file for some configurations
1266 not yet supported fully */
1268 #define BDM_BREAKPOINT {0x0,0x0,0x0,0x0} /* For ppc 8xx */
1270 #define BDM_BREAKPOINT {0x4a,0xfa} /* BGND insn used for CPU32 */
1273 /* BDM (at least on CPU32) uses a different breakpoint */
1276 ocd_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
1278 static char break_insn[] = BDM_BREAKPOINT;
1281 val = target_read_memory (addr, contents_cache, sizeof (break_insn));
1284 val = target_write_memory (addr, break_insn, sizeof (break_insn));
1290 ocd_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
1292 static char break_insn[] = BDM_BREAKPOINT;
1295 val = target_write_memory (addr, contents_cache, sizeof (break_insn));
1301 bdm_command (char *args, int from_tty)
1303 error ("bdm command must be followed by `reset'");
1307 bdm_reset_command (char *args, int from_tty)
1312 error ("Not connected to OCD device.");
1314 ocd_do_command (OCD_RESET, &status, &pktlen);
1315 dcache_invalidate (target_dcache);
1316 registers_changed ();
1320 bdm_restart_command (char *args, int from_tty)
1325 error ("Not connected to OCD device.");
1327 ocd_do_command (OCD_RESET_RUN, &status, &pktlen);
1328 last_run_status = status;
1329 clear_proceed_status ();
1330 wait_for_inferior ();
1334 /* Temporary replacement for target_store_registers(). This prevents
1335 generic_load from trying to set the PC. */
1338 noop_store_registers (int regno)
1343 bdm_update_flash_command (char *args, int from_tty)
1346 struct cleanup *old_chain;
1347 void (*store_registers_tmp) (int);
1350 error ("Not connected to OCD device.");
1353 error ("Must specify file containing new OCD code.");
1355 /* old_chain = make_cleanup (flash_cleanup, 0); */
1357 ocd_do_command (OCD_ENTER_MON, &status, &pktlen);
1359 ocd_do_command (OCD_ERASE_FLASH, &status, &pktlen);
1361 write_mem_command = OCD_PROGRAM_FLASH;
1362 store_registers_tmp = current_target.to_store_registers;
1363 current_target.to_store_registers = noop_store_registers;
1365 generic_load (args, from_tty);
1367 current_target.to_store_registers = store_registers_tmp;
1368 write_mem_command = OCD_WRITE_MEM;
1370 ocd_do_command (OCD_EXIT_MON, &status, &pktlen);
1372 /* discard_cleanups (old_chain); */
1376 bdm_read_register_command (char *args, int from_tty)
1378 /* XXX repeat should go on to the next register */
1381 error ("Not connected to OCD device.");
1384 error ("Must specify BDM register number.");
1389 _initialize_remote_ocd (void)
1391 extern struct cmd_list_element *cmdlist;
1392 static struct cmd_list_element *ocd_cmd_list = NULL;
1394 add_show_from_set (add_set_cmd ("remotetimeout", no_class,
1395 var_integer, (char *) &remote_timeout,
1396 "Set timeout value for remote read.\n", &setlist),
1399 add_prefix_cmd ("ocd", class_obscure, bdm_command, "", &ocd_cmd_list, "ocd ",
1402 add_cmd ("reset", class_obscure, bdm_reset_command, "", &ocd_cmd_list);
1403 add_cmd ("restart", class_obscure, bdm_restart_command, "", &ocd_cmd_list);
1404 add_cmd ("update-flash", class_obscure, bdm_update_flash_command, "", &ocd_cmd_list);
1405 /* add_cmd ("read-register", class_obscure, bdm_read_register_command, "", &ocd_cmd_list); */