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"
35 #include <sys/types.h>
40 /* Prototypes for local functions */
42 static int ocd_read_bytes PARAMS ((CORE_ADDR memaddr,
43 char *myaddr, int len));
45 static int ocd_start_remote PARAMS ((PTR dummy));
47 static int readchar PARAMS ((int timeout));
49 static void reset_packet PARAMS ((void));
51 static void output_packet PARAMS ((void));
53 static int get_quoted_char PARAMS ((int timeout));
55 static void put_quoted_char PARAMS ((int c));
57 static void ocd_interrupt PARAMS ((int signo));
59 static void ocd_interrupt_twice PARAMS ((int signo));
61 static void interrupt_query PARAMS ((void));
63 static unsigned char *ocd_do_command PARAMS ((int cmd, int *statusp, int *lenp));
65 static void ocd_put_packet PARAMS ((unsigned char *packet, int pktlen));
67 static unsigned char *ocd_get_packet PARAMS ((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 serial_t ocd_desc = NULL;
90 ocd_error (s, error_code)
96 fputs_filtered (s, gdb_stderr);
97 fputs_filtered (" ", gdb_stderr);
108 s = "Cable disconnected";
111 s = "Couldn't enter OCD mode";
114 s = "Target stuck in reset";
117 s = "OCD hasn't been initialized";
120 s = "Write verify failed";
123 s = "Reg buff error (during MPC5xx fp reg read/write)";
126 s = "Invalid CPU register access attempt failed";
132 s = "Checksum error";
135 s = "Illegal command";
138 s = "Parameter error";
141 s = "Internal error";
144 s = "Flash erase error";
147 sprintf (buf, "Unknown error code %d", error_code);
154 /* Return nonzero if the thread TH is still alive on the remote system. */
157 ocd_thread_alive (th)
163 /* Clean up connection to a remote debugger. */
171 SERIAL_CLOSE (ocd_desc);
175 /* Stub for catch_errors. */
178 ocd_start_remote (dummy)
181 unsigned char buf[10], *p;
186 enum ocd_target_type target_type;
188 target_type = *(enum ocd_target_type *) dummy;
190 immediate_quit = 1; /* Allow user to interrupt it */
192 SERIAL_SEND_BREAK (ocd_desc); /* Wake up the wiggler */
194 speed = 80; /* Divide clock by 4000 */
198 buf[2] = speed & 0xff;
199 buf[3] = target_type;
200 ocd_put_packet (buf, 4); /* Init OCD params */
201 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
204 error ("Truncated response packet from OCD device");
210 ocd_error ("OCD_INIT:", error_code);
212 ocd_do_command (OCD_AYT, &status, &pktlen);
214 p = ocd_do_command (OCD_GET_VERSION, &status, &pktlen);
216 printf_unfiltered ("[Wiggler version %x.%x, capability 0x%x]\n",
217 p[0], p[1], (p[2] << 16) | p[3]);
220 /* Reset the target */
222 ocd_do_command (OCD_RESET_RUN, &status, &pktlen);
223 /* ocd_do_command (OCD_RESET, &status, &pktlen); */
226 /* If processor is still running, stop it. */
228 if (!(status & OCD_FLAG_BDM))
232 /* When using a target box, we want to asynchronously return status when
233 target stops. The OCD_SET_CTL_FLAGS command is ignored by Wigglers.dll
234 when using a parallel Wiggler */
235 buf[0] = OCD_SET_CTL_FLAGS;
238 ocd_put_packet (buf, 3);
240 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
243 error ("Truncated response packet from OCD device");
249 ocd_error ("OCD_SET_CTL_FLAGS:", error_code);
254 /* This is really the job of start_remote however, that makes an assumption
255 that the target is about to print out a status message of some sort. That
256 doesn't happen here (in fact, it may not be possible to get the monitor to
257 send the appropriate packet). */
259 flush_cached_frames ();
260 registers_changed ();
261 stop_pc = read_pc ();
262 set_current_frame (create_new_frame (read_fp (), stop_pc));
263 select_frame (get_current_frame (), 0);
264 print_stack_frame (selected_frame, -1, 1);
266 buf[0] = OCD_LOG_FILE;
267 buf[1] = 3; /* close existing WIGGLERS.LOG */
268 ocd_put_packet (buf, 2);
269 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
271 buf[0] = OCD_LOG_FILE;
272 buf[1] = 2; /* append to existing WIGGLERS.LOG */
273 ocd_put_packet (buf, 2);
274 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
279 /* Open a connection to a remote debugger.
280 NAME is the filename used for communication. */
282 static DCACHE *ocd_dcache;
285 ocd_open (name, from_tty, target_type, ops)
288 enum ocd_target_type target_type;
289 struct target_ops *ops;
291 unsigned char buf[10], *p;
295 error ("To open an OCD connection, you need to specify the\n\
296 device the OCD device is attached to (e.g. /dev/ttya).");
298 target_preopen (from_tty);
302 unpush_target (current_ops);
304 ocd_dcache = dcache_init (ocd_read_bytes, ocd_write_bytes);
306 if (strncmp (name, "wiggler", 7) == 0)
308 ocd_desc = SERIAL_OPEN ("ocd");
310 perror_with_name (name);
312 buf[0] = OCD_LOG_FILE;
313 buf[1] = 1; /* open new or overwrite existing WIGGLERS.LOG */
314 ocd_put_packet (buf, 2);
315 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
317 buf[0] = OCD_SET_CONNECTION;
318 buf[1] = 0x01; /* atoi (name[11]); */
319 ocd_put_packet (buf, 2);
320 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
323 /* not using Wigglers.dll */
325 ocd_desc = SERIAL_OPEN (name);
327 perror_with_name (name);
332 if (SERIAL_SETBAUDRATE (ocd_desc, baud_rate))
334 SERIAL_CLOSE (ocd_desc);
335 perror_with_name (name);
339 SERIAL_RAW (ocd_desc);
341 /* If there is something sitting in the buffer we might take it as a
342 response to a command, which would be bad. */
343 SERIAL_FLUSH_INPUT (ocd_desc);
347 puts_filtered ("Remote target wiggler connected to ");
348 puts_filtered (name);
349 puts_filtered ("\n");
351 push_target (current_ops); /* Switch to using remote target now */
353 /* Without this, some commands which require an active target (such as kill)
354 won't work. This variable serves (at least) double duty as both the pid
355 of the target process (if it has such), and as a flag indicating that a
356 target is active. These functions should be split out into seperate
357 variables, especially since GDB will someday have a notion of debugging
358 several processes. */
360 inferior_pid = 42000;
361 /* Start the remote connection; if error (0), discard this target.
362 In particular, if the user quits, be sure to discard it
363 (we'd be in an inconsistent state otherwise). */
364 if (!catch_errors (ocd_start_remote, &target_type,
365 "Couldn't establish connection to remote target\n",
369 error ("Failed to connect to OCD.");
373 /* This takes a program previously attached to and detaches it. After
374 this is done, GDB can be used to debug some other program. We
375 better not have left any breakpoints in the target program or it'll
376 die when it hits one. */
379 ocd_detach (args, from_tty)
384 error ("Argument given to \"detach\" when remotely debugging.");
388 puts_filtered ("Ending remote debugging.\n");
391 /* Tell the remote machine to resume. */
394 ocd_resume (pid, step, siggnal)
396 enum target_signal siggnal;
400 dcache_flush (ocd_dcache);
403 ocd_do_command (OCD_STEP, &last_run_status, &pktlen);
405 ocd_do_command (OCD_RUN, &last_run_status, &pktlen);
414 ocd_do_command (OCD_STOP, &status, &pktlen);
416 if (!(status & OCD_FLAG_BDM))
417 error ("Can't stop target via BDM");
420 static volatile int ocd_interrupt_flag;
422 /* Send ^C to target to halt it. Target will respond, and send us a
426 ocd_interrupt (signo)
429 /* If this doesn't work, try more severe steps. */
430 signal (signo, ocd_interrupt_twice);
433 printf_unfiltered ("ocd_interrupt called\n");
440 ocd_put_packet (buf, 1);
441 ocd_interrupt_flag = 1;
445 static void (*ofunc) ();
447 /* The user typed ^C twice. */
449 ocd_interrupt_twice (signo)
452 signal (signo, ofunc);
456 signal (signo, ocd_interrupt);
459 /* Ask the user what to do when an interrupt is received. */
464 target_terminal_ours ();
466 if (query ("Interrupted while waiting for the program.\n\
467 Give up (and stop debugging it)? "))
469 target_mourn_inferior ();
470 return_to_top_level (RETURN_QUIT);
473 target_terminal_inferior ();
476 /* If nonzero, ignore the next kill. */
477 static int kill_kludge;
479 /* Wait until the remote machine stops, then return,
480 storing status in STATUS just as `wait' would.
481 Returns "pid" (though it's not clear what, if anything, that
482 means in the case of this target). */
492 ocd_interrupt_flag = 0;
494 /* Target might already be stopped by the time we get here. */
495 /* If we aren't already stopped, we need to loop until we've dropped
496 back into BDM mode */
498 while (!(last_run_status & OCD_FLAG_BDM))
501 ocd_put_packet (buf, 1);
502 p = ocd_get_packet (OCD_AYT, &pktlen, -1);
504 ofunc = (void (*)()) signal (SIGINT, ocd_interrupt);
505 signal (SIGINT, ofunc);
508 error ("Truncated response packet from OCD device");
510 last_run_status = p[1];
514 ocd_error ("target_wait:", error_code);
516 if (last_run_status & OCD_FLAG_PWF)
517 error ("OCD device lost VCC at BDM interface.");
518 else if (last_run_status & OCD_FLAG_CABLE_DISC)
519 error ("OCD device cable appears to have been disconnected.");
522 if (ocd_interrupt_flag)
528 /* Read registers from the OCD device. Specify the starting and ending
529 register number. Return the number of regs actually read in *NUMREGS.
530 Returns a pointer to a static array containing the register contents. */
533 ocd_read_bdm_registers (first_bdm_regno, last_bdm_regno, reglen)
538 unsigned char buf[10];
542 int error_code, status;
545 buf[0] = OCD_READ_REGS;
546 buf[1] = first_bdm_regno >> 8;
547 buf[2] = first_bdm_regno & 0xff;
548 buf[3] = last_bdm_regno >> 8;
549 buf[4] = last_bdm_regno & 0xff;
551 ocd_put_packet (buf, 5);
552 p = ocd_get_packet (OCD_READ_REGS, &pktlen, remote_timeout);
558 ocd_error ("read_bdm_registers:", error_code);
566 error ("Register block size bad: %d", i);
575 /* Read register BDM_REGNO and returns its value ala read_register() */
578 ocd_read_bdm_register (bdm_regno)
585 p = ocd_read_bdm_registers (bdm_regno, bdm_regno, ®len);
586 regval = extract_unsigned_integer (p, reglen);
592 ocd_write_bdm_registers (first_bdm_regno, regptr, reglen)
594 unsigned char *regptr;
599 int error_code, status;
602 buf = alloca (4 + reglen);
604 buf[0] = OCD_WRITE_REGS;
605 buf[1] = first_bdm_regno >> 8;
606 buf[2] = first_bdm_regno & 0xff;
608 memcpy (buf + 4, regptr, reglen);
610 ocd_put_packet (buf, 4 + reglen);
611 p = ocd_get_packet (OCD_WRITE_REGS, &pktlen, remote_timeout);
614 error ("Truncated response packet from OCD device");
620 ocd_error ("ocd_write_bdm_registers:", error_code);
624 ocd_write_bdm_register (bdm_regno, reg)
628 unsigned char buf[4];
630 store_unsigned_integer (buf, 4, reg);
632 ocd_write_bdm_registers (bdm_regno, buf, 4);
636 ocd_prepare_to_store ()
640 /* Write memory data directly to the remote machine.
641 This does not inform the data cache; the data cache uses this.
642 MEMADDR is the address in the remote memory space.
643 MYADDR is the address of the buffer in our space.
644 LEN is the number of bytes.
646 Returns number of bytes transferred, or 0 for error. */
648 static int write_mem_command = OCD_WRITE_MEM;
651 ocd_write_bytes (memaddr, myaddr, len)
662 buf[0] = write_mem_command;
663 buf[5] = 1; /* Write as bytes */
664 buf[6] = 0; /* Don't verify */
670 int status, error_code;
672 numbytes = min (len, 256 - 8);
674 buf[1] = memaddr >> 24;
675 buf[2] = memaddr >> 16;
676 buf[3] = memaddr >> 8;
681 memcpy (&buf[8], myaddr, numbytes);
682 ocd_put_packet (buf, 8 + numbytes);
683 p = ocd_get_packet (OCD_WRITE_MEM, &pktlen, remote_timeout);
685 error ("Truncated response packet from OCD device");
690 if (error_code == 0x11) /* Got a bus error? */
692 CORE_ADDR error_address;
694 error_address = p[3] << 24;
695 error_address |= p[4] << 16;
696 error_address |= p[5] << 8;
697 error_address |= p[6];
698 numbytes = error_address - memaddr;
706 else if (error_code != 0)
707 ocd_error ("ocd_write_bytes:", error_code);
714 return origlen - len;
717 /* Read memory data directly from the remote machine.
718 This does not use the data cache; the data cache uses this.
719 MEMADDR is the address in the remote memory space.
720 MYADDR is the address of the buffer in our space.
721 LEN is the number of bytes.
723 Returns number of bytes transferred, or 0 for error. */
726 ocd_read_bytes (memaddr, myaddr, len)
737 buf[0] = OCD_READ_MEM;
738 buf[5] = 1; /* Read as bytes */
744 int status, error_code;
746 numbytes = min (len, 256 - 7);
748 buf[1] = memaddr >> 24;
749 buf[2] = memaddr >> 16;
750 buf[3] = memaddr >> 8;
755 ocd_put_packet (buf, 7);
756 p = ocd_get_packet (OCD_READ_MEM, &pktlen, remote_timeout);
758 error ("Truncated response packet from OCD device");
763 if (error_code == 0x11) /* Got a bus error? */
765 CORE_ADDR error_address;
767 error_address = p[3] << 24;
768 error_address |= p[4] << 16;
769 error_address |= p[5] << 8;
770 error_address |= p[6];
771 numbytes = error_address - memaddr;
779 else if (error_code != 0)
780 ocd_error ("ocd_read_bytes:", error_code);
782 memcpy (myaddr, &p[4], numbytes);
789 return origlen - len;
792 /* Read or write LEN bytes from inferior memory at MEMADDR, transferring
793 to or from debugger address MYADDR. Write to inferior if SHOULD_WRITE is
794 nonzero. Returns length of data written or read; 0 for error. */
798 ocd_xfer_memory (memaddr, myaddr, len, should_write, target)
803 struct target_ops *target; /* ignored */
805 return dcache_xfer_memory (ocd_dcache, memaddr, myaddr, len, should_write);
809 ocd_files_info (ignore)
810 struct target_ops *ignore;
812 puts_filtered ("Debugging a target over a serial line.\n");
815 /* Stuff for dealing with the packets which are part of this protocol.
816 See comment at top of file for details. */
818 /* Read a single character from the remote side, handling wierd errors. */
826 ch = SERIAL_READCHAR (ocd_desc, timeout);
831 error ("Remote connection closed");
833 perror_with_name ("Remote communication error");
841 /* Read a character from the data stream, dequoting as necessary. SYN is
842 treated special. Any SYNs appearing in the data stream are returned as the
843 distinct value RAW_SYN (which has a value > 8 bits and therefore cannot be
844 mistaken for real data). */
847 get_quoted_char (timeout)
852 ch = readchar (timeout);
857 error ("Timeout in mid-packet, aborting");
861 ch = readchar (timeout);
870 static unsigned char pkt[256 * 2 + 10], *pktp; /* Worst case */
881 if (SERIAL_WRITE (ocd_desc, pkt, pktp - pkt))
882 perror_with_name ("output_packet: write failed");
887 /* Output a quoted character. SYNs and DLEs are quoted. Everything else goes
888 through untouched. */
905 /* Send a packet to the OCD device. The packet framed by a SYN character,
906 a byte count and a checksum. The byte count only counts the number of
907 bytes between the count and the checksum. A count of zero actually
908 means 256. Any SYNs within the packet (including the checksum and
909 count) must be quoted. The quote character must be quoted as well.
910 Quoting is done by replacing the character with the two-character sequence
911 DLE, {char} | 0100. Note that the quoting mechanism has no effect on the
915 stu_put_packet (buf, len)
919 unsigned char checksum;
922 if (len == 0 || len > 256)
923 abort (); /* Can't represent 0 length packet */
929 put_quoted_char (RAW_SYN);
943 put_quoted_char (-checksum & 0xff);
950 /* Send a packet to the OCD device. The packet framed by a SYN character,
951 a byte count and a checksum. The byte count only counts the number of
952 bytes between the count and the checksum. A count of zero actually
953 means 256. Any SYNs within the packet (including the checksum and
954 count) must be quoted. The quote character must be quoted as well.
955 Quoting is done by replacing the character with the two-character sequence
956 DLE, {char} | 0100. Note that the quoting mechanism has no effect on the
960 ocd_put_packet (buf, len)
964 unsigned char checksum;
966 unsigned char *packet, *packet_ptr;
968 packet = alloca (len + 1 + 1); /* packet + SYN + checksum */
973 *packet_ptr++ = 0x55;
983 *packet_ptr++ = -checksum;
984 if (SERIAL_WRITE (ocd_desc, packet, packet_ptr - packet))
985 perror_with_name ("output_packet: write failed");
990 /* Get a packet from the OCD device. Timeout is only enforced for the
991 first byte of the packet. Subsequent bytes are expected to arrive in
992 time <= remote_timeout. Returns a pointer to a static buffer containing
993 the payload of the packet. *LENP contains the length of the packet.
996 static unsigned char *
997 stu_get_packet (cmd, lenp, timeout)
1003 static unsigned char buf[256 + 10], *p;
1004 unsigned char checksum;
1008 ch = get_quoted_char (timeout);
1011 error ("get_packet (readchar): %d", ch);
1016 found_syn: /* Found the start of a packet */
1021 len = get_quoted_char (remote_timeout);
1031 len++; /* Include checksum */
1035 ch = get_quoted_char (remote_timeout);
1047 error ("Response phase error. Got 0x%x, expected 0x%x", buf[0], cmd);
1049 *lenp = p - buf - 1;
1055 /* Get a packet from the OCD device. Timeout is only enforced for the
1056 first byte of the packet. Subsequent bytes are expected to arrive in
1057 time <= remote_timeout. Returns a pointer to a static buffer containing
1058 the payload of the packet. *LENP contains the length of the packet.
1061 static unsigned char *
1062 ocd_get_packet (cmd, lenp, timeout)
1068 static unsigned char packet[512];
1069 unsigned char *packet_ptr;
1070 unsigned char checksum;
1072 ch = readchar (timeout);
1075 error ("ocd_get_packet (readchar): %d", ch);
1078 error ("ocd_get_packet (readchar): %d", ch);
1080 /* Found the start of a packet */
1082 packet_ptr = packet;
1085 /* Read command char. That sort of tells us how long the packet is. */
1087 ch = readchar (timeout);
1090 error ("ocd_get_packet (readchar): %d", ch);
1097 ch = readchar (timeout);
1100 error ("ocd_get_packet (readchar): %d", ch);
1104 /* Get error code. */
1106 ch = readchar (timeout);
1109 error ("ocd_get_packet (readchar): %d", ch);
1113 switch (ch) /* Figure out length of packet */
1115 case 0x7: /* Write verify error? */
1116 len = 8; /* write address, value read back */
1118 case 0x11: /* Bus error? */
1119 /* write address, read flag */
1120 case 0x15: /* Internal error */
1121 len = 5; /* error code, vector */
1123 default: /* Error w/no params */
1126 case 0x0: /* Normal result */
1129 case OCD_AYT: /* Are You There? */
1130 case OCD_SET_BAUD_RATE: /* Set Baud Rate */
1131 case OCD_INIT: /* Initialize OCD device */
1132 case OCD_SET_SPEED: /* Set Speed */
1133 case OCD_SET_FUNC_CODE: /* Set Function Code */
1134 case OCD_SET_CTL_FLAGS: /* Set Control Flags */
1135 case OCD_SET_BUF_ADDR: /* Set Register Buffer Address */
1136 case OCD_RUN: /* Run Target from PC */
1137 case OCD_RUN_ADDR: /* Run Target from Specified Address */
1138 case OCD_STOP: /* Stop Target */
1139 case OCD_RESET_RUN: /* Reset Target and Run */
1140 case OCD_RESET: /* Reset Target and Halt */
1141 case OCD_STEP: /* Single Step */
1142 case OCD_WRITE_REGS: /* Write Register */
1143 case OCD_WRITE_MEM: /* Write Memory */
1144 case OCD_FILL_MEM: /* Fill Memory */
1145 case OCD_MOVE_MEM: /* Move Memory */
1146 case OCD_WRITE_INT_MEM: /* Write Internal Memory */
1147 case OCD_JUMP: /* Jump to Subroutine */
1148 case OCD_ERASE_FLASH: /* Erase flash memory */
1149 case OCD_PROGRAM_FLASH: /* Write flash memory */
1150 case OCD_EXIT_MON: /* Exit the flash programming monitor */
1151 case OCD_ENTER_MON: /* Enter the flash programming monitor */
1152 case OCD_LOG_FILE: /* Make Wigglers.dll save Wigglers.log */
1153 case OCD_SET_CONNECTION: /* Set type of connection in Wigglers.dll */
1156 case OCD_GET_VERSION: /* Get Version */
1159 case OCD_GET_STATUS_MASK: /* Get Status Mask */
1162 case OCD_GET_CTRS: /* Get Error Counters */
1163 case OCD_READ_REGS: /* Read Register */
1164 case OCD_READ_MEM: /* Read Memory */
1165 case OCD_READ_INT_MEM: /* Read Internal Memory */
1169 error ("ocd_get_packet: unknown packet type 0x%x\n", ch);
1173 if (len == 257) /* Byte stream? */
1174 { /* Yes, byte streams contain the length */
1175 ch = readchar (timeout);
1178 error ("ocd_get_packet (readchar): %d", ch);
1186 while (len-- >= 0) /* Do rest of packet and checksum */
1188 ch = readchar (timeout);
1191 error ("ocd_get_packet (readchar): %d", ch);
1197 error ("ocd_get_packet: bad packet checksum");
1199 if (cmd != -1 && cmd != packet[0])
1200 error ("Response phase error. Got 0x%x, expected 0x%x", packet[0], cmd);
1202 *lenp = packet_ptr - packet - 1; /* Subtract checksum byte */
1207 /* Execute a simple (one-byte) command. Returns a pointer to the data
1208 following the error code. */
1210 static unsigned char *
1211 ocd_do_command (cmd, statusp, lenp)
1216 unsigned char buf[100], *p;
1217 int status, error_code;
1220 unsigned char logbuf[100];
1224 ocd_put_packet (buf, 1); /* Send command */
1225 p = ocd_get_packet (*buf, lenp, remote_timeout);
1228 error ("Truncated response packet from OCD device");
1233 if (error_code != 0)
1235 sprintf (errbuf, "ocd_do_command (0x%x):", cmd);
1236 ocd_error (errbuf, error_code);
1239 if (status & OCD_FLAG_PWF)
1240 error ("OCD device can't detect VCC at BDM interface.");
1241 else if (status & OCD_FLAG_CABLE_DISC)
1242 error ("BDM cable appears to be disconnected.");
1246 logbuf[0] = OCD_LOG_FILE;
1247 logbuf[1] = 3; /* close existing WIGGLERS.LOG */
1248 ocd_put_packet (logbuf, 2);
1249 ocd_get_packet (logbuf[0], &logpktlen, remote_timeout);
1251 logbuf[0] = OCD_LOG_FILE;
1252 logbuf[1] = 2; /* append to existing WIGGLERS.LOG */
1253 ocd_put_packet (logbuf, 2);
1254 ocd_get_packet (logbuf[0], &logpktlen, remote_timeout);
1262 /* For some mysterious reason, wait_for_inferior calls kill instead of
1263 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
1267 target_mourn_inferior ();
1271 /* Don't wait for it to die. I'm not really sure it matters whether
1273 target_mourn_inferior ();
1279 unpush_target (current_ops);
1280 generic_mourn_inferior ();
1283 /* All we actually do is set the PC to the start address of exec_bfd, and start
1284 the program at that point. */
1287 ocd_create_inferior (exec_file, args, env)
1292 if (args && (*args != '\000'))
1293 error ("Args are not supported by BDM.");
1295 clear_proceed_status ();
1296 proceed (bfd_get_start_address (exec_bfd), TARGET_SIGNAL_0, 0);
1300 ocd_load (args, from_tty)
1304 generic_load (args, from_tty);
1308 /* This is necessary because many things were based on the PC at the time that
1309 we attached to the monitor, which is no longer valid now that we have loaded
1310 new code (and just changed the PC). Another way to do this might be to call
1311 normal_stop, except that the stack may not be valid, and things would get
1312 horribly confused... */
1314 clear_symtab_users ();
1317 /* This should be defined for each target */
1318 /* But we want to be able to compile this file for some configurations
1319 not yet supported fully */
1321 #define BDM_BREAKPOINT {0x0,0x0,0x0,0x0} /* For ppc 8xx */
1323 #define BDM_BREAKPOINT {0x4a,0xfa} /* BGND insn used for CPU32 */
1326 /* BDM (at least on CPU32) uses a different breakpoint */
1329 ocd_insert_breakpoint (addr, contents_cache)
1331 char *contents_cache;
1333 static char break_insn[] = BDM_BREAKPOINT;
1336 val = target_read_memory (addr, contents_cache, sizeof (break_insn));
1339 val = target_write_memory (addr, break_insn, sizeof (break_insn));
1345 ocd_remove_breakpoint (addr, contents_cache)
1347 char *contents_cache;
1349 static char break_insn[] = BDM_BREAKPOINT;
1352 val = target_write_memory (addr, contents_cache, sizeof (break_insn));
1358 bdm_command (args, from_tty)
1362 error ("bdm command must be followed by `reset'");
1366 bdm_reset_command (args, from_tty)
1373 error ("Not connected to OCD device.");
1375 ocd_do_command (OCD_RESET, &status, &pktlen);
1376 dcache_flush (ocd_dcache);
1377 registers_changed ();
1381 bdm_restart_command (args, from_tty)
1388 error ("Not connected to OCD device.");
1390 ocd_do_command (OCD_RESET_RUN, &status, &pktlen);
1391 last_run_status = status;
1392 clear_proceed_status ();
1393 wait_for_inferior ();
1397 /* Temporary replacement for target_store_registers(). This prevents
1398 generic_load from trying to set the PC. */
1401 noop_store_registers (regno)
1407 bdm_update_flash_command (args, from_tty)
1412 struct cleanup *old_chain;
1413 void (*store_registers_tmp) PARAMS ((int));
1416 error ("Not connected to OCD device.");
1419 error ("Must specify file containing new OCD code.");
1421 /* old_chain = make_cleanup (flash_cleanup, 0); */
1423 ocd_do_command (OCD_ENTER_MON, &status, &pktlen);
1425 ocd_do_command (OCD_ERASE_FLASH, &status, &pktlen);
1427 write_mem_command = OCD_PROGRAM_FLASH;
1428 store_registers_tmp = current_target.to_store_registers;
1429 current_target.to_store_registers = noop_store_registers;
1431 generic_load (args, from_tty);
1433 current_target.to_store_registers = store_registers_tmp;
1434 write_mem_command = OCD_WRITE_MEM;
1436 ocd_do_command (OCD_EXIT_MON, &status, &pktlen);
1438 /* discard_cleanups (old_chain); */
1442 bdm_read_register_command (args, from_tty)
1446 /* XXX repeat should go on to the next register */
1449 error ("Not connected to OCD device.");
1452 error ("Must specify BDM register number.");
1457 _initialize_remote_ocd ()
1459 extern struct cmd_list_element *cmdlist;
1460 static struct cmd_list_element *ocd_cmd_list = NULL;
1462 add_show_from_set (add_set_cmd ("remotetimeout", no_class,
1463 var_integer, (char *) &remote_timeout,
1464 "Set timeout value for remote read.\n", &setlist),
1467 add_prefix_cmd ("ocd", class_obscure, bdm_command, "", &ocd_cmd_list, "ocd ",
1470 add_cmd ("reset", class_obscure, bdm_reset_command, "", &ocd_cmd_list);
1471 add_cmd ("restart", class_obscure, bdm_restart_command, "", &ocd_cmd_list);
1472 add_cmd ("update-flash", class_obscure, bdm_update_flash_command, "", &ocd_cmd_list);
1473 /* add_cmd ("read-register", class_obscure, bdm_read_register_command, "", &ocd_cmd_list); */