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 LONG
*saved_inst_pc
= 0;
138 static LONG saved_target_inst
;
139 static LONG
*saved_target_inst_pc
= 0;
142 set_step_traps (frame
)
143 struct StackFrame
*frame
;
149 LONG
*pc
= (LONG
*)frame
->ExceptionPC
;
153 opcode
= inst
.inst
.variant
.b
.opcode
;
159 case 18: /* Unconditional branch */
161 if (inst
.inst
.variant
.b
.aa
) /* Absolute? */
163 target
+= inst
.inst
.variant
.b
.li
;
166 case 16: /* Conditional branch */
168 if (!inst
.inst
.variant
.bc
.aa
) /* Absolute? */
170 target
+= inst
.inst
.variant
.bc
.bd
;
173 case 19: /* Cond. branch via ctr or lr reg */
174 switch (inst
.inst
.variant
.bclr
.type
)
177 target
= (LONG
*)frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedCTR
;
180 target
= (LONG
*)frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedLR
;
187 mem_write (pc
, breakpoint_insn
, BREAKPOINT_SIZE
);
192 saved_target_inst
= *target
;
193 mem_write (target
, breakpoint_insn
, BREAKPOINT_SIZE
);
194 saved_target_inst_pc
= target
;
198 /* Remove step breakpoints. Returns non-zero if pc was at a step breakpoint,
199 zero otherwise. This routine works even if there were no step breakpoints
203 clear_step_traps (frame
)
204 struct StackFrame
*frame
;
207 LONG
*pc
= (LONG
*)frame
->ExceptionPC
;
209 if (saved_inst_pc
== pc
|| saved_target_inst_pc
== pc
)
216 mem_write (saved_inst_pc
, saved_inst
, BREAKPOINT_SIZE
);
220 if (saved_target_inst_pc
)
222 mem_write (saved_target_inst_pc
, saved_target_inst
, BREAKPOINT_SIZE
);
223 saved_target_inst_pc
= 0;
230 do_status (ptr
, frame
)
232 struct StackFrame
*frame
;
236 sigval
= computeSignal (frame
->ExceptionNumber
);
238 sprintf (ptr
, "T%02x", sigval
);
241 sprintf (ptr
, "%02x:", PC_REGNUM
);
242 ptr
= mem2hex (&frame
->ExceptionPC
, ptr
+ 3, 4, 0);
245 sprintf (ptr
, "%02x:", SP_REGNUM
);
246 ptr
= mem2hex (&frame
->ExceptionState
.CsavedRegs
[SP_REGNUM
], ptr
+ 3, 4, 0);
249 sprintf (ptr
, "%02x:", LR_REGNUM
);
250 ptr
= mem2hex (&frame
->ExceptionState
.CsavedRegs
[LR_REGNUM
], ptr
+ 3, 4, 0);
258 * strtol : convert a string to long.
260 * Andy Wilson, 2-Oct-89.
263 /* FIXME: It'd be nice to configure around these, but the include files are too
264 painful. These macros should at least be more portable than hardwired hex
267 #define ULONG_MAX ((unsigned long)(~0L)) /* 0xFFFFFFFF */
268 #define LONG_MAX ((long)(ULONG_MAX >> 1)) /* 0x7FFFFFFF */
269 #define LONG_MIN ((long)(~LONG_MAX)) /* 0x80000000 */
273 unsigned long strtoul(const char *s
, char **ptr
, int base
);
277 const char *s
; char **ptr
; int base
;
288 *ptr
= (char *)start
;
301 * let strtoul do the hard work.
303 tmp
= strtoul(s
, &eptr
, base
);
305 *ptr
= (char *)((eptr
==s
) ? (char *)start
: eptr
);
306 if (tmp
> (minus
? - (unsigned long) LONG_MIN
: (unsigned long) LONG_MAX
))
309 return (minus
? LONG_MIN
: LONG_MAX
);
311 return (minus
? (long) -tmp
: (long) tmp
);
315 * strtol : convert a string to long.
317 * Andy Wilson, 2-Oct-89.
321 #define ULONG_MAX ((unsigned long)(~0L)) /* 0xFFFFFFFF */
327 strtoul(s
, ptr
, base
)
328 const char *s
; char **ptr
; int base
;
330 unsigned long total
= 0;
333 int did_conversion
=0;
336 unsigned long maxdiv
, maxrem
;
342 *ptr
= (char *)start
;
352 if (base
==0 || base
==16) /* the 'base==16' is for handling 0x */
357 * try to infer base from the string
360 tmp
= 10; /* doesn't start with 0 - assume decimal */
361 else if (s
[1] == 'X' || s
[1] == 'x')
362 tmp
= 16, s
+= 2; /* starts with 0x or 0X - hence hex */
364 tmp
= 8; /* starts with 0 - hence octal */
369 maxdiv
= ULONG_MAX
/ base
;
370 maxrem
= ULONG_MAX
% base
;
372 while ((digit
= *s
) != '\0')
374 if (digit
>= '0' && digit
< ('0'+base
))
379 if (digit
>= 'a' && digit
< ('a'+(base
-10)))
380 digit
= digit
- 'a' + 10;
381 else if (digit
>= 'A' && digit
< ('A'+(base
-10)))
382 digit
= digit
- 'A' + 10;
390 || (total
== maxdiv
&& digit
> maxrem
))
392 total
= (total
* base
) + digit
;
403 *ptr
= (char *) ((did_conversion
) ? (char *)s
: (char *)start
);
404 return negate
? -total
: total
;
408 void _exit (int foo
) __attribute__ ((noreturn
));