15 extern char *mem2hex (void *mem
, char *buf
, int count
, int may_fault
);
16 extern char *hex2mem (char *buf
, void *mem
, int count
, int may_fault
);
17 extern int computeSignal (int exceptionVector
);
24 /* Get the registers out of the frame information. */
27 frame_to_registers (struct StackFrame
*frame
, char *regs
)
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 (char *regs
, struct StackFrame
*frame
)
47 hex2mem (®s
[GP0_REGNUM
* 4 * 2], &frame
->ExceptionState
.CsavedRegs
, 4 * 32, 0);
49 hex2mem (®s
[FP0_REGNUM
* 4 * 2], &frame
->ExceptionState
.CSavedFPRegs
, 4 * 32, 0);
51 hex2mem (®s
[PC_REGNUM
* 4 * 2], &frame
->ExceptionPC
, 4 * 1, 0);
53 hex2mem (®s
[CR_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedSRR1
, 4 * 1, 0);
54 hex2mem (®s
[LR_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedLR
, 4 * 1, 0);
55 hex2mem (®s
[CTR_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedCTR
, 4 * 1, 0);
56 hex2mem (®s
[XER_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedXER
, 4 * 1, 0);
57 hex2mem (®s
[MQ_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedMQ
, 4 * 1, 0);
61 extern volatile int mem_err
;
63 #ifdef ALTERNATE_MEM_FUNCS
64 extern int ReadByteAltDebugger (char* addr
, char *theByte
);
65 extern int WriteByteAltDebugger (char* addr
, char theByte
);
71 if (!ReadByteAltDebugger (addr
, &c
))
78 set_char (char *addr
, int val
)
80 if (!WriteByteAltDebugger (addr
, val
))
86 mem_write (char *dst
, char *src
, int len
)
88 while (len
-- && !mem_err
)
89 set_char (dst
++, *src
++);
102 struct /* Unconditional branch */
104 unsigned opcode
: 6; /* 18 */
109 struct /* Conditional branch */
111 unsigned opcode
: 6; /* 16 */
118 struct /* Conditional branch to ctr or lr reg */
120 unsigned opcode
: 6; /* 19 */
123 unsigned type
: 15; /* 528 = ctr, 16 = lr */
130 static LONG saved_inst
;
131 static LONG
*saved_inst_pc
= 0;
132 static LONG saved_target_inst
;
133 static LONG
*saved_target_inst_pc
= 0;
136 set_step_traps (struct StackFrame
*frame
)
142 LONG
*pc
= (LONG
*)frame
->ExceptionPC
;
146 opcode
= inst
.inst
.variant
.b
.opcode
;
152 case 18: /* Unconditional branch */
154 if (inst
.inst
.variant
.b
.aa
) /* Absolute? */
156 target
+= inst
.inst
.variant
.b
.li
;
159 case 16: /* Conditional branch */
161 if (!inst
.inst
.variant
.bc
.aa
) /* Absolute? */
163 target
+= inst
.inst
.variant
.bc
.bd
;
166 case 19: /* Cond. branch via ctr or lr reg */
167 switch (inst
.inst
.variant
.bclr
.type
)
170 target
= (LONG
*)frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedCTR
;
173 target
= (LONG
*)frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedLR
;
180 mem_write (pc
, breakpoint_insn
, BREAKPOINT_SIZE
);
185 saved_target_inst
= *target
;
186 mem_write (target
, breakpoint_insn
, BREAKPOINT_SIZE
);
187 saved_target_inst_pc
= target
;
191 /* Remove step breakpoints. Returns non-zero if pc was at a step breakpoint,
192 zero otherwise. This routine works even if there were no step breakpoints
196 clear_step_traps (struct StackFrame
*frame
)
199 LONG
*pc
= (LONG
*)frame
->ExceptionPC
;
201 if (saved_inst_pc
== pc
|| saved_target_inst_pc
== pc
)
208 mem_write (saved_inst_pc
, saved_inst
, BREAKPOINT_SIZE
);
212 if (saved_target_inst_pc
)
214 mem_write (saved_target_inst_pc
, saved_target_inst
, BREAKPOINT_SIZE
);
215 saved_target_inst_pc
= 0;
222 do_status (char *ptr
, struct StackFrame
*frame
)
226 sigval
= computeSignal (frame
->ExceptionNumber
);
228 sprintf (ptr
, "T%02x", sigval
);
231 sprintf (ptr
, "%02x:", PC_REGNUM
);
232 ptr
= mem2hex (&frame
->ExceptionPC
, ptr
+ 3, 4, 0);
235 sprintf (ptr
, "%02x:", SP_REGNUM
);
236 ptr
= mem2hex (&frame
->ExceptionState
.CsavedRegs
[SP_REGNUM
], ptr
+ 3, 4, 0);
239 sprintf (ptr
, "%02x:", LR_REGNUM
);
240 ptr
= mem2hex (&frame
->ExceptionState
.CsavedRegs
[LR_REGNUM
], ptr
+ 3, 4, 0);