30bbfb9b3386874afcbb8d4467a67513dfad2b08
[deliverable/binutils-gdb.git] / gdb / remote-udi.c
1 /* Remote debugging interface for AMD 29k interfaced via UDI, for GDB.
2 Copyright 1990, 1992, 1995 Free Software Foundation, Inc.
3 Written by Daniel Mann. Contributed by 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 /* This is like remote.c but uses the Universal Debug Interface (UDI) to
22 talk to the target hardware (or simulator). UDI is a TCP/IP based
23 protocol; for hardware that doesn't run TCP, an interface adapter
24 daemon talks UDI on one side, and talks to the hardware (typically
25 over a serial port) on the other side.
26
27 - Originally written by Daniel Mann at AMD for MiniMON and gdb 3.91.6.
28 - David Wood (wood@lab.ultra.nyu.edu) at New York University adapted this
29 file to gdb 3.95. I was unable to get this working on sun3os4
30 with termio, only with sgtty.
31 - Daniel Mann at AMD took the 3.95 adaptions above and replaced
32 MiniMON interface with UDI-p interface. */
33
34 #include "defs.h"
35 #include "frame.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 "gdb_string.h"
44 #include "terminal.h"
45 #include "target.h"
46 #include "29k-share/udi/udiproc.h"
47 #include "gdbcmd.h"
48 #include "bfd.h"
49 #include "gdbcore.h" /* For download function */
50
51 /* access the register store directly, without going through
52 the normal handler functions. This avoids an extra data copy. */
53
54 extern int stop_soon_quietly; /* for wait_for_inferior */
55 extern struct value *call_function_by_hand();
56 static void udi_resume PARAMS ((int pid, int step, enum target_signal sig));
57 static void udi_fetch_registers PARAMS ((int regno));
58 static void udi_load PARAMS ((char *args, int from_tty));
59 static void fetch_register PARAMS ((int regno));
60 static void udi_store_registers PARAMS ((int regno));
61 static int store_register PARAMS ((int regno));
62 static int regnum_to_srnum PARAMS ((int regno));
63 static void udi_close PARAMS ((int quitting));
64 static CPUSpace udi_memory_space PARAMS ((CORE_ADDR addr));
65 static int udi_write_inferior_memory PARAMS ((CORE_ADDR memaddr, char *myaddr,
66 int len));
67 static int udi_read_inferior_memory PARAMS ((CORE_ADDR memaddr, char *myaddr,
68 int len));
69 static void download PARAMS ((char *load_arg_string, int from_tty));
70 char CoffFileName[100] = "";
71
72 #define FREEZE_MODE (read_register(CPS_REGNUM) & 0x400)
73 #define USE_SHADOW_PC ((processor_type == a29k_freeze_mode) && FREEZE_MODE)
74
75 static int timeout = 5;
76 extern struct target_ops udi_ops; /* Forward declaration */
77
78 /* Special register enumeration.
79 */
80
81 /******************************************************************* UDI DATA*/
82 #define MAXDATA 2*1024 /* max UDI[read/write] byte size */
83 /* Descriptor for I/O to remote machine. Initialize it to -1 so that
84 udi_open knows that we don't have a file open when the program
85 starts. */
86
87 UDISessionId udi_session_id = -1;
88 static char *udi_config_id;
89
90 CPUOffset IMemStart = 0;
91 CPUSizeT IMemSize = 0;
92 CPUOffset DMemStart = 0;
93 CPUSizeT DMemSize = 0;
94 CPUOffset RMemStart = 0;
95 CPUSizeT RMemSize = 0;
96 UDIUInt32 CPUPRL;
97 UDIUInt32 CoProcPRL;
98
99 UDIMemoryRange address_ranges[2]; /* Text and data */
100 UDIResource entry = {0, 0}; /* Entry point */
101 CPUSizeT stack_sizes[2]; /* Regular and memory stacks */
102
103 #define SBUF_MAX 1024 /* maximum size of string handling buffer */
104 char sbuf[SBUF_MAX];
105
106 typedef struct bkpt_entry_str
107 {
108 UDIResource Addr;
109 UDIUInt32 PassCount;
110 UDIBreakType Type;
111 unsigned int BreakId;
112 } bkpt_entry_t;
113 #define BKPT_TABLE_SIZE 40
114 static bkpt_entry_t bkpt_table[BKPT_TABLE_SIZE];
115 extern char dfe_errmsg[]; /* error string */
116
117 /* malloc'd name of the program on the remote system. */
118 static char *prog_name = NULL;
119
120 /* This is called not only when we first attach, but also when the
121 user types "run" after having attached. */
122
123 static void
124 udi_create_inferior (execfile, args, env)
125 char *execfile;
126 char *args;
127 char **env;
128 {
129 char *args1;
130
131 if (execfile)
132 {
133 if (prog_name != NULL)
134 free (prog_name);
135 prog_name = savestring (execfile, strlen (execfile));
136 }
137 else if (entry.Offset)
138 execfile = "";
139 else
140 error ("No image loaded into target.");
141
142 if (udi_session_id < 0)
143 {
144 /* If the TIP is not open, open it. */
145 if (UDIConnect (udi_config_id, &udi_session_id))
146 error("UDIConnect() failed: %s\n", dfe_errmsg);
147 /* We will need to download the program. */
148 entry.Offset = 0;
149 }
150
151 inferior_pid = 40000;
152
153 if (!entry.Offset)
154 download(execfile, 0);
155
156 args1 = alloca (strlen(execfile) + strlen(args) + 2);
157
158 if (execfile[0] == '\0')
159
160 /* It is empty. We need to quote it somehow, or else the target
161 will think there is no argument being passed here. According
162 to the UDI spec it is quoted "according to TIP OS rules" which
163 I guess means quoting it like the Unix shell should work
164 (sounds pretty bogus to me...). In fact it doesn't work (with
165 isstip anyway), but passing in two quotes as the argument seems
166 like a reasonable enough behavior anyway (I guess). */
167
168 strcpy (args1, "''");
169 else
170 strcpy (args1, execfile);
171 strcat (args1, " ");
172 strcat (args1, args);
173
174 UDIInitializeProcess (address_ranges, /* ProcessMemory[] */
175 (UDIInt)2, /* NumberOfRanges */
176 entry, /* EntryPoint */
177 stack_sizes, /* *StackSizes */
178 (UDIInt)2, /* NumberOfStacks */
179 args1); /* ArgString */
180
181 init_wait_for_inferior ();
182 clear_proceed_status ();
183 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
184 }
185
186 static void
187 udi_mourn()
188 {
189 #if 0
190 /* Requiring "target udi" each time you run is a major pain. I suspect
191 this was just blindy copied from remote.c, in which "target" and
192 "run" are combined. Having a udi target without an inferior seems
193 to work between "target udi" and "run", so why not now? */
194 pop_target (); /* Pop back to no-child state */
195 #endif
196 /* But if we're going to want to run it again, we better remove the
197 breakpoints... */
198 remove_breakpoints ();
199 generic_mourn_inferior ();
200 }
201
202 /******************************************************************** UDI_OPEN
203 ** Open a connection to remote TIP.
204 NAME is the socket domain used for communication with the TIP,
205 then a space and the socket name or TIP-host name.
206 '<udi_udi_config_id>' for example.
207 */
208
209 /* XXX - need cleanups for udiconnect for various failures!!! */
210
211 static void
212 udi_open (name, from_tty)
213 char *name;
214 int from_tty;
215 {
216 unsigned int prl;
217 char *p;
218 int cnt;
219 UDIMemoryRange KnownMemory[10];
220 UDIUInt32 ChipVersions[10];
221 UDIInt NumberOfRanges = 10;
222 UDIInt NumberOfChips = 10;
223 UDIPId PId;
224 UDIUInt32 TIPId, TargetId, DFEId, DFE, TIP, DFEIPCId, TIPIPCId;
225
226 target_preopen(from_tty);
227
228 entry.Offset = 0;
229
230 for (cnt = 0; cnt < BKPT_TABLE_SIZE; cnt++)
231 bkpt_table[cnt].Type = 0;
232
233 if (udi_config_id)
234 free (udi_config_id);
235
236 if (!name)
237 error("Usage: target udi config_id, where config_id appears in udi_soc file");
238
239 udi_config_id = strdup (strtok (name, " \t"));
240
241 if (UDIConnect (udi_config_id, &udi_session_id))
242 /* FIXME: Should set udi_session_id to -1 here. */
243 error("UDIConnect() failed: %s\n", dfe_errmsg);
244
245 push_target (&udi_ops);
246
247 /*
248 ** Initialize target configuration structure (global)
249 */
250 if (UDIGetTargetConfig (KnownMemory, &NumberOfRanges,
251 ChipVersions, &NumberOfChips))
252 error ("UDIGetTargetConfig() failed");
253 if (NumberOfChips > 2)
254 fprintf_unfiltered(gdb_stderr,"Target has more than one processor\n");
255 for (cnt=0; cnt < NumberOfRanges; cnt++)
256 {
257 switch(KnownMemory[cnt].Space)
258 {
259 default:
260 fprintf_unfiltered(gdb_stderr, "UDIGetTargetConfig() unknown memory space\n");
261 break;
262 case UDI29KCP_S:
263 break;
264 case UDI29KIROMSpace:
265 RMemStart = KnownMemory[cnt].Offset;
266 RMemSize = KnownMemory[cnt].Size;
267 break;
268 case UDI29KIRAMSpace:
269 IMemStart = KnownMemory[cnt].Offset;
270 IMemSize = KnownMemory[cnt].Size;
271 break;
272 case UDI29KDRAMSpace:
273 DMemStart = KnownMemory[cnt].Offset;
274 DMemSize = KnownMemory[cnt].Size;
275 break;
276 }
277 }
278
279 a29k_get_processor_type ();
280
281 if (UDICreateProcess (&PId))
282 fprintf_unfiltered(gdb_stderr, "UDICreateProcess() failed\n");
283
284 /* Print out some stuff, letting the user now what's going on */
285 if (UDICapabilities (&TIPId, &TargetId, DFEId, DFE, &TIP, &DFEIPCId,
286 &TIPIPCId, sbuf))
287 error ("UDICapabilities() failed");
288 if (from_tty)
289 {
290 printf_filtered ("Connected via UDI socket,\n\
291 DFE-IPC version %x.%x.%x TIP-IPC version %x.%x.%x TIP version %x.%x.%x\n %s\n",
292 (DFEIPCId>>8)&0xf, (DFEIPCId>>4)&0xf, DFEIPCId&0xf,
293 (TIPIPCId>>8)&0xf, (TIPIPCId>>4)&0xf, TIPIPCId&0xf,
294 (TargetId>>8)&0xf, (TargetId>>4)&0xf, TargetId&0xf,
295 sbuf);
296 }
297 }
298
299 /******************************************************************* UDI_CLOSE
300 Close the open connection to the TIP process.
301 Use this when you want to detach and do something else
302 with your gdb. */
303 static void
304 udi_close (quitting) /*FIXME: how is quitting used */
305 int quitting;
306 {
307 if (udi_session_id < 0)
308 return;
309
310 /* We should never get here if there isn't something valid in
311 udi_session_id. */
312
313 if (UDIDisconnect (udi_session_id, UDITerminateSession))
314 {
315 if (quitting)
316 warning ("UDIDisconnect() failed in udi_close");
317 else
318 error ("UDIDisconnect() failed in udi_close");
319 }
320
321 /* Do not try to close udi_session_id again, later in the program. */
322 udi_session_id = -1;
323 inferior_pid = 0;
324
325 printf_filtered (" Ending remote debugging\n");
326 }
327
328 /**************************************************************** UDI_ATACH */
329 /* Attach to a program that is already loaded and running
330 * Upon exiting the process's execution is stopped.
331 */
332 static void
333 udi_attach (args, from_tty)
334 char *args;
335 int from_tty;
336 {
337 UDIResource From;
338 UDIInt32 PC_adds;
339 UDICount Count = 1;
340 UDISizeT Size = 4;
341 UDICount CountDone;
342 UDIBool HostEndian = 0;
343 UDIError err;
344
345 if (args == NULL)
346 error_no_arg ("program to attach");
347
348 if (udi_session_id < 0)
349 error ("UDI connection not opened yet, use the 'target udi' command.\n");
350
351 if (from_tty)
352 printf_unfiltered ("Attaching to remote program %s...\n", prog_name);
353
354 UDIStop();
355 From.Space = UDI29KSpecialRegs;
356 From.Offset = 11;
357 if (err = UDIRead(From, &PC_adds, Count, Size, &CountDone, HostEndian))
358 error ("UDIRead failed in udi_attach");
359 printf_unfiltered ("Remote process is now halted, pc1 = 0x%x.\n", PC_adds);
360 }
361 /************************************************************* UDI_DETACH */
362 /* Terminate the open connection to the TIP process.
363 Use this when you want to detach and do something else
364 with your gdb. Leave remote process running (with no breakpoints set). */
365 static void
366 udi_detach (args,from_tty)
367 char *args;
368 int from_tty;
369 {
370
371 remove_breakpoints(); /* Just in case there were any left in */
372
373 if (UDIDisconnect (udi_session_id, UDIContinueSession))
374 error ("UDIDisconnect() failed in udi_detach");
375
376 /* Don't try to UDIDisconnect it again in udi_close, which is called from
377 pop_target. */
378 udi_session_id = -1;
379 inferior_pid = 0;
380
381 pop_target();
382
383 if (from_tty)
384 printf_unfiltered ("Detaching from TIP\n");
385 }
386
387
388 /****************************************************************** UDI_RESUME
389 ** Tell the remote machine to resume. */
390
391 static void
392 udi_resume (pid, step, sig)
393 int pid, step;
394 enum target_signal sig;
395 {
396 UDIError tip_error;
397 UDIUInt32 Steps = 1;
398 UDIStepType StepType = UDIStepNatural;
399 UDIRange Range;
400
401 if (step) /* step 1 instruction */
402 {
403 tip_error = UDIStep (Steps, StepType, Range);
404 if (!tip_error)
405 return;
406
407 fprintf_unfiltered (gdb_stderr, "UDIStep() error = %d\n", tip_error);
408 error ("failed in udi_resume");
409 }
410
411 if (UDIExecute())
412 error ("UDIExecute() failed in udi_resume");
413 }
414
415 /******************************************************************** UDI_WAIT
416 ** Wait until the remote machine stops, then return,
417 storing status in STATUS just as `wait' would. */
418
419 static int
420 udi_wait (pid, status)
421 int pid;
422 struct target_waitstatus *status;
423 {
424 UDIInt32 MaxTime;
425 UDIPId PId;
426 UDIInt32 StopReason;
427 UDISizeT CountDone;
428 int old_timeout = timeout;
429 int old_immediate_quit = immediate_quit;
430 int i;
431
432 status->kind = TARGET_WAITKIND_EXITED;
433 status->value.integer = 0;
434
435 /* wait for message to arrive. It should be:
436 If the target stops executing, udi_wait() should return.
437 */
438 timeout = 0; /* Wait indefinetly for a message */
439 immediate_quit = 1; /* Helps ability to QUIT */
440
441 while(1)
442 {
443 i = 0;
444 MaxTime = UDIWaitForever;
445 UDIWait(MaxTime, &PId, &StopReason);
446 QUIT; /* Let user quit if they want */
447
448 switch (StopReason & UDIGrossState)
449 {
450 case UDIStdoutReady:
451 if (UDIGetStdout (sbuf, (UDISizeT)SBUF_MAX, &CountDone))
452 /* This is said to happen if the program tries to output
453 a whole bunch of output (more than SBUF_MAX, I would
454 guess). It doesn't seem to happen with the simulator. */
455 warning ("UDIGetStdout() failed in udi_wait");
456 fwrite (sbuf, 1, CountDone, stdout);
457 gdb_flush(gdb_stdout);
458 continue;
459
460 case UDIStderrReady:
461 UDIGetStderr (sbuf, (UDISizeT)SBUF_MAX, &CountDone);
462 fwrite (sbuf, 1, CountDone, stderr);
463 gdb_flush(gdb_stderr);
464 continue;
465
466 case UDIStdinNeeded:
467 {
468 int ch;
469 i = 0;
470 do
471 {
472 ch = getchar ();
473 if (ch == EOF)
474 break;
475 sbuf[i++] = ch;
476 } while (i < SBUF_MAX && ch != '\n');
477 UDIPutStdin (sbuf, (UDISizeT)i, &CountDone);
478 continue;
479 }
480
481 case UDIRunning:
482 /* In spite of the fact that we told UDIWait to wait forever, it will
483 return spuriously sometimes. */
484 case UDIStdinModeX:
485 continue;
486 default:
487 break;
488 }
489 break;
490 }
491
492 switch (StopReason & UDIGrossState)
493 {
494 case UDITrapped:
495 printf_unfiltered("Am290*0 received vector number %d\n", StopReason >> 24);
496
497 switch ((StopReason >> 8 ) & 0xff)
498 {
499 case 0: /* Illegal opcode */
500 printf_unfiltered(" (break point)\n");
501 status->kind = TARGET_WAITKIND_STOPPED;
502 status->value.sig = TARGET_SIGNAL_TRAP;
503 break;
504 case 1: /* Unaligned Access */
505 status->kind = TARGET_WAITKIND_STOPPED;
506 status->value.sig = TARGET_SIGNAL_BUS;
507 break;
508 case 3:
509 case 4:
510 status->kind = TARGET_WAITKIND_STOPPED;
511 status->value.sig = TARGET_SIGNAL_FPE;
512 break;
513 case 5: /* Protection Violation */
514 status->kind = TARGET_WAITKIND_STOPPED;
515 /* Why not SEGV? What is a Protection Violation? */
516 status->value.sig = TARGET_SIGNAL_ILL;
517 break;
518 case 6:
519 case 7:
520 case 8: /* User Instruction Mapping Miss */
521 case 9: /* User Data Mapping Miss */
522 case 10: /* Supervisor Instruction Mapping Miss */
523 case 11: /* Supervisor Data Mapping Miss */
524 status->kind = TARGET_WAITKIND_STOPPED;
525 status->value.sig = TARGET_SIGNAL_SEGV;
526 break;
527 case 12:
528 case 13:
529 status->kind = TARGET_WAITKIND_STOPPED;
530 status->value.sig = TARGET_SIGNAL_ILL;
531 break;
532 case 14: /* Timer */
533 status->kind = TARGET_WAITKIND_STOPPED;
534 status->value.sig = TARGET_SIGNAL_ALRM;
535 break;
536 case 15: /* Trace */
537 status->kind = TARGET_WAITKIND_STOPPED;
538 status->value.sig = TARGET_SIGNAL_TRAP;
539 break;
540 case 16: /* INTR0 */
541 case 17: /* INTR1 */
542 case 18: /* INTR2 */
543 case 19: /* INTR3/Internal */
544 case 20: /* TRAP0 */
545 case 21: /* TRAP1 */
546 status->kind = TARGET_WAITKIND_STOPPED;
547 status->value.sig = TARGET_SIGNAL_INT;
548 break;
549 case 22: /* Floating-Point Exception */
550 status->kind = TARGET_WAITKIND_STOPPED;
551 /* Why not FPE? */
552 status->value.sig = TARGET_SIGNAL_ILL;
553 break;
554 case 77: /* assert 77 */
555 status->kind = TARGET_WAITKIND_STOPPED;
556 status->value.sig = TARGET_SIGNAL_TRAP;
557 break;
558 default:
559 status->kind = TARGET_WAITKIND_EXITED;
560 status->value.integer = 0;
561 }
562 break;
563 case UDINotExecuting:
564 status->kind = TARGET_WAITKIND_STOPPED;
565 status->value.sig = TARGET_SIGNAL_TERM;
566 break;
567 case UDIStopped:
568 status->kind = TARGET_WAITKIND_STOPPED;
569 status->value.sig = TARGET_SIGNAL_TSTP;
570 break;
571 case UDIWarned:
572 status->kind = TARGET_WAITKIND_STOPPED;
573 status->value.sig = TARGET_SIGNAL_URG;
574 break;
575 case UDIStepped:
576 case UDIBreak:
577 status->kind = TARGET_WAITKIND_STOPPED;
578 status->value.sig = TARGET_SIGNAL_TRAP;
579 break;
580 case UDIWaiting:
581 status->kind = TARGET_WAITKIND_STOPPED;
582 status->value.sig = TARGET_SIGNAL_STOP;
583 break;
584 case UDIHalted:
585 status->kind = TARGET_WAITKIND_STOPPED;
586 status->value.sig = TARGET_SIGNAL_KILL;
587 break;
588 case UDIExited:
589 default:
590 status->kind = TARGET_WAITKIND_EXITED;
591 status->value.integer = 0;
592 }
593
594 timeout = old_timeout; /* Restore original timeout value */
595 immediate_quit = old_immediate_quit;
596 return inferior_pid;
597 }
598
599 #if 0
600 /* Handy for debugging */
601 udi_pc()
602 {
603 UDIResource From;
604 UDIUInt32 *To;
605 UDICount Count;
606 UDISizeT Size = 4;
607 UDICount CountDone;
608 UDIBool HostEndian = 0;
609 UDIError err;
610 int pc[2];
611 unsigned long myregs[256];
612 int i;
613
614 From.Space = UDI29KPC;
615 From.Offset = 0;
616 To = (UDIUInt32 *)pc;
617 Count = 2;
618
619 err = UDIRead(From, To, Count, Size, &CountDone, HostEndian);
620
621 printf_unfiltered ("err = %d, CountDone = %d, pc[0] = 0x%x, pc[1] = 0x%x\n",
622 err, CountDone, pc[0], pc[1]);
623
624 udi_fetch_registers(-1);
625
626 printf_unfiltered("other pc1 = 0x%x, pc0 = 0x%x\n", *(int *)&registers[4 * PC_REGNUM],
627 *(int *)&registers[4 * NPC_REGNUM]);
628
629 /* Now, read all the registers globally */
630
631 From.Space = UDI29KGlobalRegs;
632 From.Offset = 0;
633 err = UDIRead(From, myregs, 256, 4, &CountDone, HostEndian);
634
635 printf ("err = %d, CountDone = %d\n", err, CountDone);
636
637 printf("\n");
638
639 for (i = 0; i < 256; i += 2)
640 printf("%d:\t%#10x\t%11d\t%#10x\t%11d\n", i, myregs[i], myregs[i],
641 myregs[i+1], myregs[i+1]);
642 printf("\n");
643
644 return pc[0];
645 }
646 #endif
647
648 /********************************************************** UDI_FETCH_REGISTERS
649 * Read a remote register 'regno'.
650 * If regno==-1 then read all the registers.
651 */
652 static void
653 udi_fetch_registers (regno)
654 int regno;
655 {
656 UDIResource From;
657 UDIUInt32 *To;
658 UDICount Count;
659 UDISizeT Size = 4;
660 UDICount CountDone;
661 UDIBool HostEndian = 0;
662 UDIError err;
663 int i;
664
665 if (regno >= 0) {
666 fetch_register(regno);
667 return;
668 }
669
670 /* Gr1/rsp */
671
672 From.Space = UDI29KGlobalRegs;
673 From.Offset = 1;
674 To = (UDIUInt32 *)&registers[4 * GR1_REGNUM];
675 Count = 1;
676 if (err = UDIRead(From, To, Count, Size, &CountDone, HostEndian))
677 error("UDIRead() failed in udi_fetch_registers");
678
679 register_valid[GR1_REGNUM] = 1;
680
681 #if defined(GR64_REGNUM) /* Read gr64-127 */
682
683 /* Global Registers gr64-gr95 */
684
685 From.Space = UDI29KGlobalRegs;
686 From.Offset = 64;
687 To = (UDIUInt32 *)&registers[4 * GR64_REGNUM];
688 Count = 32;
689 if (err = UDIRead(From, To, Count, Size, &CountDone, HostEndian))
690 error("UDIRead() failed in udi_fetch_registers");
691
692 for (i = GR64_REGNUM; i < GR64_REGNUM + 32; i++)
693 register_valid[i] = 1;
694
695 #endif /* GR64_REGNUM */
696
697 /* Global Registers gr96-gr127 */
698
699 From.Space = UDI29KGlobalRegs;
700 From.Offset = 96;
701 To = (UDIUInt32 *)&registers[4 * GR96_REGNUM];
702 Count = 32;
703 if (err = UDIRead(From, To, Count, Size, &CountDone, HostEndian))
704 error("UDIRead() failed in udi_fetch_registers");
705
706 for (i = GR96_REGNUM; i < GR96_REGNUM + 32; i++)
707 register_valid[i] = 1;
708
709 /* Local Registers */
710
711 From.Space = UDI29KLocalRegs;
712 From.Offset = 0;
713 To = (UDIUInt32 *)&registers[4 * LR0_REGNUM];
714 Count = 128;
715 if (err = UDIRead(From, To, Count, Size, &CountDone, HostEndian))
716 error("UDIRead() failed in udi_fetch_registers");
717
718 for (i = LR0_REGNUM; i < LR0_REGNUM + 128; i++)
719 register_valid[i] = 1;
720
721 /* Protected Special Registers */
722
723 From.Space = UDI29KSpecialRegs;
724 From.Offset = 0;
725 To = (UDIUInt32 *)&registers[4 * SR_REGNUM(0)];
726 Count = 15;
727 if (err = UDIRead(From, To, Count, Size, &CountDone, HostEndian))
728 error("UDIRead() failed in udi_fetch_registers");
729
730 for (i = SR_REGNUM(0); i < SR_REGNUM(0) + 15; i++)
731 register_valid[i] = 1;
732
733 if (USE_SHADOW_PC) { /* Let regno_to_srnum() handle the register number */
734 fetch_register(NPC_REGNUM);
735 fetch_register(PC_REGNUM);
736 fetch_register(PC2_REGNUM);
737
738 /* Unprotected Special Registers sr128-sr135 */
739
740 From.Space = UDI29KSpecialRegs;
741 From.Offset = 128;
742 To = (UDIUInt32 *)&registers[4 * SR_REGNUM(128)];
743 Count = 135-128 + 1;
744 if (err = UDIRead(From, To, Count, Size, &CountDone, HostEndian))
745 error("UDIRead() failed in udi_fetch_registers");
746
747 for (i = SR_REGNUM(128); i < SR_REGNUM(128) + 135-128+1; i++)
748 register_valid[i] = 1;
749 }
750
751 if (remote_debug)
752 {
753 fprintf_unfiltered (gdb_stdlog, "Fetching all registers\n");
754 fprintf_unfiltered (gdb_stdlog,
755 "Fetching PC0 = 0x%x, PC1 = 0x%x, PC2 = 0x%x\n",
756 read_register (NPC_REGNUM),
757 read_register (PC_REGNUM),
758 read_register (PC2_REGNUM));
759 }
760
761 /* There doesn't seem to be any way to get these. */
762 {
763 int val = -1;
764 supply_register (FPE_REGNUM, (char *) &val);
765 supply_register (INTE_REGNUM, (char *) &val);
766 supply_register (FPS_REGNUM, (char *) &val);
767 supply_register (EXO_REGNUM, (char *) &val);
768 }
769 }
770
771
772 /********************************************************* UDI_STORE_REGISTERS
773 ** Store register regno into the target.
774 * If regno==-1 then store all the registers.
775 */
776
777 static void
778 udi_store_registers (regno)
779 int regno;
780 {
781 UDIUInt32 *From;
782 UDIResource To;
783 UDICount Count;
784 UDISizeT Size = 4;
785 UDICount CountDone;
786 UDIBool HostEndian = 0;
787
788 if (regno >= 0)
789 {
790 store_register(regno);
791 return;
792 }
793
794 if (remote_debug)
795 {
796 fprintf_unfiltered (gdb_stdlog, "Storing all registers\n");
797 fprintf_unfiltered (gdb_stdlog,
798 "PC0 = 0x%x, PC1 = 0x%x, PC2 = 0x%x\n",
799 read_register (NPC_REGNUM),
800 read_register (PC_REGNUM),
801 read_register (PC2_REGNUM));
802 }
803
804 /* Gr1/rsp */
805
806 From = (UDIUInt32 *)&registers[4 * GR1_REGNUM];
807 To.Space = UDI29KGlobalRegs;
808 To.Offset = 1;
809 Count = 1;
810 if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian))
811 error("UDIWrite() failed in udi_store_regisetrs");
812
813 #if defined(GR64_REGNUM)
814
815 /* Global registers gr64-gr95 */
816
817 From = (UDIUInt32 *)&registers[4 * GR64_REGNUM];
818 To.Space = UDI29KGlobalRegs;
819 To.Offset = 64;
820 Count = 32;
821 if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian))
822 error("UDIWrite() failed in udi_store_regisetrs");
823
824 #endif /* GR64_REGNUM */
825
826 /* Global registers gr96-gr127 */
827
828 From = (UDIUInt32 *)&registers[4 * GR96_REGNUM];
829 To.Space = UDI29KGlobalRegs;
830 To.Offset = 96;
831 Count = 32;
832 if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian))
833 error("UDIWrite() failed in udi_store_regisetrs");
834
835 /* Local Registers */
836
837 From = (UDIUInt32 *)&registers[4 * LR0_REGNUM];
838 To.Space = UDI29KLocalRegs;
839 To.Offset = 0;
840 Count = 128;
841 if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian))
842 error("UDIWrite() failed in udi_store_regisetrs");
843
844
845 /* Protected Special Registers */ /* VAB through TMR */
846
847 From = (UDIUInt32 *)&registers[4 * SR_REGNUM(0)];
848 To.Space = UDI29KSpecialRegs;
849 To.Offset = 0;
850 Count = 10;
851 if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian))
852 error("UDIWrite() failed in udi_store_regisetrs");
853
854 /* PC0, PC1, PC2 possibly as shadow registers */
855
856 From = (UDIUInt32 *)&registers[4 * SR_REGNUM(10)];
857 To.Space = UDI29KSpecialRegs;
858 Count = 3;
859 if (USE_SHADOW_PC)
860 To.Offset = 20; /* SPC0 */
861 else
862 To.Offset = 10; /* PC0 */
863 if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian))
864 error("UDIWrite() failed in udi_store_regisetrs");
865
866 /* PC1 via UDI29KPC */
867
868 From = (UDIUInt32 *)&registers[4 * PC_REGNUM];
869 To.Space = UDI29KPC;
870 To.Offset = 0; /* PC1 */
871 Count = 1;
872 if (UDIWrite (From, To, Count, Size, &CountDone, HostEndian))
873 error ("UDIWrite() failed in udi_store_regisetrs");
874
875 /* LRU and MMU */
876
877 From = (UDIUInt32 *)&registers[4 * SR_REGNUM(13)];
878 To.Space = UDI29KSpecialRegs;
879 To.Offset = 13;
880 Count = 2;
881 if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian))
882 error("UDIWrite() failed in udi_store_regisetrs");
883
884 /* Unprotected Special Registers */
885
886 From = (UDIUInt32 *)&registers[4 * SR_REGNUM(128)];
887 To.Space = UDI29KSpecialRegs;
888 To.Offset = 128;
889 Count = 135-128 +1;
890 if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian))
891 error("UDIWrite() failed in udi_store_regisetrs");
892
893 registers_changed ();
894 }
895
896 /****************************************************** UDI_PREPARE_TO_STORE */
897 /* Get ready to modify the registers array. On machines which store
898 individual registers, this doesn't need to do anything. On machines
899 which store all the registers in one fell swoop, this makes sure
900 that registers contains all the registers from the program being
901 debugged. */
902
903 static void
904 udi_prepare_to_store ()
905 {
906 /* Do nothing, since we can store individual regs */
907 }
908
909 /********************************************************** TRANSLATE_ADDR */
910 static CORE_ADDR
911 translate_addr(addr)
912 CORE_ADDR addr;
913 {
914 #if defined(ULTRA3) && defined(KERNEL_DEBUGGING)
915 /* Check for a virtual address in the kernel */
916 /* Assume physical address of ublock is in paddr_u register */
917 /* FIXME: doesn't work for user virtual addresses */
918 if (addr >= UVADDR) {
919 /* PADDR_U register holds the physical address of the ublock */
920 CORE_ADDR i = (CORE_ADDR)read_register(PADDR_U_REGNUM);
921 return(i + addr - (CORE_ADDR)UVADDR);
922 } else {
923 return(addr);
924 }
925 #else
926 return(addr);
927 #endif
928 }
929 /************************************************* UDI_XFER_INFERIOR_MEMORY */
930 /* FIXME! Merge these two. */
931 static int
932 udi_xfer_inferior_memory (memaddr, myaddr, len, write)
933 CORE_ADDR memaddr;
934 char *myaddr;
935 int len;
936 int write;
937 {
938
939 memaddr = translate_addr(memaddr);
940
941 if (write)
942 return udi_write_inferior_memory (memaddr, myaddr, len);
943 else
944 return udi_read_inferior_memory (memaddr, myaddr, len);
945 }
946
947 /********************************************************** UDI_FILES_INFO */
948 static void
949 udi_files_info ()
950 {
951 printf_unfiltered ("\tAttached to UDI socket to %s", udi_config_id);
952 if (prog_name != NULL)
953 printf_unfiltered ("and running program %s", prog_name);
954 printf_unfiltered (".\n");
955 }
956
957 /**************************************************** UDI_INSERT_BREAKPOINT */
958 static int
959 udi_insert_breakpoint (addr, contents_cache)
960 CORE_ADDR addr;
961 char *contents_cache;
962 {
963 int cnt;
964 UDIError err;
965
966 for (cnt = 0; cnt < BKPT_TABLE_SIZE; cnt++)
967 if (bkpt_table[cnt].Type == 0) /* Find first free slot */
968 break;
969
970 if(cnt >= BKPT_TABLE_SIZE)
971 error("Too many breakpoints set");
972
973 bkpt_table[cnt].Addr.Offset = addr;
974 bkpt_table[cnt].Addr.Space = UDI29KIRAMSpace;
975 bkpt_table[cnt].PassCount = 1;
976 bkpt_table[cnt].Type = UDIBreakFlagExecute;
977
978 err = UDISetBreakpoint(bkpt_table[cnt].Addr,
979 bkpt_table[cnt].PassCount,
980 bkpt_table[cnt].Type,
981 &bkpt_table[cnt].BreakId);
982
983 if (err == 0) return 0; /* Success */
984
985 bkpt_table[cnt].Type = 0;
986 error("UDISetBreakpoint returned error code %d\n", err);
987 }
988
989 /**************************************************** UDI_REMOVE_BREAKPOINT */
990 static int
991 udi_remove_breakpoint (addr, contents_cache)
992 CORE_ADDR addr;
993 char *contents_cache;
994 {
995 int cnt;
996 UDIError err;
997
998 for (cnt = 0; cnt < BKPT_TABLE_SIZE; cnt++)
999 if (bkpt_table[cnt].Addr.Offset == addr) /* Find matching breakpoint */
1000 break;
1001
1002 if(cnt >= BKPT_TABLE_SIZE)
1003 error("Can't find breakpoint in table");
1004
1005 bkpt_table[cnt].Type = 0;
1006
1007 err = UDIClearBreakpoint(bkpt_table[cnt].BreakId);
1008 if (err == 0) return 0; /* Success */
1009
1010 error("UDIClearBreakpoint returned error code %d\n", err);
1011 }
1012
1013 static void
1014 udi_kill(arg,from_tty)
1015 char *arg;
1016 int from_tty;
1017 {
1018
1019 #if 0
1020 /*
1021 UDIStop does not really work as advertised. It causes the TIP to close it's
1022 connection, which usually results in GDB dying with a SIGPIPE. For now, we
1023 just invoke udi_close, which seems to get things right.
1024 */
1025 UDIStop();
1026
1027 udi_session_id = -1;
1028 inferior_pid = 0;
1029
1030 if (from_tty)
1031 printf_unfiltered("Target has been stopped.");
1032 #endif /* 0 */
1033 #if 0
1034 udi_close(0);
1035 pop_target();
1036 #endif /* 0 */
1037
1038 /* Keep the target around, e.g. so "run" can do the right thing when
1039 we are already debugging something. */
1040
1041 if (UDIDisconnect (udi_session_id, UDITerminateSession))
1042 {
1043 warning ("UDIDisconnect() failed");
1044 }
1045
1046 /* Do not try to close udi_session_id again, later in the program. */
1047 udi_session_id = -1;
1048 inferior_pid = 0;
1049 }
1050
1051 /*
1052 Load a program into the target. Args are: `program {options}'. The options
1053 are used to control loading of the program, and are NOT passed onto the
1054 loaded code as arguments. (You need to use the `run' command to do that.)
1055
1056 The options are:
1057 -ms %d Set mem stack size to %d
1058 -rs %d Set regular stack size to %d
1059 -i send init info (default)
1060 -noi don't send init info
1061 -[tT] Load Text section
1062 -[dD] Load Data section
1063 -[bB] Load BSS section
1064 -[lL] Load Lit section
1065 */
1066
1067 static void
1068 download(load_arg_string, from_tty)
1069 char *load_arg_string;
1070 int from_tty;
1071 {
1072 #define DEFAULT_MEM_STACK_SIZE 0x6000
1073 #define DEFAULT_REG_STACK_SIZE 0x2000
1074
1075 char *token;
1076 char *filename;
1077 asection *section;
1078 bfd *pbfd;
1079 UDIError err;
1080 int load_text = 1, load_data = 1, load_bss = 1, load_lit = 1;
1081
1082 address_ranges[0].Space = UDI29KIRAMSpace;
1083 address_ranges[0].Offset = 0xffffffff;
1084 address_ranges[0].Size = 0;
1085
1086 address_ranges[1].Space = UDI29KDRAMSpace;
1087 address_ranges[1].Offset = 0xffffffff;
1088 address_ranges[1].Size = 0;
1089
1090 stack_sizes[0] = DEFAULT_REG_STACK_SIZE;
1091 stack_sizes[1] = DEFAULT_MEM_STACK_SIZE;
1092
1093 dont_repeat ();
1094
1095 filename = strtok(load_arg_string, " \t");
1096 if (!filename)
1097 error ("Must specify at least a file name with the load command");
1098
1099 filename = tilde_expand (filename);
1100 make_cleanup ((make_cleanup_func) free, filename);
1101
1102 while (token = strtok (NULL, " \t"))
1103 {
1104 if (token[0] == '-')
1105 {
1106 token++;
1107
1108 if (STREQ (token, "ms"))
1109 stack_sizes[1] = atol (strtok (NULL, " \t"));
1110 else if (STREQ (token, "rs"))
1111 stack_sizes[0] = atol (strtok (NULL, " \t"));
1112 else
1113 {
1114 load_text = load_data = load_bss = load_lit = 0;
1115
1116 while (*token)
1117 {
1118 switch (*token++)
1119 {
1120 case 't':
1121 case 'T':
1122 load_text = 1;
1123 break;
1124 case 'd':
1125 case 'D':
1126 load_data = 1;
1127 break;
1128 case 'b':
1129 case 'B':
1130 load_bss = 1;
1131 break;
1132 case 'l':
1133 case 'L':
1134 load_lit = 1;
1135 break;
1136 default:
1137 error ("Unknown UDI load option -%s", token-1);
1138 }
1139 }
1140 }
1141 }
1142 }
1143
1144 pbfd = bfd_openr (filename, gnutarget);
1145
1146 if (!pbfd)
1147 /* FIXME: should be using bfd_errmsg, not assuming it was
1148 bfd_error_system_call. */
1149 perror_with_name (filename);
1150
1151 /* FIXME: should be checking for errors from bfd_close (for one thing,
1152 on error it does not free all the storage associated with the
1153 bfd). */
1154 make_cleanup ((make_cleanup_func) bfd_close, pbfd);
1155
1156 QUIT;
1157 immediate_quit++;
1158
1159 if (!bfd_check_format (pbfd, bfd_object))
1160 error ("It doesn't seem to be an object file");
1161
1162 for (section = pbfd->sections; section; section = section->next)
1163 {
1164 if (bfd_get_section_flags (pbfd, section) & SEC_ALLOC)
1165 {
1166 UDIResource To;
1167 UDICount Count;
1168 unsigned long section_size, section_end;
1169 const char *section_name;
1170
1171 section_name = bfd_get_section_name (pbfd, section);
1172 if (STREQ (section_name, ".text") && !load_text)
1173 continue;
1174 else if (STREQ (section_name, ".data") && !load_data)
1175 continue;
1176 else if (STREQ (section_name, ".bss") && !load_bss)
1177 continue;
1178 else if (STREQ (section_name, ".lit") && !load_lit)
1179 continue;
1180
1181 To.Offset = bfd_get_section_vma (pbfd, section);
1182 section_size = bfd_section_size (pbfd, section);
1183 section_end = To.Offset + section_size;
1184
1185 if (section_size == 0)
1186 /* This is needed at least in the BSS case, where the code
1187 below starts writing before it even checks the size. */
1188 continue;
1189
1190 printf_unfiltered("[Loading section %s at %x (%d bytes)]\n",
1191 section_name,
1192 To.Offset,
1193 section_size);
1194
1195 if (bfd_get_section_flags (pbfd, section) & SEC_CODE)
1196 {
1197 To.Space = UDI29KIRAMSpace;
1198
1199 address_ranges[0].Offset = min (address_ranges[0].Offset,
1200 To.Offset);
1201 address_ranges[0].Size = max (address_ranges[0].Size,
1202 section_end
1203 - address_ranges[0].Offset);
1204 }
1205 else
1206 {
1207 To.Space = UDI29KDRAMSpace;
1208
1209 address_ranges[1].Offset = min (address_ranges[1].Offset,
1210 To.Offset);
1211 address_ranges[1].Size = max (address_ranges[1].Size,
1212 section_end
1213 - address_ranges[1].Offset);
1214 }
1215
1216 if (bfd_get_section_flags (pbfd, section) & SEC_LOAD) /* Text, data or lit */
1217 {
1218 file_ptr fptr;
1219
1220 fptr = 0;
1221
1222 while (section_size > 0)
1223 {
1224 char buffer[1024];
1225
1226 Count = min (section_size, 1024);
1227
1228 bfd_get_section_contents (pbfd, section, buffer, fptr,
1229 Count);
1230
1231 err = UDIWrite ((UDIHostMemPtr)buffer, /* From */
1232 To, /* To */
1233 Count, /* Count */
1234 (UDISizeT)1, /* Size */
1235 &Count, /* CountDone */
1236 (UDIBool)0); /* HostEndian */
1237 if (err)
1238 error ("UDIWrite failed, error = %d", err);
1239
1240 To.Offset += Count;
1241 fptr += Count;
1242 section_size -= Count;
1243 }
1244 }
1245 else /* BSS */
1246 {
1247 UDIResource From;
1248 unsigned long zero = 0;
1249
1250 /* Write a zero byte at the vma */
1251 /* FIXME: Broken for sections of 1-3 bytes (we test for
1252 zero above). */
1253 err = UDIWrite ((UDIHostMemPtr)&zero, /* From */
1254 To, /* To */
1255 (UDICount)1, /* Count */
1256 (UDISizeT)4, /* Size */
1257 &Count, /* CountDone */
1258 (UDIBool)0); /* HostEndian */
1259 if (err)
1260 error ("UDIWrite failed, error = %d", err);
1261
1262 From = To;
1263 To.Offset+=4;
1264
1265 /* Now, duplicate it for the length of the BSS */
1266 err = UDICopy (From, /* From */
1267 To, /* To */
1268 (UDICount)(section_size/4 - 1), /* Count */
1269 (UDISizeT)4, /* Size */
1270 &Count, /* CountDone */
1271 (UDIBool)1); /* Direction */
1272 if (err)
1273 {
1274 char message[100];
1275 int xerr;
1276
1277 xerr = UDIGetErrorMsg(err, 100, message, &Count);
1278 if (!xerr)
1279 fprintf_unfiltered (gdb_stderr, "Error is %s\n", message);
1280 else
1281 fprintf_unfiltered (gdb_stderr, "xerr is %d\n", xerr);
1282 error ("UDICopy failed, error = %d", err);
1283 }
1284 }
1285
1286 }
1287 }
1288
1289 entry.Space = UDI29KIRAMSpace;
1290 entry.Offset = bfd_get_start_address (pbfd);
1291
1292 immediate_quit--;
1293 }
1294
1295 /* Function to download an image into the remote target. */
1296
1297 static void
1298 udi_load (args, from_tty)
1299 char *args;
1300 int from_tty;
1301 {
1302 download (args, from_tty);
1303
1304 /* As a convenience, pick up any symbol info that is in the program
1305 being loaded. Note that we assume that the program is the``mainline'';
1306 if this is not always true, then this code will need to be augmented. */
1307 symbol_file_add (strtok (args, " \t"), from_tty, 0, 1, 0, 0, 0, 0);
1308
1309 /* Getting new symbols may change our opinion about what is
1310 frameless. */
1311 reinit_frame_cache ();
1312 }
1313
1314 /*************************************************** UDI_WRITE_INFERIOR_MEMORY
1315 ** Copy LEN bytes of data from debugger memory at MYADDR
1316 to inferior's memory at MEMADDR. Returns number of bytes written. */
1317 static int
1318 udi_write_inferior_memory (memaddr, myaddr, len)
1319 CORE_ADDR memaddr;
1320 char *myaddr;
1321 int len;
1322 {
1323 int nwritten = 0;
1324 UDIUInt32 *From;
1325 UDIResource To;
1326 UDICount Count;
1327 UDISizeT Size = 1;
1328 UDICount CountDone = 0;
1329 UDIBool HostEndian = 0;
1330
1331 To.Space = udi_memory_space(memaddr);
1332 From = (UDIUInt32*)myaddr;
1333
1334 while (nwritten < len)
1335 { Count = len - nwritten;
1336 if (Count > MAXDATA) Count = MAXDATA;
1337 To.Offset = memaddr + nwritten;
1338 if(UDIWrite(From, To, Count, Size, &CountDone, HostEndian))
1339 { error("UDIWrite() failed in udi_write_inferior_memory");
1340 break;
1341 }
1342 else
1343 { nwritten += CountDone;
1344 From += CountDone;
1345 }
1346 }
1347 return(nwritten);
1348 }
1349
1350 /**************************************************** UDI_READ_INFERIOR_MEMORY
1351 ** Read LEN bytes from inferior memory at MEMADDR. Put the result
1352 at debugger address MYADDR. Returns number of bytes read. */
1353 static int
1354 udi_read_inferior_memory(memaddr, myaddr, len)
1355 CORE_ADDR memaddr;
1356 char *myaddr;
1357 int len;
1358 {
1359 int nread = 0;
1360 UDIResource From;
1361 UDIUInt32 *To;
1362 UDICount Count;
1363 UDISizeT Size = 1;
1364 UDICount CountDone = 0;
1365 UDIBool HostEndian = 0;
1366 UDIError err;
1367
1368 From.Space = udi_memory_space(memaddr);
1369 To = (UDIUInt32*)myaddr;
1370
1371 while (nread < len)
1372 { Count = len - nread;
1373 if (Count > MAXDATA) Count = MAXDATA;
1374 From.Offset = memaddr + nread;
1375 if(err = UDIRead(From, To, Count, Size, &CountDone, HostEndian))
1376 { error("UDIRead() failed in udi_read_inferior_memory");
1377 break;
1378 }
1379 else
1380 { nread += CountDone;
1381 To += CountDone;
1382 }
1383 }
1384 return(nread);
1385 }
1386
1387 /********************************************************************* WARNING
1388 */
1389 udi_warning(num)
1390 int num;
1391 {
1392 error ("ERROR while loading program into remote TIP: $d\n", num);
1393 }
1394
1395
1396 /*****************************************************************************/
1397 /* Fetch a single register indicatated by 'regno'.
1398 * Returns 0/-1 on success/failure.
1399 */
1400 static void
1401 fetch_register (regno)
1402 int regno;
1403 {
1404 UDIResource From;
1405 UDIUInt32 To;
1406 UDICount Count = 1;
1407 UDISizeT Size = 4;
1408 UDICount CountDone;
1409 UDIBool HostEndian = 0;
1410 UDIError err;
1411 int result;
1412
1413 if (regno == GR1_REGNUM)
1414 {
1415 From.Space = UDI29KGlobalRegs;
1416 From.Offset = 1;
1417 }
1418 else if (regno >= GR96_REGNUM && regno < GR96_REGNUM + 32)
1419 {
1420 From.Space = UDI29KGlobalRegs;
1421 From.Offset = (regno - GR96_REGNUM) + 96;;
1422 }
1423
1424 #if defined(GR64_REGNUM)
1425
1426 else if (regno >= GR64_REGNUM && regno < GR64_REGNUM + 32 )
1427 {
1428 From.Space = UDI29KGlobalRegs;
1429 From.Offset = (regno - GR64_REGNUM) + 64;
1430 }
1431
1432 #endif /* GR64_REGNUM */
1433
1434 else if (regno >= LR0_REGNUM && regno < LR0_REGNUM + 128)
1435 {
1436 From.Space = UDI29KLocalRegs;
1437 From.Offset = (regno - LR0_REGNUM);
1438 }
1439 else if (regno>=FPE_REGNUM && regno<=EXO_REGNUM)
1440 {
1441 int val = -1;
1442 /*supply_register(160 + (regno - FPE_REGNUM),(char *) &val);*/
1443 supply_register(regno, (char *) &val);
1444 return; /* Pretend Success */
1445 }
1446 else
1447 {
1448 From.Space = UDI29KSpecialRegs;
1449 From.Offset = regnum_to_srnum(regno);
1450 }
1451
1452 if (err = UDIRead(From, &To, Count, Size, &CountDone, HostEndian))
1453 error("UDIRead() failed in udi_fetch_registers");
1454
1455 supply_register(regno, (char *) &To);
1456
1457 if (remote_debug)
1458 fprintf_unfiltered (gdb_stdlog, "Fetching register %s = 0x%x\n",
1459 REGISTER_NAME (regno), To);
1460 }
1461 /*****************************************************************************/
1462 /* Store a single register indicated by 'regno'.
1463 * Returns 0/-1 on success/failure.
1464 */
1465 static int
1466 store_register (regno)
1467 int regno;
1468 {
1469 int result;
1470 UDIUInt32 From;
1471 UDIResource To;
1472 UDICount Count = 1;
1473 UDISizeT Size = 4;
1474 UDICount CountDone;
1475 UDIBool HostEndian = 0;
1476
1477 From = read_register (regno); /* get data value */
1478
1479 if (remote_debug)
1480 fprintf_unfiltered (gdb_stdlog, "Storing register %s = 0x%x\n",
1481 REGISTER_NAME (regno), From);
1482
1483 if (regno == GR1_REGNUM)
1484 {
1485 To.Space = UDI29KGlobalRegs;
1486 To.Offset = 1;
1487 result = UDIWrite(&From, To, Count, Size, &CountDone, HostEndian);
1488 /* Setting GR1 changes the numbers of all the locals, so invalidate the
1489 * register cache. Do this *after* calling read_register, because we want
1490 * read_register to return the value that write_register has just stuffed
1491 * into the registers array, not the value of the register fetched from
1492 * the inferior.
1493 */
1494 registers_changed ();
1495 }
1496 #if defined(GR64_REGNUM)
1497 else if (regno >= GR64_REGNUM && regno < GR64_REGNUM + 32 )
1498 {
1499 To.Space = UDI29KGlobalRegs;
1500 To.Offset = (regno - GR64_REGNUM) + 64;
1501 result = UDIWrite(&From, To, Count, Size, &CountDone, HostEndian);
1502 }
1503 #endif /* GR64_REGNUM */
1504 else if (regno >= GR96_REGNUM && regno < GR96_REGNUM + 32)
1505 {
1506 To.Space = UDI29KGlobalRegs;
1507 To.Offset = (regno - GR96_REGNUM) + 96;
1508 result = UDIWrite(&From, To, Count, Size, &CountDone, HostEndian);
1509 }
1510 else if (regno >= LR0_REGNUM && regno < LR0_REGNUM + 128)
1511 {
1512 To.Space = UDI29KLocalRegs;
1513 To.Offset = (regno - LR0_REGNUM);
1514 result = UDIWrite(&From, To, Count, Size, &CountDone, HostEndian);
1515 }
1516 else if (regno >= FPE_REGNUM && regno <= EXO_REGNUM)
1517 return 0; /* Pretend Success */
1518 else if (regno == PC_REGNUM)
1519 {
1520 /* PC1 via UDI29KPC */
1521
1522 To.Space = UDI29KPC;
1523 To.Offset = 0; /* PC1 */
1524 result = UDIWrite (&From, To, Count, Size, &CountDone, HostEndian);
1525
1526 /* Writing to this loc actually changes the values of pc0 & pc1 */
1527
1528 register_valid[PC_REGNUM] = 0; /* pc1 */
1529 register_valid[NPC_REGNUM] = 0; /* pc0 */
1530 }
1531 else /* An unprotected or protected special register */
1532 {
1533 To.Space = UDI29KSpecialRegs;
1534 To.Offset = regnum_to_srnum(regno);
1535 result = UDIWrite(&From, To, Count, Size, &CountDone, HostEndian);
1536 }
1537
1538 if (result != 0)
1539 error("UDIWrite() failed in store_registers");
1540
1541 return 0;
1542 }
1543 /********************************************************** REGNUM_TO_SRNUM */
1544 /*
1545 * Convert a gdb special register number to a 29000 special register number.
1546 */
1547 static int
1548 regnum_to_srnum(regno)
1549 int regno;
1550 {
1551 switch(regno) {
1552 case VAB_REGNUM: return(0);
1553 case OPS_REGNUM: return(1);
1554 case CPS_REGNUM: return(2);
1555 case CFG_REGNUM: return(3);
1556 case CHA_REGNUM: return(4);
1557 case CHD_REGNUM: return(5);
1558 case CHC_REGNUM: return(6);
1559 case RBP_REGNUM: return(7);
1560 case TMC_REGNUM: return(8);
1561 case TMR_REGNUM: return(9);
1562 case NPC_REGNUM: return(USE_SHADOW_PC ? (20) : (10));
1563 case PC_REGNUM: return(USE_SHADOW_PC ? (21) : (11));
1564 case PC2_REGNUM: return(USE_SHADOW_PC ? (22) : (12));
1565 case MMU_REGNUM: return(13);
1566 case LRU_REGNUM: return(14);
1567 case IPC_REGNUM: return(128);
1568 case IPA_REGNUM: return(129);
1569 case IPB_REGNUM: return(130);
1570 case Q_REGNUM: return(131);
1571 case ALU_REGNUM: return(132);
1572 case BP_REGNUM: return(133);
1573 case FC_REGNUM: return(134);
1574 case CR_REGNUM: return(135);
1575 case FPE_REGNUM: return(160);
1576 case INTE_REGNUM: return(161);
1577 case FPS_REGNUM: return(162);
1578 case EXO_REGNUM:return(164);
1579 default:
1580 return(255); /* Failure ? */
1581 }
1582 }
1583 /****************************************************************************/
1584 /*
1585 * Determine the Target memory space qualifier based on the addr.
1586 * FIXME: Can't distinguis I_ROM/D_ROM.
1587 * FIXME: Doesn't know anything about I_CACHE/D_CACHE.
1588 */
1589 static CPUSpace
1590 udi_memory_space(addr)
1591 CORE_ADDR addr;
1592 {
1593 UDIUInt32 tstart = IMemStart;
1594 UDIUInt32 tend = tstart + IMemSize;
1595 UDIUInt32 dstart = DMemStart;
1596 UDIUInt32 dend = tstart + DMemSize;
1597 UDIUInt32 rstart = RMemStart;
1598 UDIUInt32 rend = tstart + RMemSize;
1599
1600 if (((UDIUInt32)addr >= tstart) && ((UDIUInt32)addr < tend)) {
1601 return UDI29KIRAMSpace;
1602 } else if (((UDIUInt32)addr >= dstart) && ((UDIUInt32)addr < dend)) {
1603 return UDI29KDRAMSpace;
1604 } else if (((UDIUInt32)addr >= rstart) && ((UDIUInt32)addr < rend)) {
1605 /* FIXME: how do we determine between D_ROM and I_ROM */
1606 return UDI29KIROMSpace;
1607 } else /* FIXME: what do me do now? */
1608 return UDI29KDRAMSpace; /* Hmmm! */
1609 }
1610 /*********************************************************************** STUBS
1611 */
1612
1613 void convert16() {;}
1614 void convert32() {;}
1615 GDB_FILE * EchoFile = 0; /* used for debugging */
1616 int QuietMode = 0; /* used for debugging */
1617 \f
1618 #ifdef NO_HIF_SUPPORT
1619 service_HIF(msg)
1620 union msg_t *msg;
1621 {
1622 return(0); /* Emulate a failure */
1623 }
1624 #endif
1625 \f
1626 /* Target_ops vector. Not static because there does not seem to be
1627 any portable way to do a forward declaration of a static variable.
1628 The RS/6000 doesn't like "extern" followed by "static"; SunOS
1629 /bin/cc doesn't like "static" twice. */
1630
1631 struct target_ops udi_ops;
1632
1633 static void
1634 init_udi_ops(void)
1635 {
1636 udi_ops.to_shortname = "udi";
1637 udi_ops.to_longname = "Remote UDI connected TIP";
1638 udi_ops.to_doc = "Remote debug an AMD 29k using UDI socket connection to TIP process.\n\
1639 Arguments are\n\
1640 `configuration-id AF_INET hostname port-number'\n\
1641 To connect via the network, where hostname and port-number specify the\n\
1642 host and port where you can connect via UDI.\n\
1643 configuration-id is unused.\n\
1644 \n\
1645 `configuration-id AF_UNIX socket-name tip-program'\n\
1646 To connect using a local connection to the \"tip.exe\" program which is\n\
1647 supplied by AMD. If socket-name specifies an AF_UNIX socket then the\n\
1648 tip program must already be started; connect to it using that socket.\n\
1649 If not, start up tip-program, which should be the name of the tip\n\
1650 program. If appropriate, the PATH environment variable is searched.\n\
1651 configuration-id is unused.\n\
1652 \n\
1653 `configuration-id'\n\
1654 Look up the configuration in ./udi_soc or /etc/udi_soc, which\n\
1655 are files containing lines in the above formats. configuration-id is\n\
1656 used to pick which line of the file to use." ;
1657 udi_ops.to_open = udi_open;
1658 udi_ops.to_close = udi_close;
1659 udi_ops.to_attach = udi_attach;
1660 udi_ops.to_detach = udi_detach;
1661 udi_ops.to_resume = udi_resume;
1662 udi_ops.to_wait = udi_wait;
1663 udi_ops.to_fetch_registers = udi_fetch_registers;
1664 udi_ops.to_store_registers = udi_store_registers;
1665 udi_ops.to_prepare_to_store = udi_prepare_to_store;
1666 udi_ops.to_xfer_memory = udi_xfer_inferior_memory;
1667 udi_ops.to_files_info = udi_files_info;
1668 udi_ops.to_insert_breakpoint = udi_insert_breakpoint;
1669 udi_ops.to_remove_breakpoint = udi_remove_breakpoint;
1670 udi_ops.to_terminal_init = 0;
1671 udi_ops.to_terminal_inferior = 0;
1672 udi_ops.to_terminal_ours_for_output = 0;
1673 udi_ops.to_terminal_ours = 0;
1674 udi_ops.to_terminal_info = 0;
1675 udi_ops.to_kill = udi_kill;
1676 udi_ops.to_load = udi_load;
1677 udi_ops.to_lookup_symbol = 0;
1678 udi_ops.to_create_inferior = udi_create_inferior;
1679 udi_ops.to_mourn_inferior = udi_mourn;
1680 udi_ops.to_can_run = 0;
1681 udi_ops.to_notice_signals = 0;
1682 udi_ops.to_thread_alive = 0;
1683 udi_ops.to_stop = 0;
1684 udi_ops.to_stratum = process_stratum;
1685 udi_ops.DONT_USE = 0;
1686 udi_ops.to_has_all_memory = 1;
1687 udi_ops.to_has_memory = 1;
1688 udi_ops.to_has_stack = 1;
1689 udi_ops.to_has_registers = 1;
1690 udi_ops.to_has_execution = 1;
1691 udi_ops.to_sections = 0;
1692 udi_ops.to_sections_end = 0;
1693 udi_ops.to_magic = OPS_MAGIC;
1694 };
1695
1696 void
1697 _initialize_remote_udi ()
1698 {
1699 init_udi_ops() ;
1700 add_target (&udi_ops);
1701 }
This page took 0.07511 seconds and 4 git commands to generate.