1 /* Remote debugging interface for AMD 29k interfaced via UDI, for GDB.
2 Copyright 1990, 1992 Free Software Foundation, Inc.
3 Written by Daniel Mann. Contributed by AMD.
5 This file is part of GDB.
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.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
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.
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. Because we are only attempting to
31 use this module to debug our kernel, which is already loaded when
32 gdb is started up, I did not code up the file downloading facilities.
33 As a result this module has only the stubs to download files.
34 You should get tagged at compile time if you need to make any
36 - Daniel Mann at AMD took the 3.95 adaptions above and replaced
37 MiniMON interface with UDI-p interface. */
50 #include "29k-share/udi/udiproc.h"
54 /* access the register store directly, without going through
55 the normal handler functions. This avoids an extra data copy. */
58 extern int stop_soon_quietly
; /* for wait_for_inferior */
59 extern struct value
*call_function_by_hand();
60 static void udi_resume
PARAMS ((int step
, int sig
));
61 static void udi_fetch_registers
PARAMS ((int regno
));
62 static void udi_load
PARAMS ((char *args
, int from_tty
));
63 static void fetch_register
PARAMS ((int regno
));
64 static void udi_store_registers
PARAMS ((int regno
));
65 static int store_register
PARAMS ((int regno
));
66 static int regnum_to_srnum
PARAMS ((int regno
));
67 static void udi_close
PARAMS ((int quitting
));
68 static CPUSpace udi_memory_space
PARAMS ((CORE_ADDR addr
));
69 static int udi_write_inferior_memory
PARAMS ((CORE_ADDR memaddr
, char *myaddr
,
71 static int udi_read_inferior_memory
PARAMS ((CORE_ADDR memaddr
, char *myaddr
,
73 static void download
PARAMS ((char *load_arg_string
, int from_tty
));
74 char CoffFileName
[100] = "";
78 #define TYPE_UNKNOWN 0
82 static char *processor_name
[] = { "Unknown", "Am29000", "Am29030", "Am29050" };
83 static int processor_type
=TYPE_UNKNOWN
;
84 #define FREEZE_MODE (read_register(CPS_REGNUM) & 0x400)
85 #define USE_SHADOW_PC ((processor_type == TYPE_A29050) && FREEZE_MODE)
87 #define LLOG_FILE "udi.log"
88 #if defined (LOG_FILE)
92 static int timeout
= 5;
93 extern struct target_ops udi_ops
; /* Forward declaration */
95 /* Special register enumeration.
98 /******************************************************************* UDI DATA*/
99 #define MAXDATA 2*1024 /* max UDI[read/write] byte size */
100 /* Descriptor for I/O to remote machine. Initialize it to -1 so that
101 udi_open knows that we don't have a file open when the program
104 UDISessionId udi_session_id
= -1;
106 CPUOffset IMemStart
= 0;
107 CPUSizeT IMemSize
= 0;
108 CPUOffset DMemStart
= 0;
109 CPUSizeT DMemSize
= 0;
110 CPUOffset RMemStart
= 0;
111 CPUSizeT RMemSize
= 0;
115 UDIMemoryRange address_ranges
[2]; /* Text and data */
116 UDIResource entry
= {0, 0}; /* Entry point */
117 CPUSizeT stack_sizes
[2]; /* Regular and memory stacks */
119 #define SBUF_MAX 1024 /* maximum size of string handling buffer */
122 typedef struct bkpt_entry_str
127 unsigned int BreakId
;
129 #define BKPT_TABLE_SIZE 40
130 static bkpt_entry_t bkpt_table
[BKPT_TABLE_SIZE
];
131 extern char dfe_errmsg
[]; /* error string */
133 /* Called when SIGALRM signal sent due to alarm() timeout. */
136 volatile int n_alarms
;
143 printf ("udi_timer called\n");
147 #endif /* HAVE_TERMIO */
149 /* malloc'd name of the program on the remote system. */
150 static char *prog_name
= NULL
;
152 /* Number of SIGTRAPs we need to simulate. That is, the next
153 NEED_ARTIFICIAL_TRAP calls to udi_wait should just return
154 SIGTRAP without actually waiting for anything. */
156 /* This is called not only when we first attach, but also when the
157 user types "run" after having attached. */
160 udi_create_inferior (execfile
, args
, env
)
169 if (prog_name
!= NULL
)
171 prog_name
= savestring (execfile
, strlen (execfile
));
173 else if (entry
.Offset
)
176 error ("No image loaded into target.");
178 if (udi_session_id
< 0)
180 printf("UDI connection not open yet.\n");
184 inferior_pid
= 40000;
187 download(execfile
, 0);
189 args1
= alloca (strlen(execfile
) + strlen(args
) + 2);
191 strcpy (args1
, execfile
);
193 strcat (args1
, args
);
195 UDIInitializeProcess (address_ranges
, /* ProcessMemory[] */
196 (UDIInt
)2, /* NumberOfRanges */
197 entry
, /* EntryPoint */
198 stack_sizes
, /* *StackSizes */
199 (UDIInt
)2, /* NumberOfStacks */
200 args1
); /* ArgString */
202 init_wait_for_inferior ();
203 clear_proceed_status ();
210 pop_target (); /* Pop back to no-child state */
211 generic_mourn_inferior ();
214 /******************************************************************** UDI_OPEN
215 ** Open a connection to remote TIP.
216 NAME is the socket domain used for communication with the TIP,
217 then a space and the socket name or TIP-host name.
218 '<udi_udi_config_id>' for example.
221 /* XXX - need cleanups for udiconnect for various failures!!! */
223 static char *udi_config_id
;
225 udi_open (name
, from_tty
)
232 UDIMemoryRange KnownMemory
[10];
233 UDIUInt32 ChipVersions
[10];
234 UDIInt NumberOfRanges
= 10;
235 UDIInt NumberOfChips
= 10;
237 UDIUInt32 TIPId
, TargetId
, DFEId
, DFE
, TIP
, DFEIPCId
, TIPIPCId
;
239 target_preopen(from_tty
);
243 for (cnt
= 0; cnt
< BKPT_TABLE_SIZE
; cnt
++)
244 bkpt_table
[cnt
].Type
= 0;
247 free (udi_config_id
);
250 error("Usage: target udi config_id, where config_id appears in udi_soc file");
252 udi_config_id
= strdup (strtok (name
, " \t"));
254 if (UDIConnect (udi_config_id
, &udi_session_id
))
255 error("UDIConnect() failed: %s\n", dfe_errmsg
);
257 push_target (&udi_ops
);
260 #ifndef NO_SIGINTERRUPT
261 /* Cause SIGALRM's to make reads fail with EINTR instead of resuming
263 if (siginterrupt (SIGALRM
, 1) != 0)
264 error ("udi_open: siginterrupt() %s", safe_strerror(errno
));
267 /* Set up read timeout timer. */
268 if ((void (*)) signal (SIGALRM
, udi_timer
) == (void (*)) -1)
269 error ("udi_open: signal() %s", safe_strerror(errno
));
272 #if defined (LOG_FILE)
273 log_file
= fopen (LOG_FILE
, "w");
274 if (log_file
== NULL
)
275 error ("udi_open: fopen(%s) %s", LOG_FILE
, safe_strerror(errno
));
278 ** Initialize target configuration structure (global)
280 if (UDIGetTargetConfig (KnownMemory
, &NumberOfRanges
,
281 ChipVersions
, &NumberOfChips
))
282 error ("UDIGetTargetConfig() failed");
283 if (NumberOfChips
> 2)
284 fprintf(stderr
,"Target has more than one processor\n");
285 for (cnt
=0; cnt
< NumberOfRanges
; cnt
++)
287 switch(KnownMemory
[cnt
].Space
)
290 fprintf(stderr
, "UDIGetTargetConfig() unknown memory space\n");
294 case UDI29KIROMSpace
:
295 RMemStart
= KnownMemory
[cnt
].Offset
;
296 RMemSize
= KnownMemory
[cnt
].Size
;
298 case UDI29KIRAMSpace
:
299 IMemStart
= KnownMemory
[cnt
].Offset
;
300 IMemSize
= KnownMemory
[cnt
].Size
;
302 case UDI29KDRAMSpace
:
303 DMemStart
= KnownMemory
[cnt
].Offset
;
304 DMemSize
= KnownMemory
[cnt
].Size
;
309 /* Determine the processor revision level */
310 prl
= (unsigned int)read_register (CFG_REGNUM
) >> 24;
313 fprintf_filtered (stderr
,
314 "Remote debugging Am29000 rev %c\n",'A'+(prl
&0x1f));
315 processor_type
= TYPE_A29000
;
317 else if ((prl
&0xe0) == 0x40) /* 29030 = 0x4* */
319 fprintf_filtered (stderr
,
320 "Remote debugging Am2903* rev %c\n",'A'+(prl
&0x1f));
321 processor_type
= TYPE_A29030
;
323 else if ((prl
&0xe0) == 0x20) /* 29050 = 0x2* */
325 fprintf_filtered (stderr
,
326 "Remote debugging Am29050 rev %c\n",'A'+(prl
&0x1f));
327 processor_type
= TYPE_A29050
;
331 processor_type
= TYPE_UNKNOWN
;
332 fprintf_filtered (stderr
,"WARNING: processor type unknown.\n");
334 if (UDICreateProcess (&PId
))
335 fprintf(stderr
, "UDICreateProcess() failed\n");
337 /* Print out some stuff, letting the user now what's going on */
338 if (UDICapabilities (&TIPId
, &TargetId
, DFEId
, DFE
, &TIP
, &DFEIPCId
,
340 error ("UDICapabilities() failed");
343 printf_filtered ("Remote debugging an %s connected via UDI socket,\n\
344 DFE-IPC version %x.%x.%x TIP-IPC version %x.%x.%x TIP version %x.%x.%x\n %s\n",
345 processor_name
[processor_type
],
346 (DFEIPCId
>>8)&0xf, (DFEIPCId
>>4)&0xf, DFEIPCId
&0xf,
347 (TIPIPCId
>>8)&0xf, (TIPIPCId
>>4)&0xf, TIPIPCId
&0xf,
348 (TargetId
>>8)&0xf, (TargetId
>>4)&0xf, TargetId
&0xf,
353 /******************************************************************* UDI_CLOSE
354 Close the open connection to the TIP process.
355 Use this when you want to detach and do something else
358 udi_close (quitting
) /*FIXME: how is quitting used */
361 if (udi_session_id
< 0)
364 /* We should never get here if there isn't something valid in
367 if (UDIDisconnect (udi_session_id
, UDITerminateSession
))
368 error ("UDIDisconnect() failed in udi_close");
370 /* Do not try to close udi_session_id again, later in the program. */
374 #if defined (LOG_FILE)
375 if (ferror (log_file
))
376 printf ("Error writing log file.\n");
377 if (fclose (log_file
) != 0)
378 printf ("Error closing log file.\n");
381 printf_filtered (" Ending remote debugging\n");
384 /**************************************************************** UDI_ATACH */
385 /* Attach to a program that is already loaded and running
386 * Upon exiting the process's execution is stopped.
389 udi_attach (args
, from_tty
)
398 UDIBool HostEndian
= 0;
401 if (udi_session_id
< 0)
402 error ("UDI connection not opened yet, use the 'target udi' command.\n");
405 printf ("Attaching to remote program %s...\n", prog_name
);
408 From
.Space
= UDI29KSpecialRegs
;
410 if (err
= UDIRead(From
, &PC_adds
, Count
, Size
, &CountDone
, HostEndian
))
411 error ("UDIRead failed in udi_attach");
412 printf ("Remote process is now halted, pc1 = 0x%x.\n", PC_adds
);
414 /************************************************************* UDI_DETACH */
415 /* Terminate the open connection to the TIP process.
416 Use this when you want to detach and do something else
417 with your gdb. Leave remote process running (with no breakpoints set). */
419 udi_detach (args
,from_tty
)
424 remove_breakpoints(); /* Just in case there were any left in */
426 if (UDIDisconnect (udi_session_id
, UDIContinueSession
))
427 error ("UDIDisconnect() failed in udi_detach");
429 pop_target(); /* calls udi_close to do the real work */
432 printf ("Ending remote debugging\n");
436 /****************************************************************** UDI_RESUME
437 ** Tell the remote machine to resume. */
440 udi_resume (step
, sig
)
445 UDIStepType StepType
= UDIStepNatural
;
448 if (step
) /* step 1 instruction */
450 tip_error
= UDIStep (Steps
, StepType
, Range
);
454 fprintf (stderr
, "UDIStep() error = %d\n", tip_error
);
455 error ("failed in udi_resume");
459 error ("UDIExecute() failed in udi_resume");
462 /******************************************************************** UDI_WAIT
463 ** Wait until the remote machine stops, then return,
464 storing status in STATUS just as `wait' would. */
474 int old_timeout
= timeout
;
475 int old_immediate_quit
= immediate_quit
;
478 WSETEXIT ((*status
), 0);
480 /* wait for message to arrive. It should be:
481 If the target stops executing, udi_wait() should return.
483 timeout
= 0; /* Wait indefinetly for a message */
484 immediate_quit
= 1; /* Helps ability to QUIT */
489 MaxTime
= UDIWaitForever
;
490 UDIWait(MaxTime
, &PId
, &StopReason
);
491 QUIT
; /* Let user quit if they want */
493 switch (StopReason
& UDIGrossState
)
496 if (UDIGetStdout (sbuf
, (UDISizeT
)SBUF_MAX
, &CountDone
))
497 error ("UDIGetStdout() failed in udi_wait");
498 fwrite (sbuf
, 1, CountDone
, stdout
);
502 UDIGetStderr (sbuf
, (UDISizeT
)SBUF_MAX
, &CountDone
);
503 fwrite (sbuf
, 1, CountDone
, stderr
);
509 UDIPutStdin (sbuf
, (UDISizeT
)i
, &CountDone
);
512 /* In spite of the fact that we told UDIWait to wait forever, it will
513 return spuriously sometimes. */
522 switch (StopReason
& UDIGrossState
)
525 printf("Am290*0 received vector number %d\n", StopReason
>> 24);
527 switch (StopReason
>> 8)
529 case 0: /* Illegal opcode */
530 printf(" (break point)\n");
531 WSETSTOP ((*status
), SIGTRAP
);
533 case 1: /* Unaligned Access */
534 WSETSTOP ((*status
), SIGBUS
);
538 WSETSTOP ((*status
), SIGFPE
);
540 case 5: /* Protection Violation */
541 WSETSTOP ((*status
), SIGILL
);
545 case 8: /* User Instruction Mapping Miss */
546 case 9: /* User Data Mapping Miss */
547 case 10: /* Supervisor Instruction Mapping Miss */
548 case 11: /* Supervisor Data Mapping Miss */
549 WSETSTOP ((*status
), SIGSEGV
);
553 WSETSTOP ((*status
), SIGILL
);
556 WSETSTOP ((*status
), SIGALRM
);
559 WSETSTOP ((*status
), SIGTRAP
);
564 case 19: /* INTR3/Internal */
567 WSETSTOP ((*status
), SIGINT
);
569 case 22: /* Floating-Point Exception */
570 WSETSTOP ((*status
), SIGILL
);
572 case 77: /* assert 77 */
573 WSETSTOP ((*status
), SIGTRAP
);
576 WSETEXIT ((*status
), 0);
579 case UDINotExecuting
:
580 WSETSTOP ((*status
), SIGTERM
);
583 WSETSTOP ((*status
), SIGTSTP
);
587 WSETSTOP ((*status
), SIGLOST
);
589 WSETSTOP ((*status
), SIGURG
);
594 WSETSTOP ((*status
), SIGTRAP
);
597 WSETSTOP ((*status
), SIGSTOP
);
600 WSETSTOP ((*status
), SIGKILL
);
604 WSETEXIT ((*status
), 0);
607 timeout
= old_timeout
; /* Restore original timeout value */
608 immediate_quit
= old_immediate_quit
;
612 /********************************************************** UDI_FETCH_REGISTERS
613 * Read a remote register 'regno'.
614 * If regno==-1 then read all the registers.
617 udi_fetch_registers (regno
)
625 UDIBool HostEndian
= 0;
630 fetch_register(regno
);
636 From
.Space
= UDI29KGlobalRegs
;
638 To
= (UDIUInt32
*)®isters
[4 * GR1_REGNUM
];
640 if (err
= UDIRead(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
641 error("UDIRead() failed in udi_fetch_registers");
643 register_valid
[GR1_REGNUM
] = 1;
645 #if defined(GR64_REGNUM) /* Read gr64-127 */
647 /* Global Registers gr64-gr95 */
649 From
.Space
= UDI29KGlobalRegs
;
651 To
= (UDIUInt32
*)®isters
[4 * GR64_REGNUM
];
653 if (err
= UDIRead(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
654 error("UDIRead() failed in udi_fetch_registers");
656 for (i
= GR64_REGNUM
; i
< GR64_REGNUM
+ 32; i
++)
657 register_valid
[i
] = 1;
659 #endif /* GR64_REGNUM */
661 /* Global Registers gr96-gr127 */
663 From
.Space
= UDI29KGlobalRegs
;
665 To
= (UDIUInt32
*)®isters
[4 * GR96_REGNUM
];
667 if (err
= UDIRead(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
668 error("UDIRead() failed in udi_fetch_registers");
670 for (i
= GR96_REGNUM
; i
< GR96_REGNUM
+ 32; i
++)
671 register_valid
[i
] = 1;
673 /* Local Registers */
675 From
.Space
= UDI29KLocalRegs
;
677 To
= (UDIUInt32
*)®isters
[4 * LR0_REGNUM
];
679 if (err
= UDIRead(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
680 error("UDIRead() failed in udi_fetch_registers");
682 for (i
= LR0_REGNUM
; i
< LR0_REGNUM
+ 128; i
++)
683 register_valid
[i
] = 1;
685 /* Protected Special Registers */
687 From
.Space
= UDI29KSpecialRegs
;
689 To
= (UDIUInt32
*)®isters
[4 * SR_REGNUM(0)];
691 if (err
= UDIRead(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
692 error("UDIRead() failed in udi_fetch_registers");
694 for (i
= SR_REGNUM(0); i
< SR_REGNUM(0) + 15; i
++)
695 register_valid
[i
] = 1;
697 if (USE_SHADOW_PC
) { /* Let regno_to_srnum() handle the register number */
698 fetch_register(NPC_REGNUM
);
699 fetch_register(PC_REGNUM
);
700 fetch_register(PC2_REGNUM
);
702 /* Unprotected Special Registers sr128-sr135 */
704 From
.Space
= UDI29KSpecialRegs
;
706 To
= (UDIUInt32
*)®isters
[4 * SR_REGNUM(128)];
708 if (err
= UDIRead(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
709 error("UDIRead() failed in udi_fetch_registers");
711 for (i
= SR_REGNUM(128); i
< SR_REGNUM(128) + 135-128+1; i
++)
712 register_valid
[i
] = 1;
717 printf("Fetching all registers\n");
718 printf("Fetching PC0 = 0x%x, PC1 = 0x%x, PC2 = 0x%x\n",
719 read_register(NPC_REGNUM
), read_register(PC_REGNUM
),
720 read_register(PC2_REGNUM
));
723 /* There doesn't seem to be any way to get these. */
726 supply_register (FPE_REGNUM
, (char *) &val
);
727 supply_register (INTE_REGNUM
, (char *) &val
);
728 supply_register (FPS_REGNUM
, (char *) &val
);
729 supply_register (EXO_REGNUM
, (char *) &val
);
734 /********************************************************* UDI_STORE_REGISTERS
735 ** Store register regno into the target.
736 * If regno==-1 then store all the registers.
740 udi_store_registers (regno
)
748 UDIBool HostEndian
= 0;
752 store_register(regno
);
758 printf("Storing all registers\n");
759 printf("PC0 = 0x%x, PC1 = 0x%x, PC2 = 0x%x\n", read_register(NPC_REGNUM
),
760 read_register(PC_REGNUM
), read_register(PC2_REGNUM
));
765 From
= (UDIUInt32
*)®isters
[4 * GR1_REGNUM
];
766 To
.Space
= UDI29KGlobalRegs
;
769 if(UDIWrite(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
770 error("UDIWrite() failed in udi_store_regisetrs");
772 #if defined(GR64_REGNUM)
774 /* Global registers gr64-gr95 */
776 From
= (UDIUInt32
*)®isters
[4 * GR64_REGNUM
];
777 To
.Space
= UDI29KGlobalRegs
;
780 if(UDIWrite(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
781 error("UDIWrite() failed in udi_store_regisetrs");
783 #endif /* GR64_REGNUM */
785 /* Global registers gr96-gr127 */
787 From
= (UDIUInt32
*)®isters
[4 * GR96_REGNUM
];
788 To
.Space
= UDI29KGlobalRegs
;
791 if(UDIWrite(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
792 error("UDIWrite() failed in udi_store_regisetrs");
794 /* Local Registers */
796 From
= (UDIUInt32
*)®isters
[4 * LR0_REGNUM
];
797 To
.Space
= UDI29KLocalRegs
;
800 if(UDIWrite(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
801 error("UDIWrite() failed in udi_store_regisetrs");
804 /* Protected Special Registers */ /* VAB through TMR */
806 From
= (UDIUInt32
*)®isters
[4 * SR_REGNUM(0)];
807 To
.Space
= UDI29KSpecialRegs
;
810 if(UDIWrite(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
811 error("UDIWrite() failed in udi_store_regisetrs");
813 /* PC0, PC1, PC2 possibly as shadow registers */
815 From
= (UDIUInt32
*)®isters
[4 * SR_REGNUM(10)];
816 To
.Space
= UDI29KSpecialRegs
;
819 To
.Offset
= 20; /* SPC0 */
821 To
.Offset
= 10; /* PC0 */
822 if(UDIWrite(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
823 error("UDIWrite() failed in udi_store_regisetrs");
827 From
= (UDIUInt32
*)®isters
[4 * SR_REGNUM(13)];
828 To
.Space
= UDI29KSpecialRegs
;
831 if(UDIWrite(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
832 error("UDIWrite() failed in udi_store_regisetrs");
834 /* Unprotected Special Registers */
836 From
= (UDIUInt32
*)®isters
[4 * SR_REGNUM(128)];
837 To
.Space
= UDI29KSpecialRegs
;
840 if(UDIWrite(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
841 error("UDIWrite() failed in udi_store_regisetrs");
843 registers_changed ();
846 /****************************************************** UDI_PREPARE_TO_STORE */
847 /* Get ready to modify the registers array. On machines which store
848 individual registers, this doesn't need to do anything. On machines
849 which store all the registers in one fell swoop, this makes sure
850 that registers contains all the registers from the program being
854 udi_prepare_to_store ()
856 /* Do nothing, since we can store individual regs */
859 /********************************************************** TRANSLATE_ADDR */
864 #if defined(ULTRA3) && defined(KERNEL_DEBUGGING)
865 /* Check for a virtual address in the kernel */
866 /* Assume physical address of ublock is in paddr_u register */
867 /* FIXME: doesn't work for user virtual addresses */
868 if (addr
>= UVADDR
) {
869 /* PADDR_U register holds the physical address of the ublock */
870 CORE_ADDR i
= (CORE_ADDR
)read_register(PADDR_U_REGNUM
);
871 return(i
+ addr
- (CORE_ADDR
)UVADDR
);
879 /************************************************* UDI_XFER_INFERIOR_MEMORY */
880 /* FIXME! Merge these two. */
882 udi_xfer_inferior_memory (memaddr
, myaddr
, len
, write
)
889 memaddr
= translate_addr(memaddr
);
892 return udi_write_inferior_memory (memaddr
, myaddr
, len
);
894 return udi_read_inferior_memory (memaddr
, myaddr
, len
);
897 /********************************************************** UDI_FILES_INFO */
901 printf ("\tAttached to UDI socket to %s and running program %s.\n",
902 udi_config_id
, prog_name
);
905 /**************************************************** UDI_INSERT_BREAKPOINT */
907 udi_insert_breakpoint (addr
, contents_cache
)
909 char *contents_cache
;
914 for (cnt
= 0; cnt
< BKPT_TABLE_SIZE
; cnt
++)
915 if (bkpt_table
[cnt
].Type
== 0) /* Find first free slot */
918 if(cnt
>= BKPT_TABLE_SIZE
)
919 error("Too many breakpoints set");
921 bkpt_table
[cnt
].Addr
.Offset
= addr
;
922 bkpt_table
[cnt
].Addr
.Space
= UDI29KIRAMSpace
;
923 bkpt_table
[cnt
].PassCount
= 1;
924 bkpt_table
[cnt
].Type
= UDIBreakFlagExecute
;
926 err
= UDISetBreakpoint(bkpt_table
[cnt
].Addr
,
927 bkpt_table
[cnt
].PassCount
,
928 bkpt_table
[cnt
].Type
,
929 &bkpt_table
[cnt
].BreakId
);
931 if (err
== 0) return 0; /* Success */
933 bkpt_table
[cnt
].Type
= 0;
934 error("UDISetBreakpoint returned error code %d\n", err
);
937 /**************************************************** UDI_REMOVE_BREAKPOINT */
939 udi_remove_breakpoint (addr
, contents_cache
)
941 char *contents_cache
;
946 for (cnt
= 0; cnt
< BKPT_TABLE_SIZE
; cnt
++)
947 if (bkpt_table
[cnt
].Addr
.Offset
== addr
) /* Find matching breakpoint */
950 if(cnt
>= BKPT_TABLE_SIZE
)
951 error("Can't find breakpoint in table");
953 bkpt_table
[cnt
].Type
= 0;
955 err
= UDIClearBreakpoint(bkpt_table
[cnt
].BreakId
);
956 if (err
== 0) return 0; /* Success */
958 error("UDIClearBreakpoint returned error code %d\n", err
);
962 udi_kill(arg
,from_tty
)
969 UDIStop does not really work as advertised. It causes the TIP to close it's
970 connection, which usually results in GDB dying with a SIGPIPE. For now, we
971 just invoke udi_close, which seems to get things right.
979 printf("Target has been stopped.");
987 Load a program into the target. Args are: `program {options}'. The options
988 are used to control loading of the program, and are NOT passed onto the
989 loaded code as arguments. (You need to use the `run' command to do that.)
992 -ms %d Set mem stack size to %d
993 -rs %d Set regular stack size to %d
994 -i send init info (default)
995 -noi don't send init info
996 -[tT] Load Text section
997 -[dD] Load Data section
998 -[bB] Load BSS section
999 -[lL] Load Lit section
1003 download(load_arg_string
, from_tty
)
1004 char *load_arg_string
;
1007 #define DEFAULT_MEM_STACK_SIZE 0x6000
1008 #define DEFAULT_REG_STACK_SIZE 0x2000
1015 int load_text
= 1, load_data
= 1, load_bss
= 1, load_lit
= 1;
1017 address_ranges
[0].Space
= UDI29KIRAMSpace
;
1018 address_ranges
[0].Offset
= 0xffffffff;
1019 address_ranges
[0].Size
= 0;
1021 address_ranges
[1].Space
= UDI29KDRAMSpace
;
1022 address_ranges
[1].Offset
= 0xffffffff;
1023 address_ranges
[1].Size
= 0;
1025 stack_sizes
[0] = DEFAULT_REG_STACK_SIZE
;
1026 stack_sizes
[1] = DEFAULT_MEM_STACK_SIZE
;
1030 filename
= strtok(load_arg_string
, " \t");
1032 error ("Must specify at least a file name with the load command");
1034 filename
= tilde_expand (filename
);
1035 make_cleanup (free
, filename
);
1037 while (token
= strtok (NULL
, " \t"))
1039 if (token
[0] == '-')
1043 if (STREQ (token
, "ms"))
1044 stack_sizes
[1] = atol (strtok (NULL
, " \t"));
1045 else if (STREQ (token
, "rs"))
1046 stack_sizes
[0] = atol (strtok (NULL
, " \t"));
1049 load_text
= load_data
= load_bss
= load_lit
= 0;
1072 error ("Unknown UDI load option -%s", token
-1);
1079 pbfd
= bfd_openr (filename
, 0);
1082 perror_with_name (filename
);
1084 make_cleanup (bfd_close
, pbfd
);
1089 if (!bfd_check_format (pbfd
, bfd_object
))
1090 error ("It doesn't seem to be an object file");
1092 for (section
= pbfd
->sections
; section
; section
= section
->next
)
1094 if (bfd_get_section_flags (pbfd
, section
) & SEC_ALLOC
)
1098 unsigned long section_size
, section_end
;
1099 const char *section_name
;
1101 section_name
= bfd_get_section_name (pbfd
, section
);
1102 if (STREQ (section_name
, ".text") && !load_text
)
1104 else if (STREQ (section_name
, ".data") && !load_data
)
1106 else if (STREQ (section_name
, ".bss") && !load_bss
)
1108 else if (STREQ (section_name
, ".lit") && !load_lit
)
1111 To
.Offset
= bfd_get_section_vma (pbfd
, section
);
1112 section_size
= bfd_section_size (pbfd
, section
);
1113 section_end
= To
.Offset
+ section_size
;
1115 printf("[Loading section %s at %x (%d bytes)]\n",
1120 if (bfd_get_section_flags (pbfd
, section
) & SEC_CODE
)
1122 To
.Space
= UDI29KIRAMSpace
;
1124 address_ranges
[0].Offset
= min (address_ranges
[0].Offset
,
1126 address_ranges
[0].Size
= max (address_ranges
[0].Size
,
1128 - address_ranges
[0].Offset
);
1132 To
.Space
= UDI29KDRAMSpace
;
1134 address_ranges
[1].Offset
= min (address_ranges
[1].Offset
,
1136 address_ranges
[1].Size
= max (address_ranges
[1].Size
,
1138 - address_ranges
[1].Offset
);
1141 if (bfd_get_section_flags (pbfd
, section
) & SEC_LOAD
) /* Text, data or lit */
1147 while (section_size
> 0)
1151 Count
= min (section_size
, 1024);
1153 bfd_get_section_contents (pbfd
, section
, buffer
, fptr
,
1156 err
= UDIWrite ((UDIHostMemPtr
)buffer
, /* From */
1159 (UDISizeT
)1, /* Size */
1160 &Count
, /* CountDone */
1161 (UDIBool
)0); /* HostEndian */
1163 error ("UDIWrite failed, error = %d", err
);
1167 section_size
-= Count
;
1173 unsigned long zero
= 0;
1175 /* Write a zero byte at the vma */
1176 err
= UDIWrite ((UDIHostMemPtr
)&zero
, /* From */
1178 (UDICount
)1, /* Count */
1179 (UDISizeT
)4, /* Size */
1180 &Count
, /* CountDone */
1181 (UDIBool
)0); /* HostEndian */
1183 error ("UDIWrite failed, error = %d", err
);
1188 /* Now, duplicate it for the length of the BSS */
1189 err
= UDICopy (From
, /* From */
1191 (UDICount
)(section_size
/4 - 1), /* Count */
1192 (UDISizeT
)4, /* Size */
1193 &Count
, /* CountDone */
1194 (UDIBool
)1); /* Direction */
1200 xerr
= UDIGetErrorMsg(err
, 100, message
, &Count
);
1202 fprintf (stderr
, "Error is %s\n", message
);
1204 fprintf (stderr
, "xerr is %d\n", xerr
);
1205 error ("UDICopy failed, error = %d", err
);
1212 entry
.Space
= UDI29KIRAMSpace
;
1213 entry
.Offset
= bfd_get_start_address (pbfd
);
1218 /* User interface to download an image into the remote target. See download()
1219 * for details on args.
1223 udi_load(args
, from_tty
)
1227 download (args
, from_tty
);
1229 symbol_file_add (strtok (args
, " \t"), from_tty
, 0, 0, 0, 0);
1232 /*************************************************** UDI_WRITE_INFERIOR_MEMORY
1233 ** Copy LEN bytes of data from debugger memory at MYADDR
1234 to inferior's memory at MEMADDR. Returns number of bytes written. */
1236 udi_write_inferior_memory (memaddr
, myaddr
, len
)
1246 UDICount CountDone
= 0;
1247 UDIBool HostEndian
= 0;
1249 To
.Space
= udi_memory_space(memaddr
);
1250 From
= (UDIUInt32
*)myaddr
;
1252 while (nwritten
< len
)
1253 { Count
= len
- nwritten
;
1254 if (Count
> MAXDATA
) Count
= MAXDATA
;
1255 To
.Offset
= memaddr
+ nwritten
;
1256 if(UDIWrite(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
1257 { error("UDIWrite() failed in udi_write_inferrior_memory");
1261 { nwritten
+= CountDone
;
1268 /**************************************************** UDI_READ_INFERIOR_MEMORY
1269 ** Read LEN bytes from inferior memory at MEMADDR. Put the result
1270 at debugger address MYADDR. Returns number of bytes read. */
1272 udi_read_inferior_memory(memaddr
, myaddr
, len
)
1282 UDICount CountDone
= 0;
1283 UDIBool HostEndian
= 0;
1286 From
.Space
= udi_memory_space(memaddr
);
1287 To
= (UDIUInt32
*)myaddr
;
1290 { Count
= len
- nread
;
1291 if (Count
> MAXDATA
) Count
= MAXDATA
;
1292 From
.Offset
= memaddr
+ nread
;
1293 if(err
= UDIRead(From
, To
, Count
, Size
, &CountDone
, HostEndian
))
1294 { error("UDIRead() failed in udi_read_inferrior_memory");
1298 { nread
+= CountDone
;
1305 /********************************************************************* WARNING
1310 error ("ERROR while loading program into remote TIP: $d\n", num
);
1314 /*****************************************************************************/
1315 /* Fetch a single register indicatated by 'regno'.
1316 * Returns 0/-1 on success/failure.
1319 fetch_register (regno
)
1327 UDIBool HostEndian
= 0;
1331 if (regno
== GR1_REGNUM
)
1333 From
.Space
= UDI29KGlobalRegs
;
1336 else if (regno
>= GR96_REGNUM
&& regno
< GR96_REGNUM
+ 32)
1338 From
.Space
= UDI29KGlobalRegs
;
1339 From
.Offset
= (regno
- GR96_REGNUM
) + 96;;
1342 #if defined(GR64_REGNUM)
1344 else if (regno
>= GR64_REGNUM
&& regno
< GR64_REGNUM
+ 32 )
1346 From
.Space
= UDI29KGlobalRegs
;
1347 From
.Offset
= (regno
- GR64_REGNUM
) + 64;
1350 #endif /* GR64_REGNUM */
1352 else if (regno
>= LR0_REGNUM
&& regno
< LR0_REGNUM
+ 128)
1354 From
.Space
= UDI29KLocalRegs
;
1355 From
.Offset
= (regno
- LR0_REGNUM
);
1357 else if (regno
>=FPE_REGNUM
&& regno
<=EXO_REGNUM
)
1360 supply_register(160 + (regno
- FPE_REGNUM
),(char *) &val
);
1361 return; /* Pretend Success */
1365 From
.Space
= UDI29KSpecialRegs
;
1366 From
.Offset
= regnum_to_srnum(regno
);
1369 if (err
= UDIRead(From
, &To
, Count
, Size
, &CountDone
, HostEndian
))
1370 error("UDIRead() failed in udi_fetch_registers");
1372 supply_register(regno
, (char *) &To
);
1375 printf("Fetching register %s = 0x%x\n", reg_names
[regno
], To
);
1377 /*****************************************************************************/
1378 /* Store a single register indicated by 'regno'.
1379 * Returns 0/-1 on success/failure.
1382 store_register (regno
)
1391 UDIBool HostEndian
= 0;
1393 From
= read_register (regno
); /* get data value */
1396 printf("Storing register %s = 0x%x\n", reg_names
[regno
], From
);
1398 if (regno
== GR1_REGNUM
)
1399 { To
.Space
= UDI29KGlobalRegs
;
1401 result
= UDIWrite(&From
, To
, Count
, Size
, &CountDone
, HostEndian
);
1402 /* Setting GR1 changes the numbers of all the locals, so invalidate the
1403 * register cache. Do this *after* calling read_register, because we want
1404 * read_register to return the value that write_register has just stuffed
1405 * into the registers array, not the value of the register fetched from
1408 registers_changed ();
1410 #if defined(GR64_REGNUM)
1411 else if (regno
>= GR64_REGNUM
&& regno
< GR64_REGNUM
+ 32 )
1412 { To
.Space
= UDI29KGlobalRegs
;
1413 To
.Offset
= (regno
- GR64_REGNUM
) + 64;
1414 result
= UDIWrite(&From
, To
, Count
, Size
, &CountDone
, HostEndian
);
1416 #endif /* GR64_REGNUM */
1417 else if (regno
>= GR96_REGNUM
&& regno
< GR96_REGNUM
+ 32)
1418 { To
.Space
= UDI29KGlobalRegs
;
1419 To
.Offset
= (regno
- GR96_REGNUM
) + 96;
1420 result
= UDIWrite(&From
, To
, Count
, Size
, &CountDone
, HostEndian
);
1422 else if (regno
>= LR0_REGNUM
&& regno
< LR0_REGNUM
+ 128)
1423 { To
.Space
= UDI29KLocalRegs
;
1424 To
.Offset
= (regno
- LR0_REGNUM
);
1425 result
= UDIWrite(&From
, To
, Count
, Size
, &CountDone
, HostEndian
);
1427 else if (regno
>=FPE_REGNUM
&& regno
<=EXO_REGNUM
)
1429 return 0; /* Pretend Success */
1431 else /* An unprotected or protected special register */
1432 { To
.Space
= UDI29KSpecialRegs
;
1433 To
.Offset
= regnum_to_srnum(regno
);
1434 result
= UDIWrite(&From
, To
, Count
, Size
, &CountDone
, HostEndian
);
1439 error("UDIWrite() failed in store_registers");
1443 /********************************************************** REGNUM_TO_SRNUM */
1445 * Convert a gdb special register number to a 29000 special register number.
1448 regnum_to_srnum(regno
)
1452 case VAB_REGNUM
: return(0);
1453 case OPS_REGNUM
: return(1);
1454 case CPS_REGNUM
: return(2);
1455 case CFG_REGNUM
: return(3);
1456 case CHA_REGNUM
: return(4);
1457 case CHD_REGNUM
: return(5);
1458 case CHC_REGNUM
: return(6);
1459 case RBP_REGNUM
: return(7);
1460 case TMC_REGNUM
: return(8);
1461 case TMR_REGNUM
: return(9);
1462 case NPC_REGNUM
: return(USE_SHADOW_PC
? (20) : (10));
1463 case PC_REGNUM
: return(USE_SHADOW_PC
? (21) : (11));
1464 case PC2_REGNUM
: return(USE_SHADOW_PC
? (22) : (12));
1465 case MMU_REGNUM
: return(13);
1466 case LRU_REGNUM
: return(14);
1467 case IPC_REGNUM
: return(128);
1468 case IPA_REGNUM
: return(129);
1469 case IPB_REGNUM
: return(130);
1470 case Q_REGNUM
: return(131);
1471 case ALU_REGNUM
: return(132);
1472 case BP_REGNUM
: return(133);
1473 case FC_REGNUM
: return(134);
1474 case CR_REGNUM
: return(135);
1475 case FPE_REGNUM
: return(160);
1476 case INTE_REGNUM
: return(161);
1477 case FPS_REGNUM
: return(162);
1478 case EXO_REGNUM
:return(164);
1480 return(255); /* Failure ? */
1483 /****************************************************************************/
1485 * Determine the Target memory space qualifier based on the addr.
1486 * FIXME: Can't distinguis I_ROM/D_ROM.
1487 * FIXME: Doesn't know anything about I_CACHE/D_CACHE.
1490 udi_memory_space(addr
)
1493 UDIUInt32 tstart
= IMemStart
;
1494 UDIUInt32 tend
= tstart
+ IMemSize
;
1495 UDIUInt32 dstart
= DMemStart
;
1496 UDIUInt32 dend
= tstart
+ DMemSize
;
1497 UDIUInt32 rstart
= RMemStart
;
1498 UDIUInt32 rend
= tstart
+ RMemSize
;
1500 if (((UDIUInt32
)addr
>= tstart
) && ((UDIUInt32
)addr
< tend
)) {
1501 return UDI29KIRAMSpace
;
1502 } else if (((UDIUInt32
)addr
>= dstart
) && ((UDIUInt32
)addr
< dend
)) {
1503 return UDI29KDRAMSpace
;
1504 } else if (((UDIUInt32
)addr
>= rstart
) && ((UDIUInt32
)addr
< rend
)) {
1505 /* FIXME: how do we determine between D_ROM and I_ROM */
1506 return UDI29KIROMSpace
;
1507 } else /* FIXME: what do me do now? */
1508 return UDI29KDRAMSpace
; /* Hmmm! */
1510 /*********************************************************************** STUBS
1513 void convert16() {;}
1514 void convert32() {;}
1515 FILE* EchoFile
= 0; /* used for debugging */
1516 int QuietMode
= 0; /* used for debugging */
1518 /****************************************************************************/
1520 * Define the target subroutine names
1522 static struct target_ops udi_ops
= {
1524 "Remote UDI connected TIP",
1525 "Remote debug an AMD 29k using UDI socket connection to TIP process",
1532 udi_fetch_registers
,
1533 udi_store_registers
,
1534 udi_prepare_to_store
,
1535 udi_xfer_inferior_memory
,
1537 udi_insert_breakpoint
,
1538 udi_remove_breakpoint
,
1539 0, /* termial_init */
1540 0, /* terminal_inferior */
1541 0, /* terminal_ours_for_output */
1542 0, /* terminal_ours */
1543 0, /* terminal_info */
1544 udi_kill
, /* FIXME, kill */
1546 0, /* lookup_symbol */
1547 udi_create_inferior
,
1548 udi_mourn
, /* mourn_inferior FIXME */
1550 0, /* notice_signals */
1553 1, /* has_all_memory */
1556 1, /* has_registers */
1557 1, /* has_execution */
1559 0, /* sections_end */
1560 OPS_MAGIC
, /* Always the last thing */
1563 void _initialize_remote_udi()
1565 add_target (&udi_ops
);
1567 add_set_cmd ("remotedebug", no_class
, var_boolean
,
1569 "Set debugging of UDI I/O.\n\
1570 When enabled, debugging info is displayed.",
1575 #ifdef NO_HIF_SUPPORT
1579 return(0); /* Emulate a failure */