Commit | Line | Data |
---|---|---|
d9951af4 SG |
1 | /* Remote target communications for the Macraigor Systems BDM Wiggler |
2 | Copyright 1996 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "gdbcore.h" | |
22 | #include "gdb_string.h" | |
23 | #include <fcntl.h> | |
24 | #include "frame.h" | |
25 | #include "inferior.h" | |
26 | #include "bfd.h" | |
27 | #include "symfile.h" | |
28 | #include "target.h" | |
29 | #include "wait.h" | |
30 | #include "gdbcmd.h" | |
31 | #include "objfiles.h" | |
32 | #include "gdb-stabs.h" | |
33 | ||
34 | #include "dcache.h" | |
35 | ||
36 | #ifdef USG | |
37 | #include <sys/types.h> | |
38 | #endif | |
39 | ||
40 | #include <signal.h> | |
41 | #include "serial.h" | |
42 | ||
43 | /* Wiggler serial protocol definitions */ | |
44 | ||
45 | #define DLE 020 /* Quote char */ | |
46 | #define SYN 026 /* Start of packet */ | |
47 | #define RAW_SYN ((026 << 8) | 026) /* get_quoted_char found a naked SYN */ | |
48 | ||
49 | /* Status flags */ | |
50 | ||
51 | #define WIGGLER_FLAG_RESET 0x01 /* Target is being reset */ | |
52 | #define WIGGLER_FLAG_STOPPED 0x02 /* Target is halted */ | |
53 | #define WIGGLER_FLAG_BDM 0x04 /* Target is in BDM */ | |
54 | #define WIGGLER_FLAG_PWF 0x08 /* Power failed */ | |
55 | #define WIGGLER_FLAG_CABLE_DISC 0x10 /* BDM cable disconnected */ | |
56 | ||
57 | #define WIGGLER_AYT 0x0 /* Are you there? */ | |
58 | #define WIGGLER_GET_VERSION 0x1 /* Get Version */ | |
59 | #define WIGGLER_SET_BAUD_RATE 0x2 /* Set Baud Rate */ | |
60 | #define WIGGLER_INIT 0x10 /* Initialize Wiggler */ | |
61 | #define WIGGLER_SET_SPEED 0x11 /* Set Speed */ | |
62 | #define WIGGLER_GET_STATUS_MASK 0x12 /* Get Status Mask */ | |
63 | #define WIGGLER_GET_CTRS 0x13 /* Get Error Counters */ | |
64 | #define WIGGLER_SET_FUNC_CODE 0x14 /* Set Function Code */ | |
65 | #define WIGGLER_SET_CTL_FLAGS 0x15 /* Set Control Flags */ | |
66 | #define WIGGLER_SET_BUF_ADDR 0x16 /* Set Register Buffer Address */ | |
67 | #define WIGGLER_RUN 0x20 /* Run Target from PC */ | |
68 | #define WIGGLER_RUN_ADDR 0x21 /* Run Target from Specified Address */ | |
69 | #define WIGGLER_STOP 0x22 /* Stop Target */ | |
70 | #define WIGGLER_RESET_RUN 0x23 /* Reset Target and Run */ | |
71 | #define WIGGLER_RESET 0x24 /* Reset Target and Halt */ | |
72 | #define WIGGLER_STEP 0x25 /* Single step */ | |
73 | #define WIGGLER_READ_REGS 0x30 /* Read Registers */ | |
74 | #define WIGGLER_WRITE_REGS 0x31 /* Write Registers */ | |
75 | #define WIGGLER_READ_MEM 0x32 /* Read Memory */ | |
76 | #define WIGGLER_WRITE_MEM 0x33 /* Write Memory */ | |
77 | #define WIGGLER_FILL_MEM 0x34 /* Fill Memory */ | |
78 | #define WIGGLER_MOVE_MEM 0x35 /* Move Memory */ | |
79 | ||
80 | #define WIGGLER_READ_INT_MEM 0x80 /* Read Internal Memory */ | |
81 | #define WIGGLER_WRITE_INT_MEM 0x81 /* Write Internal Memory */ | |
82 | #define WIGGLER_JUMP 0x82 /* Jump to Subroutine */ | |
83 | ||
84 | #define WIGGLER_SET_STATUS 0x0a /* Set status */ | |
85 | #define WIGGLER_FLAG_STOP 0x0 /* Stop the target, enter BDM */ | |
86 | #define WIGGLER_FLAG_START 0x01 /* Start the target at PC */ | |
87 | #define WIGGLER_FLAG_RETURN_STATUS 0x04 /* Return async status */ | |
88 | ||
89 | /* Stuff that should be in tm-xxx files. */ | |
90 | #if 1 | |
91 | #define BDM_NUM_REGS 24 | |
92 | #define BDM_REGMAP 0, 1, 2, 3, 4, 5, 6, 7, /* d0 -> d7 */ \ | |
93 | 8, 9, 10, 11, 12, 13, 14, 15, /* a0 -> a7 */ \ | |
94 | 18, 16, /* ps, pc */ \ | |
95 | -1, -1, -1, -1, -1, -1, -1, -1, /* fp0 -> fp7 */ \ | |
96 | -1, -1, -1, -1, -1 /* fpcontrol, fpstatus, fpiaddr, fpcode, fpflags */ | |
97 | #define BDM_BREAKPOINT 0x4a, 0xfa /* BGND insn */ | |
98 | #else | |
99 | #define BDM_NUM_REGS 24 | |
100 | #define BDM_REGMAP 8, 9, 10, 11, 12, 13, 14, 15, /* d0 -> d7 */ \ | |
101 | 16, 17, 18, 19, 20, 21, 22, 23, /* a0 -> a7 */ \ | |
102 | 4, 0, /* ps, pc */ \ | |
103 | -1, -1, -1, -1, -1, -1, -1, -1, /* fp0 -> fp7 */ \ | |
104 | -1, -1, -1, -1, -1 /* fpcontrol, fpstatus, fpiaddr, fpcode, fpflags */ | |
105 | #define WIGGLER_POLL | |
106 | #endif | |
107 | ||
108 | /* Prototypes for local functions */ | |
109 | ||
110 | static void wiggler_stop PARAMS ((void)); | |
111 | ||
112 | static void put_packet PARAMS ((unsigned char *packet, int pktlen)); | |
113 | static unsigned char * get_packet PARAMS ((int cmd, int *pktlen, int timeout)); | |
114 | ||
115 | static int wiggler_write_bytes PARAMS ((CORE_ADDR memaddr, | |
116 | char *myaddr, int len)); | |
117 | ||
118 | static int wiggler_read_bytes PARAMS ((CORE_ADDR memaddr, | |
119 | char *myaddr, int len)); | |
120 | ||
121 | static void wiggler_files_info PARAMS ((struct target_ops *ignore)); | |
122 | ||
123 | static int wiggler_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr, | |
124 | int len, int should_write, | |
125 | struct target_ops *target)); | |
126 | ||
127 | static void wiggler_prepare_to_store PARAMS ((void)); | |
128 | ||
129 | static void wiggler_fetch_registers PARAMS ((int regno)); | |
130 | ||
131 | static void wiggler_resume PARAMS ((int pid, int step, | |
132 | enum target_signal siggnal)); | |
133 | ||
134 | static int wiggler_start_remote PARAMS ((char *dummy)); | |
135 | ||
136 | static void wiggler_open PARAMS ((char *name, int from_tty)); | |
137 | ||
138 | static void wiggler_close PARAMS ((int quitting)); | |
139 | ||
140 | static void wiggler_store_registers PARAMS ((int regno)); | |
141 | ||
142 | static void wiggler_mourn PARAMS ((void)); | |
143 | ||
144 | static int readchar PARAMS ((int timeout)); | |
145 | ||
146 | static void reset_packet PARAMS ((void)); | |
147 | ||
148 | static void output_packet PARAMS ((void)); | |
149 | ||
150 | static int get_quoted_char PARAMS ((int timeout)); | |
151 | ||
152 | static void put_quoted_char PARAMS ((int c)); | |
153 | ||
154 | static int wiggler_wait PARAMS ((int pid, struct target_waitstatus *status)); | |
155 | ||
156 | static void wiggler_kill PARAMS ((void)); | |
157 | ||
158 | static void wiggler_detach PARAMS ((char *args, int from_tty)); | |
159 | ||
160 | static void wiggler_interrupt PARAMS ((int signo)); | |
161 | ||
162 | static void wiggler_interrupt_twice PARAMS ((int signo)); | |
163 | ||
164 | static void interrupt_query PARAMS ((void)); | |
165 | ||
166 | static unsigned char * do_command PARAMS ((int cmd, int *statusp, int *lenp)); | |
167 | ||
168 | static unsigned char * read_bdm_registers PARAMS ((int first_bdm_regno, | |
169 | int last_bdm_regno, | |
170 | int *numregs)); | |
171 | ||
172 | extern struct target_ops wiggler_ops; /* Forward decl */ | |
173 | ||
174 | static int last_run_status; | |
175 | ||
176 | /* This was 5 seconds, which is a long time to sit and wait. | |
177 | Unless this is going though some terminal server or multiplexer or | |
178 | other form of hairy serial connection, I would think 2 seconds would | |
179 | be plenty. */ | |
180 | ||
181 | /* Changed to allow option to set timeout value. | |
182 | was static int remote_timeout = 2; */ | |
183 | extern int remote_timeout; | |
184 | ||
185 | /* Descriptor for I/O to remote machine. Initialize it to NULL so that | |
186 | wiggler_open knows that we don't have a file open when the program | |
187 | starts. */ | |
188 | serial_t wiggler_desc = NULL; | |
189 | \f | |
190 | static void | |
191 | wiggler_error (s, error_code) | |
192 | char *s; | |
193 | int error_code; | |
194 | { | |
195 | char buf[100]; | |
196 | ||
197 | fputs_filtered (s, gdb_stderr); | |
198 | ||
199 | switch (error_code) | |
200 | { | |
5819f35d SG |
201 | case 0x1: s = "Unknown fault"; break; |
202 | case 0x2: s = "Power failed"; break; | |
203 | case 0x3: s = "Cable disconnected"; break; | |
204 | case 0x4: s = "Couldn't enter BDM"; break; | |
205 | case 0x5: s = "Target stuck in reset"; break; | |
206 | case 0x6: s = "Port not configured"; break; | |
207 | case 0x7: s = "Write verify failed"; break; | |
208 | case 0x11: s = "Bus error"; break; | |
209 | case 0x12: s = "Checksum error"; break; | |
210 | case 0x13: s = "Illegal command"; break; | |
211 | case 0x14: s = "Parameter error"; break; | |
212 | case 0x15: s = "Internal error"; break; | |
213 | case 0x16: s = "Register buffer error"; break; | |
d9951af4 SG |
214 | default: |
215 | sprintf (buf, "Unknown error code %d", error_code); | |
5819f35d | 216 | s = buf; |
d9951af4 SG |
217 | } |
218 | ||
219 | error (s); | |
220 | } | |
221 | ||
222 | /* Return nonzero if the thread TH is still alive on the remote system. */ | |
223 | ||
224 | static int | |
225 | wiggler_thread_alive (th) | |
226 | int th; | |
227 | { | |
228 | return 1; | |
229 | } | |
230 | \f | |
231 | /* Clean up connection to a remote debugger. */ | |
232 | ||
233 | /* ARGSUSED */ | |
234 | static void | |
235 | wiggler_close (quitting) | |
236 | int quitting; | |
237 | { | |
238 | if (wiggler_desc) | |
239 | SERIAL_CLOSE (wiggler_desc); | |
240 | wiggler_desc = NULL; | |
241 | } | |
242 | ||
243 | /* Stub for catch_errors. */ | |
244 | ||
245 | static int | |
246 | wiggler_start_remote (dummy) | |
247 | char *dummy; | |
248 | { | |
249 | unsigned char buf[10], *p; | |
250 | int pktlen; | |
251 | int status; | |
252 | int error_code; | |
253 | int speed; | |
254 | ||
255 | immediate_quit = 1; /* Allow user to interrupt it */ | |
256 | ||
257 | SERIAL_SEND_BREAK (wiggler_desc); /* Wake up the wiggler */ | |
258 | ||
259 | do_command (WIGGLER_AYT, &status, &pktlen); | |
260 | ||
261 | p = do_command (WIGGLER_GET_VERSION, &status, &pktlen); | |
262 | ||
263 | printf_unfiltered ("[Wiggler version %x.%x, capability 0x%x]\n", | |
264 | p[0], p[1], (p[2] << 16) | p[3]); | |
265 | ||
266 | #if 1 | |
267 | speed = 80; /* Divide clock by 4000 */ | |
268 | ||
269 | buf[0] = WIGGLER_INIT; | |
270 | buf[1] = speed >> 8; | |
271 | buf[2] = speed & 0xff; | |
272 | buf[3] = 0; /* CPU32 for now */ | |
273 | put_packet (buf, 4); /* Init Wiggler params */ | |
274 | p = get_packet (buf[0], &pktlen, remote_timeout); | |
275 | ||
276 | if (pktlen < 2) | |
277 | error ("Truncated response packet from Wiggler"); | |
278 | ||
279 | status = p[1]; | |
280 | error_code = p[2]; | |
281 | ||
282 | if (error_code != 0) | |
283 | wiggler_error ("WIGGLER_INIT:", error_code); | |
284 | #endif | |
285 | ||
286 | #if 0 | |
287 | /* Reset the target */ | |
288 | ||
289 | do_command (WIGGLER_RESET_RUN, &status, &pktlen); | |
290 | /* do_command (WIGGLER_RESET, &status, &pktlen);*/ | |
291 | #endif | |
292 | ||
293 | /* If processor is still running, stop it. */ | |
294 | ||
295 | if (!(status & WIGGLER_FLAG_BDM)) | |
296 | wiggler_stop (); | |
297 | ||
298 | #if 1 | |
299 | buf[0] = WIGGLER_SET_CTL_FLAGS; | |
300 | buf[1] = 0; | |
301 | buf[2] = 1; /* Asynchronously return status when target stops */ | |
302 | put_packet (buf, 3); | |
303 | ||
304 | p = get_packet (buf[0], &pktlen, remote_timeout); | |
305 | ||
306 | if (pktlen < 2) | |
307 | error ("Truncated response packet from Wiggler"); | |
308 | ||
309 | status = p[1]; | |
310 | error_code = p[2]; | |
311 | ||
312 | if (error_code != 0) | |
313 | wiggler_error ("WIGGLER_SET_CTL_FLAGS:", error_code); | |
314 | #endif | |
315 | ||
316 | immediate_quit = 0; | |
317 | ||
318 | /* This is really the job of start_remote however, that makes an assumption | |
319 | that the target is about to print out a status message of some sort. That | |
320 | doesn't happen here (in fact, it may not be possible to get the monitor to | |
321 | send the appropriate packet). */ | |
322 | ||
323 | flush_cached_frames (); | |
324 | registers_changed (); | |
325 | stop_pc = read_pc (); | |
326 | set_current_frame (create_new_frame (read_fp (), stop_pc)); | |
327 | select_frame (get_current_frame (), 0); | |
328 | print_stack_frame (selected_frame, -1, 1); | |
329 | ||
330 | return 1; | |
331 | } | |
332 | ||
333 | /* Open a connection to a remote debugger. | |
334 | NAME is the filename used for communication. */ | |
335 | ||
336 | static DCACHE *wiggler_dcache; | |
337 | ||
338 | static void | |
339 | wiggler_open (name, from_tty) | |
340 | char *name; | |
341 | int from_tty; | |
342 | { | |
343 | if (name == 0) | |
344 | error ("To open a Wiggler connection, you need to specify what serial\n\ | |
345 | device the Wiggler is attached to (e.g. /dev/ttya)."); | |
346 | ||
347 | target_preopen (from_tty); | |
348 | ||
349 | unpush_target (&wiggler_ops); | |
350 | ||
351 | wiggler_dcache = dcache_init (wiggler_read_bytes, wiggler_write_bytes); | |
352 | ||
353 | wiggler_desc = SERIAL_OPEN (name); | |
354 | if (!wiggler_desc) | |
355 | perror_with_name (name); | |
356 | ||
357 | if (baud_rate != -1) | |
358 | { | |
359 | if (SERIAL_SETBAUDRATE (wiggler_desc, baud_rate)) | |
360 | { | |
361 | SERIAL_CLOSE (wiggler_desc); | |
362 | perror_with_name (name); | |
363 | } | |
364 | } | |
365 | ||
366 | SERIAL_RAW (wiggler_desc); | |
367 | ||
368 | /* If there is something sitting in the buffer we might take it as a | |
369 | response to a command, which would be bad. */ | |
370 | SERIAL_FLUSH_INPUT (wiggler_desc); | |
371 | ||
372 | if (from_tty) | |
373 | { | |
374 | puts_filtered ("Remote target wiggler connected to "); | |
375 | puts_filtered (name); | |
376 | puts_filtered ("\n"); | |
377 | } | |
378 | push_target (&wiggler_ops); /* Switch to using remote target now */ | |
379 | ||
380 | /* Without this, some commands which require an active target (such as kill) | |
381 | won't work. This variable serves (at least) double duty as both the pid | |
382 | of the target process (if it has such), and as a flag indicating that a | |
383 | target is active. These functions should be split out into seperate | |
384 | variables, especially since GDB will someday have a notion of debugging | |
385 | several processes. */ | |
386 | ||
387 | inferior_pid = 42000; | |
388 | /* Start the remote connection; if error (0), discard this target. | |
389 | In particular, if the user quits, be sure to discard it | |
390 | (we'd be in an inconsistent state otherwise). */ | |
391 | if (!catch_errors (wiggler_start_remote, (char *)0, | |
392 | "Couldn't establish connection to remote target\n", RETURN_MASK_ALL)) | |
393 | pop_target(); | |
394 | } | |
395 | ||
396 | /* This takes a program previously attached to and detaches it. After | |
397 | this is done, GDB can be used to debug some other program. We | |
398 | better not have left any breakpoints in the target program or it'll | |
399 | die when it hits one. */ | |
400 | ||
401 | static void | |
402 | wiggler_detach (args, from_tty) | |
403 | char *args; | |
404 | int from_tty; | |
405 | { | |
406 | if (args) | |
407 | error ("Argument given to \"detach\" when remotely debugging."); | |
408 | ||
409 | pop_target (); | |
410 | if (from_tty) | |
411 | puts_filtered ("Ending remote debugging.\n"); | |
412 | } | |
413 | \f | |
414 | /* Tell the remote machine to resume. */ | |
415 | ||
416 | static void | |
417 | wiggler_resume (pid, step, siggnal) | |
418 | int pid, step; | |
419 | enum target_signal siggnal; | |
420 | { | |
421 | int pktlen; | |
422 | ||
423 | dcache_flush (wiggler_dcache); | |
424 | ||
425 | if (step) | |
426 | do_command (WIGGLER_STEP, &last_run_status, &pktlen); | |
427 | else | |
428 | do_command (WIGGLER_RUN, &last_run_status, &pktlen); | |
429 | } | |
430 | \f | |
431 | static void | |
432 | wiggler_stop () | |
433 | { | |
434 | int status; | |
435 | int pktlen; | |
436 | ||
437 | do_command (WIGGLER_STOP, &status, &pktlen); | |
438 | ||
439 | if (!(status & WIGGLER_FLAG_BDM)) | |
440 | error ("Can't stop target via BDM"); | |
441 | } | |
442 | ||
443 | static volatile int wiggler_interrupt_flag; | |
444 | ||
445 | /* Send ^C to target to halt it. Target will respond, and send us a | |
446 | packet. */ | |
447 | ||
448 | static void | |
449 | wiggler_interrupt (signo) | |
450 | int signo; | |
451 | { | |
452 | /* If this doesn't work, try more severe steps. */ | |
453 | signal (signo, wiggler_interrupt_twice); | |
454 | ||
455 | if (remote_debug) | |
456 | printf_unfiltered ("wiggler_interrupt called\n"); | |
457 | ||
458 | { | |
459 | char buf[1]; | |
460 | ||
461 | wiggler_stop (); | |
462 | buf[0] = WIGGLER_AYT; | |
463 | put_packet (buf, 1); | |
464 | wiggler_interrupt_flag = 1; | |
465 | } | |
466 | } | |
467 | ||
468 | static void (*ofunc)(); | |
469 | ||
470 | /* The user typed ^C twice. */ | |
471 | static void | |
472 | wiggler_interrupt_twice (signo) | |
473 | int signo; | |
474 | { | |
475 | signal (signo, ofunc); | |
476 | ||
477 | interrupt_query (); | |
478 | ||
479 | signal (signo, wiggler_interrupt); | |
480 | } | |
481 | ||
482 | /* Ask the user what to do when an interrupt is received. */ | |
483 | ||
484 | static void | |
485 | interrupt_query () | |
486 | { | |
487 | target_terminal_ours (); | |
488 | ||
489 | if (query ("Interrupted while waiting for the program.\n\ | |
490 | Give up (and stop debugging it)? ")) | |
491 | { | |
492 | target_mourn_inferior (); | |
493 | return_to_top_level (RETURN_QUIT); | |
494 | } | |
495 | ||
496 | target_terminal_inferior (); | |
497 | } | |
498 | ||
499 | /* If nonzero, ignore the next kill. */ | |
500 | static int kill_kludge; | |
501 | ||
502 | /* Wait until the remote machine stops, then return, | |
503 | storing status in STATUS just as `wait' would. | |
504 | Returns "pid" (though it's not clear what, if anything, that | |
505 | means in the case of this target). */ | |
506 | ||
507 | static int | |
508 | wiggler_wait (pid, target_status) | |
509 | int pid; | |
510 | struct target_waitstatus *target_status; | |
511 | { | |
512 | unsigned char *p; | |
513 | int error_code, status; | |
514 | int pktlen; | |
515 | ||
516 | wiggler_interrupt_flag = 0; | |
517 | ||
518 | target_status->kind = TARGET_WAITKIND_STOPPED; | |
519 | target_status->value.sig = TARGET_SIGNAL_TRAP; | |
520 | ||
521 | /* Target may already be stopped by the time we get here. */ | |
522 | ||
523 | if (!(last_run_status & WIGGLER_FLAG_BDM)) | |
524 | { | |
525 | ofunc = (void (*)()) signal (SIGINT, wiggler_interrupt); | |
526 | ||
527 | p = get_packet (WIGGLER_AYT, &pktlen, -1); | |
528 | ||
529 | signal (SIGINT, ofunc); | |
530 | ||
531 | if (pktlen < 2) | |
532 | error ("Truncated response packet from Wiggler"); | |
533 | ||
534 | status = p[1]; | |
535 | error_code = p[2]; | |
536 | ||
537 | if (error_code != 0) | |
538 | wiggler_error ("target_wait:", error_code); | |
539 | ||
540 | if (status & WIGGLER_FLAG_PWF) | |
541 | error ("Wiggler lost VCC at BDM interface."); | |
542 | else if (status & WIGGLER_FLAG_CABLE_DISC) | |
543 | error ("BDM cable appears to have been disconnected."); | |
544 | ||
545 | if (!(status & WIGGLER_FLAG_BDM)) | |
546 | error ("Wiggler woke up, but wasn't stopped: 0x%x", status); | |
547 | ||
548 | if (wiggler_interrupt_flag) | |
549 | target_status->value.sig = TARGET_SIGNAL_INT; | |
550 | } | |
551 | ||
552 | /* This test figures out if we just executed a BGND insn, and if it's one of | |
553 | our breakpoints. If so, then we back up PC. N.B. When a BGND insn is | |
554 | executed, the PC points at the loc just after the insn (ie: it's always | |
555 | two bytes *after* the BGND). So, it's not sufficient to just see if PC-2 | |
556 | is a BGND insn because we could have gotten there via a jump. We dis- | |
557 | ambiguate this case by examining the ATEMP register (which is only | |
558 | accessible from BDM). This will tell us if we entered BDM because we | |
559 | executed a BGND insn. */ | |
560 | ||
561 | if (breakpoint_inserted_here_p (read_pc () - 2)) /* One of our breakpoints? */ | |
562 | { /* Yes, see if we actually executed it */ | |
563 | #if 0 /* Temporarily disabled until atemp reading is fixed. */ | |
564 | int atemp; | |
565 | int numregs; | |
566 | ||
567 | p = read_bdm_registers (23, 23, &numregs); | |
568 | atemp = extract_unsigned_integer (p, 4); | |
569 | ||
570 | if (atemp == 1) /* And, did we hit a breakpoint insn? */ | |
571 | #endif | |
572 | write_pc (read_pc () - 2); /* Yes, then back up PC */ | |
573 | } | |
574 | ||
575 | return inferior_pid; | |
576 | } | |
577 | ||
578 | /* Read the remote registers into the block REGS. */ | |
579 | /* Currently we just read all the registers, so we don't use regno. */ | |
580 | /* ARGSUSED */ | |
581 | ||
582 | static unsigned char * | |
583 | read_bdm_registers (first_bdm_regno, last_bdm_regno, numregs) | |
584 | int first_bdm_regno; | |
585 | int last_bdm_regno; | |
586 | int *numregs; | |
587 | { | |
588 | unsigned char buf[10]; | |
589 | int i; | |
590 | unsigned char *p; | |
591 | unsigned char *regs; | |
592 | int error_code, status; | |
593 | int pktlen; | |
594 | ||
595 | buf[0] = WIGGLER_READ_REGS; | |
596 | buf[1] = first_bdm_regno >> 8; | |
597 | buf[2] = first_bdm_regno & 0xff; | |
598 | buf[3] = last_bdm_regno >> 8; | |
599 | buf[4] = last_bdm_regno & 0xff; | |
600 | ||
601 | put_packet (buf, 5); | |
602 | p = get_packet (WIGGLER_READ_REGS, &pktlen, remote_timeout); | |
603 | ||
604 | if (pktlen < 5) | |
605 | error ("Truncated response packet from Wiggler"); | |
606 | ||
607 | status = p[1]; | |
608 | error_code = p[2]; | |
609 | ||
610 | if (error_code != 0) | |
611 | wiggler_error ("read_bdm_registers:", error_code); | |
612 | ||
613 | i = p[3]; | |
614 | if (i == 0) | |
615 | i = 256; | |
616 | ||
617 | if (i > pktlen - 4 | |
618 | || ((i & 3) != 0)) | |
619 | error ("Register block size bad: %d", i); | |
620 | ||
621 | *numregs = i / 4; | |
622 | ||
623 | regs = p + 4; | |
624 | ||
625 | return regs; | |
626 | } | |
627 | ||
628 | static void | |
629 | dump_all_bdm_regs () | |
630 | { | |
631 | unsigned char *regs; | |
632 | int numregs; | |
633 | int i; | |
634 | ||
635 | regs = read_bdm_registers (0, BDM_NUM_REGS - 1, &numregs); | |
636 | ||
637 | printf_unfiltered ("rpc = 0x%x ", | |
638 | (int)extract_unsigned_integer (regs, 4)); | |
639 | regs += 4; | |
640 | printf_unfiltered ("usp = 0x%x ", | |
641 | (int)extract_unsigned_integer (regs, 4)); | |
642 | regs += 4; | |
643 | printf_unfiltered ("ssp = 0x%x ", | |
644 | (int)extract_unsigned_integer (regs, 4)); | |
645 | regs += 4; | |
646 | printf_unfiltered ("vbr = 0x%x ", | |
647 | (int)extract_unsigned_integer (regs, 4)); | |
648 | regs += 4; | |
649 | printf_unfiltered ("sr = 0x%x ", | |
650 | (int)extract_unsigned_integer (regs, 4)); | |
651 | regs += 4; | |
652 | printf_unfiltered ("sfc = 0x%x ", | |
653 | (int)extract_unsigned_integer (regs, 4)); | |
654 | regs += 4; | |
655 | printf_unfiltered ("dfc = 0x%x ", | |
656 | (int)extract_unsigned_integer (regs, 4)); | |
657 | regs += 4; | |
658 | printf_unfiltered ("atemp = 0x%x ", | |
659 | (int)extract_unsigned_integer (regs, 4)); | |
660 | regs += 4; | |
661 | printf_unfiltered ("\n"); | |
662 | ||
663 | for (i = 0; i <= 7; i++) | |
664 | printf_unfiltered ("d%i = 0x%x ", i, | |
665 | (int)extract_unsigned_integer (regs + i * 4, 4)); | |
666 | regs += 8 * 4; | |
667 | printf_unfiltered ("\n"); | |
668 | ||
669 | for (i = 0; i <= 7; i++) | |
670 | printf_unfiltered ("a%i = 0x%x ", i, | |
671 | (int)extract_unsigned_integer (regs + i * 4, 4)); | |
672 | printf_unfiltered ("\n"); | |
673 | } | |
674 | ||
675 | static int bdm_regmap[] = {BDM_REGMAP}; | |
676 | ||
677 | /* Read the remote registers into the block REGS. */ | |
678 | /* Currently we just read all the registers, so we don't use regno. */ | |
679 | /* ARGSUSED */ | |
680 | static void | |
681 | wiggler_fetch_registers (regno) | |
682 | int regno; | |
683 | { | |
684 | int i; | |
685 | unsigned char *regs; | |
686 | int first_regno, last_regno; | |
687 | int first_bdm_regno, last_bdm_regno; | |
688 | int numregs; | |
689 | ||
690 | if (regno == -1) | |
691 | { | |
692 | first_regno = 0; | |
693 | last_regno = NUM_REGS - 1; | |
694 | ||
695 | first_bdm_regno = 0; | |
696 | last_bdm_regno = BDM_NUM_REGS - 1; | |
697 | } | |
698 | else | |
699 | { | |
700 | first_regno = regno; | |
701 | last_regno = regno; | |
702 | ||
703 | first_bdm_regno = bdm_regmap [regno]; | |
704 | last_bdm_regno = bdm_regmap [regno]; | |
705 | } | |
706 | ||
707 | if (first_bdm_regno == -1) | |
708 | { | |
709 | supply_register (first_regno, NULL); | |
710 | return; /* Unsupported register */ | |
711 | } | |
712 | ||
713 | regs = read_bdm_registers (first_bdm_regno, last_bdm_regno, &numregs); | |
714 | ||
715 | for (i = first_regno; i <= last_regno; i++) | |
716 | { | |
717 | int bdm_regno, regoffset; | |
718 | ||
719 | bdm_regno = bdm_regmap [i]; | |
720 | if (bdm_regno != -1) | |
721 | { | |
722 | regoffset = bdm_regno - first_bdm_regno; | |
723 | ||
724 | if (regoffset >= numregs) | |
725 | continue; | |
726 | ||
727 | supply_register (i, regs + 4 * regoffset); | |
728 | } | |
729 | else | |
730 | supply_register (i, NULL); /* Unsupported register */ | |
731 | } | |
732 | } | |
733 | ||
734 | static void | |
735 | wiggler_prepare_to_store () | |
736 | { | |
737 | } | |
738 | ||
739 | /* Store register REGNO, or all registers if REGNO == -1, from the contents | |
740 | of REGISTERS. FIXME: ignores errors. */ | |
741 | ||
742 | static void | |
743 | wiggler_store_registers (regno) | |
744 | int regno; | |
745 | { | |
746 | unsigned char buf[10 + 256]; | |
747 | int i; | |
748 | unsigned char *p; | |
749 | int error_code, status; | |
750 | int pktlen; | |
751 | int first_regno, last_regno; | |
752 | int first_bdm_regno, last_bdm_regno; | |
753 | ||
754 | if (regno == -1) | |
755 | { | |
756 | first_regno = 0; | |
757 | last_regno = NUM_REGS - 1; | |
758 | ||
759 | first_bdm_regno = 0; | |
760 | last_bdm_regno = BDM_NUM_REGS - 1; | |
761 | } | |
762 | else | |
763 | { | |
764 | first_regno = regno; | |
765 | last_regno = regno; | |
766 | ||
767 | first_bdm_regno = bdm_regmap [regno]; | |
768 | last_bdm_regno = bdm_regmap [regno]; | |
769 | } | |
770 | ||
771 | if (first_bdm_regno == -1) | |
772 | return; /* Unsupported register */ | |
773 | ||
774 | buf[0] = WIGGLER_WRITE_REGS; | |
775 | buf[3] = 4; | |
776 | ||
777 | for (i = first_regno; i <= last_regno; i++) | |
778 | { | |
779 | int bdm_regno; | |
780 | ||
781 | bdm_regno = bdm_regmap [i]; | |
782 | ||
783 | buf[1] = bdm_regno >> 8; | |
784 | buf[2] = bdm_regno & 0xff; | |
785 | ||
786 | memcpy (&buf[4], ®isters[REGISTER_BYTE (i)], 4); | |
787 | put_packet (buf, 4 + 4); | |
788 | p = get_packet (WIGGLER_WRITE_REGS, &pktlen, remote_timeout); | |
789 | ||
790 | if (pktlen < 3) | |
791 | error ("Truncated response packet from Wiggler"); | |
792 | ||
793 | status = p[1]; | |
794 | error_code = p[2]; | |
795 | ||
796 | if (error_code != 0) | |
797 | wiggler_error ("wiggler_store_registers:", error_code); | |
798 | } | |
799 | } | |
800 | \f | |
801 | /* Write memory data directly to the remote machine. | |
802 | This does not inform the data cache; the data cache uses this. | |
803 | MEMADDR is the address in the remote memory space. | |
804 | MYADDR is the address of the buffer in our space. | |
805 | LEN is the number of bytes. | |
806 | ||
807 | Returns number of bytes transferred, or 0 for error. */ | |
808 | ||
809 | static int | |
810 | wiggler_write_bytes (memaddr, myaddr, len) | |
811 | CORE_ADDR memaddr; | |
812 | char *myaddr; | |
813 | int len; | |
814 | { | |
815 | char buf[256 + 10]; | |
816 | unsigned char *p; | |
817 | int origlen; | |
818 | ||
819 | origlen = len; | |
820 | ||
821 | buf[0] = WIGGLER_WRITE_MEM; | |
822 | buf[5] = 1; /* Write as bytes */ | |
823 | buf[6] = 0; /* Don't verify */ | |
824 | ||
825 | while (len > 0) | |
826 | { | |
827 | int numbytes; | |
828 | int pktlen; | |
829 | int status, error_code; | |
830 | ||
831 | numbytes = min (len, 256 - 8); | |
832 | /* numbytes = min (len, 40);*/ | |
833 | ||
834 | buf[1] = memaddr >> 24; | |
835 | buf[2] = memaddr >> 16; | |
836 | buf[3] = memaddr >> 8; | |
837 | buf[4] = memaddr; | |
838 | ||
839 | buf[7] = numbytes; | |
840 | ||
841 | memcpy (&buf[8], myaddr, numbytes); | |
842 | put_packet (buf, 8 + numbytes); | |
843 | p = get_packet (WIGGLER_WRITE_MEM, &pktlen, remote_timeout); | |
844 | if (pktlen < 3) | |
845 | error ("Truncated response packet from Wiggler"); | |
846 | ||
847 | status = p[1]; | |
848 | error_code = p[2]; | |
849 | ||
850 | if (error_code == 11) /* Got a bus error? */ | |
851 | { | |
852 | CORE_ADDR error_address; | |
853 | ||
854 | error_address = p[3] << 24; | |
855 | error_address |= p[4] << 16; | |
856 | error_address |= p[5] << 8; | |
857 | error_address |= p[6]; | |
858 | numbytes = error_address - memaddr; | |
859 | ||
860 | len -= numbytes; | |
861 | ||
862 | errno = EIO; | |
863 | ||
864 | break; | |
865 | } | |
866 | else if (error_code != 0) | |
867 | wiggler_error ("wiggler_store_registers:", error_code); | |
868 | ||
869 | len -= numbytes; | |
870 | memaddr += numbytes; | |
871 | myaddr += numbytes; | |
872 | } | |
873 | ||
874 | return origlen - len; | |
875 | } | |
876 | ||
877 | /* Read memory data directly from the remote machine. | |
878 | This does not use the data cache; the data cache uses this. | |
879 | MEMADDR is the address in the remote memory space. | |
880 | MYADDR is the address of the buffer in our space. | |
881 | LEN is the number of bytes. | |
882 | ||
883 | Returns number of bytes transferred, or 0 for error. */ | |
884 | ||
885 | static int | |
886 | wiggler_read_bytes (memaddr, myaddr, len) | |
887 | CORE_ADDR memaddr; | |
888 | char *myaddr; | |
889 | int len; | |
890 | { | |
891 | char buf[256 + 10]; | |
892 | unsigned char *p; | |
893 | int origlen; | |
894 | ||
895 | origlen = len; | |
896 | ||
897 | buf[0] = WIGGLER_READ_MEM; | |
898 | buf[5] = 1; /* Read as bytes */ | |
899 | ||
900 | while (len > 0) | |
901 | { | |
902 | int numbytes; | |
903 | int pktlen; | |
904 | int status, error_code; | |
905 | ||
906 | numbytes = min (len, 256 - 7); | |
907 | ||
908 | buf[1] = memaddr >> 24; | |
909 | buf[2] = memaddr >> 16; | |
910 | buf[3] = memaddr >> 8; | |
911 | buf[4] = memaddr; | |
912 | ||
913 | buf[6] = numbytes; | |
914 | ||
915 | put_packet (buf, 7); | |
916 | p = get_packet (WIGGLER_READ_MEM, &pktlen, remote_timeout); | |
917 | if (pktlen < 4) | |
918 | error ("Truncated response packet from Wiggler"); | |
919 | ||
920 | status = p[1]; | |
921 | error_code = p[2]; | |
922 | ||
923 | if (error_code == 0x11) /* Got a bus error? */ | |
924 | { | |
925 | CORE_ADDR error_address; | |
926 | ||
927 | error_address = p[3] << 24; | |
928 | error_address |= p[4] << 16; | |
929 | error_address |= p[5] << 8; | |
930 | error_address |= p[6]; | |
931 | numbytes = error_address - memaddr; | |
932 | ||
933 | len -= numbytes; | |
934 | ||
935 | errno = EIO; | |
936 | ||
937 | break; | |
938 | } | |
939 | else if (error_code != 0) | |
940 | wiggler_error ("wiggler_store_registers:", error_code); | |
941 | ||
942 | memcpy (myaddr, &p[4], numbytes); | |
943 | ||
944 | len -= numbytes; | |
945 | memaddr += numbytes; | |
946 | myaddr += numbytes; | |
947 | } | |
948 | ||
949 | return origlen - len; | |
950 | } | |
951 | \f | |
952 | /* Read or write LEN bytes from inferior memory at MEMADDR, transferring | |
953 | to or from debugger address MYADDR. Write to inferior if SHOULD_WRITE is | |
954 | nonzero. Returns length of data written or read; 0 for error. */ | |
955 | ||
956 | /* ARGSUSED */ | |
957 | static int | |
958 | wiggler_xfer_memory(memaddr, myaddr, len, should_write, target) | |
959 | CORE_ADDR memaddr; | |
960 | char *myaddr; | |
961 | int len; | |
962 | int should_write; | |
963 | struct target_ops *target; /* ignored */ | |
964 | { | |
965 | return dcache_xfer_memory (wiggler_dcache, memaddr, myaddr, len, should_write); | |
966 | } | |
967 | \f | |
968 | static void | |
969 | wiggler_files_info (ignore) | |
970 | struct target_ops *ignore; | |
971 | { | |
972 | puts_filtered ("Debugging a target over a serial line.\n"); | |
973 | } | |
974 | \f | |
975 | /* Stuff for dealing with the packets which are part of this protocol. | |
976 | See comment at top of file for details. */ | |
977 | ||
978 | /* Read a single character from the remote side, handling wierd errors. */ | |
979 | ||
980 | static int | |
981 | readchar (timeout) | |
982 | int timeout; | |
983 | { | |
984 | int ch; | |
985 | ||
986 | ch = SERIAL_READCHAR (wiggler_desc, timeout); | |
987 | ||
988 | switch (ch) | |
989 | { | |
990 | case SERIAL_EOF: | |
991 | error ("Remote connection closed"); | |
992 | case SERIAL_ERROR: | |
993 | perror_with_name ("Remote communication error"); | |
994 | case SERIAL_TIMEOUT: | |
995 | default: | |
996 | return ch; | |
997 | } | |
998 | } | |
999 | ||
1000 | #if 0 | |
1001 | /* Read a character from the data stream, dequoting as necessary. SYN is | |
1002 | treated special. Any SYNs appearing in the data stream are returned as the | |
1003 | distinct value RAW_SYN (which has a value > 8 bits and therefore cannot be | |
1004 | mistaken for real data). */ | |
1005 | ||
1006 | static int | |
1007 | get_quoted_char (timeout) | |
1008 | int timeout; | |
1009 | { | |
1010 | int ch; | |
1011 | ||
1012 | ch = readchar (timeout); | |
1013 | ||
1014 | switch (ch) | |
1015 | { | |
1016 | case SERIAL_TIMEOUT: | |
1017 | error ("Timeout in mid-packet, aborting"); | |
1018 | case SYN: | |
1019 | return RAW_SYN; | |
1020 | case DLE: | |
1021 | ch = readchar (timeout); | |
1022 | if (ch == SYN) | |
1023 | return RAW_SYN; | |
1024 | return ch & ~0100; | |
1025 | default: | |
1026 | return ch; | |
1027 | } | |
1028 | } | |
1029 | ||
1030 | static unsigned char pkt[256 * 2 + 10], *pktp; /* Worst case */ | |
1031 | ||
1032 | static void | |
1033 | reset_packet () | |
1034 | { | |
1035 | pktp = pkt; | |
1036 | } | |
1037 | ||
1038 | static void | |
1039 | output_packet () | |
1040 | { | |
1041 | if (SERIAL_WRITE (wiggler_desc, pkt, pktp - pkt)) | |
1042 | perror_with_name ("output_packet: write failed"); | |
1043 | ||
1044 | reset_packet (); | |
1045 | } | |
1046 | ||
1047 | /* Output a quoted character. SYNs and DLEs are quoted. Everything else goes | |
1048 | through untouched. */ | |
1049 | ||
1050 | static void | |
1051 | put_quoted_char (c) | |
1052 | int c; | |
1053 | { | |
1054 | switch (c) | |
1055 | { | |
1056 | case SYN: | |
1057 | case DLE: | |
1058 | *pktp++ = DLE; | |
1059 | c |= 0100; | |
1060 | } | |
1061 | ||
1062 | *pktp++ = c; | |
1063 | } | |
1064 | ||
1065 | /* Send a packet to the Wiggler. The packet framed by a SYN character, a byte | |
1066 | count and a checksum. The byte count only counts the number of bytes | |
1067 | between the count and the checksum. A count of zero actually means 256. | |
1068 | Any SYNs within the packet (including the checksum and count) must be | |
1069 | quoted. The quote character must be quoted as well. Quoting is done by | |
1070 | replacing the character with the two-character sequence DLE, {char} | 0100. | |
1071 | Note that the quoting mechanism has no effect on the byte count. | |
1072 | */ | |
1073 | ||
1074 | static void | |
1075 | stu_put_packet (buf, len) | |
1076 | unsigned char *buf; | |
1077 | int len; | |
1078 | { | |
1079 | unsigned char checksum; | |
1080 | unsigned char c; | |
1081 | ||
1082 | if (len == 0 || len > 256) | |
1083 | abort (); /* Can't represent 0 length packet */ | |
1084 | ||
1085 | reset_packet (); | |
1086 | ||
1087 | checksum = 0; | |
1088 | ||
1089 | put_quoted_char (RAW_SYN); | |
1090 | ||
1091 | c = len; | |
1092 | ||
1093 | do | |
1094 | { | |
1095 | checksum += c; | |
1096 | ||
1097 | put_quoted_char (c); | |
1098 | ||
1099 | c = *buf++; | |
1100 | } | |
1101 | while (len-- > 0); | |
1102 | ||
1103 | put_quoted_char (-checksum & 0xff); | |
1104 | ||
1105 | output_packet (); | |
1106 | } | |
1107 | ||
1108 | #else | |
1109 | ||
1110 | /* Send a packet to the Wiggler. The packet framed by a SYN character, a byte | |
1111 | count and a checksum. The byte count only counts the number of bytes | |
1112 | between the count and the checksum. A count of zero actually means 256. | |
1113 | Any SYNs within the packet (including the checksum and count) must be | |
1114 | quoted. The quote character must be quoted as well. Quoting is done by | |
1115 | replacing the character with the two-character sequence DLE, {char} | 0100. | |
1116 | Note that the quoting mechanism has no effect on the byte count. | |
1117 | */ | |
1118 | ||
1119 | static void | |
1120 | put_packet (buf, len) | |
1121 | unsigned char *buf; | |
1122 | int len; | |
1123 | { | |
1124 | unsigned char checksum; | |
1125 | unsigned char c; | |
1126 | unsigned char *packet, *packet_ptr; | |
1127 | ||
1128 | packet = alloca (len + 1 + 1); /* packet + SYN + checksum */ | |
1129 | packet_ptr = packet; | |
1130 | ||
1131 | checksum = 0; | |
1132 | ||
1133 | *packet_ptr++ = 0x55; | |
1134 | ||
1135 | while (len-- > 0) | |
1136 | { | |
1137 | c = *buf++; | |
1138 | ||
1139 | checksum += c; | |
1140 | *packet_ptr++ = c; | |
1141 | } | |
1142 | ||
1143 | *packet_ptr++ = -checksum; | |
1144 | if (SERIAL_WRITE (wiggler_desc, packet, packet_ptr - packet)) | |
1145 | perror_with_name ("output_packet: write failed"); | |
1146 | } | |
1147 | #endif | |
1148 | ||
1149 | #if 0 | |
1150 | /* Get a packet from the Wiggler. Timeout is only enforced for the first byte | |
1151 | of the packet. Subsequent bytes are expected to arrive in time <= | |
1152 | remote_timeout. Returns a pointer to a static buffer containing the payload | |
1153 | of the packet. *LENP contains the length of the packet. | |
1154 | */ | |
1155 | ||
1156 | static unsigned char * | |
1157 | stu_get_packet (cmd, lenp, timeout) | |
1158 | unsigned char cmd; | |
1159 | int *lenp; | |
1160 | { | |
1161 | int ch; | |
1162 | int len; | |
1163 | static unsigned char buf[256 + 10], *p; | |
1164 | unsigned char checksum; | |
1165 | ||
1166 | find_packet: | |
1167 | ||
1168 | ch = get_quoted_char (timeout); | |
1169 | ||
1170 | if (ch < 0) | |
1171 | error ("get_packet (readchar): %d", ch); | |
1172 | ||
1173 | if (ch != RAW_SYN) | |
1174 | goto find_packet; | |
1175 | ||
1176 | found_syn: /* Found the start of a packet */ | |
1177 | ||
1178 | p = buf; | |
1179 | checksum = 0; | |
1180 | ||
1181 | len = get_quoted_char (remote_timeout); | |
1182 | ||
1183 | if (len == RAW_SYN) | |
1184 | goto found_syn; | |
1185 | ||
1186 | checksum += len; | |
1187 | ||
1188 | if (len == 0) | |
1189 | len = 256; | |
1190 | ||
1191 | len++; /* Include checksum */ | |
1192 | ||
1193 | while (len-- > 0) | |
1194 | { | |
1195 | ch = get_quoted_char (remote_timeout); | |
1196 | if (ch == RAW_SYN) | |
1197 | goto found_syn; | |
1198 | ||
1199 | *p++ = ch; | |
1200 | checksum += ch; | |
1201 | } | |
1202 | ||
1203 | if (checksum != 0) | |
1204 | goto find_packet; | |
1205 | ||
1206 | if (cmd != buf[0]) | |
1207 | error ("Response phase error. Got 0x%x, expected 0x%x", buf[0], cmd); | |
1208 | ||
1209 | *lenp = p - buf - 1; | |
1210 | return buf; | |
1211 | } | |
1212 | ||
1213 | #else | |
1214 | ||
1215 | /* Get a packet from the Wiggler. Timeout is only enforced for the first byte | |
1216 | of the packet. Subsequent bytes are expected to arrive in time <= | |
1217 | remote_timeout. Returns a pointer to a static buffer containing the payload | |
1218 | of the packet. *LENP contains the length of the packet. | |
1219 | */ | |
1220 | ||
1221 | static unsigned char * | |
1222 | get_packet (cmd, lenp, timeout) | |
1223 | int cmd; | |
1224 | int *lenp; | |
1225 | { | |
1226 | int ch; | |
1227 | int len; | |
1228 | int i; | |
1229 | static unsigned char packet[512]; | |
1230 | unsigned char *packet_ptr; | |
1231 | unsigned char checksum; | |
1232 | ||
1233 | find_packet: | |
1234 | ||
1235 | ch = readchar (timeout); | |
1236 | ||
1237 | if (ch < 0) | |
1238 | error ("get_packet (readchar): %d", ch); | |
1239 | ||
1240 | if (ch != 0x55) | |
1241 | goto find_packet; | |
1242 | ||
1243 | /* Found the start of a packet */ | |
1244 | ||
1245 | packet_ptr = packet; | |
1246 | checksum = 0; | |
1247 | ||
1248 | /* Read command char. That sort of tells us how long the packet is. */ | |
1249 | ||
1250 | ch = readchar (timeout); | |
1251 | ||
1252 | if (ch < 0) | |
1253 | error ("get_packet (readchar): %d", ch); | |
1254 | ||
1255 | *packet_ptr++ = ch; | |
1256 | checksum += ch; | |
1257 | ||
1258 | /* Get status. */ | |
1259 | ||
1260 | ch = readchar (timeout); | |
1261 | ||
1262 | if (ch < 0) | |
1263 | error ("get_packet (readchar): %d", ch); | |
1264 | *packet_ptr++ = ch; | |
1265 | checksum += ch; | |
1266 | ||
1267 | /* Get error code. */ | |
1268 | ||
1269 | ch = readchar (timeout); | |
1270 | ||
1271 | if (ch < 0) | |
1272 | error ("get_packet (readchar): %d", ch); | |
1273 | *packet_ptr++ = ch; | |
1274 | checksum += ch; | |
1275 | ||
1276 | switch (ch) /* Figure out length of packet */ | |
1277 | { | |
1278 | case 0x7: /* Write verify error? */ | |
1279 | len = 8; /* write address, value read back */ | |
1280 | break; | |
1281 | case 0x11: /* Bus error? */ | |
1282 | /* write address, read flag */ | |
1283 | case 0x15: /* Internal error */ | |
1284 | len = 5; /* error code, vector */ | |
1285 | break; | |
1286 | default: /* Error w/no params */ | |
1287 | len = 0; | |
1288 | case 0x0: /* Normal result */ | |
1289 | switch (packet[0]) | |
1290 | { | |
1291 | case WIGGLER_AYT: /* Are You There? */ | |
1292 | case WIGGLER_SET_BAUD_RATE: /* Set Baud Rate */ | |
1293 | case WIGGLER_INIT: /* Initialize wiggler */ | |
1294 | case WIGGLER_SET_SPEED: /* Set Speed */ | |
1295 | case WIGGLER_SET_FUNC_CODE: /* Set Function Code */ | |
1296 | case WIGGLER_SET_CTL_FLAGS: /* Set Control Flags */ | |
1297 | case WIGGLER_SET_BUF_ADDR: /* Set Register Buffer Address */ | |
1298 | case WIGGLER_RUN: /* Run Target from PC */ | |
1299 | case WIGGLER_RUN_ADDR: /* Run Target from Specified Address */ | |
1300 | case WIGGLER_STOP: /* Stop Target */ | |
1301 | case WIGGLER_RESET_RUN: /* Reset Target and Run */ | |
1302 | case WIGGLER_RESET: /* Reset Target and Halt */ | |
1303 | case WIGGLER_STEP: /* Single Step */ | |
1304 | case WIGGLER_WRITE_REGS: /* Write Register */ | |
1305 | case WIGGLER_WRITE_MEM: /* Write Memory */ | |
1306 | case WIGGLER_FILL_MEM: /* Fill Memory */ | |
1307 | case WIGGLER_MOVE_MEM: /* Move Memory */ | |
1308 | case WIGGLER_WRITE_INT_MEM: /* Write Internal Memory */ | |
1309 | case WIGGLER_JUMP: /* Jump to Subroutine */ | |
1310 | len = 0; | |
1311 | break; | |
1312 | case WIGGLER_GET_VERSION: /* Get Version */ | |
1313 | len = 4; | |
1314 | break; | |
1315 | case WIGGLER_GET_STATUS_MASK: /* Get Status Mask */ | |
1316 | len = 1; | |
1317 | break; | |
1318 | case WIGGLER_GET_CTRS: /* Get Error Counters */ | |
1319 | case WIGGLER_READ_REGS: /* Read Register */ | |
1320 | case WIGGLER_READ_MEM: /* Read Memory */ | |
1321 | case WIGGLER_READ_INT_MEM: /* Read Internal Memory */ | |
1322 | len = 257; | |
1323 | break; | |
1324 | default: | |
1325 | fprintf_filtered (gdb_stderr, "Unknown packet type 0x%x\n", ch); | |
1326 | goto find_packet; | |
1327 | } | |
1328 | } | |
1329 | ||
1330 | if (len == 257) /* Byte stream? */ | |
1331 | { /* Yes, byte streams contain the length */ | |
1332 | ch = readchar (timeout); | |
1333 | ||
1334 | if (ch < 0) | |
1335 | error ("get_packet (readchar): %d", ch); | |
1336 | *packet_ptr++ = ch; | |
1337 | checksum += ch; | |
1338 | len = ch; | |
1339 | if (len == 0) | |
1340 | len = 256; | |
1341 | } | |
1342 | ||
1343 | while (len-- >= 0) /* Do rest of packet and checksum */ | |
1344 | { | |
1345 | ch = readchar (timeout); | |
1346 | ||
1347 | if (ch < 0) | |
1348 | error ("get_packet (readchar): %d", ch); | |
1349 | *packet_ptr++ = ch; | |
1350 | checksum += ch; | |
1351 | } | |
1352 | ||
1353 | if (checksum != 0) | |
1354 | goto find_packet; | |
1355 | ||
1356 | if (cmd != -1 && cmd != packet[0]) | |
1357 | error ("Response phase error. Got 0x%x, expected 0x%x", packet[0], cmd); | |
1358 | ||
1359 | *lenp = packet_ptr - packet - 1; /* Subtract checksum byte */ | |
1360 | return packet; | |
1361 | } | |
1362 | #endif | |
1363 | ||
1364 | /* Execute a simple (one-byte) command. Returns a pointer to the data | |
1365 | following the error code. */ | |
1366 | ||
1367 | static unsigned char * | |
1368 | do_command (cmd, statusp, lenp) | |
1369 | int cmd; | |
1370 | int *statusp; | |
1371 | int *lenp; | |
1372 | { | |
1373 | unsigned char buf[100], *p; | |
1374 | int status, error_code; | |
1375 | char errbuf[100]; | |
1376 | ||
1377 | buf[0] = cmd; | |
1378 | put_packet (buf, 1); /* Send command */ | |
1379 | p = get_packet (*buf, lenp, remote_timeout); | |
1380 | ||
1381 | if (*lenp < 3) | |
1382 | error ("Truncated response packet from Wiggler"); | |
1383 | ||
1384 | status = p[1]; | |
1385 | error_code = p[2]; | |
1386 | ||
1387 | if (error_code != 0) | |
1388 | { | |
1389 | sprintf (errbuf, "do_command (0x%x):", cmd); | |
1390 | wiggler_error (errbuf, error_code); | |
1391 | } | |
1392 | ||
1393 | if (status & WIGGLER_FLAG_PWF) | |
1394 | error ("Wiggler can't detect VCC at BDM interface."); | |
1395 | else if (status & WIGGLER_FLAG_CABLE_DISC) | |
1396 | error ("BDM cable appears to be disconnected."); | |
1397 | ||
1398 | *statusp = status; | |
1399 | ||
1400 | return p + 3; | |
1401 | } | |
1402 | \f | |
1403 | static void | |
1404 | wiggler_kill () | |
1405 | { | |
1406 | /* For some mysterious reason, wait_for_inferior calls kill instead of | |
1407 | mourn after it gets TARGET_WAITKIND_SIGNALLED. Work around it. */ | |
1408 | if (kill_kludge) | |
1409 | { | |
1410 | kill_kludge = 0; | |
1411 | target_mourn_inferior (); | |
1412 | return; | |
1413 | } | |
1414 | ||
1415 | /* Don't wait for it to die. I'm not really sure it matters whether | |
1416 | we do or not. */ | |
1417 | target_mourn_inferior (); | |
1418 | } | |
1419 | ||
1420 | static void | |
1421 | wiggler_mourn () | |
1422 | { | |
1423 | unpush_target (&wiggler_ops); | |
1424 | generic_mourn_inferior (); | |
1425 | } | |
1426 | ||
1427 | /* All we actually do is set the PC to the start address of exec_bfd, and start | |
1428 | the program at that point. */ | |
1429 | ||
1430 | static void | |
1431 | wiggler_create_inferior (exec_file, args, env) | |
1432 | char *exec_file; | |
1433 | char *args; | |
1434 | char **env; | |
1435 | { | |
1436 | if (args && (*args != '\000')) | |
1437 | error ("Args are not supported by BDM."); | |
1438 | ||
1439 | clear_proceed_status (); | |
1440 | proceed (bfd_get_start_address (exec_bfd), TARGET_SIGNAL_0, 0); | |
1441 | } | |
1442 | ||
1443 | static void | |
1444 | wiggler_load (args, from_tty) | |
1445 | char *args; | |
1446 | int from_tty; | |
1447 | { | |
1448 | generic_load (args, from_tty); | |
1449 | inferior_pid = 0; | |
1450 | } | |
1451 | ||
1452 | /* BDM (at least on CPU32) uses a different breakpoint */ | |
1453 | ||
1454 | static int | |
1455 | wiggler_insert_breakpoint (addr, contents_cache) | |
1456 | CORE_ADDR addr; | |
1457 | char *contents_cache; | |
1458 | { | |
1459 | static char break_insn[] = {BDM_BREAKPOINT}; | |
1460 | int val; | |
1461 | ||
1462 | val = target_read_memory (addr, contents_cache, sizeof break_insn); | |
1463 | ||
1464 | if (val == 0) | |
1465 | val = target_write_memory (addr, break_insn, sizeof break_insn); | |
1466 | ||
1467 | return val; | |
1468 | } | |
1469 | ||
1470 | static void | |
1471 | bdm_command (args, from_tty) | |
1472 | char *args; | |
1473 | int from_tty; | |
1474 | { | |
1475 | error ("bdm command must be followed by `reset'"); | |
1476 | } | |
1477 | ||
1478 | static void | |
1479 | bdm_reset_command (args, from_tty) | |
1480 | char *args; | |
1481 | int from_tty; | |
1482 | { | |
1483 | int status, pktlen; | |
1484 | ||
1485 | if (!wiggler_desc) | |
1486 | error ("Not connected to wiggler."); | |
1487 | ||
1488 | do_command (WIGGLER_RESET, &status, &pktlen); | |
1489 | dcache_flush (wiggler_dcache); | |
1490 | registers_changed (); | |
1491 | } | |
1492 | ||
1493 | static void | |
1494 | bdm_restart_command (args, from_tty) | |
1495 | char *args; | |
1496 | int from_tty; | |
1497 | { | |
1498 | int status, pktlen; | |
1499 | ||
1500 | if (!wiggler_desc) | |
1501 | error ("Not connected to wiggler."); | |
1502 | ||
1503 | do_command (WIGGLER_RESET_RUN, &status, &pktlen); | |
1504 | last_run_status = status; | |
1505 | clear_proceed_status (); | |
1506 | wait_for_inferior (); | |
1507 | normal_stop (); | |
1508 | } | |
1509 | \f | |
1510 | /* Define the target subroutine names */ | |
1511 | ||
1512 | struct target_ops wiggler_ops = { | |
1513 | "wiggler", /* to_shortname */ | |
1514 | "", /* to_longname */ | |
1515 | "", /* to_doc */ | |
1516 | wiggler_open, /* to_open */ | |
1517 | wiggler_close, /* to_close */ | |
1518 | NULL, /* to_attach */ | |
1519 | wiggler_detach, /* to_detach */ | |
1520 | wiggler_resume, /* to_resume */ | |
1521 | wiggler_wait, /* to_wait */ | |
1522 | wiggler_fetch_registers, /* to_fetch_registers */ | |
1523 | wiggler_store_registers, /* to_store_registers */ | |
1524 | wiggler_prepare_to_store, /* to_prepare_to_store */ | |
1525 | wiggler_xfer_memory, /* to_xfer_memory */ | |
1526 | wiggler_files_info, /* to_files_info */ | |
1527 | wiggler_insert_breakpoint, /* to_insert_breakpoint */ | |
1528 | memory_remove_breakpoint, /* to_remove_breakpoint */ | |
1529 | NULL, /* to_terminal_init */ | |
1530 | NULL, /* to_terminal_inferior */ | |
1531 | NULL, /* to_terminal_ours_for_output */ | |
1532 | NULL, /* to_terminal_ours */ | |
1533 | NULL, /* to_terminal_info */ | |
1534 | wiggler_kill, /* to_kill */ | |
1535 | wiggler_load, /* to_load */ | |
1536 | NULL, /* to_lookup_symbol */ | |
1537 | wiggler_create_inferior, /* to_create_inferior */ | |
1538 | wiggler_mourn, /* to_mourn_inferior */ | |
1539 | 0, /* to_can_run */ | |
1540 | 0, /* to_notice_signals */ | |
1541 | wiggler_thread_alive, /* to_thread_alive */ | |
1542 | 0, /* to_stop */ | |
1543 | process_stratum, /* to_stratum */ | |
1544 | NULL, /* to_next */ | |
1545 | 1, /* to_has_all_memory */ | |
1546 | 1, /* to_has_memory */ | |
1547 | 1, /* to_has_stack */ | |
1548 | 1, /* to_has_registers */ | |
1549 | 1, /* to_has_execution */ | |
1550 | NULL, /* sections */ | |
1551 | NULL, /* sections_end */ | |
1552 | OPS_MAGIC /* to_magic */ | |
1553 | }; | |
1554 | ||
1555 | void | |
1556 | _initialize_remote_wiggler () | |
1557 | { | |
1558 | extern struct cmd_list_element *cmdlist; | |
1559 | static struct cmd_list_element *bdm_cmd_list = NULL; | |
1560 | ||
1561 | add_target (&wiggler_ops); | |
1562 | ||
1563 | add_show_from_set (add_set_cmd ("remotetimeout", no_class, | |
1564 | var_integer, (char *)&remote_timeout, | |
1565 | "Set timeout value for remote read.\n", &setlist), | |
1566 | &showlist); | |
1567 | ||
1568 | add_prefix_cmd ("bdm", class_obscure, bdm_command, "", &bdm_cmd_list, "bdm ", | |
1569 | 0, &cmdlist); | |
1570 | ||
1571 | add_cmd ("reset", class_obscure, bdm_reset_command, "", &bdm_cmd_list); | |
1572 | add_cmd ("restart", class_obscure, bdm_restart_command, "", &bdm_cmd_list); | |
1573 | } |