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 (void *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. */
163 ocd_close (int quitting
)
166 serial_close (ocd_desc
);
170 /* Stub for catch_errors. */
173 ocd_start_remote (void *dummy
)
175 unsigned char buf
[10], *p
;
180 enum ocd_target_type target_type
;
182 target_type
= *(enum ocd_target_type
*) dummy
;
184 immediate_quit
++; /* Allow user to interrupt it */
186 serial_send_break (ocd_desc
); /* Wake up the wiggler */
188 speed
= 80; /* Divide clock by 4000 */
192 buf
[2] = speed
& 0xff;
193 buf
[3] = target_type
;
194 ocd_put_packet (buf
, 4); /* Init OCD params */
195 p
= ocd_get_packet (buf
[0], &pktlen
, remote_timeout
);
198 error ("Truncated response packet from OCD device");
204 ocd_error ("OCD_INIT:", error_code
);
206 ocd_do_command (OCD_AYT
, &status
, &pktlen
);
208 p
= ocd_do_command (OCD_GET_VERSION
, &status
, &pktlen
);
210 printf_unfiltered ("[Wiggler version %x.%x, capability 0x%x]\n",
211 p
[0], p
[1], (p
[2] << 16) | p
[3]);
214 /* Reset the target */
216 ocd_do_command (OCD_RESET_RUN
, &status
, &pktlen
);
217 /* ocd_do_command (OCD_RESET, &status, &pktlen); */
220 /* If processor is still running, stop it. */
222 if (!(status
& OCD_FLAG_BDM
))
226 /* When using a target box, we want to asynchronously return status when
227 target stops. The OCD_SET_CTL_FLAGS command is ignored by Wigglers.dll
228 when using a parallel Wiggler */
229 buf
[0] = OCD_SET_CTL_FLAGS
;
232 ocd_put_packet (buf
, 3);
234 p
= ocd_get_packet (buf
[0], &pktlen
, remote_timeout
);
237 error ("Truncated response packet from OCD device");
243 ocd_error ("OCD_SET_CTL_FLAGS:", error_code
);
248 /* This is really the job of start_remote however, that makes an assumption
249 that the target is about to print out a status message of some sort. That
250 doesn't happen here (in fact, it may not be possible to get the monitor to
251 send the appropriate packet). */
253 flush_cached_frames ();
254 registers_changed ();
255 stop_pc
= read_pc ();
256 print_stack_frame (get_selected_frame (), -1, 1);
258 buf
[0] = OCD_LOG_FILE
;
259 buf
[1] = 3; /* close existing WIGGLERS.LOG */
260 ocd_put_packet (buf
, 2);
261 p
= ocd_get_packet (buf
[0], &pktlen
, remote_timeout
);
263 buf
[0] = OCD_LOG_FILE
;
264 buf
[1] = 2; /* append to existing WIGGLERS.LOG */
265 ocd_put_packet (buf
, 2);
266 p
= ocd_get_packet (buf
[0], &pktlen
, remote_timeout
);
271 /* Open a connection to a remote debugger.
272 NAME is the filename used for communication. */
275 ocd_open (char *name
, int from_tty
, enum ocd_target_type target_type
,
276 struct target_ops
*ops
)
278 unsigned char buf
[10], *p
;
282 error ("To open an OCD connection, you need to specify the\n\
283 device the OCD device is attached to (e.g. /dev/ttya).");
285 target_preopen (from_tty
);
289 unpush_target (current_ops
);
291 ocd_desc
= serial_open (name
);
293 perror_with_name (name
);
297 if (serial_setbaudrate (ocd_desc
, baud_rate
))
299 serial_close (ocd_desc
);
300 perror_with_name (name
);
304 serial_raw (ocd_desc
);
306 /* If there is something sitting in the buffer we might take it as a
307 response to a command, which would be bad. */
308 serial_flush_input (ocd_desc
);
312 puts_filtered ("Remote target wiggler connected to ");
313 puts_filtered (name
);
314 puts_filtered ("\n");
316 push_target (current_ops
); /* Switch to using remote target now */
318 /* Without this, some commands which require an active target (such as kill)
319 won't work. This variable serves (at least) double duty as both the pid
320 of the target process (if it has such), and as a flag indicating that a
321 target is active. These functions should be split out into seperate
322 variables, especially since GDB will someday have a notion of debugging
323 several processes. */
325 inferior_ptid
= pid_to_ptid (42000);
326 /* Start the remote connection; if error (0), discard this target.
327 In particular, if the user quits, be sure to discard it
328 (we'd be in an inconsistent state otherwise). */
329 if (!catch_errors (ocd_start_remote
, &target_type
,
330 "Couldn't establish connection to remote target\n",
334 error ("Failed to connect to OCD.");
338 /* This takes a program previously attached to and detaches it. After
339 this is done, GDB can be used to debug some other program. We
340 better not have left any breakpoints in the target program or it'll
341 die when it hits one. */
344 ocd_detach (char *args
, int from_tty
)
347 error ("Argument given to \"detach\" when remotely debugging.");
351 puts_filtered ("Ending remote debugging.\n");
354 /* Tell the remote machine to resume. */
357 ocd_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
362 ocd_do_command (OCD_STEP
, &last_run_status
, &pktlen
);
364 ocd_do_command (OCD_RUN
, &last_run_status
, &pktlen
);
373 ocd_do_command (OCD_STOP
, &status
, &pktlen
);
375 if (!(status
& OCD_FLAG_BDM
))
376 error ("Can't stop target via BDM");
379 static volatile int ocd_interrupt_flag
;
381 /* Send ^C to target to halt it. Target will respond, and send us a
385 ocd_interrupt (int signo
)
387 /* If this doesn't work, try more severe steps. */
388 signal (signo
, ocd_interrupt_twice
);
391 printf_unfiltered ("ocd_interrupt called\n");
398 ocd_put_packet (buf
, 1);
399 ocd_interrupt_flag
= 1;
403 static void (*ofunc
) ();
405 /* The user typed ^C twice. */
407 ocd_interrupt_twice (int signo
)
409 signal (signo
, ofunc
);
413 signal (signo
, ocd_interrupt
);
416 /* Ask the user what to do when an interrupt is received. */
419 interrupt_query (void)
421 target_terminal_ours ();
423 if (query ("Interrupted while waiting for the program.\n\
424 Give up (and stop debugging it)? "))
426 target_mourn_inferior ();
427 throw_exception (RETURN_QUIT
);
430 target_terminal_inferior ();
433 /* If nonzero, ignore the next kill. */
434 static int kill_kludge
;
436 /* Wait until the remote machine stops, then return,
437 storing status in STATUS just as `wait' would.
438 Returns "pid" (though it's not clear what, if anything, that
439 means in the case of this target). */
449 ocd_interrupt_flag
= 0;
451 /* Target might already be stopped by the time we get here. */
452 /* If we aren't already stopped, we need to loop until we've dropped
453 back into BDM mode */
455 while (!(last_run_status
& OCD_FLAG_BDM
))
458 ocd_put_packet (buf
, 1);
459 p
= ocd_get_packet (OCD_AYT
, &pktlen
, -1);
461 ofunc
= (void (*)()) signal (SIGINT
, ocd_interrupt
);
462 signal (SIGINT
, ofunc
);
465 error ("Truncated response packet from OCD device");
467 last_run_status
= p
[1];
471 ocd_error ("target_wait:", error_code
);
473 if (last_run_status
& OCD_FLAG_PWF
)
474 error ("OCD device lost VCC at BDM interface.");
475 else if (last_run_status
& OCD_FLAG_CABLE_DISC
)
476 error ("OCD device cable appears to have been disconnected.");
479 if (ocd_interrupt_flag
)
485 /* Read registers from the OCD device. Specify the starting and ending
486 register number. Return the number of regs actually read in *NUMREGS.
487 Returns a pointer to a static array containing the register contents. */
490 ocd_read_bdm_registers (int first_bdm_regno
, int last_bdm_regno
, int *reglen
)
492 unsigned char buf
[10];
496 int error_code
, status
;
499 buf
[0] = OCD_READ_REGS
;
500 buf
[1] = first_bdm_regno
>> 8;
501 buf
[2] = first_bdm_regno
& 0xff;
502 buf
[3] = last_bdm_regno
>> 8;
503 buf
[4] = last_bdm_regno
& 0xff;
505 ocd_put_packet (buf
, 5);
506 p
= ocd_get_packet (OCD_READ_REGS
, &pktlen
, remote_timeout
);
512 ocd_error ("read_bdm_registers:", error_code
);
520 error ("Register block size bad: %d", i
);
529 /* Read register BDM_REGNO and returns its value ala read_register() */
532 ocd_read_bdm_register (int bdm_regno
)
538 p
= ocd_read_bdm_registers (bdm_regno
, bdm_regno
, ®len
);
539 regval
= extract_unsigned_integer (p
, reglen
);
545 ocd_write_bdm_registers (int first_bdm_regno
, unsigned char *regptr
, int reglen
)
549 int error_code
, status
;
552 buf
= alloca (4 + reglen
);
554 buf
[0] = OCD_WRITE_REGS
;
555 buf
[1] = first_bdm_regno
>> 8;
556 buf
[2] = first_bdm_regno
& 0xff;
558 memcpy (buf
+ 4, regptr
, reglen
);
560 ocd_put_packet (buf
, 4 + reglen
);
561 p
= ocd_get_packet (OCD_WRITE_REGS
, &pktlen
, remote_timeout
);
564 error ("Truncated response packet from OCD device");
570 ocd_error ("ocd_write_bdm_registers:", error_code
);
574 ocd_write_bdm_register (int bdm_regno
, CORE_ADDR reg
)
576 unsigned char buf
[4];
578 store_unsigned_integer (buf
, 4, reg
);
580 ocd_write_bdm_registers (bdm_regno
, buf
, 4);
584 ocd_prepare_to_store (void)
588 /* Write memory data directly to the remote machine.
589 This does not inform the data cache; the data cache uses this.
590 MEMADDR is the address in the remote memory space.
591 MYADDR is the address of the buffer in our space.
592 LEN is the number of bytes.
594 Returns number of bytes transferred, or 0 for error. */
596 static int write_mem_command
= OCD_WRITE_MEM
;
599 ocd_write_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
607 buf
[0] = write_mem_command
;
608 buf
[5] = 1; /* Write as bytes */
609 buf
[6] = 0; /* Don't verify */
615 int status
, error_code
;
617 numbytes
= min (len
, 256 - 8);
619 buf
[1] = memaddr
>> 24;
620 buf
[2] = memaddr
>> 16;
621 buf
[3] = memaddr
>> 8;
626 memcpy (&buf
[8], myaddr
, numbytes
);
627 ocd_put_packet (buf
, 8 + numbytes
);
628 p
= ocd_get_packet (OCD_WRITE_MEM
, &pktlen
, remote_timeout
);
630 error ("Truncated response packet from OCD device");
635 if (error_code
== 0x11) /* Got a bus error? */
637 CORE_ADDR error_address
;
639 error_address
= p
[3] << 24;
640 error_address
|= p
[4] << 16;
641 error_address
|= p
[5] << 8;
642 error_address
|= p
[6];
643 numbytes
= error_address
- memaddr
;
651 else if (error_code
!= 0)
652 ocd_error ("ocd_write_bytes:", error_code
);
659 return origlen
- len
;
662 /* Read memory data directly from the remote machine.
663 This does not use the data cache; the data cache uses this.
664 MEMADDR is the address in the remote memory space.
665 MYADDR is the address of the buffer in our space.
666 LEN is the number of bytes.
668 Returns number of bytes transferred, or 0 for error. */
671 ocd_read_bytes (CORE_ADDR memaddr
, char *myaddr
, int len
)
679 buf
[0] = OCD_READ_MEM
;
680 buf
[5] = 1; /* Read as bytes */
686 int status
, error_code
;
688 numbytes
= min (len
, 256 - 7);
690 buf
[1] = memaddr
>> 24;
691 buf
[2] = memaddr
>> 16;
692 buf
[3] = memaddr
>> 8;
697 ocd_put_packet (buf
, 7);
698 p
= ocd_get_packet (OCD_READ_MEM
, &pktlen
, remote_timeout
);
700 error ("Truncated response packet from OCD device");
705 if (error_code
== 0x11) /* Got a bus error? */
707 CORE_ADDR error_address
;
709 error_address
= p
[3] << 24;
710 error_address
|= p
[4] << 16;
711 error_address
|= p
[5] << 8;
712 error_address
|= p
[6];
713 numbytes
= error_address
- memaddr
;
721 else if (error_code
!= 0)
722 ocd_error ("ocd_read_bytes:", error_code
);
724 memcpy (myaddr
, &p
[4], numbytes
);
731 return origlen
- len
;
734 /* Read or write LEN bytes from inferior memory at MEMADDR, transferring
735 to or from debugger address MYADDR. Write to inferior if SHOULD_WRITE is
736 nonzero. Returns length of data written or read; 0 for error. TARGET
740 ocd_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int should_write
,
741 struct mem_attrib
*attrib
, struct target_ops
*target
)
746 res
= ocd_write_bytes (memaddr
, myaddr
, len
);
748 res
= ocd_read_bytes (memaddr
, myaddr
, len
);
754 ocd_files_info (struct target_ops
*ignore
)
756 puts_filtered ("Debugging a target over a serial line.\n");
759 /* Stuff for dealing with the packets which are part of this protocol.
760 See comment at top of file for details. */
762 /* Read a single character from the remote side, handling wierd errors. */
765 readchar (int timeout
)
769 ch
= serial_readchar (ocd_desc
, timeout
);
774 error ("Remote connection closed");
776 perror_with_name ("Remote communication error");
784 /* Read a character from the data stream, dequoting as necessary. SYN is
785 treated special. Any SYNs appearing in the data stream are returned as the
786 distinct value RAW_SYN (which has a value > 8 bits and therefore cannot be
787 mistaken for real data). */
790 get_quoted_char (int timeout
)
794 ch
= readchar (timeout
);
799 error ("Timeout in mid-packet, aborting");
803 ch
= readchar (timeout
);
812 static unsigned char pkt
[256 * 2 + 10], *pktp
; /* Worst case */
823 if (serial_write (ocd_desc
, pkt
, pktp
- pkt
))
824 perror_with_name ("output_packet: write failed");
829 /* Output a quoted character. SYNs and DLEs are quoted. Everything else goes
830 through untouched. */
833 put_quoted_char (int c
)
846 /* Send a packet to the OCD device. The packet framed by a SYN character,
847 a byte count and a checksum. The byte count only counts the number of
848 bytes between the count and the checksum. A count of zero actually
849 means 256. Any SYNs within the packet (including the checksum and
850 count) must be quoted. The quote character must be quoted as well.
851 Quoting is done by replacing the character with the two-character sequence
852 DLE, {char} | 0100. Note that the quoting mechanism has no effect on the
856 stu_put_packet (unsigned char *buf
, int len
)
858 unsigned char checksum
;
861 if (len
== 0 || len
> 256)
862 internal_error (__FILE__
, __LINE__
, "failed internal consistency check"); /* Can't represent 0 length packet */
868 put_quoted_char (RAW_SYN
);
882 put_quoted_char (-checksum
& 0xff);
889 /* Send a packet to the OCD device. The packet framed by a SYN character,
890 a byte count and a checksum. The byte count only counts the number of
891 bytes between the count and the checksum. A count of zero actually
892 means 256. Any SYNs within the packet (including the checksum and
893 count) must be quoted. The quote character must be quoted as well.
894 Quoting is done by replacing the character with the two-character sequence
895 DLE, {char} | 0100. Note that the quoting mechanism has no effect on the
899 ocd_put_packet (unsigned char *buf
, int len
)
901 unsigned char checksum
;
903 unsigned char *packet
, *packet_ptr
;
905 packet
= alloca (len
+ 1 + 1); /* packet + SYN + checksum */
910 *packet_ptr
++ = 0x55;
920 *packet_ptr
++ = -checksum
;
921 if (serial_write (ocd_desc
, packet
, packet_ptr
- packet
))
922 perror_with_name ("output_packet: write failed");
927 /* Get a packet from the OCD device. Timeout is only enforced for the
928 first byte of the packet. Subsequent bytes are expected to arrive in
929 time <= remote_timeout. Returns a pointer to a static buffer containing
930 the payload of the packet. *LENP contains the length of the packet.
933 static unsigned char *
934 stu_get_packet (unsigned char cmd
, int *lenp
, int timeout
)
938 static unsigned char buf
[256 + 10], *p
;
939 unsigned char checksum
;
943 ch
= get_quoted_char (timeout
);
946 error ("get_packet (readchar): %d", ch
);
951 found_syn
: /* Found the start of a packet */
956 len
= get_quoted_char (remote_timeout
);
966 len
++; /* Include checksum */
970 ch
= get_quoted_char (remote_timeout
);
982 error ("Response phase error. Got 0x%x, expected 0x%x", buf
[0], cmd
);
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 ocd_get_packet (int cmd
, int *lenp
, int timeout
)
1001 static unsigned char packet
[512];
1002 unsigned char *packet_ptr
;
1003 unsigned char checksum
;
1005 ch
= readchar (timeout
);
1008 error ("ocd_get_packet (readchar): %d", ch
);
1011 error ("ocd_get_packet (readchar): %d", ch
);
1013 /* Found the start of a packet */
1015 packet_ptr
= packet
;
1018 /* Read command char. That sort of tells us how long the packet is. */
1020 ch
= readchar (timeout
);
1023 error ("ocd_get_packet (readchar): %d", ch
);
1030 ch
= readchar (timeout
);
1033 error ("ocd_get_packet (readchar): %d", ch
);
1037 /* Get error code. */
1039 ch
= readchar (timeout
);
1042 error ("ocd_get_packet (readchar): %d", ch
);
1046 switch (ch
) /* Figure out length of packet */
1048 case 0x7: /* Write verify error? */
1049 len
= 8; /* write address, value read back */
1051 case 0x11: /* Bus error? */
1052 /* write address, read flag */
1053 case 0x15: /* Internal error */
1054 len
= 5; /* error code, vector */
1056 default: /* Error w/no params */
1059 case 0x0: /* Normal result */
1062 case OCD_AYT
: /* Are You There? */
1063 case OCD_SET_BAUD_RATE
: /* Set Baud Rate */
1064 case OCD_INIT
: /* Initialize OCD device */
1065 case OCD_SET_SPEED
: /* Set Speed */
1066 case OCD_SET_FUNC_CODE
: /* Set Function Code */
1067 case OCD_SET_CTL_FLAGS
: /* Set Control Flags */
1068 case OCD_SET_BUF_ADDR
: /* Set Register Buffer Address */
1069 case OCD_RUN
: /* Run Target from PC */
1070 case OCD_RUN_ADDR
: /* Run Target from Specified Address */
1071 case OCD_STOP
: /* Stop Target */
1072 case OCD_RESET_RUN
: /* Reset Target and Run */
1073 case OCD_RESET
: /* Reset Target and Halt */
1074 case OCD_STEP
: /* Single Step */
1075 case OCD_WRITE_REGS
: /* Write Register */
1076 case OCD_WRITE_MEM
: /* Write Memory */
1077 case OCD_FILL_MEM
: /* Fill Memory */
1078 case OCD_MOVE_MEM
: /* Move Memory */
1079 case OCD_WRITE_INT_MEM
: /* Write Internal Memory */
1080 case OCD_JUMP
: /* Jump to Subroutine */
1081 case OCD_ERASE_FLASH
: /* Erase flash memory */
1082 case OCD_PROGRAM_FLASH
: /* Write flash memory */
1083 case OCD_EXIT_MON
: /* Exit the flash programming monitor */
1084 case OCD_ENTER_MON
: /* Enter the flash programming monitor */
1085 case OCD_LOG_FILE
: /* Make Wigglers.dll save Wigglers.log */
1086 case OCD_SET_CONNECTION
: /* Set type of connection in Wigglers.dll */
1089 case OCD_GET_VERSION
: /* Get Version */
1092 case OCD_GET_STATUS_MASK
: /* Get Status Mask */
1095 case OCD_GET_CTRS
: /* Get Error Counters */
1096 case OCD_READ_REGS
: /* Read Register */
1097 case OCD_READ_MEM
: /* Read Memory */
1098 case OCD_READ_INT_MEM
: /* Read Internal Memory */
1102 error ("ocd_get_packet: unknown packet type 0x%x\n", ch
);
1106 if (len
== 257) /* Byte stream? */
1107 { /* Yes, byte streams contain the length */
1108 ch
= readchar (timeout
);
1111 error ("ocd_get_packet (readchar): %d", ch
);
1119 while (len
-- >= 0) /* Do rest of packet and checksum */
1121 ch
= readchar (timeout
);
1124 error ("ocd_get_packet (readchar): %d", ch
);
1130 error ("ocd_get_packet: bad packet checksum");
1132 if (cmd
!= -1 && cmd
!= packet
[0])
1133 error ("Response phase error. Got 0x%x, expected 0x%x", packet
[0], cmd
);
1135 *lenp
= packet_ptr
- packet
- 1; /* Subtract checksum byte */
1140 /* Execute a simple (one-byte) command. Returns a pointer to the data
1141 following the error code. */
1143 static unsigned char *
1144 ocd_do_command (int cmd
, int *statusp
, int *lenp
)
1146 unsigned char buf
[100], *p
;
1147 int status
, error_code
;
1150 unsigned char logbuf
[100];
1154 ocd_put_packet (buf
, 1); /* Send command */
1155 p
= ocd_get_packet (*buf
, lenp
, remote_timeout
);
1158 error ("Truncated response packet from OCD device");
1163 if (error_code
!= 0)
1165 sprintf (errbuf
, "ocd_do_command (0x%x):", cmd
);
1166 ocd_error (errbuf
, error_code
);
1169 if (status
& OCD_FLAG_PWF
)
1170 error ("OCD device can't detect VCC at BDM interface.");
1171 else if (status
& OCD_FLAG_CABLE_DISC
)
1172 error ("BDM cable appears to be disconnected.");
1176 logbuf
[0] = OCD_LOG_FILE
;
1177 logbuf
[1] = 3; /* close existing WIGGLERS.LOG */
1178 ocd_put_packet (logbuf
, 2);
1179 ocd_get_packet (logbuf
[0], &logpktlen
, remote_timeout
);
1181 logbuf
[0] = OCD_LOG_FILE
;
1182 logbuf
[1] = 2; /* append to existing WIGGLERS.LOG */
1183 ocd_put_packet (logbuf
, 2);
1184 ocd_get_packet (logbuf
[0], &logpktlen
, remote_timeout
);
1192 /* For some mysterious reason, wait_for_inferior calls kill instead of
1193 mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */
1197 target_mourn_inferior ();
1201 /* Don't wait for it to die. I'm not really sure it matters whether
1203 target_mourn_inferior ();
1209 unpush_target (current_ops
);
1210 generic_mourn_inferior ();
1213 /* All we actually do is set the PC to the start address of exec_bfd, and start
1214 the program at that point. */
1217 ocd_create_inferior (char *exec_file
, char *args
, char **env
)
1219 if (args
&& (*args
!= '\000'))
1220 error ("Args are not supported by BDM.");
1222 clear_proceed_status ();
1223 proceed (bfd_get_start_address (exec_bfd
), TARGET_SIGNAL_0
, 0);
1227 ocd_load (char *args
, int from_tty
)
1229 generic_load (args
, from_tty
);
1231 inferior_ptid
= null_ptid
;
1233 /* This is necessary because many things were based on the PC at the time that
1234 we attached to the monitor, which is no longer valid now that we have loaded
1235 new code (and just changed the PC). Another way to do this might be to call
1236 normal_stop, except that the stack may not be valid, and things would get
1237 horribly confused... */
1239 clear_symtab_users ();
1242 /* This should be defined for each target */
1243 /* But we want to be able to compile this file for some configurations
1244 not yet supported fully */
1246 #define BDM_BREAKPOINT {0x0,0x0,0x0,0x0} /* For ppc 8xx */
1248 #define BDM_BREAKPOINT {0x4a,0xfa} /* BGND insn used for CPU32 */
1251 /* BDM (at least on CPU32) uses a different breakpoint */
1254 ocd_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
1256 static char break_insn
[] = BDM_BREAKPOINT
;
1259 val
= target_read_memory (addr
, contents_cache
, sizeof (break_insn
));
1262 val
= target_write_memory (addr
, break_insn
, sizeof (break_insn
));
1268 ocd_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
1270 static char break_insn
[] = BDM_BREAKPOINT
;
1273 val
= target_write_memory (addr
, contents_cache
, sizeof (break_insn
));
1279 bdm_command (char *args
, int from_tty
)
1281 error ("bdm command must be followed by `reset'");
1285 bdm_reset_command (char *args
, int from_tty
)
1290 error ("Not connected to OCD device.");
1292 ocd_do_command (OCD_RESET
, &status
, &pktlen
);
1293 dcache_invalidate (target_dcache
);
1294 registers_changed ();
1298 bdm_restart_command (char *args
, int from_tty
)
1303 error ("Not connected to OCD device.");
1305 ocd_do_command (OCD_RESET_RUN
, &status
, &pktlen
);
1306 last_run_status
= status
;
1307 clear_proceed_status ();
1308 wait_for_inferior ();
1312 /* Temporary replacement for target_store_registers(). This prevents
1313 generic_load from trying to set the PC. */
1316 noop_store_registers (int regno
)
1321 bdm_update_flash_command (char *args
, int from_tty
)
1324 struct cleanup
*old_chain
;
1325 void (*store_registers_tmp
) (int);
1328 error ("Not connected to OCD device.");
1331 error ("Must specify file containing new OCD code.");
1333 /* old_chain = make_cleanup (flash_cleanup, 0); */
1335 ocd_do_command (OCD_ENTER_MON
, &status
, &pktlen
);
1337 ocd_do_command (OCD_ERASE_FLASH
, &status
, &pktlen
);
1339 write_mem_command
= OCD_PROGRAM_FLASH
;
1340 store_registers_tmp
= current_target
.to_store_registers
;
1341 current_target
.to_store_registers
= noop_store_registers
;
1343 generic_load (args
, from_tty
);
1345 current_target
.to_store_registers
= store_registers_tmp
;
1346 write_mem_command
= OCD_WRITE_MEM
;
1348 ocd_do_command (OCD_EXIT_MON
, &status
, &pktlen
);
1350 /* discard_cleanups (old_chain); */
1354 bdm_read_register_command (char *args
, int from_tty
)
1356 /* XXX repeat should go on to the next register */
1359 error ("Not connected to OCD device.");
1362 error ("Must specify BDM register number.");
1366 extern initialize_file_ftype _initialize_remote_ocd
; /* -Wmissing-prototypes */
1369 _initialize_remote_ocd (void)
1371 extern struct cmd_list_element
*cmdlist
;
1372 static struct cmd_list_element
*ocd_cmd_list
= NULL
;
1374 add_show_from_set (add_set_cmd ("remotetimeout", no_class
,
1375 var_integer
, (char *) &remote_timeout
,
1376 "Set timeout value for remote read.\n", &setlist
),
1379 add_prefix_cmd ("ocd", class_obscure
, bdm_command
, "", &ocd_cmd_list
, "ocd ",
1382 add_cmd ("reset", class_obscure
, bdm_reset_command
, "", &ocd_cmd_list
);
1383 add_cmd ("restart", class_obscure
, bdm_restart_command
, "", &ocd_cmd_list
);
1384 add_cmd ("update-flash", class_obscure
, bdm_update_flash_command
, "", &ocd_cmd_list
);
1385 /* add_cmd ("read-register", class_obscure, bdm_read_register_command, "", &ocd_cmd_list); */