Commit | Line | Data |
---|---|---|
5140562f JG |
1 | /* Remote debugging interface for Am290*0 running MiniMON monitor, for GDB. |
2 | Copyright 1990, 1992 Free Software Foundation, Inc. | |
3 | Written by Daniel Mann. Contributed by AMD. | |
9bddba9a SG |
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 | |
5140562f JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
9bddba9a SG |
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 | |
5140562f JG |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
9bddba9a | 20 | |
5140562f JG |
21 | /* This is like remote.c but expects MiniMON to be running on the Am29000 |
22 | target hardware. | |
23 | - Originally written by Daniel Mann at AMD for gdb 3.91.6. | |
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 | *- Daniel Mann at AMD took the 3.95 adaptions above and replaced | |
33 | MiniMON interface with UDI-p interface. */ | |
34 | ||
9bddba9a SG |
35 | #include "defs.h" |
36 | #include "inferior.h" | |
37 | #include "wait.h" | |
38 | #include "value.h" | |
39 | #include <ctype.h> | |
40 | #include <fcntl.h> | |
41 | #include <signal.h> | |
42 | #include <errno.h> | |
43 | #include <string.h> | |
44 | #include "terminal.h" | |
45 | #include "target.h" | |
aa942355 | 46 | #include "29k-share/udi/udiproc.h" |
9bddba9a SG |
47 | |
48 | /* access the register store directly, without going through | |
49 | the normal handler functions. This avoids an extra data copy | |
50 | */ | |
51 | ||
52 | /* #define DEBUG 1 /* */ | |
53 | #ifdef DEBUG | |
54 | # define DENTER(NAME) (printf("Entering %s\n",NAME), fflush(stdout)) | |
55 | # define DEXIT(NAME) (printf("Exiting %s\n",NAME), fflush(stdout)) | |
56 | #else | |
57 | # define DENTER(NAME) | |
58 | # define DEXIT(NAME) | |
59 | #endif | |
60 | ||
61 | ||
9bddba9a SG |
62 | extern int stop_soon_quietly; /* for wait_for_inferior */ |
63 | extern struct value *call_function_by_hand(); | |
64 | static void udi_resume(); | |
65 | static void udi_fetch_registers (); | |
66 | static void udi_load(); | |
67 | static int fetch_register (); | |
68 | static void udi_store_registers (); | |
69 | static int store_register (); | |
70 | static int regnum_to_srnum(); | |
71 | static void udi_close (); | |
72 | static CPUSpace udi_memory_space(); | |
73 | static int udi_write_inferior_memory(); | |
74 | static int udi_read_inferior_memory(); | |
75 | char CoffFileName[100] = ""; | |
76 | /* | |
77 | * Processor types. | |
78 | */ | |
79 | #define TYPE_UNKNOWN 0 | |
80 | #define TYPE_A29000 1 | |
81 | #define TYPE_A29030 2 | |
82 | #define TYPE_A29050 3 | |
83 | static char *processor_name[] = { "Unknown", "Am29000", "Am29030", "Am29050" }; | |
84 | static int processor_type=TYPE_UNKNOWN; | |
85 | #define FREEZE_MODE (read_register(CPS_REGNUM) && 0x400) | |
86 | #define USE_SHADOW_PC ((processor_type == TYPE_A29050) && FREEZE_MODE) | |
87 | ||
88 | #define LLOG_FILE "udi.log" | |
89 | #if defined (LOG_FILE) | |
90 | FILE *log_file; | |
91 | #endif | |
92 | ||
93 | static int timeout = 5; | |
94 | extern struct target_ops udi_ops; /* Forward declaration */ | |
95 | ||
96 | /* Special register enumeration. | |
97 | */ | |
98 | ||
99 | /******************************************************************* UDI DATA*/ | |
100 | #define MAXDATA 2*1024 /* max UDI[read/write] byte size */ | |
101 | /* Descriptor for I/O to remote machine. Initialize it to -1 so that | |
102 | udi_open knows that we don't have a file open when the program | |
103 | starts. */ | |
104 | UDISessionId udi_session_id = -1; | |
105 | ||
106 | CPUOffset IMemStart = 0; | |
107 | CPUSizeT IMemSize = 0; | |
108 | CPUOffset DMemStart = 0; | |
109 | CPUSizeT DMemSize = 0; | |
110 | CPUOffset RMemStart = 0; | |
111 | CPUSizeT RMemSize = 0; | |
112 | UDIUInt32 CPUPRL; | |
113 | UDIUInt32 CoProcPRL; | |
114 | ||
115 | #define SBUF_MAX 1024 /* maximum size of string handling buffer */ | |
116 | char sbuf[SBUF_MAX]; | |
117 | ||
118 | typedef struct bkpt_entry_str | |
119 | { | |
120 | UDIResource Addr; | |
121 | UDIUInt32 PassCount; | |
122 | UDIBreakType Type; | |
123 | unsigned int BreakId; | |
124 | } bkpt_entry_t; | |
54847287 SG |
125 | #define BKPT_TABLE_SIZE 40 |
126 | static bkpt_entry_t bkpt_table[BKPT_TABLE_SIZE]; | |
9bddba9a SG |
127 | extern char dfe_errmsg[]; /* error string */ |
128 | ||
129 | /*********************************************************** SIGNAL SUPPORT */ | |
130 | /* Called when SIGALRM signal sent due to alarm() timeout. */ | |
131 | #ifndef HAVE_TERMIO | |
132 | ||
133 | #ifndef __STDC__ | |
134 | # ifndef volatile | |
135 | # define volatile /**/ | |
136 | # endif | |
137 | #endif | |
138 | volatile int n_alarms; | |
139 | ||
140 | static void | |
141 | udi_timer () | |
142 | { | |
143 | #if 0 | |
144 | if (kiodebug) | |
145 | printf ("udi_timer called\n"); | |
146 | #endif | |
147 | n_alarms++; | |
148 | } | |
149 | #endif /* HAVE_TERMIO */ | |
150 | ||
151 | /* malloc'd name of the program on the remote system. */ | |
152 | static char *prog_name = NULL; | |
153 | ||
154 | ||
155 | /* Number of SIGTRAPs we need to simulate. That is, the next | |
156 | NEED_ARTIFICIAL_TRAP calls to udi_wait should just return | |
157 | SIGTRAP without actually waiting for anything. */ | |
158 | ||
159 | /******************************************************* UDI_CREATE_INFERIOR */ | |
160 | /* This is called not only when we first attach, but also when the | |
161 | user types "run" after having attached. */ | |
162 | static void | |
163 | udi_create_inferior (execfile, args, env) | |
164 | char *execfile; | |
165 | char *args; | |
166 | char **env; | |
167 | { | |
168 | DENTER("udi_create_inferior()"); | |
169 | ||
170 | if (execfile) | |
171 | { if (prog_name != NULL) | |
172 | free (prog_name); | |
173 | prog_name = savestring (execfile, strlen (execfile)); | |
174 | } | |
175 | ||
176 | if (prog_name == 0 /* || exec_bfd == 0 */ ) | |
177 | error ("No exec file specified"); | |
178 | ||
179 | if (udi_session_id < 0){ | |
180 | printf("UDI connection not open yet.\n"); | |
181 | return; | |
182 | } | |
183 | ||
d0b04c6a SG |
184 | inferior_pid = 40000; |
185 | ||
9bddba9a SG |
186 | #if defined(ULTRA3) && defined(KERNEL_DEBUGGING) |
187 | /* On ultra3 (NYU) we assume the kernel is already running so there is | |
188 | * no file to download | |
189 | */ | |
190 | #else | |
191 | if(*args == '\0') args = prog_name; | |
192 | udi_load(args, 0); | |
193 | #endif /* !ULTRA3 */ | |
194 | ||
195 | /* We will get a task spawn event immediately. */ | |
196 | #ifdef NOTDEF /* start_remote() now does a wait without a resume | |
197 | so don't use it*/ | |
198 | start_remote (); | |
199 | #else | |
200 | init_wait_for_inferior (); | |
201 | clear_proceed_status (); | |
202 | proceed(-1,-1,0); | |
203 | #endif | |
204 | DEXIT("udi_create_inferior()"); | |
205 | } | |
206 | /******************************************************* UDI_MOURN_INFERIOR */ | |
207 | static void | |
208 | udi_mourn() | |
209 | { | |
210 | DENTER("udi_mourn()"); | |
211 | pop_target (); /* Pop back to no-child state */ | |
212 | generic_mourn_inferior (); | |
213 | DEXIT("udi_mourn()"); | |
214 | } | |
215 | ||
216 | /******************************************************************** UDI_OPEN | |
217 | ** Open a connection to remote TIP. | |
218 | NAME is the socket domain used for communication with the TIP, | |
219 | then a space and the socket name or TIP-host name. | |
220 | '<udi_udi_config_id> [progname]' for example. | |
221 | */ | |
222 | ||
d0b04c6a SG |
223 | /* XXX - need cleanups for udiconnect for various failures!!! */ |
224 | ||
9bddba9a SG |
225 | static char *udi_config_id; |
226 | static void | |
227 | udi_open (name, from_tty) | |
228 | char *name; | |
229 | int from_tty; | |
230 | { | |
231 | unsigned int prl; | |
232 | char *p; | |
233 | int cnt; | |
234 | UDIMemoryRange KnownMemory[10]; | |
235 | UDIUInt32 ChipVersions[10]; | |
236 | UDIInt NumberOfRanges = 10; | |
237 | UDIInt NumberOfChips = 10; | |
238 | UDIPId PId; | |
239 | UDIUInt32 TIPId, TargetId, DFEId, DFE, TIP, DFEIPCId, TIPIPCId; | |
240 | ||
241 | DENTER("udi_open()"); | |
242 | ||
d0b04c6a SG |
243 | target_preopen(from_tty); |
244 | ||
9bddba9a SG |
245 | /* Find the first whitespace character, it separates udi_config_id |
246 | from prog_name. */ | |
247 | if(!name) goto erroid; | |
248 | for (p = name; | |
249 | *p != '\0' && !isspace (*p); p++) | |
250 | ; | |
251 | if (*p == '\0') | |
252 | erroid: | |
253 | error("Usage: target udi config_id progname, where config_id appears in udi_soc file"); | |
d0b04c6a | 254 | |
9bddba9a SG |
255 | udi_config_id = (char*)malloc (p - name + 1); |
256 | strncpy (udi_config_id, name, p - name); | |
257 | udi_config_id[p - name] = '\0'; | |
258 | ||
259 | /* Skip over the whitespace after udi_config_id */ | |
260 | for (; isspace (*p); p++) | |
261 | /*EMPTY*/; | |
262 | ||
263 | if (prog_name != NULL) | |
264 | free (prog_name); | |
265 | prog_name = savestring (p, strlen (p)); | |
266 | ||
d0b04c6a SG |
267 | if (UDIConnect(udi_config_id, &udi_session_id)) |
268 | error("UDIConnect() failed: %s\n", dfe_errmsg); | |
9bddba9a | 269 | |
9bddba9a SG |
270 | push_target (&udi_ops); |
271 | ||
272 | #ifndef HAVE_TERMIO | |
273 | #ifndef NO_SIGINTERRUPT | |
274 | /* Cause SIGALRM's to make reads fail with EINTR instead of resuming | |
275 | the read. */ | |
276 | if (siginterrupt (SIGALRM, 1) != 0) | |
d0b04c6a | 277 | error ("udi_open: siginterrupt() %s", safe_strerror(errno)); |
9bddba9a SG |
278 | #endif |
279 | ||
280 | /* Set up read timeout timer. */ | |
281 | if ((void (*)) signal (SIGALRM, udi_timer) == (void (*)) -1) | |
d0b04c6a | 282 | error ("udi_open: signal() %s", safe_strerror(errno)); |
9bddba9a SG |
283 | #endif |
284 | ||
285 | #if defined (LOG_FILE) | |
286 | log_file = fopen (LOG_FILE, "w"); | |
287 | if (log_file == NULL) | |
d0b04c6a | 288 | error ("udi_open: fopen(%s) %s", LOG_FILE, safe_strerror(errno)); |
9bddba9a SG |
289 | #endif |
290 | /* | |
291 | ** Initialize target configuration structure (global) | |
292 | */ | |
293 | if(UDIGetTargetConfig( KnownMemory, &NumberOfRanges, | |
294 | ChipVersions, &NumberOfChips)) | |
295 | error ("UDIGetTargetConfig() failed"); | |
296 | if(NumberOfChips > 2) | |
297 | fprintf(stderr,"Taret has more than one processor\n"); | |
298 | for(cnt=0; cnt<NumberOfRanges; cnt++) | |
299 | { switch(KnownMemory[cnt].Space) | |
300 | { | |
301 | default: fprintf(stderr, "UDIGetTargetConfig() unknown memory space\n"); | |
302 | break; | |
303 | case UDI29KCP_S: | |
304 | break; | |
305 | case UDI29KIROMSpace: | |
306 | RMemStart = KnownMemory[cnt].Offset; | |
307 | RMemSize = KnownMemory[cnt].Size; | |
308 | break; | |
309 | case UDI29KIRAMSpace: | |
310 | IMemStart = KnownMemory[cnt].Offset; | |
311 | IMemSize = KnownMemory[cnt].Size; | |
312 | break; | |
313 | case UDI29KDRAMSpace: | |
314 | DMemStart = KnownMemory[cnt].Offset; | |
315 | DMemSize = KnownMemory[cnt].Size; | |
316 | break; | |
317 | } | |
318 | } | |
319 | ||
320 | /* Determine the processor revision level */ | |
321 | prl = (unsigned int)read_register(CFG_REGNUM) >> 24; | |
322 | if ((prl&0xe0) == 0) | |
323 | { fprintf_filtered(stderr, | |
324 | "Remote debugging Am29000 rev %c\n",'A'+(prl&0x1f)); | |
325 | processor_type = TYPE_A29000; | |
326 | } else if ((prl&0xe0) == 0x40) /* 29030 = 0x4* */ | |
327 | { fprintf_filtered(stderr, | |
328 | "Remote debugging Am2903* rev %c\n",'A'+(prl&0x1f)); | |
329 | processor_type = TYPE_A29030; | |
330 | } else if ((prl&0xe0) == 0x20) /* 29050 = 0x2* */ | |
331 | { fprintf_filtered(stderr, | |
332 | "Remote debugging Am29050 rev %c\n",'A'+(prl&0x1f)); | |
333 | processor_type = TYPE_A29050; | |
334 | } else { | |
335 | processor_type = TYPE_UNKNOWN; | |
336 | fprintf_filtered(stderr,"WARNING: processor type unknown.\n"); | |
337 | } | |
338 | if(UDICreateProcess(&PId)) | |
339 | fprintf(stderr, "UDICreateProcess() failed\n"); | |
340 | ||
341 | /* Print out some stuff, letting the user now what's going on */ | |
342 | if(UDICapabilities( &TIPId, &TargetId, DFEId, DFE, &TIP, &DFEIPCId, | |
343 | &TIPIPCId, sbuf)) | |
344 | error ("UDICapabilities() failed"); | |
345 | if (from_tty) { | |
346 | printf_filtered("Remote debugging an %s connected via UDI socket,\n\ | |
347 | DFE-IPC version %x.%x.%x TIP-IPC version %x.%x.%x TIP version %x.%x.%x\n %s\n", | |
348 | processor_name[processor_type], | |
349 | (DFEIPCId>>8)&0xf, (DFEIPCId>>4)&0xf, DFEIPCId&0xf, | |
350 | (TIPIPCId>>8)&0xf, (TIPIPCId>>4)&0xf, TIPIPCId&0xf, | |
351 | (TargetId>>8)&0xf, (TargetId>>4)&0xf, TargetId&0xf, | |
352 | sbuf); | |
353 | #ifdef ULTRA3 | |
354 | /* FIXME: can this restriction be removed? */ | |
355 | printf_filtered("Remote debugging using virtual addresses works only\n"); | |
356 | printf_filtered(" when virtual addresses map 1:1 to physical addresses.\n"); | |
357 | #endif | |
358 | } | |
359 | #ifdef ULTRA3 | |
360 | if (processor_type != TYPE_A29050) { | |
361 | fprintf_filtered(stderr, | |
362 | "Freeze-mode debugging can only be done on an Am29050,\n"); | |
363 | fprintf_filtered(stderr, | |
364 | " unless GDB is being used with a 29K simulator.\n"); | |
365 | } | |
366 | #endif | |
367 | } | |
368 | ||
369 | /******************************************************************* UDI_CLOSE | |
370 | Close the open connection to the TIP process. | |
371 | Use this when you want to detach and do something else | |
372 | with your gdb. */ | |
373 | static void | |
374 | udi_close (quitting) /*FIXME: how is quitting used */ | |
375 | int quitting; | |
376 | { | |
377 | int Terminate = -1; | |
378 | DENTER("udi_close()"); | |
379 | ||
380 | if (udi_session_id < 0) | |
381 | error ("Can't close udi connection: not debugging remotely."); | |
382 | ||
383 | /* We should never get here if there isn't something valid in | |
384 | udi_session_id. | |
385 | ||
386 | if(UDIDisconnect(udi_stream, Terminate);) | |
387 | error ("UDIDisconnect() failed in udi_close"); | |
388 | ||
389 | /* Do not try to close udi_session_id again, later in the program. */ | |
390 | udi_session_id = -1; | |
d0b04c6a | 391 | inferior_pid = 0; |
9bddba9a SG |
392 | |
393 | #if defined (LOG_FILE) | |
394 | if (ferror (log_file)) | |
395 | printf ("Error writing log file.\n"); | |
396 | if (fclose (log_file) != 0) | |
397 | printf ("Error closing log file.\n"); | |
398 | #endif | |
399 | ||
d0b04c6a | 400 | printf_filtered (" Ending remote debugging\n"); |
9bddba9a SG |
401 | |
402 | DEXIT("udi_close()"); | |
403 | } | |
404 | ||
405 | /**************************************************************** UDI_ATACH */ | |
406 | /* Attach to a program that is already loaded and running | |
407 | * Upon exiting the process's execution is stopped. | |
408 | */ | |
409 | static void | |
410 | udi_attach (args, from_tty) | |
411 | char *args; | |
412 | int from_tty; | |
413 | { | |
414 | UDIResource From; | |
415 | UDIInt32 PC_adds; | |
416 | UDICount Count = 1; | |
417 | UDISizeT Size = 4; | |
418 | UDICount CountDone; | |
419 | UDIBool HostEndian = 0; | |
420 | DENTER("udi_attach()"); | |
421 | ||
422 | if (udi_session_id < 0) | |
423 | printf ("UDI connection not opened yet, use the 'target udi' command.\n"); | |
424 | ||
425 | if (from_tty) | |
426 | printf ("Attaching to remote program %s...\n", prog_name); | |
427 | ||
428 | mark_breakpoints_out (); | |
429 | UDIStop(); | |
430 | From.Space = 11; | |
431 | From.Offset = UDI29KSpecialRegs; | |
432 | if(UDIRead(From, &PC_adds, Count, Size, &CountDone, HostEndian)) | |
433 | error ("UDIRead failed in udi_attach"); | |
434 | printf ("Remote process is now halted, pc1 = 0x%x.\n", PC_adds); | |
435 | ||
436 | DEXIT("udi_attach()"); | |
437 | } | |
438 | /************************************************************* UDI_DETACH */ | |
439 | /* Terminate the open connection to the TIP process. | |
440 | Use this when you want to detach and do something else | |
441 | with your gdb. Leave remote process running (with no breakpoints set). */ | |
442 | static void | |
443 | udi_detach (args,from_tty) | |
444 | char *args; | |
445 | int from_tty; | |
446 | { | |
447 | DENTER("udi_dettach()"); | |
448 | remove_breakpoints(); /* Just in case there were any left in */ | |
449 | if(UDIDisconnect(udi_session_id)) | |
450 | error ("UDIDisconnect() failed in udi_detach"); | |
451 | pop_target(); /* calls udi_close to do the real work */ | |
452 | if (from_tty) | |
453 | printf ("Ending remote debugging\n"); | |
454 | DEXIT("udi_dettach()"); | |
455 | } | |
456 | ||
457 | ||
458 | /****************************************************************** UDI_RESUME | |
459 | ** Tell the remote machine to resume. */ | |
460 | ||
461 | static void | |
462 | udi_resume (step, sig) | |
463 | int step, sig; | |
464 | { | |
465 | UDIError tip_error; | |
466 | UDIUInt32 Steps = 1; | |
467 | UDIStepType StepType = UDIStepNatural; | |
468 | UDIRange Range; | |
469 | DENTER("udi_resume()"); | |
470 | if (step) /* step 1 instruction */ | |
471 | { tip_error = tip_error = UDIStep(Steps, StepType, Range); | |
472 | if(tip_error)fprintf(stderr, "UDIStep() error = %d\n", tip_error); | |
473 | if(tip_error)error ("failed in udi_resume"); | |
474 | ||
475 | } | |
476 | else | |
477 | { if(UDIExecute()) | |
478 | error ("UDIExecute() failed in udi_resume"); | |
479 | } | |
480 | ||
481 | DEXIT("udi_resume()"); | |
482 | } | |
483 | ||
484 | /******************************************************************** UDI_WAIT | |
485 | ** Wait until the remote machine stops, then return, | |
486 | storing status in STATUS just as `wait' would. */ | |
487 | ||
488 | static int | |
489 | udi_wait (status) | |
490 | WAITTYPE *status; | |
491 | { | |
492 | UDIInt32 MaxTime; | |
493 | UDIPId PId; | |
494 | UDIInt32 StopReason; | |
495 | UDISizeT CountDone; | |
496 | int old_timeout = timeout; | |
497 | int old_immediate_quit = immediate_quit; | |
498 | int i; | |
499 | ||
500 | DENTER("udi_wait()"); | |
501 | WSETEXIT ((*status), 0); | |
502 | ||
503 | /* wait for message to arrive. It should be: | |
504 | If the target stops executing, udi_wait() should return. | |
505 | */ | |
506 | timeout = 0; /* Wait indefinetly for a message */ | |
507 | immediate_quit = 1; /* Helps ability to QUIT */ | |
508 | while(1) | |
509 | { | |
510 | i = 0; | |
511 | MaxTime = UDIWaitForever; | |
512 | UDIWait(MaxTime, &PId, &StopReason); | |
513 | QUIT; /* Let user quit if they want */ | |
514 | switch (StopReason & 0xff) | |
515 | { | |
516 | default: | |
517 | goto halted; | |
518 | case UDIStdoutReady: | |
519 | if(UDIGetStdout(sbuf, (UDISizeT)SBUF_MAX, &CountDone)) | |
520 | error("UDIGetStdin() failed in udi_wait"); | |
521 | while(CountDone--)putc(sbuf[i++], stdout); | |
522 | fflush(stdout); | |
523 | break; | |
524 | case UDIStderrReady: | |
525 | UDIGetStderr(sbuf, (UDISizeT)SBUF_MAX, &CountDone); | |
526 | while(CountDone--)putc(sbuf[i++], stderr); | |
527 | fflush(stderr); | |
528 | fflush(stderr); | |
529 | break; | |
530 | case UDIStdinNeeded: | |
531 | printf("DEBUG: stdin requested ... continue\n"); | |
532 | /* UDIPutStdin(sbuf, (UDISizeT)i, &CountDone); */ | |
533 | break; | |
534 | case UDIStdinModeX: | |
535 | break; | |
536 | } | |
537 | continue; | |
538 | } | |
539 | halted: | |
540 | if (StopReason & 0xff == UDITrapped ) /* lower 8-bits == 0 */ | |
541 | { | |
542 | if (StopReason >> 24 == 0) | |
543 | { printf("Am290*0 received vector number 0 (break point)\n"); | |
544 | WSETSTOP ((*status), SIGTRAP); | |
545 | } | |
546 | else if (StopReason >> 24 == 1) | |
547 | { printf("Am290*0 received vector 1\n"); | |
548 | WSETSTOP ((*status), SIGBUS); | |
549 | } | |
550 | else if (StopReason >> 24 == 3 | |
551 | || StopReason >> 24 == 4) | |
552 | { printf("Am290*0 received vector number %d\n", | |
553 | StopReason >> 24); | |
554 | WSETSTOP ((*status), SIGFPE); | |
555 | } | |
556 | else if (StopReason >> 24 == 5) | |
557 | { printf("Am290*0 received vector number %d\n", | |
558 | StopReason >> 24); | |
559 | WSETSTOP ((*status), SIGILL); | |
560 | } | |
561 | else if (StopReason >> 24 >= 6 | |
562 | && StopReason >> 24 <= 11) | |
563 | { printf("Am290*0 received vector number %d\n", | |
564 | StopReason >> 24); | |
565 | WSETSTOP ((*status), SIGSEGV); | |
566 | } | |
567 | else if (StopReason >> 24 == 12 | |
568 | || StopReason >> 24 == 13) | |
569 | { printf("Am290*0 received vector number %d\n", | |
570 | StopReason >> 24); | |
571 | WSETSTOP ((*status), SIGILL); | |
572 | } | |
573 | else if ((StopReason & 0xff) == 14) | |
574 | { printf("Am290*0 received vector number %d\n", | |
575 | StopReason >> 24); | |
576 | WSETSTOP ((*status), SIGALRM); | |
577 | } | |
578 | else if ((StopReason & 0xff) == 15) | |
579 | WSETSTOP ((*status), SIGTRAP); | |
580 | else if ((StopReason >> 24) >= 16 | |
581 | && (StopReason >> 24) <= 21) | |
582 | { printf("Am290*0 received vector number %d\n", | |
583 | StopReason >> 24); | |
584 | WSETSTOP ((*status), SIGINT); | |
585 | } | |
586 | else if ((StopReason & 0xff) == 22) | |
587 | { printf("Am290*0 received vector number %d\n", | |
588 | StopReason >> 24); | |
589 | WSETSTOP ((*status), SIGILL); | |
590 | } | |
591 | else if ((StopReason & 0xff) == 77) | |
592 | WSETSTOP ((*status), SIGTRAP); | |
593 | else | |
594 | exit: | |
595 | WSETEXIT ((*status), 0); | |
596 | } | |
597 | else if ((StopReason & 0xff) == UDIBreak) | |
598 | WSETSTOP ((*status), SIGTRAP); | |
599 | else if ((StopReason & 0xff) == UDINotExecuting) | |
600 | WSETSTOP ((*status), SIGTERM); | |
601 | else if ((StopReason & 0xff) == UDIRunning) | |
602 | WSETSTOP ((*status), SIGILL); | |
603 | else if ((StopReason & 0xff) == UDIStopped) | |
604 | WSETSTOP ((*status), SIGTSTP); | |
605 | else if ((StopReason & 0xff) == UDIWarned) | |
606 | WSETSTOP ((*status), SIGLOST); | |
607 | else if ((StopReason & 0xff) == UDIStepped) | |
608 | WSETSTOP ((*status), SIGTRAP); | |
609 | else if ((StopReason & 0xff) == UDIWaiting) | |
610 | WSETSTOP ((*status), SIGSTOP); | |
611 | else if ((StopReason & 0xff) == UDIHalted) | |
612 | WSETSTOP ((*status), SIGKILL); | |
613 | else | |
614 | WSETEXIT ((*status), 0); | |
615 | ||
616 | timeout = old_timeout; /* Restore original timeout value */ | |
617 | immediate_quit = old_immediate_quit; | |
618 | DEXIT("udi_wait()"); | |
619 | return 0; | |
620 | } | |
621 | ||
622 | /********************************************************** UDI_FETCH_REGISTERS | |
623 | * Read a remote register 'regno'. | |
624 | * If regno==-1 then read all the registers. | |
625 | */ | |
626 | static void | |
627 | udi_fetch_registers (regno) | |
628 | int regno; | |
629 | { | |
630 | UDIResource From; | |
631 | UDIUInt32 *To; | |
632 | UDICount Count; | |
633 | UDISizeT Size = 4; | |
634 | UDICount CountDone; | |
635 | UDIBool HostEndian = 0; | |
636 | int i; | |
637 | ||
638 | if (regno >= 0) { | |
d0b04c6a SG |
639 | fetch_register(regno); |
640 | return; | |
9bddba9a | 641 | } |
9bddba9a SG |
642 | |
643 | /* Gr1/rsp */ | |
d0b04c6a | 644 | |
9bddba9a SG |
645 | From.Space = UDI29KGlobalRegs; |
646 | From.Offset = 1; | |
d0b04c6a | 647 | To = (UDIUInt32 *)®isters[4 * GR1_REGNUM]; |
9bddba9a | 648 | Count = 1; |
d0b04c6a | 649 | if (UDIRead(From, To, Count, Size, &CountDone, HostEndian)) |
9bddba9a | 650 | error("UDIRead() failed in udi_fetch_registers"); |
d0b04c6a SG |
651 | |
652 | register_valid[GR1_REGNUM] = 1; | |
9bddba9a SG |
653 | |
654 | #if defined(GR64_REGNUM) /* Read gr64-127 */ | |
d0b04c6a | 655 | |
9bddba9a | 656 | /* Global Registers gr64-gr95 */ |
d0b04c6a | 657 | |
9bddba9a SG |
658 | From.Space = UDI29KGlobalRegs; |
659 | From.Offset = 64; | |
d0b04c6a | 660 | To = (UDIUInt32 *)®isters[4 * GR64_REGNUM]; |
9bddba9a | 661 | Count = 32; |
d0b04c6a | 662 | if (UDIRead(From, To, Count, Size, &CountDone, HostEndian)) |
9bddba9a | 663 | error("UDIRead() failed in udi_fetch_registers"); |
d0b04c6a SG |
664 | |
665 | for (i = GR64_REGNUM; i < GR64_REGNUM + 32; i++) | |
666 | register_valid[i] = 1; | |
667 | ||
9bddba9a SG |
668 | #endif /* GR64_REGNUM */ |
669 | ||
670 | /* Global Registers gr96-gr127 */ | |
d0b04c6a | 671 | |
9bddba9a | 672 | From.Space = UDI29KGlobalRegs; |
d0b04c6a SG |
673 | From.Offset = 96; |
674 | To = (UDIUInt32 *)®isters[4 * GR96_REGNUM]; | |
9bddba9a | 675 | Count = 32; |
d0b04c6a | 676 | if (UDIRead(From, To, Count, Size, &CountDone, HostEndian)) |
9bddba9a | 677 | error("UDIRead() failed in udi_fetch_registers"); |
9bddba9a | 678 | |
d0b04c6a SG |
679 | for (i = GR96_REGNUM; i < GR96_REGNUM + 32; i++) |
680 | register_valid[i] = 1; | |
681 | ||
682 | /* Local Registers */ | |
683 | ||
9bddba9a SG |
684 | From.Space = UDI29KLocalRegs; |
685 | From.Offset = 0; | |
d0b04c6a | 686 | To = (UDIUInt32 *)®isters[4 * LR0_REGNUM]; |
9bddba9a | 687 | Count = 128; |
d0b04c6a | 688 | if (UDIRead(From, To, Count, Size, &CountDone, HostEndian)) |
9bddba9a | 689 | error("UDIRead() failed in udi_fetch_registers"); |
9bddba9a | 690 | |
d0b04c6a SG |
691 | for (i = LR0_REGNUM; i < LR0_REGNUM + 128; i++) |
692 | register_valid[i] = 1; | |
693 | ||
694 | /* Protected Special Registers */ | |
695 | ||
9bddba9a SG |
696 | From.Space = UDI29KSpecialRegs; |
697 | From.Offset = 0; | |
d0b04c6a | 698 | To = (UDIUInt32 *)®isters[4 * SR_REGNUM(0)]; |
9bddba9a | 699 | Count = 15; |
d0b04c6a | 700 | if (UDIRead(From, To, Count, Size, &CountDone, HostEndian)) |
9bddba9a | 701 | error("UDIRead() failed in udi_fetch_registers"); |
d0b04c6a SG |
702 | |
703 | for (i = SR_REGNUM(0); i < SR_REGNUM(0) + 15; i++) | |
704 | register_valid[i] = 1; | |
9bddba9a SG |
705 | |
706 | if (USE_SHADOW_PC) { /* Let regno_to_srnum() handle the register number */ | |
d0b04c6a SG |
707 | fetch_register(NPC_REGNUM); |
708 | fetch_register(PC_REGNUM); | |
709 | fetch_register(PC2_REGNUM); | |
9bddba9a | 710 | |
d0b04c6a SG |
711 | /* Unprotected Special Registers sr128-sr135 */ |
712 | ||
713 | From.Space = UDI29KSpecialRegs; | |
9bddba9a | 714 | From.Offset = 128; |
d0b04c6a SG |
715 | To = (UDIUInt32 *)®isters[4 * SR_REGNUM(128)]; |
716 | Count = 135-128 + 1; | |
717 | if (UDIRead(From, To, Count, Size, &CountDone, HostEndian)) | |
9bddba9a | 718 | error("UDIRead() failed in udi_fetch_registers"); |
d0b04c6a SG |
719 | |
720 | for (i = SR_REGNUM(128); i < SR_REGNUM(128) + 135-128+1; i++) | |
721 | register_valid[i] = 1; | |
9bddba9a SG |
722 | } |
723 | ||
724 | /* There doesn't seem to be any way to get these. */ | |
725 | { | |
726 | int val = -1; | |
727 | supply_register (FPE_REGNUM, (char *) &val); | |
d0b04c6a | 728 | supply_register (INTE_REGNUM, (char *) &val); |
9bddba9a SG |
729 | supply_register (FPS_REGNUM, (char *) &val); |
730 | supply_register (EXO_REGNUM, (char *) &val); | |
731 | } | |
9bddba9a SG |
732 | } |
733 | ||
734 | ||
735 | /********************************************************* UDI_STORE_REGISTERS | |
736 | ** Store register regno into the target. | |
737 | * If regno==-1 then store all the registers. | |
738 | */ | |
739 | ||
740 | static void | |
741 | udi_store_registers (regno) | |
742 | int regno; | |
743 | { | |
744 | UDIUInt32 *From; | |
745 | UDIResource To; | |
746 | UDICount Count; | |
747 | UDISizeT Size = 4; | |
748 | UDICount CountDone; | |
749 | UDIBool HostEndian = 0; | |
750 | ||
751 | if (regno >= 0) | |
752 | { | |
753 | store_register(regno); | |
754 | return; | |
755 | } | |
756 | ||
9bddba9a | 757 | /* Gr1/rsp */ |
d0b04c6a SG |
758 | |
759 | From = (UDIUInt32 *)®isters[4 * GR1_REGNUM]; | |
9bddba9a SG |
760 | To.Space = UDI29KGlobalRegs; |
761 | To.Offset = 1; | |
762 | Count = 1; | |
763 | if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian)) | |
764 | error("UDIWrite() failed in udi_store_regisetrs"); | |
765 | ||
766 | #if defined(GR64_REGNUM) | |
d0b04c6a | 767 | |
9bddba9a | 768 | /* Global registers gr64-gr95 */ |
d0b04c6a SG |
769 | |
770 | From = (UDIUInt32 *)®isters[4 * GR64_REGNUM]; | |
9bddba9a SG |
771 | To.Space = UDI29KGlobalRegs; |
772 | To.Offset = 64; | |
773 | Count = 32; | |
774 | if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian)) | |
775 | error("UDIWrite() failed in udi_store_regisetrs"); | |
d0b04c6a | 776 | |
9bddba9a SG |
777 | #endif /* GR64_REGNUM */ |
778 | ||
779 | /* Global registers gr96-gr127 */ | |
d0b04c6a SG |
780 | |
781 | From = (UDIUInt32 *)®isters[4 * GR96_REGNUM]; | |
9bddba9a SG |
782 | To.Space = UDI29KGlobalRegs; |
783 | To.Offset = 96; | |
784 | Count = 32; | |
785 | if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian)) | |
786 | error("UDIWrite() failed in udi_store_regisetrs"); | |
787 | ||
788 | /* Local Registers */ | |
d0b04c6a SG |
789 | |
790 | From = (UDIUInt32 *)®isters[4 * LR0_REGNUM]; | |
9bddba9a SG |
791 | To.Space = UDI29KLocalRegs; |
792 | To.Offset = 0; | |
793 | Count = 128; | |
794 | if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian)) | |
795 | error("UDIWrite() failed in udi_store_regisetrs"); | |
796 | ||
797 | ||
798 | /* Protected Special Registers */ /* VAB through TMR */ | |
d0b04c6a SG |
799 | |
800 | From = (UDIUInt32 *)®isters[4 * SR_REGNUM(0)]; | |
9bddba9a SG |
801 | To.Space = UDI29KSpecialRegs; |
802 | To.Offset = 0; | |
803 | Count = 10; | |
804 | if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian)) | |
805 | error("UDIWrite() failed in udi_store_regisetrs"); | |
806 | ||
d0b04c6a SG |
807 | /* PC0, PC1, PC2 possibly as shadow registers */ |
808 | ||
809 | From = (UDIUInt32 *)®isters[4 * SR_REGNUM(10)]; | |
9bddba9a SG |
810 | To.Space = UDI29KSpecialRegs; |
811 | Count = 3; | |
812 | if (USE_SHADOW_PC) | |
813 | To.Offset = 20; /* SPC0 */ | |
814 | else | |
815 | To.Offset = 10; /* PC0 */ | |
816 | if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian)) | |
817 | error("UDIWrite() failed in udi_store_regisetrs"); | |
818 | ||
819 | /* LRU and MMU */ | |
d0b04c6a SG |
820 | |
821 | From = (UDIUInt32 *)®isters[4 * SR_REGNUM(13)]; | |
9bddba9a SG |
822 | To.Space = UDI29KSpecialRegs; |
823 | To.Offset = 13; | |
824 | Count = 2; | |
825 | if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian)) | |
826 | error("UDIWrite() failed in udi_store_regisetrs"); | |
827 | ||
828 | /* Unprotected Special Registers */ | |
d0b04c6a SG |
829 | |
830 | From = (UDIUInt32 *)®isters[4 * SR_REGNUM(128)]; | |
9bddba9a SG |
831 | To.Space = UDI29KSpecialRegs; |
832 | To.Offset = 128; | |
833 | Count = 135-128 +1; | |
834 | if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian)) | |
835 | error("UDIWrite() failed in udi_store_regisetrs"); | |
836 | ||
837 | registers_changed (); | |
9bddba9a SG |
838 | } |
839 | ||
840 | /****************************************************** UDI_PREPARE_TO_STORE */ | |
841 | /* Get ready to modify the registers array. On machines which store | |
842 | individual registers, this doesn't need to do anything. On machines | |
843 | which store all the registers in one fell swoop, this makes sure | |
844 | that registers contains all the registers from the program being | |
845 | debugged. */ | |
846 | ||
847 | static void | |
848 | udi_prepare_to_store () | |
849 | { | |
850 | /* Do nothing, since we can store individual regs */ | |
851 | } | |
852 | ||
853 | /********************************************************** TRANSLATE_ADDR */ | |
854 | static CORE_ADDR | |
855 | translate_addr(addr) | |
856 | CORE_ADDR addr; | |
857 | { | |
858 | #if defined(ULTRA3) && defined(KERNEL_DEBUGGING) | |
859 | /* Check for a virtual address in the kernel */ | |
860 | /* Assume physical address of ublock is in paddr_u register */ | |
861 | /* FIXME: doesn't work for user virtual addresses */ | |
862 | if (addr >= UVADDR) { | |
863 | /* PADDR_U register holds the physical address of the ublock */ | |
864 | CORE_ADDR i = (CORE_ADDR)read_register(PADDR_U_REGNUM); | |
865 | return(i + addr - (CORE_ADDR)UVADDR); | |
866 | } else { | |
867 | return(addr); | |
868 | } | |
869 | #else | |
870 | return(addr); | |
871 | #endif | |
872 | } | |
873 | /************************************************* UDI_XFER_INFERIOR_MEMORY */ | |
874 | /* FIXME! Merge these two. */ | |
875 | static int | |
876 | udi_xfer_inferior_memory (memaddr, myaddr, len, write) | |
877 | CORE_ADDR memaddr; | |
878 | char *myaddr; | |
879 | int len; | |
880 | int write; | |
881 | { | |
882 | ||
883 | memaddr = translate_addr(memaddr); | |
884 | ||
885 | if (write) | |
886 | return udi_write_inferior_memory (memaddr, myaddr, len); | |
887 | else | |
888 | return udi_read_inferior_memory (memaddr, myaddr, len); | |
889 | } | |
890 | ||
891 | /********************************************************** UDI_FILES_INFO */ | |
892 | static void | |
893 | udi_files_info () | |
894 | { | |
895 | printf ("\tAttached to UDI socket to %s and running program %s.\n", | |
896 | udi_config_id, prog_name); | |
897 | } | |
898 | ||
899 | /**************************************************** UDI_INSERT_BREAKPOINT */ | |
900 | static int | |
901 | udi_insert_breakpoint (addr, contents_cache) | |
902 | CORE_ADDR addr; | |
903 | char *contents_cache; | |
904 | { | |
54847287 SG |
905 | int cnt; |
906 | UDIError err; | |
907 | ||
908 | for (cnt = 0; cnt < BKPT_TABLE_SIZE; cnt++) | |
909 | if (bkpt_table[cnt].Type == 0) /* Find first free slot */ | |
910 | break; | |
911 | ||
912 | if(cnt >= BKPT_TABLE_SIZE) | |
913 | error("Too many breakpoints set"); | |
9bddba9a | 914 | |
9bddba9a SG |
915 | bkpt_table[cnt].Addr.Offset = addr; |
916 | bkpt_table[cnt].Addr.Space = UDI29KIRAMSpace; | |
917 | bkpt_table[cnt].PassCount = 1; | |
918 | bkpt_table[cnt].Type = UDIBreakFlagExecute; | |
919 | ||
54847287 SG |
920 | err = UDISetBreakpoint(bkpt_table[cnt].Addr, |
921 | bkpt_table[cnt].PassCount, | |
922 | bkpt_table[cnt].Type, | |
923 | &bkpt_table[cnt].BreakId); | |
924 | ||
925 | if (err == 0) return 0; /* Success */ | |
926 | ||
927 | bkpt_table[cnt].Type = 0; | |
928 | error("UDISetBreakpoint returned error code %d\n", err); | |
9bddba9a SG |
929 | } |
930 | ||
931 | /**************************************************** UDI_REMOVE_BREAKPOINT */ | |
932 | static int | |
933 | udi_remove_breakpoint (addr, contents_cache) | |
934 | CORE_ADDR addr; | |
935 | char *contents_cache; | |
936 | { | |
54847287 SG |
937 | int cnt; |
938 | UDIError err; | |
939 | ||
940 | for (cnt = 0; cnt < BKPT_TABLE_SIZE; cnt++) | |
941 | if (bkpt_table[cnt].Addr.Offset == addr) /* Find matching breakpoint */ | |
942 | break; | |
943 | ||
944 | if(cnt >= BKPT_TABLE_SIZE) | |
945 | error("Can't find breakpoint in table"); | |
946 | ||
9bddba9a SG |
947 | bkpt_table[cnt].Type = 0; |
948 | ||
54847287 SG |
949 | err = UDIClearBreakpoint(bkpt_table[cnt].BreakId); |
950 | if (err == 0) return 0; /* Success */ | |
9bddba9a | 951 | |
54847287 SG |
952 | error("UDIClearBreakpoint returned error code %d\n", err); |
953 | } | |
9bddba9a SG |
954 | |
955 | /***************************************************************** UDI_KILL */ | |
956 | static void | |
957 | udi_kill(arg,from_tty) | |
958 | char *arg; | |
959 | int from_tty; | |
960 | { | |
961 | char buf[4]; | |
962 | ||
963 | DENTER("udi_kill()"); | |
964 | #if defined(ULTRA3) && defined(KERNEL_DEBUGGING) | |
965 | /* We don't ever kill the kernel */ | |
966 | if (from_tty) { | |
d0b04c6a SG |
967 | printf_filtered("Kernel not killed, but left in current state.\n"); |
968 | printf_filtered("Use detach to leave kernel running.\n"); | |
9bddba9a SG |
969 | } |
970 | #else | |
971 | UDIStop(); | |
d0b04c6a | 972 | inferior_pid = 0; |
9bddba9a SG |
973 | if (from_tty) { |
974 | printf("Target has been stopped."); | |
975 | } | |
976 | pop_target(); | |
977 | #endif | |
978 | DEXIT("udi_kill()"); | |
979 | } | |
980 | ||
981 | ||
982 | ||
983 | /***************************************************************** UDI_LOAD */ | |
984 | /* | |
985 | * Load a program into the target. | |
986 | */ | |
987 | static void | |
988 | udi_load(arg_string,from_tty) | |
989 | char *arg_string; | |
990 | int from_tty; | |
991 | { | |
992 | #define MAX_TOKENS 25 | |
993 | #define BUFFER_SIZE 256 | |
994 | int token_count; | |
995 | char *token[MAX_TOKENS]; | |
996 | char cmd_line[BUFFER_SIZE]; | |
997 | ||
998 | dont_repeat (); | |
999 | ||
1000 | #if defined(KERNEL_DEBUGGING) && defined(ULTRA3) | |
1001 | printf("The kernel had better be loaded already! Loading not done.\n"); | |
1002 | #else | |
1003 | if (arg_string == 0) | |
1004 | error ("The load command takes a file name"); | |
1005 | arg_string = tilde_expand (arg_string); | |
1006 | sprintf(cmd_line,"y %s %s", prog_name, arg_string); | |
1007 | ||
1008 | token_count = 0; | |
1009 | token[0] = cmd_line; | |
1010 | ||
1011 | if (cmd_line[0] != '\0') | |
1012 | { token[token_count] = strtok(cmd_line, " \t,;\n\r"); | |
1013 | ||
1014 | if (token[token_count] != NULL) | |
1015 | { do { | |
1016 | token_count = token_count + 1; | |
1017 | token[token_count] = strtok((char *) NULL, " \t,;\n\r"); | |
1018 | } while ((token[token_count] != NULL) && | |
1019 | (token_count < MAX_TOKENS)); | |
1020 | } | |
1021 | else | |
1022 | *token[0] = '\0'; | |
1023 | } | |
1024 | make_cleanup (free, arg_string); | |
1025 | QUIT; | |
1026 | immediate_quit++; | |
1027 | if(yank_cmd(token, token_count)) | |
1028 | error("Failure when tring to load program"); | |
1029 | immediate_quit--; | |
1030 | symbol_file_add (arg_string, from_tty, 0, 0, 0, 0);/*DEBUG need to add text_addr */ | |
1031 | #endif | |
1032 | ||
1033 | } | |
1034 | ||
1035 | /*************************************************** UDI_WRITE_INFERIOR_MEMORY | |
1036 | ** Copy LEN bytes of data from debugger memory at MYADDR | |
1037 | to inferior's memory at MEMADDR. Returns number of bytes written. */ | |
1038 | static int | |
1039 | udi_write_inferior_memory (memaddr, myaddr, len) | |
1040 | CORE_ADDR memaddr; | |
1041 | char *myaddr; | |
1042 | int len; | |
1043 | { | |
1044 | int nwritten = 0; | |
1045 | UDIUInt32 *From; | |
1046 | UDIResource To; | |
1047 | UDICount Count; | |
1048 | UDISizeT Size = 1; | |
1049 | UDICount CountDone = 0; | |
1050 | UDIBool HostEndian = 0; | |
1051 | ||
1052 | ||
1053 | /* DENTER("udi_write_inferior_memory()"); */ | |
1054 | To.Space = udi_memory_space(memaddr); | |
1055 | From = (UDIUInt32*)myaddr; | |
1056 | ||
1057 | while (nwritten < len) | |
1058 | { Count = len - nwritten; | |
1059 | if (Count > MAXDATA) Count = MAXDATA; | |
1060 | To.Offset = memaddr + nwritten; | |
1061 | if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian)) | |
1062 | { error("UDIWrite() failed in udi_write_inferrior_memory"); | |
1063 | break; | |
1064 | } | |
1065 | else | |
1066 | { nwritten += CountDone; | |
1067 | From += CountDone; | |
1068 | } | |
1069 | } | |
1070 | /* DEXIT("udi_write_inferior_memory()"); */ | |
1071 | return(nwritten); | |
1072 | } | |
1073 | ||
1074 | /**************************************************** UDI_READ_INFERIOR_MEMORY | |
1075 | ** Read LEN bytes from inferior memory at MEMADDR. Put the result | |
1076 | at debugger address MYADDR. Returns number of bytes read. */ | |
1077 | static int | |
1078 | udi_read_inferior_memory(memaddr, myaddr, len) | |
1079 | CORE_ADDR memaddr; | |
1080 | char *myaddr; | |
1081 | int len; | |
1082 | { | |
1083 | int nread = 0; | |
1084 | UDIResource From; | |
1085 | UDIUInt32 *To; | |
1086 | UDICount Count; | |
1087 | UDISizeT Size = 1; | |
1088 | UDICount CountDone = 0; | |
1089 | UDIBool HostEndian = 0; | |
1090 | ||
1091 | ||
1092 | /* DENTER("udi_read_inferior_memory()"); */ | |
1093 | From.Space = udi_memory_space(memaddr); | |
1094 | To = (UDIUInt32*)myaddr; | |
1095 | ||
1096 | while (nread < len) | |
1097 | { Count = len - nread; | |
1098 | if (Count > MAXDATA) Count = MAXDATA; | |
1099 | From.Offset = memaddr + nread; | |
1100 | if(UDIRead(From, To, Count, Size, &CountDone, HostEndian)) | |
1101 | { error("UDIWrite() failed in udi_read_inferrior_memory"); | |
1102 | break; | |
1103 | } | |
1104 | else | |
1105 | { nread += CountDone; | |
1106 | To += CountDone; | |
1107 | } | |
1108 | } | |
1109 | return(nread); | |
1110 | } | |
1111 | ||
1112 | /********************************************************************* WARNING | |
1113 | */ | |
1114 | udi_warning(num) | |
1115 | int num; | |
1116 | { | |
1117 | error ("ERROR while loading program into remote TIP: $d\n", num); | |
1118 | } | |
1119 | ||
1120 | ||
1121 | /*****************************************************************************/ | |
1122 | /* Fetch a single register indicatated by 'regno'. | |
1123 | * Returns 0/-1 on success/failure. | |
1124 | */ | |
1125 | static int | |
1126 | fetch_register (regno) | |
1127 | int regno; | |
1128 | { | |
1129 | UDIResource From; | |
1130 | UDIUInt32 To; | |
1131 | UDICount Count = 1; | |
1132 | UDISizeT Size = 4; | |
1133 | UDICount CountDone; | |
1134 | UDIBool HostEndian = 0; | |
1135 | int result; | |
1136 | ||
9bddba9a | 1137 | if (regno == GR1_REGNUM) |
d0b04c6a SG |
1138 | { |
1139 | From.Space = UDI29KGlobalRegs; | |
1140 | From.Offset = 1; | |
1141 | } | |
9bddba9a | 1142 | else if (regno >= GR96_REGNUM && regno < GR96_REGNUM + 32) |
d0b04c6a SG |
1143 | { |
1144 | From.Space = UDI29KGlobalRegs; | |
1145 | From.Offset = (regno - GR96_REGNUM) + 96;; | |
1146 | } | |
1147 | ||
9bddba9a | 1148 | #if defined(GR64_REGNUM) |
d0b04c6a | 1149 | |
9bddba9a | 1150 | else if (regno >= GR64_REGNUM && regno < GR64_REGNUM + 32 ) |
d0b04c6a SG |
1151 | { |
1152 | From.Space = UDI29KGlobalRegs; | |
1153 | From.Offset = (regno - GR64_REGNUM) + 64; | |
1154 | } | |
1155 | ||
9bddba9a | 1156 | #endif /* GR64_REGNUM */ |
d0b04c6a | 1157 | |
9bddba9a | 1158 | else if (regno >= LR0_REGNUM && regno < LR0_REGNUM + 128) |
d0b04c6a SG |
1159 | { |
1160 | From.Space = UDI29KLocalRegs; | |
1161 | From.Offset = (regno - LR0_REGNUM); | |
1162 | } | |
9bddba9a | 1163 | else if (regno>=FPE_REGNUM && regno<=EXO_REGNUM) |
d0b04c6a SG |
1164 | { |
1165 | int val = -1; | |
1166 | supply_register(160 + (regno - FPE_REGNUM),(char *) &val); | |
1167 | return 0; /* Pretend Success */ | |
1168 | } | |
9bddba9a | 1169 | else |
d0b04c6a SG |
1170 | { |
1171 | From.Space = UDI29KSpecialRegs; | |
1172 | From.Offset = regnum_to_srnum(regno); | |
1173 | } | |
1174 | ||
1175 | if (UDIRead(From, &To, Count, Size, &CountDone, HostEndian)) | |
9bddba9a | 1176 | error("UDIRead() failed in udi_fetch_registers"); |
d0b04c6a | 1177 | |
9bddba9a SG |
1178 | supply_register(regno, (char *) &To); |
1179 | return result; | |
1180 | } | |
1181 | /*****************************************************************************/ | |
1182 | /* Store a single register indicated by 'regno'. | |
1183 | * Returns 0/-1 on success/failure. | |
1184 | */ | |
1185 | static int | |
1186 | store_register (regno) | |
1187 | int regno; | |
1188 | { | |
1189 | int result; | |
1190 | UDIUInt32 From; | |
1191 | UDIResource To; | |
1192 | UDICount Count = 1; | |
1193 | UDISizeT Size = 4; | |
1194 | UDICount CountDone; | |
1195 | UDIBool HostEndian = 0; | |
1196 | ||
1197 | DENTER("store_register()"); | |
1198 | From = read_register (regno); /* get data value */ | |
1199 | ||
1200 | if (regno == GR1_REGNUM) | |
1201 | { To.Space = UDI29KGlobalRegs; | |
1202 | To.Offset = 1; | |
1203 | result = UDIWrite(&From, To, Count, Size, &CountDone, HostEndian); | |
1204 | /* Setting GR1 changes the numbers of all the locals, so invalidate the | |
1205 | * register cache. Do this *after* calling read_register, because we want | |
1206 | * read_register to return the value that write_register has just stuffed | |
1207 | * into the registers array, not the value of the register fetched from | |
1208 | * the inferior. | |
1209 | */ | |
1210 | registers_changed (); | |
1211 | } | |
1212 | #if defined(GR64_REGNUM) | |
1213 | else if (regno >= GR64_REGNUM && regno < GR64_REGNUM + 32 ) | |
1214 | { To.Space = UDI29KGlobalRegs; | |
1215 | To.Offset = (regno - GR64_REGNUM) + 64; | |
1216 | result = UDIWrite(&From, To, Count, Size, &CountDone, HostEndian); | |
1217 | } | |
1218 | #endif /* GR64_REGNUM */ | |
1219 | else if (regno >= GR96_REGNUM && regno < GR96_REGNUM + 32) | |
1220 | { To.Space = UDI29KGlobalRegs; | |
1221 | To.Offset = (regno - GR96_REGNUM) + 96; | |
1222 | result = UDIWrite(&From, To, Count, Size, &CountDone, HostEndian); | |
1223 | } | |
1224 | else if (regno >= LR0_REGNUM && regno < LR0_REGNUM + 128) | |
1225 | { To.Space = UDI29KLocalRegs; | |
1226 | To.Offset = (regno - LR0_REGNUM); | |
1227 | result = UDIWrite(&From, To, Count, Size, &CountDone, HostEndian); | |
1228 | } | |
1229 | else if (regno>=FPE_REGNUM && regno<=EXO_REGNUM) | |
1230 | { | |
1231 | return 0; /* Pretend Success */ | |
1232 | } | |
1233 | else /* An unprotected or protected special register */ | |
1234 | { To.Space = UDI29KSpecialRegs; | |
1235 | To.Offset = regnum_to_srnum(regno); | |
1236 | result = UDIWrite(&From, To, Count, Size, &CountDone, HostEndian); | |
1237 | } | |
1238 | ||
1239 | DEXIT("store_register()"); | |
1240 | if(result) | |
1241 | { result = -1; | |
1242 | error("UDIWrite() failed in store_registers"); | |
1243 | } | |
1244 | return result; | |
1245 | } | |
1246 | /********************************************************** REGNUM_TO_SRNUM */ | |
1247 | /* | |
1248 | * Convert a gdb special register number to a 29000 special register number. | |
1249 | */ | |
1250 | static int | |
1251 | regnum_to_srnum(regno) | |
1252 | int regno; | |
1253 | { | |
1254 | switch(regno) { | |
1255 | case VAB_REGNUM: return(0); | |
1256 | case OPS_REGNUM: return(1); | |
1257 | case CPS_REGNUM: return(2); | |
1258 | case CFG_REGNUM: return(3); | |
1259 | case CHA_REGNUM: return(4); | |
1260 | case CHD_REGNUM: return(5); | |
1261 | case CHC_REGNUM: return(6); | |
1262 | case RBP_REGNUM: return(7); | |
1263 | case TMC_REGNUM: return(8); | |
1264 | case TMR_REGNUM: return(9); | |
1265 | case NPC_REGNUM: return(USE_SHADOW_PC ? (20) : (10)); | |
1266 | case PC_REGNUM: return(USE_SHADOW_PC ? (21) : (11)); | |
1267 | case PC2_REGNUM: return(USE_SHADOW_PC ? (22) : (12)); | |
1268 | case MMU_REGNUM: return(13); | |
1269 | case LRU_REGNUM: return(14); | |
1270 | case IPC_REGNUM: return(128); | |
1271 | case IPA_REGNUM: return(129); | |
1272 | case IPB_REGNUM: return(130); | |
1273 | case Q_REGNUM: return(131); | |
1274 | case ALU_REGNUM: return(132); | |
1275 | case BP_REGNUM: return(133); | |
1276 | case FC_REGNUM: return(134); | |
1277 | case CR_REGNUM: return(135); | |
1278 | case FPE_REGNUM: return(160); | |
d0b04c6a | 1279 | case INTE_REGNUM: return(161); |
9bddba9a SG |
1280 | case FPS_REGNUM: return(162); |
1281 | case EXO_REGNUM:return(164); | |
1282 | default: | |
1283 | return(255); /* Failure ? */ | |
1284 | } | |
1285 | } | |
1286 | /****************************************************************************/ | |
1287 | /* | |
1288 | * Determine the Target memory space qualifier based on the addr. | |
1289 | * FIXME: Can't distinguis I_ROM/D_ROM. | |
1290 | * FIXME: Doesn't know anything about I_CACHE/D_CACHE. | |
1291 | */ | |
1292 | static CPUSpace | |
1293 | udi_memory_space(addr) | |
1294 | CORE_ADDR *addr; | |
1295 | { | |
1296 | UDIUInt32 tstart = IMemStart; | |
1297 | UDIUInt32 tend = tstart + IMemSize; | |
1298 | UDIUInt32 dstart = DMemStart; | |
1299 | UDIUInt32 dend = tstart + DMemSize; | |
1300 | UDIUInt32 rstart = RMemStart; | |
1301 | UDIUInt32 rend = tstart + RMemSize; | |
1302 | ||
1303 | if (((UDIUInt32)addr >= tstart) && ((UDIUInt32)addr < tend)) { | |
1304 | return UDI29KIRAMSpace; | |
1305 | } else if (((UDIUInt32)addr >= dstart) && ((UDIUInt32)addr < dend)) { | |
1306 | return UDI29KDRAMSpace; | |
1307 | } else if (((UDIUInt32)addr >= rstart) && ((UDIUInt32)addr < rend)) { | |
1308 | /* FIXME: how do we determine between D_ROM and I_ROM */ | |
1309 | return UDI29KIROMSpace; | |
1310 | } else /* FIXME: what do me do now? */ | |
1311 | return UDI29KDRAMSpace; /* Hmmm! */ | |
1312 | } | |
1313 | /*********************************************************************** STUBS | |
1314 | */ | |
1315 | ||
1316 | void convert16() {;} | |
1317 | void convert32() {;} | |
1318 | FILE* EchoFile = 0; /* used for debugging */ | |
1319 | int QuietMode = 0; /* used for debugging */ | |
1320 | ||
1321 | /****************************************************************************/ | |
1322 | /* | |
1323 | * Define the target subroutine names | |
1324 | */ | |
1325 | static struct target_ops udi_ops = { | |
1326 | "udi", "Remote UDI connected TIP", | |
1327 | "Remote debug an Am290*0 using socket connection to TIP process ", | |
1328 | udi_open, udi_close, | |
1329 | udi_attach, udi_detach, udi_resume, udi_wait, | |
1330 | udi_fetch_registers, udi_store_registers, | |
1331 | udi_prepare_to_store, 0, 0, /* conv_to, conv_from */ | |
1332 | udi_xfer_inferior_memory, | |
1333 | udi_files_info, | |
1334 | udi_insert_breakpoint, udi_remove_breakpoint, /* Breakpoints */ | |
1335 | 0, 0, 0, 0, 0, /* Terminal handling */ | |
1336 | udi_kill, /* FIXME, kill */ | |
1337 | udi_load, | |
1338 | 0, /* lookup_symbol */ | |
1339 | udi_create_inferior, /* create_inferior */ | |
1340 | udi_mourn, /* mourn_inferior FIXME */ | |
1341 | process_stratum, 0, /* next */ | |
1342 | 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */ | |
1343 | 0, 0, /* Section pointers */ | |
1344 | OPS_MAGIC, /* Always the last thing */ | |
1345 | }; | |
1346 | ||
1347 | void _initialize_remote_udi() | |
1348 | { | |
1349 | add_target (&udi_ops); | |
1350 | } | |
1351 | ||
1352 | #ifdef NO_HIF_SUPPORT | |
1353 | service_HIF(msg) | |
1354 | union msg_t *msg; | |
1355 | { | |
1356 | return(0); /* Emulate a failure */ | |
1357 | } | |
1358 | #endif |