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, Boston, MA 02111-1307, USA. */
22 #include "gdb_string.h"
32 #include "gdb-stabs.h"
34 #include <sys/types.h>
39 /* Prototypes for local functions */
41 static int ocd_read_bytes PARAMS ((CORE_ADDR memaddr,
42 char *myaddr, int len));
44 static int ocd_start_remote PARAMS ((char *dummy));
46 static int readchar PARAMS ((int timeout));
48 static void reset_packet PARAMS ((void));
50 static void output_packet PARAMS ((void));
52 static int get_quoted_char PARAMS ((int timeout));
54 static void put_quoted_char PARAMS ((int c));
56 static void ocd_interrupt PARAMS ((int signo));
58 static void ocd_interrupt_twice PARAMS ((int signo));
60 static void interrupt_query PARAMS ((void));
62 static unsigned char * ocd_do_command PARAMS ((int cmd, int *statusp, int *lenp));
64 static void ocd_put_packet PARAMS ((unsigned char *packet, int pktlen));
66 static unsigned char * ocd_get_packet PARAMS ((int cmd, int *pktlen, int timeout));
68 static struct target_ops *current_ops = NULL;
70 static int last_run_status;
72 /* This was 5 seconds, which is a long time to sit and wait.
73 Unless this is going though some terminal server or multiplexer or
74 other form of hairy serial connection, I would think 2 seconds would
77 /* Changed to allow option to set timeout value.
78 was static int remote_timeout = 2; */
79 extern int remote_timeout;
81 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
82 ocd_open knows that we don't have a file open when the program
84 static serial_t ocd_desc = NULL;
87 ocd_error (s, error_code)
93 fputs_filtered (s, gdb_stderr);
94 fputs_filtered (" ", gdb_stderr);
98 case 0x1: s = "Unknown fault"; break;
99 case 0x2: s = "Power failed"; break;
100 case 0x3: s = "Cable disconnected"; break;
101 case 0x4: s = "Couldn't enter OCD mode"; break;
102 case 0x5: s = "Target stuck in reset"; break;
103 case 0x6: s = "OCD hasn't been initialized"; break;
104 case 0x7: s = "Write verify failed"; break;
105 case 0x8: s = "Reg buff error (during MPC5xx fp reg read/write)"; break;
106 case 0x9: s = "Invalid CPU register access attempt failed"; break;
107 case 0x11: s = "Bus error"; break;
108 case 0x12: s = "Checksum error"; break;
109 case 0x13: s = "Illegal command"; break;
110 case 0x14: s = "Parameter error"; break;
111 case 0x15: s = "Internal error"; break;
112 case 0x80: s = "Flash erase error"; break;
114 sprintf (buf, "Unknown error code %d", error_code);
121 /* Return nonzero if the thread TH is still alive on the remote system. */
124 ocd_thread_alive (th)
130 /* Clean up connection to a remote debugger. */
138 SERIAL_CLOSE (ocd_desc);
142 /* Stub for catch_errors. */
145 ocd_start_remote (dummy)
148 unsigned char buf[10], *p;
153 enum ocd_target_type target_type;
155 target_type = (enum ocd_target_type)dummy;
157 immediate_quit = 1; /* Allow user to interrupt it */
159 SERIAL_SEND_BREAK (ocd_desc); /* Wake up the wiggler */
161 speed = 0; /* 80; /* Divide clock by 4000 */
165 buf[2] = speed & 0xff;
166 buf[3] = target_type;
167 ocd_put_packet (buf, 4); /* Init OCD params */
168 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
171 error ("Truncated response packet from OCD device");
177 ocd_error ("OCD_INIT:", error_code);
179 ocd_do_command (OCD_AYT, &status, &pktlen);
181 p = ocd_do_command (OCD_GET_VERSION, &status, &pktlen);
183 printf_unfiltered ("[Wiggler version %x.%x, capability 0x%x]\n",
184 p[0], p[1], (p[2] << 16) | p[3]);
187 /* Reset the target */
189 ocd_do_command (OCD_RESET_RUN, &status, &pktlen);
190 /* ocd_do_command (OCD_RESET, &status, &pktlen);*/
193 /* If processor is still running, stop it. */
195 if (!(status & OCD_FLAG_BDM))
199 buf[0] = OCD_SET_CTL_FLAGS;
201 buf[2] = 1; /* Asynchronously return status when target stops */
202 ocd_put_packet (buf, 3);
204 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
207 error ("Truncated response packet from OCD device");
213 ocd_error ("OCD_SET_CTL_FLAGS:", error_code);
218 /* This is really the job of start_remote however, that makes an assumption
219 that the target is about to print out a status message of some sort. That
220 doesn't happen here (in fact, it may not be possible to get the monitor to
221 send the appropriate packet). */
223 flush_cached_frames ();
224 registers_changed ();
225 stop_pc = read_pc ();
226 set_current_frame (create_new_frame (read_fp (), stop_pc));
227 select_frame (get_current_frame (), 0);
228 print_stack_frame (selected_frame, -1, 1);
230 buf[0] = OCD_LOG_FILE;
231 buf[1] = 3; /* close existing WIGGLERS.LOG */
232 ocd_put_packet (buf, 2);
233 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
235 buf[0] = OCD_LOG_FILE;
236 buf[1] = 2; /* append to existing WIGGLERS.LOG */
237 ocd_put_packet (buf, 2);
238 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
243 /* Open a connection to a remote debugger.
244 NAME is the filename used for communication. */
246 static DCACHE *ocd_dcache;
249 ocd_open (name, from_tty, target_type, ops)
252 enum ocd_target_type target_type;
253 struct target_ops *ops;
255 unsigned char buf[10], *p;
260 error ("To open an OCD connection, you need to specify the\n\
261 device the OCD device is attached to (e.g. /dev/ttya).");
263 target_preopen (from_tty);
267 unpush_target (current_ops);
269 ocd_dcache = dcache_init (ocd_read_bytes, ocd_write_bytes);
271 if (strncmp(name,"wiggler",7) == 0)
273 ocd_desc = SERIAL_OPEN ("ocd");
275 perror_with_name (name);
277 buf[0] = OCD_LOG_FILE;
278 buf[1] = 1; /* open new or overwrite existing WIGGLERS.LOG */
279 ocd_put_packet (buf, 2);
280 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
282 buf[0] = OCD_SET_CONNECTION;
283 buf[1] = 0x01; /* atoi (name[11]); */
284 ocd_put_packet (buf, 2);
285 p = ocd_get_packet (buf[0], &pktlen, remote_timeout);
287 else /* not using Wigglers.dll */
289 ocd_desc = SERIAL_OPEN (name);
291 perror_with_name (name);
296 if (SERIAL_SETBAUDRATE (ocd_desc, baud_rate))
298 SERIAL_CLOSE (ocd_desc);
299 perror_with_name (name);
303 SERIAL_RAW (ocd_desc);
305 /* If there is something sitting in the buffer we might take it as a
306 response to a command, which would be bad. */
307 SERIAL_FLUSH_INPUT (ocd_desc);
311 puts_filtered ("Remote target wiggler connected to ");
312 puts_filtered (name);
313 puts_filtered ("\n");
315 push_target (current_ops); /* Switch to using remote target now */
317 /* Without this, some commands which require an active target (such as kill)
318 won't work. This variable serves (at least) double duty as both the pid
319 of the target process (if it has such), and as a flag indicating that a
320 target is active. These functions should be split out into seperate
321 variables, especially since GDB will someday have a notion of debugging
322 several processes. */
324 inferior_pid = 42000;
325 /* Start the remote connection; if error (0), discard this target.
326 In particular, if the user quits, be sure to discard it
327 (we'd be in an inconsistent state otherwise). */
328 if (!catch_errors (ocd_start_remote, (char *)target_type,
329 "Couldn't establish connection to remote target\n",
334 /* This takes a program previously attached to and detaches it. After
335 this is done, GDB can be used to debug some other program. We
336 better not have left any breakpoints in the target program or it'll
337 die when it hits one. */
340 ocd_detach (args, from_tty)
345 error ("Argument given to \"detach\" when remotely debugging.");
349 puts_filtered ("Ending remote debugging.\n");
352 /* Tell the remote machine to resume. */
355 ocd_resume (pid, step, siggnal)
357 enum target_signal siggnal;
361 dcache_flush (ocd_dcache);
364 ocd_do_command (OCD_STEP, &last_run_status, &pktlen);
366 ocd_do_command (OCD_RUN, &last_run_status, &pktlen);
375 ocd_do_command (OCD_STOP, &status, &pktlen);
377 if (!(status & OCD_FLAG_BDM))
378 error ("Can't stop target via BDM");
381 static volatile int ocd_interrupt_flag;
383 /* Send ^C to target to halt it. Target will respond, and send us a
387 ocd_interrupt (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 (signo)
413 signal (signo, ofunc);
417 signal (signo, ocd_interrupt);
420 /* Ask the user what to do when an interrupt is received. */
425 target_terminal_ours ();
427 if (query ("Interrupted while waiting for the program.\n\
428 Give up (and stop debugging it)? "))
430 target_mourn_inferior ();
431 return_to_top_level (RETURN_QUIT);
434 target_terminal_inferior ();
437 /* If nonzero, ignore the next kill. */
438 static int kill_kludge;
440 /* Wait until the remote machine stops, then return,
441 storing status in STATUS just as `wait' would.
442 Returns "pid" (though it's not clear what, if anything, that
443 means in the case of this target). */
449 int error_code, status;
452 ocd_interrupt_flag = 0;
454 /* Target may already be stopped by the time we get here. */
456 if (!(last_run_status & OCD_FLAG_BDM))
458 ofunc = (void (*)()) signal (SIGINT, ocd_interrupt);
460 p = ocd_get_packet (OCD_AYT, &pktlen, -1);
462 signal (SIGINT, ofunc);
465 error ("Truncated response packet from OCD device");
471 ocd_error ("target_wait:", error_code);
473 if (status & OCD_FLAG_PWF)
474 error ("OCD device lost VCC at BDM interface.");
475 else if (status & OCD_FLAG_CABLE_DISC)
476 error ("BDM cable appears to have been disconnected.");
478 if (!(status & OCD_FLAG_BDM))
479 error ("OCD device woke up, but wasn't stopped: 0x%x", status);
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 (first_bdm_regno, last_bdm_regno, reglen)
498 unsigned char buf[10];
502 int error_code, status;
505 buf[0] = OCD_READ_REGS;
506 buf[1] = first_bdm_regno >> 8;
507 buf[2] = first_bdm_regno & 0xff;
508 buf[3] = last_bdm_regno >> 8;
509 buf[4] = last_bdm_regno & 0xff;
511 ocd_put_packet (buf, 5);
512 p = ocd_get_packet (OCD_READ_REGS, &pktlen, remote_timeout);
518 ocd_error ("read_bdm_registers:", error_code);
526 error ("Register block size bad: %d", i);
535 /* Read register BDM_REGNO and returns its value ala read_register() */
538 ocd_read_bdm_register (bdm_regno)
545 p = ocd_read_bdm_registers (bdm_regno, bdm_regno, ®len);
546 regval = extract_unsigned_integer (p, reglen);
552 ocd_write_bdm_registers (first_bdm_regno, regptr, reglen)
554 unsigned char *regptr;
559 int error_code, status;
562 buf = alloca (4 + reglen);
564 buf[0] = OCD_WRITE_REGS;
565 buf[1] = first_bdm_regno >> 8;
566 buf[2] = first_bdm_regno & 0xff;
568 memcpy (buf + 4, regptr, reglen);
570 ocd_put_packet (buf, 4 + reglen);
571 p = ocd_get_packet (OCD_WRITE_REGS, &pktlen, remote_timeout);
574 error ("Truncated response packet from OCD device");
580 ocd_error ("ocd_write_bdm_registers:", error_code);
584 ocd_write_bdm_register (bdm_regno, reg)
588 unsigned char buf[4];
590 store_unsigned_integer (buf, 4, reg);
592 ocd_write_bdm_registers (bdm_regno, buf, 4);
596 ocd_prepare_to_store ()
600 /* Write memory data directly to the remote machine.
601 This does not inform the data cache; the data cache uses this.
602 MEMADDR is the address in the remote memory space.
603 MYADDR is the address of the buffer in our space.
604 LEN is the number of bytes.
606 Returns number of bytes transferred, or 0 for error. */
608 static int write_mem_command = OCD_WRITE_MEM;
611 ocd_write_bytes (memaddr, myaddr, len)
622 buf[0] = write_mem_command;
623 buf[5] = 1; /* Write as bytes */
624 buf[6] = 0; /* Don't verify */
630 int status, error_code;
632 numbytes = min (len, 256 - 8);
634 buf[1] = memaddr >> 24;
635 buf[2] = memaddr >> 16;
636 buf[3] = memaddr >> 8;
641 memcpy (&buf[8], myaddr, numbytes);
642 ocd_put_packet (buf, 8 + numbytes);
643 p = ocd_get_packet (OCD_WRITE_MEM, &pktlen, remote_timeout);
645 error ("Truncated response packet from OCD device");
650 if (error_code == 0x11) /* Got a bus error? */
652 CORE_ADDR error_address;
654 error_address = p[3] << 24;
655 error_address |= p[4] << 16;
656 error_address |= p[5] << 8;
657 error_address |= p[6];
658 numbytes = error_address - memaddr;
666 else if (error_code != 0)
667 ocd_error ("ocd_write_bytes:", error_code);
674 return origlen - len;
677 /* Read memory data directly from the remote machine.
678 This does not use the data cache; the data cache uses this.
679 MEMADDR is the address in the remote memory space.
680 MYADDR is the address of the buffer in our space.
681 LEN is the number of bytes.
683 Returns number of bytes transferred, or 0 for error. */
686 ocd_read_bytes (memaddr, myaddr, len)
697 buf[0] = OCD_READ_MEM;
698 buf[5] = 1; /* Read as bytes */
704 int status, error_code;
706 numbytes = min (len, 256 - 7);
708 buf[1] = memaddr >> 24;
709 buf[2] = memaddr >> 16;
710 buf[3] = memaddr >> 8;
715 ocd_put_packet (buf, 7);
716 p = ocd_get_packet (OCD_READ_MEM, &pktlen, remote_timeout);
718 error ("Truncated response packet from OCD device");
723 if (error_code == 0x11) /* Got a bus error? */
725 CORE_ADDR error_address;
727 error_address = p[3] << 24;
728 error_address |= p[4] << 16;
729 error_address |= p[5] << 8;
730 error_address |= p[6];
731 numbytes = error_address - memaddr;
739 else if (error_code != 0)
740 ocd_error ("ocd_read_bytes:", error_code);
742 memcpy (myaddr, &p[4], numbytes);
749 return origlen - len;
752 /* Read or write LEN bytes from inferior memory at MEMADDR, transferring
753 to or from debugger address MYADDR. Write to inferior if SHOULD_WRITE is
754 nonzero. Returns length of data written or read; 0 for error. */
758 ocd_xfer_memory (memaddr, myaddr, len, should_write, target)
763 struct target_ops *target; /* ignored */
765 return dcache_xfer_memory (ocd_dcache, memaddr, myaddr, len, should_write);
769 ocd_files_info (ignore)
770 struct target_ops *ignore;
772 puts_filtered ("Debugging a target over a serial line.\n");
775 /* Stuff for dealing with the packets which are part of this protocol.
776 See comment at top of file for details. */
778 /* Read a single character from the remote side, handling wierd errors. */
786 ch = SERIAL_READCHAR (ocd_desc, timeout);
791 error ("Remote connection closed");
793 perror_with_name ("Remote communication error");
801 /* Read a character from the data stream, dequoting as necessary. SYN is
802 treated special. Any SYNs appearing in the data stream are returned as the
803 distinct value RAW_SYN (which has a value > 8 bits and therefore cannot be
804 mistaken for real data). */
807 get_quoted_char (timeout)
812 ch = readchar (timeout);
817 error ("Timeout in mid-packet, aborting");
821 ch = readchar (timeout);
830 static unsigned char pkt[256 * 2 + 10], *pktp; /* Worst case */
841 if (SERIAL_WRITE (ocd_desc, pkt, pktp - pkt))
842 perror_with_name ("output_packet: write failed");
847 /* Output a quoted character. SYNs and DLEs are quoted. Everything else goes
848 through untouched. */
865 /* Send a packet to the OCD device. The packet framed by a SYN character,
866 a byte count and a checksum. The byte count only counts the number of
867 bytes between the count and the checksum. A count of zero actually
868 means 256. Any SYNs within the packet (including the checksum and
869 count) must be quoted. The quote character must be quoted as well.
870 Quoting is done by replacing the character with the two-character sequence
871 DLE, {char} | 0100. Note that the quoting mechanism has no effect on the
875 stu_put_packet (buf, len)
879 unsigned char checksum;
882 if (len == 0 || len > 256)
883 abort (); /* Can't represent 0 length packet */
889 put_quoted_char (RAW_SYN);
903 put_quoted_char (-checksum & 0xff);
910 /* Send a packet to the OCD device. The packet framed by a SYN character,
911 a byte count and a checksum. The byte count only counts the number of
912 bytes between the count and the checksum. A count of zero actually
913 means 256. Any SYNs within the packet (including the checksum and
914 count) must be quoted. The quote character must be quoted as well.
915 Quoting is done by replacing the character with the two-character sequence
916 DLE, {char} | 0100. Note that the quoting mechanism has no effect on the
920 ocd_put_packet (buf, len)
924 unsigned char checksum;
926 unsigned char *packet, *packet_ptr;
928 packet = alloca (len + 1 + 1); /* packet + SYN + checksum */
933 *packet_ptr++ = 0x55;
943 *packet_ptr++ = -checksum;
944 if (SERIAL_WRITE (ocd_desc, packet, packet_ptr - packet))
945 perror_with_name ("output_packet: write failed");
950 /* Get a packet from the OCD device. Timeout is only enforced for the
951 first byte of the packet. Subsequent bytes are expected to arrive in
952 time <= remote_timeout. Returns a pointer to a static buffer containing
953 the payload of the packet. *LENP contains the length of the packet.
956 static unsigned char *
957 stu_get_packet (cmd, lenp, timeout)
963 static unsigned char buf[256 + 10], *p;
964 unsigned char checksum;
968 ch = get_quoted_char (timeout);
971 error ("get_packet (readchar): %d", ch);
976 found_syn: /* Found the start of a packet */
981 len = get_quoted_char (remote_timeout);
991 len++; /* Include checksum */
995 ch = get_quoted_char (remote_timeout);
1007 error ("Response phase error. Got 0x%x, expected 0x%x", buf[0], cmd);
1009 *lenp = p - buf - 1;
1015 /* Get a packet from the OCD device. Timeout is only enforced for the
1016 first byte of the packet. Subsequent bytes are expected to arrive in
1017 time <= remote_timeout. Returns a pointer to a static buffer containing
1018 the payload of the packet. *LENP contains the length of the packet.
1021 static unsigned char *
1022 ocd_get_packet (cmd, lenp, timeout)
1029 static unsigned char packet[512];
1030 unsigned char *packet_ptr;
1031 unsigned char checksum;
1035 ch = readchar (timeout);
1038 error ("ocd_get_packet (readchar): %d", ch);
1043 /* Found the start of a packet */
1045 packet_ptr = packet;
1048 /* Read command char. That sort of tells us how long the packet is. */
1050 ch = readchar (timeout);
1053 error ("ocd_get_packet (readchar): %d", ch);
1060 ch = readchar (timeout);
1063 error ("ocd_get_packet (readchar): %d", ch);
1067 /* Get error code. */
1069 ch = readchar (timeout);
1072 error ("ocd_get_packet (readchar): %d", ch);
1076 switch (ch) /* Figure out length of packet */
1078 case 0x7: /* Write verify error? */
1079 len = 8; /* write address, value read back */
1081 case 0x11: /* Bus error? */
1082 /* write address, read flag */
1083 case 0x15: /* Internal error */
1084 len = 5; /* error code, vector */
1086 default: /* Error w/no params */
1089 case 0x0: /* Normal result */
1092 case OCD_AYT: /* Are You There? */
1093 case OCD_SET_BAUD_RATE: /* Set Baud Rate */
1094 case OCD_INIT: /* Initialize OCD device */
1095 case OCD_SET_SPEED: /* Set Speed */
1096 case OCD_SET_FUNC_CODE: /* Set Function Code */
1097 case OCD_SET_CTL_FLAGS: /* Set Control Flags */
1098 case OCD_SET_BUF_ADDR: /* Set Register Buffer Address */
1099 case OCD_RUN: /* Run Target from PC */
1100 case OCD_RUN_ADDR: /* Run Target from Specified Address */
1101 case OCD_STOP: /* Stop Target */
1102 case OCD_RESET_RUN: /* Reset Target and Run */
1103 case OCD_RESET: /* Reset Target and Halt */
1104 case OCD_STEP: /* Single Step */
1105 case OCD_WRITE_REGS: /* Write Register */
1106 case OCD_WRITE_MEM: /* Write Memory */
1107 case OCD_FILL_MEM: /* Fill Memory */
1108 case OCD_MOVE_MEM: /* Move Memory */
1109 case OCD_WRITE_INT_MEM: /* Write Internal Memory */
1110 case OCD_JUMP: /* Jump to Subroutine */
1111 case OCD_ERASE_FLASH: /* Erase flash memory */
1112 case OCD_PROGRAM_FLASH: /* Write flash memory */
1113 case OCD_EXIT_MON: /* Exit the flash programming monitor */
1114 case OCD_ENTER_MON: /* Enter the flash programming monitor */
1115 case OCD_LOG_FILE: /* Make Wigglers.dll save Wigglers.log */
1116 case OCD_SET_CONNECTION: /* Set type of connection in Wigglers.dll */
1119 case OCD_GET_VERSION: /* Get Version */
1122 case OCD_GET_STATUS_MASK: /* Get Status Mask */
1125 case OCD_GET_CTRS: /* Get Error Counters */
1126 case OCD_READ_REGS: /* Read Register */
1127 case OCD_READ_MEM: /* Read Memory */
1128 case OCD_READ_INT_MEM: /* Read Internal Memory */
1132 fprintf_filtered (gdb_stderr, "Unknown packet type 0x%x\n", ch);
1137 if (len == 257) /* Byte stream? */
1138 { /* Yes, byte streams contain the length */
1139 ch = readchar (timeout);
1142 error ("ocd_get_packet (readchar): %d", ch);
1150 while (len-- >= 0) /* Do rest of packet and checksum */
1152 ch = readchar (timeout);
1155 error ("ocd_get_packet (readchar): %d", ch);
1163 if (cmd != -1 && cmd != packet[0])
1164 error ("Response phase error. Got 0x%x, expected 0x%x", packet[0], cmd);
1166 *lenp = packet_ptr - packet - 1; /* Subtract checksum byte */
1171 /* Execute a simple (one-byte) command. Returns a pointer to the data
1172 following the error code. */
1174 static unsigned char *
1175 ocd_do_command (cmd, statusp, lenp)
1180 unsigned char buf[100], *p;
1181 int status, error_code;
1184 unsigned char logbuf[100];
1188 ocd_put_packet (buf, 1); /* Send command */
1189 p = ocd_get_packet (*buf, lenp, remote_timeout);
1192 error ("Truncated response packet from OCD device");
1197 if (error_code != 0)
1199 sprintf (errbuf, "ocd_do_command (0x%x):", cmd);
1200 ocd_error (errbuf, error_code);
1203 if (status & OCD_FLAG_PWF)
1204 error ("OCD device can't detect VCC at BDM interface.");
1205 else if (status & OCD_FLAG_CABLE_DISC)
1206 error ("BDM cable appears to be disconnected.");
1210 logbuf[0] = OCD_LOG_FILE;
1211 logbuf[1] = 3; /* close existing WIGGLERS.LOG */
1212 ocd_put_packet (logbuf, 2);
1213 ocd_get_packet (logbuf[0], &logpktlen, remote_timeout);
1215 logbuf[0] = OCD_LOG_FILE;
1216 logbuf[1] = 2; /* append to existing WIGGLERS.LOG */
1217 ocd_put_packet (logbuf, 2);
1218 ocd_get_packet (logbuf[0], &logpktlen, remote_timeout);
1226 /* For some mysterious reason, wait_for_inferior calls kill instead of
1227 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
1231 target_mourn_inferior ();
1235 /* Don't wait for it to die. I'm not really sure it matters whether
1237 target_mourn_inferior ();
1243 unpush_target (current_ops);
1244 generic_mourn_inferior ();
1247 /* All we actually do is set the PC to the start address of exec_bfd, and start
1248 the program at that point. */
1251 ocd_create_inferior (exec_file, args, env)
1256 if (args && (*args != '\000'))
1257 error ("Args are not supported by BDM.");
1259 clear_proceed_status ();
1260 proceed (bfd_get_start_address (exec_bfd), TARGET_SIGNAL_0, 0);
1264 ocd_load (args, from_tty)
1268 generic_load (args, from_tty);
1272 /* This is necessary because many things were based on the PC at the time that
1273 we attached to the monitor, which is no longer valid now that we have loaded
1274 new code (and just changed the PC). Another way to do this might be to call
1275 normal_stop, except that the stack may not be valid, and things would get
1276 horribly confused... */
1278 clear_symtab_users ();
1281 /* This should be defined in each targets tm.h file */
1282 /* But we want to be able to compile this file for some configurations
1283 not yet supported fully */
1285 #ifndef BDM_BREAKPOINT
1286 #define BDM_BREAKPOINT 0x4a, 0xfa /* BGND insn on CPU32*/
1289 /* BDM (at least on CPU32) uses a different breakpoint */
1292 ocd_insert_breakpoint (addr, contents_cache)
1294 char *contents_cache;
1296 static char break_insn[] = {BDM_BREAKPOINT};
1299 val = target_read_memory (addr, contents_cache, sizeof (break_insn));
1302 val = target_write_memory (addr, break_insn, sizeof (break_insn));
1308 ocd_remove_breakpoint (addr, contents_cache)
1310 char *contents_cache;
1312 static char break_insn[] = {BDM_BREAKPOINT};
1315 val = target_write_memory (addr, contents_cache, sizeof (break_insn));
1321 bdm_command (args, from_tty)
1325 error ("bdm command must be followed by `reset'");
1329 bdm_reset_command (args, from_tty)
1336 error ("Not connected to OCD device.");
1338 ocd_do_command (OCD_RESET, &status, &pktlen);
1339 dcache_flush (ocd_dcache);
1340 registers_changed ();
1344 bdm_restart_command (args, from_tty)
1351 error ("Not connected to OCD device.");
1353 ocd_do_command (OCD_RESET_RUN, &status, &pktlen);
1354 last_run_status = status;
1355 clear_proceed_status ();
1356 wait_for_inferior ();
1360 /* Temporary replacement for target_store_registers(). This prevents
1361 generic_load from trying to set the PC. */
1364 noop_store_registers (regno)
1370 bdm_update_flash_command (args, from_tty)
1375 struct cleanup *old_chain;
1376 void (*store_registers_tmp) PARAMS ((int));
1379 error ("Not connected to OCD device.");
1382 error ("Must specify file containing new OCD code.");
1384 /* old_chain = make_cleanup (flash_cleanup, 0);*/
1386 ocd_do_command (OCD_ENTER_MON, &status, &pktlen);
1388 ocd_do_command (OCD_ERASE_FLASH, &status, &pktlen);
1390 write_mem_command = OCD_PROGRAM_FLASH;
1391 store_registers_tmp = current_target.to_store_registers;
1392 current_target.to_store_registers = noop_store_registers;
1394 generic_load (args, from_tty);
1396 current_target.to_store_registers = store_registers_tmp;
1397 write_mem_command = OCD_WRITE_MEM;
1399 ocd_do_command (OCD_EXIT_MON, &status, &pktlen);
1401 /* discard_cleanups (old_chain);*/
1405 bdm_read_register_command (args, from_tty)
1409 /* XXX repeat should go on to the next register */
1412 error ("Not connected to OCD device.");
1415 error ("Must specify BDM register number.");
1420 _initialize_remote_ocd ()
1422 extern struct cmd_list_element *cmdlist;
1423 static struct cmd_list_element *ocd_cmd_list = NULL;
1425 add_show_from_set (add_set_cmd ("remotetimeout", no_class,
1426 var_integer, (char *)&remote_timeout,
1427 "Set timeout value for remote read.\n", &setlist),
1430 add_prefix_cmd ("ocd", class_obscure, bdm_command, "", &ocd_cmd_list, "ocd ",
1433 add_cmd ("reset", class_obscure, bdm_reset_command, "", &ocd_cmd_list);
1434 add_cmd ("restart", class_obscure, bdm_restart_command, "", &ocd_cmd_list);
1435 add_cmd ("update-flash", class_obscure, bdm_update_flash_command, "", &ocd_cmd_list);
1436 /* add_cmd ("read-register", class_obscure, bdm_read_register_command, "", &ocd_cmd_list);*/