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);
65 extern volatile int mem_err
;
67 #ifdef ALTERNATE_MEM_FUNCS
68 extern int ReadByteAltDebugger (char* addr
, char *theByte
);
69 extern int WriteByteAltDebugger (char* addr
, char theByte
);
76 if (!ReadByteAltDebugger (addr
, &c
))
87 if (!WriteByteAltDebugger (addr
, val
))
93 mem_write (dst
, src
, len
)
97 while (len
-- && !mem_err
)
98 set_char (dst
++, *src
++);
111 struct /* Unconditional branch */
113 unsigned opcode
: 6; /* 18 */
118 struct /* Conditional branch */
120 unsigned opcode
: 6; /* 16 */
127 struct /* Conditional branch to ctr or lr reg */
129 unsigned opcode
: 6; /* 19 */
132 unsigned type
: 15; /* 528 = ctr, 16 = lr */
139 static LONG saved_inst
;
140 static LONG
*saved_inst_pc
= 0;
141 static LONG saved_target_inst
;
142 static LONG
*saved_target_inst_pc
= 0;
145 set_step_traps (frame
)
146 struct StackFrame
*frame
;
152 LONG
*pc
= (LONG
*)frame
->ExceptionPC
;
156 opcode
= inst
.inst
.variant
.b
.opcode
;
162 case 18: /* Unconditional branch */
164 if (inst
.inst
.variant
.b
.aa
) /* Absolute? */
166 target
+= inst
.inst
.variant
.b
.li
;
169 case 16: /* Conditional branch */
171 if (!inst
.inst
.variant
.bc
.aa
) /* Absolute? */
173 target
+= inst
.inst
.variant
.bc
.bd
;
176 case 19: /* Cond. branch via ctr or lr reg */
177 switch (inst
.inst
.variant
.bclr
.type
)
180 target
= (LONG
*)frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedCTR
;
183 target
= (LONG
*)frame
->ExceptionState
.u
.SpecialRegistersEnumerated
.CsavedLR
;
190 mem_write (pc
, breakpoint_insn
, BREAKPOINT_SIZE
);
195 saved_target_inst
= *target
;
196 mem_write (target
, breakpoint_insn
, BREAKPOINT_SIZE
);
197 saved_target_inst_pc
= target
;
201 /* Remove step breakpoints. Returns non-zero if pc was at a step breakpoint,
202 zero otherwise. This routine works even if there were no step breakpoints
206 clear_step_traps (frame
)
207 struct StackFrame
*frame
;
210 LONG
*pc
= (LONG
*)frame
->ExceptionPC
;
212 if (saved_inst_pc
== pc
|| saved_target_inst_pc
== pc
)
219 mem_write (saved_inst_pc
, saved_inst
, BREAKPOINT_SIZE
);
223 if (saved_target_inst_pc
)
225 mem_write (saved_target_inst_pc
, saved_target_inst
, BREAKPOINT_SIZE
);
226 saved_target_inst_pc
= 0;
233 do_status (ptr
, frame
)
235 struct StackFrame
*frame
;
239 sigval
= computeSignal (frame
->ExceptionNumber
);
241 sprintf (ptr
, "T%02x", sigval
);
244 sprintf (ptr
, "%02x:", PC_REGNUM
);
245 ptr
= mem2hex (&frame
->ExceptionPC
, ptr
+ 3, 4, 0);
248 sprintf (ptr
, "%02x:", SP_REGNUM
);
249 ptr
= mem2hex (&frame
->ExceptionState
.CsavedRegs
[SP_REGNUM
], ptr
+ 3, 4, 0);
252 sprintf (ptr
, "%02x:", LR_REGNUM
);
253 ptr
= mem2hex (&frame
->ExceptionState
.CsavedRegs
[LR_REGNUM
], ptr
+ 3, 4, 0);