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