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 (frame
, regs
)
28 struct StackFrame
*frame
;
31 mem2hex (&frame
->ExceptionState
.CsavedRegs
, ®s
[GP0_REGNUM
* 4 * 2], 4 * 32, 0);
33 mem2hex (&frame
->ExceptionState
.CSavedFPRegs
, ®s
[FP0_REGNUM
* 4 * 2], 4 * 32, 0);
35 mem2hex (&frame
->ExceptionPC
, ®s
[PC_REGNUM
* 4 * 2], 4 * 1, 0);
37 mem2hex (&frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedSRR1
, ®s
[CR_REGNUM
* 4 * 2], 4 * 1, 0);
38 mem2hex (&frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedLR
, ®s
[LR_REGNUM
* 4 * 2], 4 * 1, 0);
39 mem2hex (&frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedCTR
, ®s
[CTR_REGNUM
* 4 * 2], 4 * 1, 0);
40 mem2hex (&frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedXER
, ®s
[XER_REGNUM
* 4 * 2], 4 * 1, 0);
41 mem2hex (&frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedMQ
, ®s
[MQ_REGNUM
* 4 * 2], 4 * 1, 0);
44 /* Put the registers back into the frame information. */
47 registers_to_frame (regs
, frame
)
49 struct StackFrame
*frame
;
51 hex2mem (®s
[GP0_REGNUM
* 4 * 2], &frame
->ExceptionState
.CsavedRegs
, 4 * 32, 0);
53 hex2mem (®s
[FP0_REGNUM
* 4 * 2], &frame
->ExceptionState
.CSavedFPRegs
, 4 * 32, 0);
55 hex2mem (®s
[PC_REGNUM
* 4 * 2], &frame
->ExceptionPC
, 4 * 1, 0);
57 hex2mem (®s
[CR_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedSRR1
, 4 * 1, 0);
58 hex2mem (®s
[LR_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedLR
, 4 * 1, 0);
59 hex2mem (®s
[CTR_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedCTR
, 4 * 1, 0);
60 hex2mem (®s
[XER_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedXER
, 4 * 1, 0);
61 hex2mem (®s
[MQ_REGNUM
* 4 * 2], &frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedMQ
, 4 * 1, 0);
64 extern int ReadByteAltDebugger (char* addr
, char *theByte
);
66 extern int WriteByteAltDebugger (char* addr
, char theByte
);
68 extern volatile int mem_err
;
76 if (!ReadByteAltDebugger (addr
, &c
))
87 if (!WriteByteAltDebugger (addr
, val
))
92 mem_write (dst
, src
, len
)
96 while (len
-- && !mem_err
)
97 set_char (dst
++, *src
++);
110 struct /* Unconditional branch */
112 unsigned opcode
: 6; /* 18 */
117 struct /* Conditional branch */
119 unsigned opcode
: 6; /* 16 */
126 struct /* Conditional branch to ctr or lr reg */
128 unsigned opcode
: 6; /* 19 */
131 unsigned type
: 15; /* 528 = ctr, 16 = lr */
138 static LONG saved_inst
;
139 static LONG
*saved_inst_pc
= 0;
140 static LONG saved_target_inst
;
141 static LONG
*saved_target_inst_pc
= 0;
144 set_step_traps (frame
)
145 struct StackFrame
*frame
;
151 LONG
*pc
= (LONG
*)frame
->ExceptionPC
;
155 opcode
= inst
.inst
.variant
.b
.opcode
;
161 case 18: /* Unconditional branch */
163 if (inst
.inst
.variant
.b
.aa
) /* Absolute? */
165 target
+= inst
.inst
.variant
.b
.li
;
168 case 16: /* Conditional branch */
170 if (!inst
.inst
.variant
.bc
.aa
) /* Absolute? */
172 target
+= inst
.inst
.variant
.bc
.bd
;
175 case 19: /* Cond. branch via ctr or lr reg */
176 switch (inst
.inst
.variant
.bclr
.type
)
179 target
= (LONG
*)frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedCTR
;
182 target
= (LONG
*)frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedLR
;
189 mem_write (pc
, breakpoint_insn
, BREAKPOINT_SIZE
);
194 saved_target_inst
= *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 LONG
*pc
= (LONG
*)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);