13 extern char *mem2hex (void *mem
, char *buf
, int count
, int may_fault
);
14 extern char *hex2mem (char *buf
, void *mem
, int count
, int may_fault
);
15 extern int computeSignal (int exceptionVector
);
22 /* Get the registers out of the frame information. */
25 frame_to_registers (frame
, regs
)
26 struct StackFrame
*frame
;
29 mem2hex (&frame
->ExceptionState
.CsavedRegs
, ®s
[GP0_REGNUM
* 4 * 2], 4 * 32, 0);
31 mem2hex (&frame
->ExceptionState
.CSavedFPRegs
, ®s
[FP0_REGNUM
* 4 * 2], 4 * 32, 0);
33 mem2hex (&frame
->ExceptionPC
, ®s
[PC_REGNUM
* 4 * 2], 4 * 1, 0);
35 mem2hex (&frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedSRR1
, ®s
[CR_REGNUM
* 4 * 2], 4 * 1, 0);
36 mem2hex (&frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedLR
, ®s
[LR_REGNUM
* 4 * 2], 4 * 1, 0);
37 mem2hex (&frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedCTR
, ®s
[CTR_REGNUM
* 4 * 2], 4 * 1, 0);
38 mem2hex (&frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedXER
, ®s
[XER_REGNUM
* 4 * 2], 4 * 1, 0);
39 mem2hex (&frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedMQ
, ®s
[MQ_REGNUM
* 4 * 2], 4 * 1, 0);
42 /* Put the registers back into the frame information. */
45 registers_to_frame (regs
, frame
)
47 struct StackFrame
*frame
;
49 hex2mem (®s
[GP0_REGNUM
* 4 * 2], &frame
->ExceptionState
.CsavedRegs
, 4 * 32, 0);
51 hex2mem (®s
[FP0_REGNUM
* 4 * 2], &frame
->ExceptionState
.CSavedFPRegs
, 4 * 32, 0);
53 hex2mem (®s
[PC_REGNUM
* 4 * 2], &frame
->ExceptionPC
, 4 * 1, 0);
55 hex2mem (®s
[CR_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedSRR1
, 4 * 1, 0);
56 hex2mem (®s
[LR_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedLR
, 4 * 1, 0);
57 hex2mem (®s
[CTR_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedCTR
, 4 * 1, 0);
58 hex2mem (®s
[XER_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedXER
, 4 * 1, 0);
59 hex2mem (®s
[MQ_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedMQ
, 4 * 1, 0);
62 extern int ReadByteAltDebugger (char* addr
, char *theByte
);
64 extern int WriteByteAltDebugger (char* addr
, char theByte
);
66 extern volatile int mem_err
;
74 if (!ReadByteAltDebugger (addr
, &c
))
85 if (!WriteByteAltDebugger (addr
, val
))
90 mem_write (dst
, src
, len
)
94 while (len
-- && !mem_err
)
95 set_char (dst
++, *src
++);
108 struct /* Unconditional branch */
110 unsigned opcode
: 6; /* 18 */
115 struct /* Conditional branch */
117 unsigned opcode
: 6; /* 16 */
124 struct /* Conditional branch to ctr or lr reg */
126 unsigned opcode
: 6; /* 19 */
129 unsigned type
: 15; /* 528 = ctr, 16 = lr */
136 static LONG saved_inst
;
137 static char *saved_inst_pc
= 0;
138 static LONG saved_target_inst
;
139 static char *saved_target_inst_pc
= 0;
142 set_step_traps (frame
)
143 struct StackFrame
*frame
;
149 char *pc
= (char *)frame
->ExceptionPC
;
151 inst
.l
= *(LONG
*)pc
;
153 opcode
= inst
.inst
.variant
.b
.opcode
;
157 case 18: /* Unconditional branch */
158 target
= (char *)(inst
.inst
.variant
.b
.li
<< 2);
160 if (!inst
.inst
.variant
.b
.aa
) /* Relative? */
164 case 16: /* Conditional branch */
165 target
= (char *)(inst
.inst
.variant
.bc
.bd
<< 2);
167 if (!inst
.inst
.variant
.bc
.aa
) /* Relative? */
171 case 19: /* Cond. branch via ctr or lr reg */
172 switch (inst
.inst
.variant
.bclr
.type
)
175 target
= (char *)frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedCTR
;
178 target
= (char *)frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedLR
;
188 saved_inst
= *(LONG
*)pc
;
189 mem_write (pc
, breakpoint_insn
, BREAKPOINT_SIZE
);
194 saved_target_inst
= *(LONG
*)target
;
195 mem_write (target
, breakpoint_insn
, BREAKPOINT_SIZE
);
196 saved_target_inst_pc
= target
;
200 /* Remove step breakpoints. Returns non-zero if pc was at a step breakpoint,
201 zero otherwise. This routine works even if there were no step breakpoints
205 clear_step_traps (frame
)
206 struct StackFrame
*frame
;
209 char *pc
= (char *)frame
->ExceptionPC
;
211 if (saved_inst_pc
== pc
|| saved_target_inst_pc
== pc
)
218 mem_write (saved_inst_pc
, saved_inst
, BREAKPOINT_SIZE
);
222 if (saved_target_inst_pc
)
224 mem_write (saved_target_inst_pc
, saved_target_inst
, BREAKPOINT_SIZE
);
225 saved_target_inst_pc
= 0;
232 do_status (ptr
, frame
)
234 struct StackFrame
*frame
;
238 sigval
= computeSignal (frame
->ExceptionNumber
);
240 sprintf (ptr
, "T%02x", sigval
);
243 sprintf (ptr
, "%02x:", PC_REGNUM
);
244 ptr
= mem2hex (&frame
->ExceptionPC
, ptr
+ 3, 4, 0);
247 sprintf (ptr
, "%02x:", SP_REGNUM
);
248 ptr
= mem2hex (&frame
->ExceptionState
.CsavedRegs
[SP_REGNUM
], ptr
+ 3, 4, 0);
251 sprintf (ptr
, "%02x:", LR_REGNUM
);
252 ptr
= mem2hex (&frame
->ExceptionState
.CsavedRegs
[LR_REGNUM
], ptr
+ 3, 4, 0);
259 * strtol : convert a string to long.
261 * Andy Wilson, 2-Oct-89.
264 /* FIXME: It'd be nice to configure around these, but the include files are too
265 painful. These macros should at least be more portable than hardwired hex
268 #define ULONG_MAX ((unsigned long)(~0L)) /* 0xFFFFFFFF */
269 #define LONG_MAX ((long)(ULONG_MAX >> 1)) /* 0x7FFFFFFF */
270 #define LONG_MIN ((long)(~LONG_MAX)) /* 0x80000000 */
274 unsigned long strtoul(const char *s
, char **ptr
, int base
);
278 const char *s
; char **ptr
; int base
;
289 *ptr
= (char *)start
;
302 * let strtoul do the hard work.
304 tmp
= strtoul(s
, &eptr
, base
);
306 *ptr
= (char *)((eptr
==s
) ? (char *)start
: eptr
);
307 if (tmp
> (minus
? - (unsigned long) LONG_MIN
: (unsigned long) LONG_MAX
))
310 return (minus
? LONG_MIN
: LONG_MAX
);
312 return (minus
? (long) -tmp
: (long) tmp
);
316 * strtol : convert a string to long.
318 * Andy Wilson, 2-Oct-89.
322 #define ULONG_MAX ((unsigned long)(~0L)) /* 0xFFFFFFFF */
328 strtoul(s
, ptr
, base
)
329 const char *s
; char **ptr
; int base
;
331 unsigned long total
= 0;
334 int did_conversion
=0;
337 unsigned long maxdiv
, maxrem
;
343 *ptr
= (char *)start
;
353 if (base
==0 || base
==16) /* the 'base==16' is for handling 0x */
358 * try to infer base from the string
361 tmp
= 10; /* doesn't start with 0 - assume decimal */
362 else if (s
[1] == 'X' || s
[1] == 'x')
363 tmp
= 16, s
+= 2; /* starts with 0x or 0X - hence hex */
365 tmp
= 8; /* starts with 0 - hence octal */
370 maxdiv
= ULONG_MAX
/ base
;
371 maxrem
= ULONG_MAX
% base
;
373 while ((digit
= *s
) != '\0')
375 if (digit
>= '0' && digit
< ('0'+base
))
380 if (digit
>= 'a' && digit
< ('a'+(base
-10)))
381 digit
= digit
- 'a' + 10;
382 else if (digit
>= 'A' && digit
< ('A'+(base
-10)))
383 digit
= digit
- 'A' + 10;
391 || (total
== maxdiv
&& digit
> maxrem
))
393 total
= (total
* base
) + digit
;
404 *ptr
= (char *) ((did_conversion
) ? (char *)s
: (char *)start
);
405 return negate
? -total
: total
;
408 void _exit (int foo
) __attribute__ ((noreturn
));