Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Remote debugging interface for Am290*0 running MiniMON monitor, for GDB. |
29e57380 | 2 | Copyright 1990, 1991, 1992, 2001 Free Software Foundation, Inc. |
c906108c SS |
3 | Originally written by Daniel Mann at AMD. |
4 | ||
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b JM |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
21 | |
22 | /* This is like remote.c but ecpects MiniMON to be running on the Am29000 | |
23 | target hardware. | |
c5aa993b JM |
24 | - David Wood (wood@lab.ultra.nyu.edu) at New York University adapted this |
25 | file to gdb 3.95. I was unable to get this working on sun3os4 | |
26 | with termio, only with sgtty. Because we are only attempting to | |
27 | use this module to debug our kernel, which is already loaded when | |
28 | gdb is started up, I did not code up the file downloading facilities. | |
29 | As a result this module has only the stubs to download files. | |
30 | You should get tagged at compile time if you need to make any | |
31 | changes/additions. */ | |
32 | ||
c906108c SS |
33 | #include "defs.h" |
34 | #include "inferior.h" | |
c906108c SS |
35 | #include "value.h" |
36 | #include <ctype.h> | |
37 | #include <fcntl.h> | |
38 | #include <signal.h> | |
39 | #include <errno.h> | |
40 | #include "gdb_string.h" | |
41 | #include "terminal.h" | |
42 | #include "minimon.h" | |
43 | #include "target.h" | |
44 | ||
45 | /* Offset of member MEMBER in a struct of type TYPE. */ | |
46 | #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER) | |
47 | ||
48 | #define DRAIN_INPUT() (msg_recv_serial((union msg_t*)0)) | |
49 | ||
c5aa993b | 50 | extern int stop_soon_quietly; /* for wait_for_inferior */ |
c906108c | 51 | |
c5aa993b | 52 | static void mm_resume (); |
c906108c SS |
53 | static void mm_fetch_registers (); |
54 | static int fetch_register (); | |
55 | static void mm_store_registers (); | |
56 | static int store_register (); | |
c5aa993b JM |
57 | static int regnum_to_srnum (); |
58 | static void mm_close (); | |
59 | static char *msg_str (); | |
60 | static char *error_msg_str (); | |
61 | static int expect_msg (); | |
62 | static void init_target_mm (); | |
63 | static int mm_memory_space (); | |
c906108c SS |
64 | |
65 | #define FREEZE_MODE (read_register(CPS_REGNUM) && 0x400) | |
66 | #define USE_SHADOW_PC ((processor_type == a29k_freeze_mode) && FREEZE_MODE) | |
67 | ||
68 | /* FIXME: Replace with `set remotedebug'. */ | |
69 | #define LLOG_FILE "minimon.log" | |
70 | #if defined (LOG_FILE) | |
71 | FILE *log_file; | |
72 | #endif | |
73 | ||
74 | /* | |
75 | * Size of message buffers. I couldn't get memory reads to work when | |
76 | * the byte_count was larger than 512 (it may be a baud rate problem). | |
77 | */ | |
c5aa993b | 78 | #define BUFER_SIZE 512 |
c906108c SS |
79 | /* |
80 | * Size of data area in message buffer on the TARGET (remote system). | |
81 | */ | |
82 | #define MAXDATA_T (target_config.max_msg_size - \ | |
83 | offsetof(struct write_r_msg_t,data[0])) | |
c5aa993b | 84 | /* |
c906108c SS |
85 | * Size of data area in message buffer on the HOST (gdb). |
86 | */ | |
87 | #define MAXDATA_H (BUFER_SIZE - offsetof(struct write_r_msg_t,data[0])) | |
88 | /* | |
89 | * Defined as the minimum size of data areas of the two message buffers | |
90 | */ | |
91 | #define MAXDATA (MAXDATA_H < MAXDATA_T ? MAXDATA_H : MAXDATA_T) | |
92 | ||
93 | static char out_buf[BUFER_SIZE]; | |
c5aa993b | 94 | static char in_buf[BUFER_SIZE]; |
c906108c | 95 | |
c5aa993b JM |
96 | int msg_recv_serial (); |
97 | int msg_send_serial (); | |
c906108c SS |
98 | |
99 | #define MAX_RETRIES 5000 | |
c5aa993b JM |
100 | extern struct target_ops mm_ops; /* Forward declaration */ |
101 | struct config_msg_t target_config; /* HIF needs this */ | |
102 | union msg_t *out_msg_buf = (union msg_t *) out_buf; | |
103 | union msg_t *in_msg_buf = (union msg_t *) in_buf; | |
c906108c SS |
104 | |
105 | static int timeout = 5; | |
106 | ||
107 | /* Descriptor for I/O to remote machine. Initialize it to -1 so that | |
108 | mm_open knows that we don't have a file open when the program | |
109 | starts. */ | |
110 | int mm_desc = -1; | |
111 | ||
112 | /* stream which is fdopen'd from mm_desc. Only valid when | |
113 | mm_desc != -1. */ | |
114 | FILE *mm_stream; | |
115 | ||
116 | /* Called when SIGALRM signal sent due to alarm() timeout. */ | |
117 | #ifndef HAVE_TERMIO | |
118 | ||
119 | #ifndef __STDC__ | |
c5aa993b JM |
120 | #ifndef volatile |
121 | #define volatile | |
122 | /**/ | |
c906108c SS |
123 | # endif |
124 | #endif | |
125 | volatile int n_alarms; | |
126 | ||
127 | static void | |
fba45db2 | 128 | mm_timer (void) |
c906108c SS |
129 | { |
130 | #if 0 | |
131 | if (kiodebug) | |
132 | printf ("mm_timer called\n"); | |
133 | #endif | |
134 | n_alarms++; | |
135 | } | |
136 | #endif /* HAVE_TERMIO */ | |
137 | ||
138 | /* malloc'd name of the program on the remote system. */ | |
139 | static char *prog_name = NULL; | |
140 | ||
141 | ||
142 | /* Number of SIGTRAPs we need to simulate. That is, the next | |
143 | NEED_ARTIFICIAL_TRAP calls to mm_wait should just return | |
144 | SIGTRAP without actually waiting for anything. */ | |
145 | ||
146 | /**************************************************** REMOTE_CREATE_INFERIOR */ | |
147 | /* This is called not only when we first attach, but also when the | |
148 | user types "run" after having attached. */ | |
149 | static void | |
fba45db2 | 150 | mm_create_inferior (char *execfile, char *args, char **env) |
c906108c SS |
151 | { |
152 | #define MAX_TOKENS 25 | |
153 | #define BUFFER_SIZE 256 | |
c5aa993b JM |
154 | int token_count; |
155 | int result; | |
156 | char *token[MAX_TOKENS]; | |
157 | char cmd_line[BUFFER_SIZE]; | |
c906108c SS |
158 | |
159 | if (args && *args) | |
160 | error ("Can't pass arguments to remote mm process (yet)."); | |
161 | ||
162 | if (execfile == 0 /* || exec_bfd == 0 */ ) | |
163 | error ("No executable file specified"); | |
164 | ||
c5aa993b JM |
165 | if (!mm_stream) |
166 | { | |
167 | printf ("Minimon not open yet.\n"); | |
168 | return; | |
169 | } | |
c906108c SS |
170 | |
171 | /* On ultra3 (NYU) we assume the kernel is already running so there is | |
172 | no file to download. | |
173 | FIXME: Fixed required here -> load your program, possibly with mm_load(). | |
c5aa993b | 174 | */ |
c906108c SS |
175 | printf_filtered ("\n\ |
176 | Assuming you are at NYU debuging a kernel, i.e., no need to download.\n\n"); | |
177 | ||
178 | /* We will get a task spawn event immediately. */ | |
179 | init_wait_for_inferior (); | |
180 | clear_proceed_status (); | |
181 | stop_soon_quietly = 1; | |
182 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); | |
183 | normal_stop (); | |
184 | } | |
185 | /**************************************************** REMOTE_MOURN_INFERIOR */ | |
186 | static void | |
fba45db2 | 187 | mm_mourn (void) |
c906108c | 188 | { |
c5aa993b JM |
189 | pop_target (); /* Pop back to no-child state */ |
190 | generic_mourn_inferior (); | |
c906108c SS |
191 | } |
192 | ||
193 | /********************************************************************** damn_b | |
194 | */ | |
195 | /* Translate baud rates from integers to damn B_codes. Unix should | |
196 | have outgrown this crap years ago, but even POSIX wouldn't buck it. */ | |
197 | ||
198 | #ifndef B19200 | |
199 | #define B19200 EXTA | |
200 | #endif | |
201 | #ifndef B38400 | |
202 | #define B38400 EXTB | |
203 | #endif | |
204 | ||
c5aa993b JM |
205 | static struct |
206 | { | |
207 | int rate, damn_b; | |
208 | } | |
209 | baudtab[] = | |
210 | { | |
211 | { | |
212 | 0, B0 | |
213 | } | |
214 | , | |
215 | { | |
216 | 50, B50 | |
217 | } | |
218 | , | |
219 | { | |
220 | 75, B75 | |
221 | } | |
222 | , | |
223 | { | |
224 | 110, B110 | |
225 | } | |
226 | , | |
227 | { | |
228 | 134, B134 | |
229 | } | |
230 | , | |
231 | { | |
232 | 150, B150 | |
233 | } | |
234 | , | |
235 | { | |
236 | 200, B200 | |
237 | } | |
238 | , | |
239 | { | |
240 | 300, B300 | |
241 | } | |
242 | , | |
243 | { | |
244 | 600, B600 | |
245 | } | |
246 | , | |
247 | { | |
248 | 1200, B1200 | |
249 | } | |
250 | , | |
251 | { | |
252 | 1800, B1800 | |
253 | } | |
254 | , | |
255 | { | |
256 | 2400, B2400 | |
257 | } | |
258 | , | |
259 | { | |
260 | 4800, B4800 | |
261 | } | |
262 | , | |
263 | { | |
264 | 9600, B9600 | |
265 | } | |
266 | , | |
267 | { | |
268 | 19200, B19200 | |
269 | } | |
270 | , | |
271 | { | |
272 | 38400, B38400 | |
273 | } | |
274 | , | |
275 | { | |
276 | -1, -1 | |
277 | } | |
278 | , | |
c906108c SS |
279 | }; |
280 | ||
c5aa993b | 281 | static int |
fba45db2 | 282 | damn_b (int rate) |
c906108c SS |
283 | { |
284 | int i; | |
285 | ||
286 | for (i = 0; baudtab[i].rate != -1; i++) | |
c5aa993b JM |
287 | if (rate == baudtab[i].rate) |
288 | return baudtab[i].damn_b; | |
289 | return B38400; /* Random */ | |
c906108c SS |
290 | } |
291 | ||
292 | ||
293 | /***************************************************************** REMOTE_OPEN | |
294 | ** Open a connection to remote minimon. | |
295 | NAME is the filename used for communication, then a space, | |
296 | then the baud rate. | |
297 | 'target adapt /dev/ttya 9600 [prognam]' for example. | |
298 | */ | |
299 | ||
300 | static char *dev_name; | |
301 | int baudrate = 9600; | |
302 | static void | |
fba45db2 | 303 | mm_open (char *name, int from_tty) |
c906108c SS |
304 | { |
305 | TERMINAL sg; | |
306 | unsigned int prl; | |
307 | char *p; | |
308 | ||
309 | /* Find the first whitespace character, it separates dev_name from | |
310 | prog_name. */ | |
311 | for (p = name; | |
312 | p && *p && !isspace (*p); p++) | |
313 | ; | |
314 | if (p == 0 || *p == '\0') | |
c5aa993b | 315 | erroid: |
c906108c | 316 | error ("Usage : <command> <serial-device> <baud-rate> [progname]"); |
c5aa993b | 317 | dev_name = (char *) xmalloc (p - name + 1); |
c906108c SS |
318 | strncpy (dev_name, name, p - name); |
319 | dev_name[p - name] = '\0'; | |
320 | ||
321 | /* Skip over the whitespace after dev_name */ | |
322 | for (; isspace (*p); p++) | |
c5aa993b JM |
323 | /*EMPTY */ ; |
324 | ||
c906108c SS |
325 | if (1 != sscanf (p, "%d ", &baudrate)) |
326 | goto erroid; | |
327 | ||
328 | /* Skip the number and then the spaces */ | |
329 | for (; isdigit (*p); p++) | |
c5aa993b | 330 | /*EMPTY */ ; |
c906108c | 331 | for (; isspace (*p); p++) |
c5aa993b JM |
332 | /*EMPTY */ ; |
333 | ||
c906108c | 334 | if (prog_name != NULL) |
b8c9b27d | 335 | xfree (prog_name); |
c906108c SS |
336 | prog_name = savestring (p, strlen (p)); |
337 | ||
338 | ||
339 | if (mm_desc >= 0) | |
340 | close (mm_desc); | |
341 | ||
342 | mm_desc = open (dev_name, O_RDWR); | |
343 | if (mm_desc < 0) | |
344 | perror_with_name (dev_name); | |
345 | ioctl (mm_desc, TIOCGETP, &sg); | |
346 | #ifdef HAVE_TERMIO | |
347 | sg.c_cc[VMIN] = 0; /* read with timeout. */ | |
348 | sg.c_cc[VTIME] = timeout * 10; | |
349 | sg.c_lflag &= ~(ICANON | ECHO); | |
350 | sg.c_cflag = (sg.c_cflag & ~CBAUD) | damn_b (baudrate); | |
351 | #else | |
352 | sg.sg_ispeed = damn_b (baudrate); | |
353 | sg.sg_ospeed = damn_b (baudrate); | |
354 | sg.sg_flags |= RAW; | |
355 | sg.sg_flags |= ANYP; | |
356 | sg.sg_flags &= ~ECHO; | |
357 | #endif | |
358 | ||
359 | ||
360 | ioctl (mm_desc, TIOCSETP, &sg); | |
361 | mm_stream = fdopen (mm_desc, "r+"); | |
362 | ||
363 | push_target (&mm_ops); | |
364 | ||
365 | #ifndef HAVE_TERMIO | |
366 | #ifndef NO_SIGINTERRUPT | |
367 | /* Cause SIGALRM's to make reads fail with EINTR instead of resuming | |
368 | the read. */ | |
369 | if (siginterrupt (SIGALRM, 1) != 0) | |
370 | perror ("mm_open: error in siginterrupt"); | |
371 | #endif | |
372 | ||
373 | /* Set up read timeout timer. */ | |
374 | if ((void (*)) signal (SIGALRM, mm_timer) == (void (*)) -1) | |
375 | perror ("mm_open: error in signal"); | |
376 | #endif | |
377 | ||
378 | #if defined (LOG_FILE) | |
379 | log_file = fopen (LOG_FILE, "w"); | |
380 | if (log_file == NULL) | |
381 | perror_with_name (LOG_FILE); | |
382 | #endif | |
c5aa993b JM |
383 | /* |
384 | ** Initialize target configuration structure (global) | |
c906108c | 385 | */ |
c5aa993b JM |
386 | DRAIN_INPUT (); |
387 | out_msg_buf->config_req_msg.code = CONFIG_REQ; | |
388 | out_msg_buf->config_req_msg.length = 4 * 0; | |
389 | msg_send_serial (out_msg_buf); /* send config request message */ | |
c906108c | 390 | |
c5aa993b | 391 | expect_msg (CONFIG, in_msg_buf, 1); |
c906108c SS |
392 | |
393 | a29k_get_processor_type (); | |
394 | ||
395 | /* Print out some stuff, letting the user now what's going on */ | |
c5aa993b JM |
396 | printf_filtered ("Connected to MiniMon via %s.\n", dev_name); |
397 | /* FIXME: can this restriction be removed? */ | |
398 | printf_filtered ("Remote debugging using virtual addresses works only\n"); | |
399 | printf_filtered ("\twhen virtual addresses map 1:1 to physical addresses.\n") | |
400 | ; | |
401 | if (processor_type != a29k_freeze_mode) | |
402 | { | |
403 | fprintf_filtered (gdb_stderr, | |
404 | "Freeze-mode debugging not available, and can only be done on an A29050.\n"); | |
405 | } | |
c906108c | 406 | |
c5aa993b JM |
407 | target_config.code = CONFIG; |
408 | target_config.length = 0; | |
409 | target_config.processor_id = in_msg_buf->config_msg.processor_id; | |
410 | target_config.version = in_msg_buf->config_msg.version; | |
411 | target_config.I_mem_start = in_msg_buf->config_msg.I_mem_start; | |
412 | target_config.I_mem_size = in_msg_buf->config_msg.I_mem_size; | |
413 | target_config.D_mem_start = in_msg_buf->config_msg.D_mem_start; | |
414 | target_config.D_mem_size = in_msg_buf->config_msg.D_mem_size; | |
415 | target_config.ROM_start = in_msg_buf->config_msg.ROM_start; | |
416 | target_config.ROM_size = in_msg_buf->config_msg.ROM_size; | |
417 | target_config.max_msg_size = in_msg_buf->config_msg.max_msg_size; | |
418 | target_config.max_bkpts = in_msg_buf->config_msg.max_bkpts; | |
419 | target_config.coprocessor = in_msg_buf->config_msg.coprocessor; | |
420 | target_config.reserved = in_msg_buf->config_msg.reserved; | |
421 | if (from_tty) | |
422 | { | |
423 | printf ("Connected to MiniMON :\n"); | |
424 | printf (" Debugcore version %d.%d\n", | |
425 | 0x0f & (target_config.version >> 4), | |
426 | 0x0f & (target_config.version)); | |
427 | printf (" Configuration version %d.%d\n", | |
428 | 0x0f & (target_config.version >> 12), | |
429 | 0x0f & (target_config.version >> 8)); | |
430 | printf (" Message system version %d.%d\n", | |
431 | 0x0f & (target_config.version >> 20), | |
432 | 0x0f & (target_config.version >> 16)); | |
433 | printf (" Communication driver version %d.%d\n", | |
434 | 0x0f & (target_config.version >> 28), | |
435 | 0x0f & (target_config.version >> 24)); | |
436 | } | |
c906108c SS |
437 | |
438 | /* Leave the target running... | |
439 | * The above message stopped the target in the dbg core (MiniMon), | |
440 | * so restart the target out of MiniMon, | |
441 | */ | |
442 | out_msg_buf->go_msg.code = GO; | |
443 | out_msg_buf->go_msg.length = 0; | |
c5aa993b | 444 | msg_send_serial (out_msg_buf); |
c906108c SS |
445 | /* No message to expect after a GO */ |
446 | } | |
447 | ||
448 | /**************************************************************** REMOTE_CLOSE | |
449 | ** Close the open connection to the minimon debugger. | |
450 | Use this when you want to detach and do something else | |
451 | with your gdb. */ | |
452 | static void | |
fba45db2 KB |
453 | mm_close ( /*FIXME: how is quitting used */ |
454 | int quitting) | |
c906108c SS |
455 | { |
456 | if (mm_desc < 0) | |
457 | error ("Can't close remote connection: not debugging remotely."); | |
458 | ||
459 | /* We should never get here if there isn't something valid in | |
460 | mm_desc and mm_stream. | |
461 | ||
462 | Due to a bug in Unix, fclose closes not only the stdio stream, | |
463 | but also the file descriptor. So we don't actually close | |
464 | mm_desc. */ | |
c5aa993b JM |
465 | DRAIN_INPUT (); |
466 | fclose (mm_stream); | |
c906108c SS |
467 | /* close (mm_desc); */ |
468 | ||
469 | /* Do not try to close mm_desc again, later in the program. */ | |
470 | mm_stream = NULL; | |
471 | mm_desc = -1; | |
472 | ||
473 | #if defined (LOG_FILE) | |
474 | if (ferror (log_file)) | |
475 | printf ("Error writing log file.\n"); | |
476 | if (fclose (log_file) != 0) | |
477 | printf ("Error closing log file.\n"); | |
478 | #endif | |
479 | ||
480 | printf ("Ending remote debugging\n"); | |
c5aa993b | 481 | } |
c906108c SS |
482 | |
483 | /************************************************************* REMOTE_ATACH */ | |
484 | /* Attach to a program that is already loaded and running | |
485 | * Upon exiting the process's execution is stopped. | |
486 | */ | |
487 | static void | |
fba45db2 | 488 | mm_attach (char *args, int from_tty) |
c906108c SS |
489 | { |
490 | ||
491 | if (!mm_stream) | |
c5aa993b JM |
492 | error ("MiniMon not opened yet, use the 'target minimon' command.\n"); |
493 | ||
c906108c | 494 | if (from_tty) |
c5aa993b | 495 | printf ("Attaching to remote program %s...\n", prog_name); |
c906108c SS |
496 | |
497 | /* Make sure the target is currently running, it is supposed to be. */ | |
498 | /* FIXME: is it ok to send MiniMon a BREAK if it is already stopped in | |
c5aa993b | 499 | * the dbg core. If so, we don't need to send this GO. |
c906108c SS |
500 | */ |
501 | out_msg_buf->go_msg.code = GO; | |
502 | out_msg_buf->go_msg.length = 0; | |
c5aa993b JM |
503 | msg_send_serial (out_msg_buf); |
504 | sleep (2); /* At the worst it will stop, receive a message, continue */ | |
505 | ||
506 | /* Send the mm a break. */ | |
c906108c SS |
507 | out_msg_buf->break_msg.code = BREAK; |
508 | out_msg_buf->break_msg.length = 0; | |
c5aa993b | 509 | msg_send_serial (out_msg_buf); |
c906108c SS |
510 | } |
511 | /********************************************************** REMOTE_DETACH */ | |
512 | /* Terminate the open connection to the remote debugger. | |
513 | Use this when you want to detach and do something else | |
514 | with your gdb. Leave remote process running (with no breakpoints set). */ | |
515 | static void | |
fba45db2 | 516 | mm_detach (char *args, int from_tty) |
c906108c | 517 | { |
c5aa993b | 518 | remove_breakpoints (); /* Just in case there were any left in */ |
c906108c SS |
519 | out_msg_buf->go_msg.code = GO; |
520 | out_msg_buf->go_msg.length = 0; | |
c5aa993b JM |
521 | msg_send_serial (out_msg_buf); |
522 | pop_target (); /* calls mm_close to do the real work */ | |
c906108c SS |
523 | } |
524 | ||
525 | ||
526 | /*************************************************************** REMOTE_RESUME | |
527 | ** Tell the remote machine to resume. */ | |
528 | ||
529 | static void | |
fba45db2 | 530 | mm_resume (int pid, int step, enum target_signal sig) |
c906108c SS |
531 | { |
532 | if (sig != TARGET_SIGNAL_0) | |
533 | warning ("Can't send signals to a remote MiniMon system."); | |
534 | ||
c5aa993b JM |
535 | if (step) |
536 | { | |
537 | out_msg_buf->step_msg.code = STEP; | |
538 | out_msg_buf->step_msg.length = 1 * 4; | |
539 | out_msg_buf->step_msg.count = 1; /* step 1 instruction */ | |
540 | msg_send_serial (out_msg_buf); | |
541 | } | |
542 | else | |
543 | { | |
544 | out_msg_buf->go_msg.code = GO; | |
c906108c | 545 | out_msg_buf->go_msg.length = 0; |
c5aa993b JM |
546 | msg_send_serial (out_msg_buf); |
547 | } | |
c906108c SS |
548 | } |
549 | ||
550 | /***************************************************************** REMOTE_WAIT | |
551 | ** Wait until the remote machine stops, then return, | |
552 | storing status in STATUS just as `wait' would. */ | |
553 | ||
554 | static int | |
fba45db2 | 555 | mm_wait (struct target_waitstatus *status) |
c906108c SS |
556 | { |
557 | int i, result; | |
558 | int old_timeout = timeout; | |
559 | int old_immediate_quit = immediate_quit; | |
560 | ||
561 | status->kind = TARGET_WAITKIND_EXITED; | |
562 | status->value.integer = 0; | |
563 | ||
564 | /* wait for message to arrive. It should be: | |
c5aa993b JM |
565 | - A HIF service request. |
566 | - A HIF exit service request. | |
567 | - A CHANNEL0_ACK. | |
568 | - A CHANNEL1 request. | |
569 | - a debugcore HALT message. | |
570 | HIF services must be responded too, and while-looping continued. | |
571 | If the target stops executing, mm_wait() should return. | |
572 | */ | |
573 | timeout = 0; /* Wait indefinetly for a message */ | |
574 | immediate_quit = 1; /* Helps ability to QUIT */ | |
575 | while (1) | |
c906108c | 576 | { |
c5aa993b JM |
577 | while (msg_recv_serial (in_msg_buf)) |
578 | { | |
579 | QUIT; /* Let user quit if they want */ | |
580 | } | |
581 | switch (in_msg_buf->halt_msg.code) | |
582 | { | |
583 | case HIF_CALL: | |
584 | i = in_msg_buf->hif_call_rtn_msg.service_number; | |
585 | result = service_HIF (in_msg_buf); | |
586 | if (i == 1) /* EXIT */ | |
c906108c | 587 | goto exit; |
c5aa993b JM |
588 | if (result) |
589 | printf ("Warning: failure during HIF service %d\n", i); | |
590 | break; | |
591 | case CHANNEL0_ACK: | |
592 | service_HIF (in_msg_buf); | |
593 | break; | |
594 | case CHANNEL1: | |
595 | i = in_msg_buf->channel1_msg.length; | |
596 | in_msg_buf->channel1_msg.data[i] = '\0'; | |
597 | printf ("%s", in_msg_buf->channel1_msg.data); | |
598 | gdb_flush (gdb_stdout); | |
599 | /* Send CHANNEL1_ACK message */ | |
600 | out_msg_buf->channel1_ack_msg.code = CHANNEL1_ACK; | |
601 | out_msg_buf->channel1_ack_msg.length = 0; | |
602 | result = msg_send_serial (out_msg_buf); | |
603 | break; | |
604 | case HALT: | |
605 | goto halted; | |
606 | default: | |
607 | goto halted; | |
608 | } | |
c906108c | 609 | } |
c906108c SS |
610 | halted: |
611 | /* FIXME, these printfs should not be here. This is a source level | |
612 | debugger, guys! */ | |
c5aa993b | 613 | if (in_msg_buf->halt_msg.trap_number == 0) |
c906108c | 614 | { |
c5aa993b JM |
615 | printf ("Am290*0 received vector number %d (break point)\n", |
616 | in_msg_buf->halt_msg.trap_number); | |
617 | status->kind = TARGET_WAITKIND_STOPPED; | |
618 | status->value.sig = TARGET_SIGNAL_TRAP; | |
619 | } | |
620 | else if (in_msg_buf->halt_msg.trap_number == 1) | |
621 | { | |
622 | printf ("Am290*0 received vector number %d\n", | |
623 | in_msg_buf->halt_msg.trap_number); | |
c906108c SS |
624 | status->kind = TARGET_WAITKIND_STOPPED; |
625 | status->value.sig = TARGET_SIGNAL_BUS; | |
626 | } | |
c5aa993b JM |
627 | else if (in_msg_buf->halt_msg.trap_number == 3 |
628 | || in_msg_buf->halt_msg.trap_number == 4) | |
629 | { | |
630 | printf ("Am290*0 received vector number %d\n", | |
631 | in_msg_buf->halt_msg.trap_number); | |
c906108c SS |
632 | status->kind = TARGET_WAITKIND_STOPPED; |
633 | status->value.sig = TARGET_SIGNAL_FPE; | |
c5aa993b JM |
634 | } |
635 | else if (in_msg_buf->halt_msg.trap_number == 5) | |
636 | { | |
637 | printf ("Am290*0 received vector number %d\n", | |
638 | in_msg_buf->halt_msg.trap_number); | |
c906108c SS |
639 | status->kind = TARGET_WAITKIND_STOPPED; |
640 | status->value.sig = TARGET_SIGNAL_ILL; | |
c5aa993b | 641 | } |
c906108c | 642 | else if (in_msg_buf->halt_msg.trap_number >= 6 |
c5aa993b JM |
643 | && in_msg_buf->halt_msg.trap_number <= 11) |
644 | { | |
645 | printf ("Am290*0 received vector number %d\n", | |
646 | in_msg_buf->halt_msg.trap_number); | |
c906108c SS |
647 | status->kind = TARGET_WAITKIND_STOPPED; |
648 | status->value.sig = TARGET_SIGNAL_SEGV; | |
c5aa993b JM |
649 | } |
650 | else if (in_msg_buf->halt_msg.trap_number == 12 | |
651 | || in_msg_buf->halt_msg.trap_number == 13) | |
652 | { | |
653 | printf ("Am290*0 received vector number %d\n", | |
654 | in_msg_buf->halt_msg.trap_number); | |
c906108c SS |
655 | status->kind = TARGET_WAITKIND_STOPPED; |
656 | status->value.sig = TARGET_SIGNAL_ILL; | |
c5aa993b JM |
657 | } |
658 | else if (in_msg_buf->halt_msg.trap_number == 14) | |
659 | { | |
660 | printf ("Am290*0 received vector number %d\n", | |
661 | in_msg_buf->halt_msg.trap_number); | |
c906108c SS |
662 | status->kind = TARGET_WAITKIND_STOPPED; |
663 | status->value.sig = TARGET_SIGNAL_ALRM; | |
c5aa993b JM |
664 | } |
665 | else if (in_msg_buf->halt_msg.trap_number == 15) | |
c906108c SS |
666 | { |
667 | status->kind = TARGET_WAITKIND_STOPPED; | |
668 | status->value.sig = TARGET_SIGNAL_TRAP; | |
669 | } | |
670 | else if (in_msg_buf->halt_msg.trap_number >= 16 | |
c5aa993b JM |
671 | && in_msg_buf->halt_msg.trap_number <= 21) |
672 | { | |
673 | printf ("Am290*0 received vector number %d\n", | |
674 | in_msg_buf->halt_msg.trap_number); | |
c906108c SS |
675 | status->kind = TARGET_WAITKIND_STOPPED; |
676 | status->value.sig = TARGET_SIGNAL_INT; | |
c5aa993b JM |
677 | } |
678 | else if (in_msg_buf->halt_msg.trap_number == 22) | |
679 | { | |
680 | printf ("Am290*0 received vector number %d\n", | |
681 | in_msg_buf->halt_msg.trap_number); | |
c906108c SS |
682 | status->kind = TARGET_WAITKIND_STOPPED; |
683 | status->value.sig = TARGET_SIGNAL_ILL; | |
c5aa993b JM |
684 | } /* BREAK message was sent */ |
685 | else if (in_msg_buf->halt_msg.trap_number == 75) | |
c906108c SS |
686 | { |
687 | status->kind = TARGET_WAITKIND_STOPPED; | |
688 | status->value.sig = TARGET_SIGNAL_TRAP; | |
689 | } | |
690 | else | |
c5aa993b | 691 | exit: |
c906108c SS |
692 | { |
693 | status->kind = TARGET_WAITKIND_EXITED; | |
694 | status->value.integer = 0; | |
695 | } | |
696 | ||
697 | timeout = old_timeout; /* Restore original timeout value */ | |
698 | immediate_quit = old_immediate_quit; | |
699 | return 0; | |
700 | } | |
701 | ||
702 | /******************************************************* REMOTE_FETCH_REGISTERS | |
703 | * Read a remote register 'regno'. | |
704 | * If regno==-1 then read all the registers. | |
705 | */ | |
c5aa993b | 706 | static void |
fba45db2 | 707 | mm_fetch_registers (int regno) |
c906108c SS |
708 | { |
709 | INT32 *data_p; | |
710 | ||
c5aa993b JM |
711 | if (regno >= 0) |
712 | { | |
713 | fetch_register (regno); | |
714 | return; | |
715 | } | |
c906108c SS |
716 | |
717 | /* Gr1/rsp */ | |
c5aa993b | 718 | out_msg_buf->read_req_msg.byte_count = 4 * 1; |
c906108c SS |
719 | out_msg_buf->read_req_msg.memory_space = GLOBAL_REG; |
720 | out_msg_buf->read_req_msg.address = 1; | |
c5aa993b JM |
721 | msg_send_serial (out_msg_buf); |
722 | expect_msg (READ_ACK, in_msg_buf, 1); | |
c906108c | 723 | data_p = &(in_msg_buf->read_r_ack_msg.data[0]); |
c5aa993b | 724 | supply_register (GR1_REGNUM, data_p); |
c906108c SS |
725 | |
726 | #if defined(GR64_REGNUM) /* Read gr64-127 */ | |
c5aa993b JM |
727 | /* Global Registers gr64-gr95 */ |
728 | out_msg_buf->read_req_msg.code = READ_REQ; | |
729 | out_msg_buf->read_req_msg.length = 4 * 3; | |
730 | out_msg_buf->read_req_msg.byte_count = 4 * 32; | |
c906108c SS |
731 | out_msg_buf->read_req_msg.memory_space = GLOBAL_REG; |
732 | out_msg_buf->read_req_msg.address = 64; | |
c5aa993b JM |
733 | msg_send_serial (out_msg_buf); |
734 | expect_msg (READ_ACK, in_msg_buf, 1); | |
c906108c SS |
735 | data_p = &(in_msg_buf->read_r_ack_msg.data[0]); |
736 | ||
c5aa993b JM |
737 | for (regno = GR64_REGNUM; regno < GR64_REGNUM + 32; regno++) |
738 | { | |
c906108c | 739 | supply_register (regno, data_p++); |
c5aa993b JM |
740 | } |
741 | #endif /* GR64_REGNUM */ | |
c906108c | 742 | |
c5aa993b JM |
743 | /* Global Registers gr96-gr127 */ |
744 | out_msg_buf->read_req_msg.code = READ_REQ; | |
745 | out_msg_buf->read_req_msg.length = 4 * 3; | |
c906108c SS |
746 | out_msg_buf->read_req_msg.byte_count = 4 * 32; |
747 | out_msg_buf->read_req_msg.memory_space = GLOBAL_REG; | |
748 | out_msg_buf->read_req_msg.address = 96; | |
c5aa993b JM |
749 | msg_send_serial (out_msg_buf); |
750 | expect_msg (READ_ACK, in_msg_buf, 1); | |
c906108c SS |
751 | data_p = &(in_msg_buf->read_r_ack_msg.data[0]); |
752 | ||
c5aa993b JM |
753 | for (regno = GR96_REGNUM; regno < GR96_REGNUM + 32; regno++) |
754 | { | |
c906108c | 755 | supply_register (regno, data_p++); |
c5aa993b | 756 | } |
c906108c | 757 | |
c5aa993b | 758 | /* Local Registers */ |
c906108c SS |
759 | out_msg_buf->read_req_msg.byte_count = 4 * (128); |
760 | out_msg_buf->read_req_msg.memory_space = LOCAL_REG; | |
761 | out_msg_buf->read_req_msg.address = 0; | |
c5aa993b JM |
762 | msg_send_serial (out_msg_buf); |
763 | expect_msg (READ_ACK, in_msg_buf, 1); | |
c906108c SS |
764 | data_p = &(in_msg_buf->read_r_ack_msg.data[0]); |
765 | ||
c5aa993b JM |
766 | for (regno = LR0_REGNUM; regno < LR0_REGNUM + 128; regno++) |
767 | { | |
c906108c | 768 | supply_register (regno, data_p++); |
c5aa993b | 769 | } |
c906108c | 770 | |
c5aa993b JM |
771 | /* Protected Special Registers */ |
772 | out_msg_buf->read_req_msg.byte_count = 4 * 15; | |
c906108c SS |
773 | out_msg_buf->read_req_msg.memory_space = SPECIAL_REG; |
774 | out_msg_buf->read_req_msg.address = 0; | |
c5aa993b JM |
775 | msg_send_serial (out_msg_buf); |
776 | expect_msg (READ_ACK, in_msg_buf, 1); | |
c906108c SS |
777 | data_p = &(in_msg_buf->read_r_ack_msg.data[0]); |
778 | ||
c5aa993b JM |
779 | for (regno = 0; regno <= 14; regno++) |
780 | { | |
781 | supply_register (SR_REGNUM (regno), data_p++); | |
782 | } | |
783 | if (USE_SHADOW_PC) | |
784 | { /* Let regno_to_srnum() handle the register number */ | |
785 | fetch_register (NPC_REGNUM); | |
786 | fetch_register (PC_REGNUM); | |
787 | fetch_register (PC2_REGNUM); | |
788 | } | |
c906108c | 789 | |
c5aa993b JM |
790 | /* Unprotected Special Registers */ |
791 | out_msg_buf->read_req_msg.byte_count = 4 * 8; | |
c906108c SS |
792 | out_msg_buf->read_req_msg.memory_space = SPECIAL_REG; |
793 | out_msg_buf->read_req_msg.address = 128; | |
c5aa993b JM |
794 | msg_send_serial (out_msg_buf); |
795 | expect_msg (READ_ACK, in_msg_buf, 1); | |
c906108c SS |
796 | data_p = &(in_msg_buf->read_r_ack_msg.data[0]); |
797 | ||
c5aa993b JM |
798 | for (regno = 128; regno <= 135; regno++) |
799 | { | |
800 | supply_register (SR_REGNUM (regno), data_p++); | |
801 | } | |
c906108c SS |
802 | |
803 | /* There doesn't seem to be any way to get these. */ | |
804 | { | |
805 | int val = -1; | |
806 | supply_register (FPE_REGNUM, &val); | |
807 | supply_register (INTE_REGNUM, &val); | |
808 | supply_register (FPS_REGNUM, &val); | |
809 | supply_register (EXO_REGNUM, &val); | |
810 | } | |
811 | } | |
812 | ||
813 | ||
814 | /****************************************************** REMOTE_STORE_REGISTERS | |
815 | * Store register regno into the target. | |
816 | * If regno==-1 then store all the registers. | |
817 | * Result is 0 for success, -1 for failure. | |
818 | */ | |
819 | ||
820 | static void | |
fba45db2 | 821 | mm_store_registers (int regno) |
c906108c SS |
822 | { |
823 | int result; | |
c5aa993b JM |
824 | |
825 | if (regno >= 0) | |
826 | { | |
827 | store_register (regno); | |
828 | return; | |
829 | } | |
c906108c SS |
830 | |
831 | result = 0; | |
832 | ||
c5aa993b | 833 | out_msg_buf->write_r_msg.code = WRITE_REQ; |
c906108c SS |
834 | |
835 | /* Gr1/rsp */ | |
c5aa993b JM |
836 | out_msg_buf->write_r_msg.byte_count = 4 * 1; |
837 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; | |
c906108c SS |
838 | out_msg_buf->write_r_msg.memory_space = GLOBAL_REG; |
839 | out_msg_buf->write_r_msg.address = 1; | |
840 | out_msg_buf->write_r_msg.data[0] = read_register (GR1_REGNUM); | |
841 | ||
c5aa993b JM |
842 | msg_send_serial (out_msg_buf); |
843 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) | |
844 | { | |
845 | result = -1; | |
846 | } | |
c906108c SS |
847 | |
848 | #if defined(GR64_REGNUM) | |
849 | /* Global registers gr64-gr95 */ | |
c5aa993b JM |
850 | out_msg_buf->write_r_msg.byte_count = 4 * (32); |
851 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; | |
c906108c SS |
852 | out_msg_buf->write_r_msg.address = 64; |
853 | ||
c5aa993b | 854 | for (regno = GR64_REGNUM; regno < GR64_REGNUM + 32; regno++) |
c906108c | 855 | { |
c5aa993b | 856 | out_msg_buf->write_r_msg.data[regno - GR64_REGNUM] = read_register (regno); |
c906108c | 857 | } |
c5aa993b JM |
858 | msg_send_serial (out_msg_buf); |
859 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) | |
860 | { | |
861 | result = -1; | |
862 | } | |
863 | #endif /* GR64_REGNUM */ | |
c906108c SS |
864 | |
865 | /* Global registers gr96-gr127 */ | |
c5aa993b JM |
866 | out_msg_buf->write_r_msg.byte_count = 4 * (32); |
867 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; | |
c906108c | 868 | out_msg_buf->write_r_msg.address = 96; |
c5aa993b | 869 | for (regno = GR96_REGNUM; regno < GR96_REGNUM + 32; regno++) |
c906108c | 870 | { |
c5aa993b JM |
871 | out_msg_buf->write_r_msg.data[regno - GR96_REGNUM] = read_register (regno); |
872 | } | |
873 | msg_send_serial (out_msg_buf); | |
874 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) | |
875 | { | |
876 | result = -1; | |
c906108c | 877 | } |
c906108c SS |
878 | |
879 | /* Local Registers */ | |
880 | out_msg_buf->write_r_msg.memory_space = LOCAL_REG; | |
c5aa993b JM |
881 | out_msg_buf->write_r_msg.byte_count = 4 * 128; |
882 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; | |
c906108c SS |
883 | out_msg_buf->write_r_msg.address = 0; |
884 | ||
c5aa993b | 885 | for (regno = LR0_REGNUM; regno < LR0_REGNUM + 128; regno++) |
c906108c | 886 | { |
c5aa993b JM |
887 | out_msg_buf->write_r_msg.data[regno - LR0_REGNUM] = read_register (regno); |
888 | } | |
889 | msg_send_serial (out_msg_buf); | |
890 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) | |
891 | { | |
892 | result = -1; | |
c906108c | 893 | } |
c906108c | 894 | |
c5aa993b | 895 | /* Protected Special Registers */ |
c906108c SS |
896 | /* VAB through TMR */ |
897 | out_msg_buf->write_r_msg.memory_space = SPECIAL_REG; | |
c5aa993b JM |
898 | out_msg_buf->write_r_msg.byte_count = 4 * 10; |
899 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; | |
c906108c | 900 | out_msg_buf->write_r_msg.address = 0; |
c5aa993b JM |
901 | for (regno = 0; regno <= 9; regno++) /* VAB through TMR */ |
902 | out_msg_buf->write_r_msg.data[regno] = read_register (SR_REGNUM (regno)); | |
903 | msg_send_serial (out_msg_buf); | |
904 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) | |
905 | { | |
906 | result = -1; | |
907 | } | |
c906108c SS |
908 | |
909 | /* PC0, PC1, PC2 possibly as shadow registers */ | |
c5aa993b JM |
910 | out_msg_buf->write_r_msg.byte_count = 4 * 3; |
911 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; | |
912 | for (regno = 10; regno <= 12; regno++) /* LRU and MMU */ | |
913 | out_msg_buf->write_r_msg.data[regno - 10] = read_register (SR_REGNUM (regno)); | |
914 | if (USE_SHADOW_PC) | |
c906108c | 915 | out_msg_buf->write_r_msg.address = 20; /* SPC0 */ |
c5aa993b | 916 | else |
c906108c | 917 | out_msg_buf->write_r_msg.address = 10; /* PC0 */ |
c5aa993b JM |
918 | msg_send_serial (out_msg_buf); |
919 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) | |
920 | { | |
921 | result = -1; | |
922 | } | |
c906108c SS |
923 | |
924 | /* LRU and MMU */ | |
c5aa993b JM |
925 | out_msg_buf->write_r_msg.byte_count = 4 * 2; |
926 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; | |
c906108c | 927 | out_msg_buf->write_r_msg.address = 13; |
c5aa993b JM |
928 | for (regno = 13; regno <= 14; regno++) /* LRU and MMU */ |
929 | out_msg_buf->write_r_msg.data[regno - 13] = read_register (SR_REGNUM (regno)); | |
930 | msg_send_serial (out_msg_buf); | |
931 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) | |
932 | { | |
933 | result = -1; | |
934 | } | |
c906108c | 935 | |
c5aa993b JM |
936 | /* Unprotected Special Registers */ |
937 | out_msg_buf->write_r_msg.byte_count = 4 * 8; | |
938 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; | |
c906108c | 939 | out_msg_buf->write_r_msg.address = 128; |
c5aa993b JM |
940 | for (regno = 128; regno <= 135; regno++) |
941 | out_msg_buf->write_r_msg.data[regno - 128] = read_register (SR_REGNUM (regno)); | |
942 | msg_send_serial (out_msg_buf); | |
943 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) | |
944 | { | |
945 | result = -1; | |
946 | } | |
947 | ||
c906108c SS |
948 | registers_changed (); |
949 | } | |
950 | ||
951 | /*************************************************** REMOTE_PREPARE_TO_STORE */ | |
952 | /* Get ready to modify the registers array. On machines which store | |
953 | individual registers, this doesn't need to do anything. On machines | |
954 | which store all the registers in one fell swoop, this makes sure | |
955 | that registers contains all the registers from the program being | |
956 | debugged. */ | |
957 | ||
958 | static void | |
fba45db2 | 959 | mm_prepare_to_store (void) |
c906108c SS |
960 | { |
961 | /* Do nothing, since we can store individual regs */ | |
962 | } | |
963 | ||
964 | /******************************************************* REMOTE_XFER_MEMORY */ | |
965 | static CORE_ADDR | |
fba45db2 | 966 | translate_addr (CORE_ADDR addr) |
c906108c SS |
967 | { |
968 | #if defined(KERNEL_DEBUGGING) | |
c5aa993b JM |
969 | /* Check for a virtual address in the kernel */ |
970 | /* Assume physical address of ublock is in paddr_u register */ | |
971 | /* FIXME: doesn't work for user virtual addresses */ | |
972 | if (addr >= UVADDR) | |
973 | { | |
974 | /* PADDR_U register holds the physical address of the ublock */ | |
975 | CORE_ADDR i = (CORE_ADDR) read_register (PADDR_U_REGNUM); | |
976 | return (i + addr - (CORE_ADDR) UVADDR); | |
977 | } | |
978 | else | |
979 | { | |
980 | return (addr); | |
981 | } | |
c906108c | 982 | #else |
c5aa993b | 983 | return (addr); |
c906108c SS |
984 | #endif |
985 | } | |
986 | ||
987 | /******************************************************* REMOTE_FILES_INFO */ | |
988 | static void | |
fba45db2 | 989 | mm_files_info (void) |
c906108c SS |
990 | { |
991 | printf ("\tAttached to %s at %d baud and running program %s.\n", | |
c5aa993b | 992 | dev_name, baudrate, prog_name); |
c906108c SS |
993 | } |
994 | ||
995 | /************************************************* REMOTE_INSERT_BREAKPOINT */ | |
996 | static int | |
fba45db2 | 997 | mm_insert_breakpoint (CORE_ADDR addr, char *contents_cache) |
c906108c SS |
998 | { |
999 | out_msg_buf->bkpt_set_msg.code = BKPT_SET; | |
c5aa993b | 1000 | out_msg_buf->bkpt_set_msg.length = 4 * 4; |
c906108c SS |
1001 | out_msg_buf->bkpt_set_msg.memory_space = I_MEM; |
1002 | out_msg_buf->bkpt_set_msg.bkpt_addr = (ADDR32) addr; | |
1003 | out_msg_buf->bkpt_set_msg.pass_count = 1; | |
1004 | out_msg_buf->bkpt_set_msg.bkpt_type = -1; /* use illop for 29000 */ | |
c5aa993b JM |
1005 | msg_send_serial (out_msg_buf); |
1006 | if (expect_msg (BKPT_SET_ACK, in_msg_buf, 1)) | |
1007 | { | |
1008 | return 0; /* Success */ | |
1009 | } | |
1010 | else | |
1011 | { | |
1012 | return 1; /* Failure */ | |
1013 | } | |
c906108c SS |
1014 | } |
1015 | ||
1016 | /************************************************* REMOTE_DELETE_BREAKPOINT */ | |
1017 | static int | |
fba45db2 | 1018 | mm_remove_breakpoint (CORE_ADDR addr, char *contents_cache) |
c906108c SS |
1019 | { |
1020 | out_msg_buf->bkpt_rm_msg.code = BKPT_RM; | |
c5aa993b | 1021 | out_msg_buf->bkpt_rm_msg.length = 4 * 3; |
c906108c SS |
1022 | out_msg_buf->bkpt_rm_msg.memory_space = I_MEM; |
1023 | out_msg_buf->bkpt_rm_msg.bkpt_addr = (ADDR32) addr; | |
c5aa993b JM |
1024 | msg_send_serial (out_msg_buf); |
1025 | if (expect_msg (BKPT_RM_ACK, in_msg_buf, 1)) | |
1026 | { | |
1027 | return 0; /* Success */ | |
1028 | } | |
1029 | else | |
1030 | { | |
1031 | return 1; /* Failure */ | |
1032 | } | |
c906108c SS |
1033 | } |
1034 | ||
1035 | ||
1036 | /******************************************************* REMOTE_KILL */ | |
1037 | static void | |
fba45db2 | 1038 | mm_kill (char *arg, int from_tty) |
c906108c | 1039 | { |
c5aa993b | 1040 | char buf[4]; |
c906108c SS |
1041 | |
1042 | #if defined(KERNEL_DEBUGGING) | |
c5aa993b JM |
1043 | /* We don't ever kill the kernel */ |
1044 | if (from_tty) | |
1045 | { | |
1046 | printf ("Kernel not killed, but left in current state.\n"); | |
1047 | printf ("Use detach to leave kernel running.\n"); | |
1048 | } | |
c906108c | 1049 | #else |
c5aa993b JM |
1050 | out_msg_buf->break_msg.code = BREAK; |
1051 | out_msg_buf->bkpt_set_msg.length = 4 * 0; | |
1052 | expect_msg (HALT, in_msg_buf, from_tty); | |
1053 | if (from_tty) | |
1054 | { | |
1055 | printf ("Target has been stopped."); | |
1056 | printf ("Would you like to do a hardware reset (y/n) [n] "); | |
1057 | fgets (buf, 3, stdin); | |
1058 | if (buf[0] == 'y') | |
1059 | { | |
1060 | out_msg_buf->reset_msg.code = RESET; | |
1061 | out_msg_buf->bkpt_set_msg.length = 4 * 0; | |
1062 | expect_msg (RESET_ACK, in_msg_buf, from_tty); | |
1063 | printf ("Target has been reset."); | |
c906108c | 1064 | } |
c5aa993b JM |
1065 | } |
1066 | pop_target (); | |
1067 | #endif | |
c906108c SS |
1068 | } |
1069 | ||
1070 | ||
1071 | ||
1072 | /***************************************************************************/ | |
1073 | /* | |
1074 | * Load a program into the target. | |
1075 | */ | |
1076 | static void | |
fba45db2 | 1077 | mm_load (char *arg_string, int from_tty) |
c906108c SS |
1078 | { |
1079 | dont_repeat (); | |
1080 | ||
1081 | #if defined(KERNEL_DEBUGGING) | |
c5aa993b | 1082 | printf ("The kernel had better be loaded already! Loading not done.\n"); |
c906108c SS |
1083 | #else |
1084 | if (arg_string == 0) | |
1085 | error ("The load command takes a file name"); | |
1086 | ||
1087 | arg_string = tilde_expand (arg_string); | |
b8c9b27d | 1088 | make_cleanup (xfree, arg_string); |
c906108c SS |
1089 | QUIT; |
1090 | immediate_quit++; | |
c5aa993b | 1091 | error ("File loading is not yet supported for MiniMon."); |
c906108c SS |
1092 | /* FIXME, code to load your file here... */ |
1093 | /* You may need to do an init_target_mm() */ | |
1094 | /* init_target_mm(?,?,?,?,?,?,?,?); */ | |
1095 | immediate_quit--; | |
2df3850c | 1096 | /* symbol_file_add (arg_string, from_tty, text_addr, 0, 0); */ |
c906108c SS |
1097 | #endif |
1098 | ||
1099 | } | |
1100 | ||
1101 | /************************************************ REMOTE_WRITE_INFERIOR_MEMORY | |
1102 | ** Copy LEN bytes of data from debugger memory at MYADDR | |
1103 | to inferior's memory at MEMADDR. Returns number of bytes written. */ | |
1104 | static int | |
fba45db2 | 1105 | mm_write_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len) |
c906108c | 1106 | { |
c5aa993b JM |
1107 | int i, nwritten; |
1108 | ||
1109 | out_msg_buf->write_req_msg.code = WRITE_REQ; | |
1110 | out_msg_buf->write_req_msg.memory_space = mm_memory_space (memaddr); | |
1111 | ||
1112 | nwritten = 0; | |
1113 | while (nwritten < len) | |
1114 | { | |
1115 | int num_to_write = len - nwritten; | |
1116 | if (num_to_write > MAXDATA) | |
1117 | num_to_write = MAXDATA; | |
1118 | for (i = 0; i < num_to_write; i++) | |
1119 | out_msg_buf->write_req_msg.data[i] = myaddr[i + nwritten]; | |
1120 | out_msg_buf->write_req_msg.byte_count = num_to_write; | |
1121 | out_msg_buf->write_req_msg.length = 3 * 4 + num_to_write; | |
1122 | out_msg_buf->write_req_msg.address = memaddr + nwritten; | |
1123 | msg_send_serial (out_msg_buf); | |
1124 | ||
1125 | if (expect_msg (WRITE_ACK, in_msg_buf, 1)) | |
1126 | { | |
1127 | nwritten += in_msg_buf->write_ack_msg.byte_count; | |
1128 | } | |
1129 | else | |
1130 | { | |
1131 | break; | |
1132 | } | |
1133 | } | |
1134 | return (nwritten); | |
c906108c SS |
1135 | } |
1136 | ||
1137 | /************************************************* REMOTE_READ_INFERIOR_MEMORY | |
1138 | ** Read LEN bytes from inferior memory at MEMADDR. Put the result | |
1139 | at debugger address MYADDR. Returns number of bytes read. */ | |
1140 | static int | |
fba45db2 | 1141 | mm_read_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len) |
c906108c | 1142 | { |
c5aa993b JM |
1143 | int i, nread; |
1144 | ||
1145 | out_msg_buf->read_req_msg.code = READ_REQ; | |
1146 | out_msg_buf->read_req_msg.memory_space = mm_memory_space (memaddr); | |
1147 | ||
1148 | nread = 0; | |
1149 | while (nread < len) | |
1150 | { | |
1151 | int num_to_read = (len - nread); | |
1152 | if (num_to_read > MAXDATA) | |
1153 | num_to_read = MAXDATA; | |
1154 | out_msg_buf->read_req_msg.byte_count = num_to_read; | |
1155 | out_msg_buf->read_req_msg.length = 3 * 4 + num_to_read; | |
1156 | out_msg_buf->read_req_msg.address = memaddr + nread; | |
1157 | msg_send_serial (out_msg_buf); | |
1158 | ||
1159 | if (expect_msg (READ_ACK, in_msg_buf, 1)) | |
1160 | { | |
1161 | for (i = 0; i < in_msg_buf->read_ack_msg.byte_count; i++) | |
1162 | myaddr[i + nread] = in_msg_buf->read_ack_msg.data[i]; | |
1163 | nread += in_msg_buf->read_ack_msg.byte_count; | |
1164 | } | |
1165 | else | |
1166 | { | |
1167 | break; | |
1168 | } | |
1169 | } | |
1170 | return (nread); | |
c906108c SS |
1171 | } |
1172 | ||
1173 | /* FIXME! Merge these two. */ | |
1174 | static int | |
29e57380 C |
1175 | mm_xfer_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len, int write, |
1176 | struct mem_attrib *attrib ATTRIBUTE_UNUSED, | |
1177 | struct target_ops *target ATTRIBUTE_UNUSED) | |
c906108c SS |
1178 | { |
1179 | ||
c5aa993b | 1180 | memaddr = translate_addr (memaddr); |
c906108c SS |
1181 | |
1182 | if (write) | |
1183 | return mm_write_inferior_memory (memaddr, myaddr, len); | |
1184 | else | |
1185 | return mm_read_inferior_memory (memaddr, myaddr, len); | |
1186 | } | |
1187 | ||
1188 | ||
1189 | /********************************************************** MSG_SEND_SERIAL | |
1190 | ** This function is used to send a message over the | |
1191 | ** serial line. | |
1192 | ** | |
1193 | ** If the message is successfully sent, a zero is | |
1194 | ** returned. If the message was not sendable, a -1 | |
1195 | ** is returned. This function blocks. That is, it | |
1196 | ** does not return until the message is completely | |
1197 | ** sent, or until an error is encountered. | |
1198 | ** | |
1199 | */ | |
1200 | ||
1201 | int | |
fba45db2 | 1202 | msg_send_serial (union msg_t *msg_ptr) |
c906108c | 1203 | { |
c5aa993b JM |
1204 | INT32 message_size; |
1205 | int byte_count; | |
1206 | int result; | |
1207 | char c; | |
1208 | ||
1209 | /* Send message header */ | |
1210 | byte_count = 0; | |
1211 | message_size = msg_ptr->generic_msg.length + (2 * sizeof (INT32)); | |
1212 | do | |
1213 | { | |
1214 | c = *((char *) msg_ptr + byte_count); | |
1215 | result = write (mm_desc, &c, 1); | |
1216 | if (result == 1) | |
1217 | { | |
1218 | byte_count = byte_count + 1; | |
1219 | } | |
1220 | } | |
1221 | while ((byte_count < message_size)); | |
1222 | ||
1223 | return (0); | |
1224 | } /* end msg_send_serial() */ | |
c906108c SS |
1225 | |
1226 | /********************************************************** MSG_RECV_SERIAL | |
1227 | ** This function is used to receive a message over a | |
1228 | ** serial line. | |
1229 | ** | |
1230 | ** If the message is waiting in the buffer, a zero is | |
1231 | ** returned and the buffer pointed to by msg_ptr is filled | |
1232 | ** in. If no message was available, a -1 is returned. | |
1233 | ** If timeout==0, wait indefinetly for a character. | |
1234 | ** | |
1235 | */ | |
1236 | ||
1237 | int | |
fba45db2 | 1238 | msg_recv_serial (union msg_t *msg_ptr) |
c906108c | 1239 | { |
c5aa993b JM |
1240 | static INT32 length = 0; |
1241 | static INT32 byte_count = 0; | |
1242 | int result; | |
1243 | char c; | |
1244 | if (msg_ptr == 0) /* re-sync request */ | |
1245 | { | |
1246 | length = 0; | |
1247 | byte_count = 0; | |
c906108c | 1248 | #ifdef HAVE_TERMIO |
c5aa993b JM |
1249 | /* The timeout here is the prevailing timeout set with VTIME */ |
1250 | ->"timeout==0 semantics not supported" | |
1251 | read (mm_desc, in_buf, BUFER_SIZE); | |
c906108c | 1252 | #else |
c5aa993b JM |
1253 | alarm (1); |
1254 | read (mm_desc, in_buf, BUFER_SIZE); | |
1255 | alarm (0); | |
c906108c | 1256 | #endif |
c5aa993b JM |
1257 | return (0); |
1258 | } | |
1259 | /* Receive message */ | |
c906108c SS |
1260 | #ifdef HAVE_TERMIO |
1261 | /* Timeout==0, help support the mm_wait() routine */ | |
c5aa993b JM |
1262 | ->"timeout==0 semantics not supported (and its nice if they are)" |
1263 | result = read (mm_desc, &c, 1); | |
c906108c | 1264 | #else |
c5aa993b JM |
1265 | alarm (timeout); |
1266 | result = read (mm_desc, &c, 1); | |
c906108c SS |
1267 | alarm (0); |
1268 | #endif | |
c5aa993b JM |
1269 | if (result < 0) |
1270 | { | |
1271 | if (errno == EINTR) | |
1272 | { | |
1273 | error ("Timeout reading from remote system."); | |
1274 | } | |
1275 | else | |
c906108c | 1276 | perror_with_name ("remote"); |
c5aa993b JM |
1277 | } |
1278 | else if (result == 1) | |
1279 | { | |
1280 | *((char *) msg_ptr + byte_count) = c; | |
c906108c | 1281 | byte_count = byte_count + 1; |
c5aa993b | 1282 | } |
c906108c | 1283 | |
c5aa993b JM |
1284 | /* Message header received. Save message length. */ |
1285 | if (byte_count == (2 * sizeof (INT32))) | |
1286 | length = msg_ptr->generic_msg.length; | |
c906108c | 1287 | |
c5aa993b JM |
1288 | if (byte_count >= (length + (2 * sizeof (INT32)))) |
1289 | { | |
c906108c SS |
1290 | /* Message received */ |
1291 | byte_count = 0; | |
c5aa993b JM |
1292 | return (0); |
1293 | } | |
1294 | else | |
1295 | return (-1); | |
c906108c | 1296 | |
c5aa993b | 1297 | } /* end msg_recv_serial() */ |
c906108c SS |
1298 | |
1299 | /********************************************************************* KBD_RAW | |
1300 | ** This function is used to put the keyboard in "raw" | |
1301 | ** mode for BSD Unix. The original status is saved | |
1302 | ** so that it may be restored later. | |
1303 | */ | |
1304 | TERMINAL kbd_tbuf; | |
1305 | ||
1306 | int | |
fba45db2 | 1307 | kbd_raw (void) |
c5aa993b JM |
1308 | { |
1309 | int result; | |
1310 | TERMINAL tbuf; | |
c906108c | 1311 | |
c5aa993b | 1312 | /* Get keyboard termio (to save to restore original modes) */ |
c906108c | 1313 | #ifdef HAVE_TERMIO |
c5aa993b | 1314 | result = ioctl (0, TCGETA, &kbd_tbuf); |
c906108c | 1315 | #else |
c5aa993b | 1316 | result = ioctl (0, TIOCGETP, &kbd_tbuf); |
c906108c | 1317 | #endif |
c5aa993b JM |
1318 | if (result == -1) |
1319 | return (errno); | |
c906108c | 1320 | |
c5aa993b | 1321 | /* Get keyboard TERMINAL (for modification) */ |
c906108c | 1322 | #ifdef HAVE_TERMIO |
c5aa993b | 1323 | result = ioctl (0, TCGETA, &tbuf); |
c906108c | 1324 | #else |
c5aa993b | 1325 | result = ioctl (0, TIOCGETP, &tbuf); |
c906108c | 1326 | #endif |
c5aa993b JM |
1327 | if (result == -1) |
1328 | return (errno); | |
c906108c | 1329 | |
c5aa993b | 1330 | /* Set up new parameters */ |
c906108c | 1331 | #ifdef HAVE_TERMIO |
c5aa993b JM |
1332 | tbuf.c_iflag = tbuf.c_iflag & |
1333 | ~(INLCR | ICRNL | IUCLC | ISTRIP | IXON | BRKINT); | |
1334 | tbuf.c_lflag = tbuf.c_lflag & ~(ICANON | ISIG | ECHO); | |
1335 | tbuf.c_cc[4] = 0; /* MIN */ | |
1336 | tbuf.c_cc[5] = 0; /* TIME */ | |
c906108c | 1337 | #else |
c5aa993b JM |
1338 | /* FIXME: not sure if this is correct (matches HAVE_TERMIO). */ |
1339 | tbuf.sg_flags |= RAW; | |
1340 | tbuf.sg_flags |= ANYP; | |
1341 | tbuf.sg_flags &= ~ECHO; | |
c906108c SS |
1342 | #endif |
1343 | ||
c5aa993b | 1344 | /* Set keyboard termio to new mode (RAW) */ |
c906108c | 1345 | #ifdef HAVE_TERMIO |
c5aa993b | 1346 | result = ioctl (0, TCSETAF, &tbuf); |
c906108c | 1347 | #else |
c5aa993b JM |
1348 | result = ioctl (0, TIOCSETP, &tbuf); |
1349 | #endif | |
1350 | if (result == -1) | |
1351 | return (errno); | |
c906108c | 1352 | |
c5aa993b JM |
1353 | return (0); |
1354 | } /* end kbd_raw() */ | |
c906108c SS |
1355 | |
1356 | ||
1357 | ||
1358 | /***************************************************************** KBD_RESTORE | |
1359 | ** This function is used to put the keyboard back in the | |
1360 | ** mode it was in before kbk_raw was called. Note that | |
1361 | ** kbk_raw() must have been called at least once before | |
1362 | ** kbd_restore() is called. | |
1363 | */ | |
1364 | ||
1365 | int | |
fba45db2 | 1366 | kbd_restore (void) |
c5aa993b JM |
1367 | { |
1368 | int result; | |
c906108c | 1369 | |
c5aa993b | 1370 | /* Set keyboard termio to original mode */ |
c906108c | 1371 | #ifdef HAVE_TERMIO |
c5aa993b | 1372 | result = ioctl (0, TCSETAF, &kbd_tbuf); |
c906108c | 1373 | #else |
c5aa993b | 1374 | result = ioctl (0, TIOCGETP, &kbd_tbuf); |
c906108c SS |
1375 | #endif |
1376 | ||
c5aa993b JM |
1377 | if (result == -1) |
1378 | return (errno); | |
c906108c | 1379 | |
c5aa993b JM |
1380 | return (0); |
1381 | } /* end kbd_cooked() */ | |
c906108c SS |
1382 | |
1383 | ||
c5aa993b | 1384 | /*****************************************************************************/ |
c906108c SS |
1385 | /* Fetch a single register indicatated by 'regno'. |
1386 | * Returns 0/-1 on success/failure. | |
1387 | */ | |
1388 | static int | |
fba45db2 | 1389 | fetch_register (int regno) |
c906108c | 1390 | { |
c5aa993b JM |
1391 | int result; |
1392 | out_msg_buf->read_req_msg.code = READ_REQ; | |
1393 | out_msg_buf->read_req_msg.length = 4 * 3; | |
c906108c SS |
1394 | out_msg_buf->read_req_msg.byte_count = 4; |
1395 | ||
1396 | if (regno == GR1_REGNUM) | |
c5aa993b JM |
1397 | { |
1398 | out_msg_buf->read_req_msg.memory_space = GLOBAL_REG; | |
1399 | out_msg_buf->read_req_msg.address = 1; | |
1400 | } | |
c906108c | 1401 | else if (regno >= GR96_REGNUM && regno < GR96_REGNUM + 32) |
c5aa993b JM |
1402 | { |
1403 | out_msg_buf->read_req_msg.memory_space = GLOBAL_REG; | |
1404 | out_msg_buf->read_req_msg.address = (regno - GR96_REGNUM) + 96; | |
1405 | } | |
c906108c | 1406 | #if defined(GR64_REGNUM) |
c5aa993b JM |
1407 | else if (regno >= GR64_REGNUM && regno < GR64_REGNUM + 32) |
1408 | { | |
1409 | out_msg_buf->read_req_msg.memory_space = GLOBAL_REG; | |
1410 | out_msg_buf->read_req_msg.address = (regno - GR64_REGNUM) + 64; | |
1411 | } | |
1412 | #endif /* GR64_REGNUM */ | |
c906108c | 1413 | else if (regno >= LR0_REGNUM && regno < LR0_REGNUM + 128) |
c5aa993b JM |
1414 | { |
1415 | out_msg_buf->read_req_msg.memory_space = LOCAL_REG; | |
1416 | out_msg_buf->read_req_msg.address = (regno - LR0_REGNUM); | |
1417 | } | |
1418 | else if (regno >= FPE_REGNUM && regno <= EXO_REGNUM) | |
1419 | { | |
1420 | int val = -1; | |
1421 | supply_register (160 + (regno - FPE_REGNUM), &val); | |
1422 | return 0; /* Pretend Success */ | |
1423 | } | |
1424 | else | |
1425 | { | |
1426 | out_msg_buf->read_req_msg.memory_space = SPECIAL_REG; | |
1427 | out_msg_buf->read_req_msg.address = regnum_to_srnum (regno); | |
1428 | } | |
1429 | ||
1430 | msg_send_serial (out_msg_buf); | |
1431 | ||
1432 | if (expect_msg (READ_ACK, in_msg_buf, 1)) | |
1433 | { | |
1434 | supply_register (regno, &(in_msg_buf->read_r_ack_msg.data[0])); | |
1435 | result = 0; | |
1436 | } | |
1437 | else | |
1438 | { | |
1439 | result = -1; | |
1440 | } | |
c906108c SS |
1441 | return result; |
1442 | } | |
c5aa993b | 1443 | /*****************************************************************************/ |
c906108c SS |
1444 | /* Store a single register indicated by 'regno'. |
1445 | * Returns 0/-1 on success/failure. | |
1446 | */ | |
1447 | static int | |
fba45db2 | 1448 | store_register (int regno) |
c906108c | 1449 | { |
c5aa993b | 1450 | int result; |
c906108c | 1451 | |
c5aa993b JM |
1452 | out_msg_buf->write_req_msg.code = WRITE_REQ; |
1453 | out_msg_buf->write_req_msg.length = 4 * 4; | |
c906108c SS |
1454 | out_msg_buf->write_req_msg.byte_count = 4; |
1455 | out_msg_buf->write_r_msg.data[0] = read_register (regno); | |
1456 | ||
1457 | if (regno == GR1_REGNUM) | |
c5aa993b JM |
1458 | { |
1459 | out_msg_buf->write_req_msg.memory_space = GLOBAL_REG; | |
1460 | out_msg_buf->write_req_msg.address = 1; | |
1461 | /* Setting GR1 changes the numbers of all the locals, so invalidate the | |
1462 | * register cache. Do this *after* calling read_register, because we want | |
1463 | * read_register to return the value that write_register has just stuffed | |
1464 | * into the registers array, not the value of the register fetched from | |
1465 | * the inferior. | |
1466 | */ | |
1467 | registers_changed (); | |
1468 | } | |
c906108c | 1469 | #if defined(GR64_REGNUM) |
c5aa993b JM |
1470 | else if (regno >= GR64_REGNUM && regno < GR64_REGNUM + 32) |
1471 | { | |
1472 | out_msg_buf->write_req_msg.memory_space = GLOBAL_REG; | |
1473 | out_msg_buf->write_req_msg.address = (regno - GR64_REGNUM) + 64; | |
1474 | } | |
1475 | #endif /* GR64_REGNUM */ | |
c906108c | 1476 | else if (regno >= GR96_REGNUM && regno < GR96_REGNUM + 32) |
c5aa993b JM |
1477 | { |
1478 | out_msg_buf->write_req_msg.memory_space = GLOBAL_REG; | |
1479 | out_msg_buf->write_req_msg.address = (regno - GR96_REGNUM) + 96; | |
1480 | } | |
c906108c | 1481 | else if (regno >= LR0_REGNUM && regno < LR0_REGNUM + 128) |
c5aa993b JM |
1482 | { |
1483 | out_msg_buf->write_req_msg.memory_space = LOCAL_REG; | |
1484 | out_msg_buf->write_req_msg.address = (regno - LR0_REGNUM); | |
1485 | } | |
1486 | else if (regno >= FPE_REGNUM && regno <= EXO_REGNUM) | |
1487 | { | |
1488 | return 0; /* Pretend Success */ | |
1489 | } | |
1490 | else | |
1491 | /* An unprotected or protected special register */ | |
1492 | { | |
1493 | out_msg_buf->write_req_msg.memory_space = SPECIAL_REG; | |
1494 | out_msg_buf->write_req_msg.address = regnum_to_srnum (regno); | |
1495 | } | |
c906108c | 1496 | |
c5aa993b | 1497 | msg_send_serial (out_msg_buf); |
c906108c | 1498 | |
c5aa993b JM |
1499 | if (expect_msg (WRITE_ACK, in_msg_buf, 1)) |
1500 | { | |
1501 | result = 0; | |
1502 | } | |
1503 | else | |
1504 | { | |
1505 | result = -1; | |
1506 | } | |
c906108c SS |
1507 | return result; |
1508 | } | |
1509 | /****************************************************************************/ | |
1510 | /* | |
1511 | * Convert a gdb special register number to a 29000 special register number. | |
1512 | */ | |
1513 | static int | |
fba45db2 | 1514 | regnum_to_srnum (int regno) |
c906108c | 1515 | { |
c5aa993b JM |
1516 | switch (regno) |
1517 | { | |
1518 | case VAB_REGNUM: | |
1519 | return (0); | |
1520 | case OPS_REGNUM: | |
1521 | return (1); | |
1522 | case CPS_REGNUM: | |
1523 | return (2); | |
1524 | case CFG_REGNUM: | |
1525 | return (3); | |
1526 | case CHA_REGNUM: | |
1527 | return (4); | |
1528 | case CHD_REGNUM: | |
1529 | return (5); | |
1530 | case CHC_REGNUM: | |
1531 | return (6); | |
1532 | case RBP_REGNUM: | |
1533 | return (7); | |
1534 | case TMC_REGNUM: | |
1535 | return (8); | |
1536 | case TMR_REGNUM: | |
1537 | return (9); | |
1538 | case NPC_REGNUM: | |
1539 | return (USE_SHADOW_PC ? (20) : (10)); | |
1540 | case PC_REGNUM: | |
1541 | return (USE_SHADOW_PC ? (21) : (11)); | |
1542 | case PC2_REGNUM: | |
1543 | return (USE_SHADOW_PC ? (22) : (12)); | |
1544 | case MMU_REGNUM: | |
1545 | return (13); | |
1546 | case LRU_REGNUM: | |
1547 | return (14); | |
1548 | case IPC_REGNUM: | |
1549 | return (128); | |
1550 | case IPA_REGNUM: | |
1551 | return (129); | |
1552 | case IPB_REGNUM: | |
1553 | return (130); | |
1554 | case Q_REGNUM: | |
1555 | return (131); | |
1556 | case ALU_REGNUM: | |
1557 | return (132); | |
1558 | case BP_REGNUM: | |
1559 | return (133); | |
1560 | case FC_REGNUM: | |
1561 | return (134); | |
1562 | case CR_REGNUM: | |
1563 | return (135); | |
1564 | case FPE_REGNUM: | |
1565 | return (160); | |
1566 | case INTE_REGNUM: | |
1567 | return (161); | |
1568 | case FPS_REGNUM: | |
1569 | return (162); | |
1570 | case EXO_REGNUM: | |
1571 | return (164); | |
1572 | default: | |
1573 | return (255); /* Failure ? */ | |
1574 | } | |
c906108c SS |
1575 | } |
1576 | /****************************************************************************/ | |
1577 | /* | |
1578 | * Initialize the target debugger (minimon only). | |
1579 | */ | |
1580 | static void | |
fba45db2 KB |
1581 | init_target_mm (ADDR32 tstart, ADDR32 tend, ADDR32 dstart, ADDR32 dend, |
1582 | ADDR32 entry, INT32 ms_size, INT32 rs_size, ADDR32 arg_start) | |
c906108c | 1583 | { |
c5aa993b JM |
1584 | out_msg_buf->init_msg.code = INIT; |
1585 | out_msg_buf->init_msg.length = sizeof (struct init_msg_t) - 2 * sizeof (INT32); | |
1586 | out_msg_buf->init_msg.text_start = tstart; | |
1587 | out_msg_buf->init_msg.text_end = tend; | |
1588 | out_msg_buf->init_msg.data_start = dstart; | |
1589 | out_msg_buf->init_msg.data_end = dend; | |
1590 | out_msg_buf->init_msg.entry_point = entry; | |
1591 | out_msg_buf->init_msg.mem_stack_size = ms_size; | |
1592 | out_msg_buf->init_msg.reg_stack_size = rs_size; | |
1593 | out_msg_buf->init_msg.arg_start = arg_start; | |
1594 | msg_send_serial (out_msg_buf); | |
1595 | expect_msg (INIT_ACK, in_msg_buf, 1); | |
c906108c SS |
1596 | } |
1597 | /****************************************************************************/ | |
1598 | /* | |
1599 | * Return a pointer to a string representing the given message code. | |
1600 | * Not all messages are represented here, only the ones that we expect | |
1601 | * to be called with. | |
1602 | */ | |
c5aa993b | 1603 | static char * |
fba45db2 | 1604 | msg_str (INT32 code) |
c906108c | 1605 | { |
c5aa993b JM |
1606 | static char cbuf[32]; |
1607 | ||
1608 | switch (code) | |
1609 | { | |
1610 | case BKPT_SET_ACK: | |
1611 | sprintf (cbuf, "%s (%d)", "BKPT_SET_ACK", code); | |
1612 | break; | |
1613 | case BKPT_RM_ACK: | |
1614 | sprintf (cbuf, "%s (%d)", "BKPT_RM_ACK", code); | |
1615 | break; | |
1616 | case INIT_ACK: | |
1617 | sprintf (cbuf, "%s (%d)", "INIT_ACK", code); | |
1618 | break; | |
1619 | case READ_ACK: | |
1620 | sprintf (cbuf, "%s (%d)", "READ_ACK", code); | |
1621 | break; | |
1622 | case WRITE_ACK: | |
1623 | sprintf (cbuf, "%s (%d)", "WRITE_ACK", code); | |
1624 | break; | |
1625 | case ERROR: | |
1626 | sprintf (cbuf, "%s (%d)", "ERROR", code); | |
1627 | break; | |
1628 | case HALT: | |
1629 | sprintf (cbuf, "%s (%d)", "HALT", code); | |
1630 | break; | |
1631 | default: | |
1632 | sprintf (cbuf, "UNKNOWN (%d)", code); | |
1633 | break; | |
1634 | } | |
1635 | return (cbuf); | |
c906108c SS |
1636 | } |
1637 | /****************************************************************************/ | |
1638 | /* | |
1639 | * Selected (not all of them) error codes that we might get. | |
1640 | */ | |
c5aa993b | 1641 | static char * |
fba45db2 | 1642 | error_msg_str (INT32 code) |
c906108c | 1643 | { |
c5aa993b JM |
1644 | static char cbuf[50]; |
1645 | ||
1646 | switch (code) | |
1647 | { | |
1648 | case EMFAIL: | |
1649 | return ("EMFAIL: unrecoverable error"); | |
1650 | case EMBADADDR: | |
1651 | return ("EMBADADDR: Illegal address"); | |
1652 | case EMBADREG: | |
1653 | return ("EMBADREG: Illegal register "); | |
1654 | case EMACCESS: | |
1655 | return ("EMACCESS: Could not access memory"); | |
1656 | case EMBADMSG: | |
1657 | return ("EMBADMSG: Unknown message type"); | |
1658 | case EMMSG2BIG: | |
1659 | return ("EMMSG2BIG: Message to large"); | |
1660 | case EMNOSEND: | |
1661 | return ("EMNOSEND: Could not send message"); | |
1662 | case EMNORECV: | |
1663 | return ("EMNORECV: Could not recv message"); | |
1664 | case EMRESET: | |
1665 | return ("EMRESET: Could not RESET target"); | |
1666 | case EMCONFIG: | |
1667 | return ("EMCONFIG: Could not get target CONFIG"); | |
1668 | case EMSTATUS: | |
1669 | return ("EMSTATUS: Could not get target STATUS"); | |
1670 | case EMREAD: | |
1671 | return ("EMREAD: Could not READ target memory"); | |
1672 | case EMWRITE: | |
1673 | return ("EMWRITE: Could not WRITE target memory"); | |
1674 | case EMBKPTSET: | |
1675 | return ("EMBKPTSET: Could not set breakpoint"); | |
1676 | case EMBKPTRM: | |
1677 | return ("EMBKPTRM: Could not remove breakpoint"); | |
1678 | case EMBKPTSTAT: | |
1679 | return ("EMBKPTSTAT: Could not get breakpoint status"); | |
1680 | case EMBKPTNONE: | |
1681 | return ("EMBKPTNONE: All breakpoints in use"); | |
1682 | case EMBKPTUSED: | |
1683 | return ("EMBKPTUSED: Breakpoints already in use"); | |
1684 | case EMINIT: | |
1685 | return ("EMINIT: Could not init target memory"); | |
1686 | case EMGO: | |
1687 | return ("EMGO: Could not start execution"); | |
1688 | case EMSTEP: | |
1689 | return ("EMSTEP: Could not single step"); | |
1690 | case EMBREAK: | |
1691 | return ("EMBREAK: Could not BREAK"); | |
1692 | case EMCOMMERR: | |
1693 | return ("EMCOMMERR: Communication error"); | |
1694 | default: | |
1695 | sprintf (cbuf, "error number %d", code); | |
1696 | break; | |
1697 | } /* end switch */ | |
1698 | ||
1699 | return (cbuf); | |
c906108c SS |
1700 | } |
1701 | /****************************************************************************/ | |
d742f2c2 KB |
1702 | |
1703 | /* Receive a message, placing it in MSG_BUF, and expect it to be of | |
1704 | type MSGCODE. If an error occurs, a non-zero FROM_TTY indicates | |
1705 | that the message should be printed. | |
1706 | ||
1707 | Return 0 for failure, 1 for success. */ | |
1708 | ||
c906108c | 1709 | static int |
d742f2c2 | 1710 | expect_msg (INT32 msgcode, union msg_t *msg_buf, int from_tty) |
c906108c | 1711 | { |
c5aa993b JM |
1712 | int retries = 0; |
1713 | while (msg_recv_serial (msg_buf) && (retries++ < MAX_RETRIES)); | |
1714 | if (retries >= MAX_RETRIES) | |
1715 | { | |
1716 | printf ("Expected msg %s, ", msg_str (msgcode)); | |
1717 | printf ("no message received!\n"); | |
1718 | return (0); /* Failure */ | |
1719 | } | |
c906108c | 1720 | |
c5aa993b JM |
1721 | if (msg_buf->generic_msg.code != msgcode) |
1722 | { | |
1723 | if (from_tty) | |
1724 | { | |
1725 | printf ("Expected msg %s, ", msg_str (msgcode)); | |
1726 | printf ("got msg %s\n", msg_str (msg_buf->generic_msg.code)); | |
1727 | if (msg_buf->generic_msg.code == ERROR) | |
1728 | printf ("%s\n", error_msg_str (msg_buf->error_msg.error_code)); | |
1729 | } | |
1730 | return (0); /* Failure */ | |
1731 | } | |
1732 | return (1); /* Success */ | |
1733 | } | |
c906108c SS |
1734 | /****************************************************************************/ |
1735 | /* | |
1736 | * Determine the MiniMon memory space qualifier based on the addr. | |
1737 | * FIXME: Can't distinguis I_ROM/D_ROM. | |
1738 | * FIXME: Doesn't know anything about I_CACHE/D_CACHE. | |
1739 | */ | |
1740 | static int | |
fba45db2 | 1741 | mm_memory_space (CORE_ADDR *addr) |
c906108c | 1742 | { |
c5aa993b JM |
1743 | ADDR32 tstart = target_config.I_mem_start; |
1744 | ADDR32 tend = tstart + target_config.I_mem_size; | |
1745 | ADDR32 dstart = target_config.D_mem_start; | |
1746 | ADDR32 dend = tstart + target_config.D_mem_size; | |
1747 | ADDR32 rstart = target_config.ROM_start; | |
1748 | ADDR32 rend = tstart + target_config.ROM_size; | |
1749 | ||
1750 | if (((ADDR32) addr >= tstart) && ((ADDR32) addr < tend)) | |
1751 | { | |
1752 | return I_MEM; | |
1753 | } | |
1754 | else if (((ADDR32) addr >= dstart) && ((ADDR32) addr < dend)) | |
1755 | { | |
1756 | return D_MEM; | |
1757 | } | |
1758 | else if (((ADDR32) addr >= rstart) && ((ADDR32) addr < rend)) | |
1759 | { | |
1760 | /* FIXME: how do we determine between D_ROM and I_ROM */ | |
1761 | return D_ROM; | |
1762 | } | |
1763 | else /* FIXME: what do me do now? */ | |
1764 | return D_MEM; /* Hmmm! */ | |
c906108c SS |
1765 | } |
1766 | ||
1767 | /****************************************************************************/ | |
1768 | /* | |
1769 | * Define the target subroutine names | |
1770 | */ | |
c5aa993b | 1771 | struct target_ops mm_ops; |
c906108c | 1772 | |
c5aa993b JM |
1773 | static void |
1774 | init_mm_ops (void) | |
c906108c | 1775 | { |
c5aa993b JM |
1776 | mm_ops.to_shortname = "minimon"; |
1777 | mm_ops.to_longname = "Remote AMD/Minimon target"; | |
1778 | mm_ops.to_doc = "Remote debug an AMD 290*0 using the MiniMon dbg core on the target"; | |
1779 | mm_ops.to_open = mm_open; | |
1780 | mm_ops.to_close = mm_close; | |
1781 | mm_ops.to_attach = mm_attach; | |
c906108c SS |
1782 | mm_ops.to_post_attach = NULL; |
1783 | mm_ops.to_require_attach = NULL; | |
c5aa993b | 1784 | mm_ops.to_detach = mm_detach; |
c906108c | 1785 | mm_ops.to_require_detach = NULL; |
c5aa993b JM |
1786 | mm_ops.to_resume = mm_resume; |
1787 | mm_ops.to_wait = mm_wait; | |
c906108c | 1788 | mm_ops.to_post_wait = NULL; |
c5aa993b JM |
1789 | mm_ops.to_fetch_registers = mm_fetch_registers; |
1790 | mm_ops.to_store_registers = mm_store_registers; | |
1791 | mm_ops.to_prepare_to_store = mm_prepare_to_store; | |
1792 | mm_ops.to_xfer_memory = mm_xfer_inferior_memory; | |
1793 | mm_ops.to_files_info = mm_files_info; | |
1794 | mm_ops.to_insert_breakpoint = mm_insert_breakpoint; | |
1795 | mm_ops.to_remove_breakpoint = mm_remove_breakpoint; | |
1796 | mm_ops.to_terminal_init = 0; | |
1797 | mm_ops.to_terminal_inferior = 0; | |
1798 | mm_ops.to_terminal_ours_for_output = 0; | |
1799 | mm_ops.to_terminal_ours = 0; | |
1800 | mm_ops.to_terminal_info = 0; | |
1801 | mm_ops.to_kill = mm_kill; | |
1802 | mm_ops.to_load = mm_load; | |
1803 | mm_ops.to_lookup_symbol = 0; | |
1804 | mm_ops.to_create_inferior = mm_create_inferior; | |
c906108c SS |
1805 | mm_ops.to_post_startup_inferior = NULL; |
1806 | mm_ops.to_acknowledge_created_inferior = NULL; | |
1807 | mm_ops.to_clone_and_follow_inferior = NULL; | |
1808 | mm_ops.to_post_follow_inferior_by_clone = NULL; | |
1809 | mm_ops.to_insert_fork_catchpoint = NULL; | |
1810 | mm_ops.to_remove_fork_catchpoint = NULL; | |
1811 | mm_ops.to_insert_vfork_catchpoint = NULL; | |
1812 | mm_ops.to_remove_vfork_catchpoint = NULL; | |
1813 | mm_ops.to_has_forked = NULL; | |
1814 | mm_ops.to_has_vforked = NULL; | |
1815 | mm_ops.to_can_follow_vfork_prior_to_exec = NULL; | |
c5aa993b | 1816 | mm_ops.to_post_follow_vfork = NULL; |
c906108c SS |
1817 | mm_ops.to_insert_exec_catchpoint = NULL; |
1818 | mm_ops.to_remove_exec_catchpoint = NULL; | |
1819 | mm_ops.to_has_execd = NULL; | |
1820 | mm_ops.to_reported_exec_events_per_exec_call = NULL; | |
1821 | mm_ops.to_has_exited = NULL; | |
c5aa993b JM |
1822 | mm_ops.to_mourn_inferior = mm_mourn; |
1823 | mm_ops.to_can_run = 0; | |
1824 | mm_ops.to_notice_signals = 0; | |
1825 | mm_ops.to_thread_alive = 0; | |
1826 | mm_ops.to_stop = 0; | |
c906108c SS |
1827 | mm_ops.to_pid_to_exec_file = NULL; |
1828 | mm_ops.to_core_file_to_sym_file = NULL; | |
c5aa993b JM |
1829 | mm_ops.to_stratum = process_stratum; |
1830 | mm_ops.DONT_USE = 0; | |
1831 | mm_ops.to_has_all_memory = 1; | |
1832 | mm_ops.to_has_memory = 1; | |
1833 | mm_ops.to_has_stack = 1; | |
1834 | mm_ops.to_has_registers = 1; | |
1835 | mm_ops.to_has_execution = 1; | |
1836 | mm_ops.to_sections = 0; | |
1837 | mm_ops.to_sections_end = 0; | |
1838 | mm_ops.to_magic = OPS_MAGIC; | |
c906108c SS |
1839 | }; |
1840 | ||
1841 | void | |
fba45db2 | 1842 | _initialize_remote_mm (void) |
c906108c | 1843 | { |
c5aa993b | 1844 | init_mm_ops (); |
c906108c SS |
1845 | add_target (&mm_ops); |
1846 | } | |
1847 | ||
1848 | #ifdef NO_HIF_SUPPORT | |
fba45db2 | 1849 | service_HIF (union msg_t *msg) |
c906108c | 1850 | { |
c5aa993b | 1851 | return (0); /* Emulate a failure */ |
c906108c SS |
1852 | } |
1853 | #endif |