Commit | Line | Data |
---|---|---|
b7da2494 SG |
1 | #include <stdio.h> |
2 | #include <string.h> | |
3 | #include <stdlib.h> | |
4 | #include <time.h> | |
9db29b17 C |
5 | #include <errno.h> |
6 | ||
7 | #include <nwtypes.h> | |
8 | #include <nwdfs.h> | |
b7da2494 SG |
9 | #include <nwconio.h> |
10 | #include <nwadv.h> | |
11 | #include <nwdbgapi.h> | |
b7da2494 SG |
12 | #include <nwthread.h> |
13 | #include "ppc.h" | |
14 | ||
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); | |
18 | ||
19 | void | |
20 | flush_i_cache (void) | |
21 | { | |
22 | } | |
23 | ||
24 | /* Get the registers out of the frame information. */ | |
25 | ||
26 | void | |
27 | frame_to_registers (frame, regs) | |
28 | struct StackFrame *frame; | |
29 | char *regs; | |
30 | { | |
31 | mem2hex (&frame->ExceptionState.CsavedRegs, ®s[GP0_REGNUM * 4 * 2], 4 * 32, 0); | |
32 | ||
33 | mem2hex (&frame->ExceptionState.CSavedFPRegs, ®s[FP0_REGNUM * 4 * 2], 4 * 32, 0); | |
34 | ||
35 | mem2hex (&frame->ExceptionPC, ®s[PC_REGNUM * 4 * 2], 4 * 1, 0); | |
36 | ||
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); | |
42 | } | |
43 | ||
44 | /* Put the registers back into the frame information. */ | |
45 | ||
46 | void | |
47 | registers_to_frame (regs, frame) | |
48 | char *regs; | |
49 | struct StackFrame *frame; | |
50 | { | |
51 | hex2mem (®s[GP0_REGNUM * 4 * 2], &frame->ExceptionState.CsavedRegs, 4 * 32, 0); | |
52 | ||
53 | hex2mem (®s[FP0_REGNUM * 4 * 2], &frame->ExceptionState.CSavedFPRegs, 4 * 32, 0); | |
54 | ||
55 | hex2mem (®s[PC_REGNUM * 4 * 2], &frame->ExceptionPC, 4 * 1, 0); | |
56 | ||
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); | |
62 | } | |
63 | ||
64 | extern int ReadByteAltDebugger (char* addr, char *theByte); | |
65 | ||
66 | extern int WriteByteAltDebugger (char* addr, char theByte); | |
67 | ||
68 | extern volatile int mem_err; | |
69 | ||
70 | int | |
71 | get_char (addr) | |
72 | char *addr; | |
73 | { | |
74 | char c; | |
75 | ||
76 | if (!ReadByteAltDebugger (addr, &c)) | |
77 | mem_err = 1; | |
78 | ||
79 | return c; | |
80 | } | |
81 | ||
82 | void | |
83 | set_char (addr, val) | |
84 | char *addr; | |
85 | int val; | |
86 | { | |
87 | if (!WriteByteAltDebugger (addr, val)) | |
88 | mem_err = 1; | |
89 | } | |
90 | ||
91 | int | |
92 | mem_write (dst, src, len) | |
93 | char *dst, *src; | |
94 | int len; | |
95 | { | |
96 | while (len-- && !mem_err) | |
97 | set_char (dst++, *src++); | |
98 | ||
99 | return mem_err; | |
100 | } | |
101 | ||
102 | union inst | |
103 | { | |
104 | LONG l; | |
105 | ||
106 | struct | |
107 | { | |
108 | union | |
109 | { | |
110 | struct /* Unconditional branch */ | |
111 | { | |
112 | unsigned opcode : 6; /* 18 */ | |
113 | signed li : 24; | |
114 | unsigned aa : 1; | |
115 | unsigned lk : 1; | |
116 | } b; | |
117 | struct /* Conditional branch */ | |
118 | { | |
119 | unsigned opcode : 6; /* 16 */ | |
120 | unsigned bo : 5; | |
121 | unsigned bi : 5; | |
122 | signed bd : 14; | |
123 | unsigned aa : 1; | |
124 | unsigned lk : 1; | |
125 | } bc; | |
126 | struct /* Conditional branch to ctr or lr reg */ | |
127 | { | |
128 | unsigned opcode : 6; /* 19 */ | |
129 | unsigned bo : 5; | |
130 | unsigned bi : 5; | |
131 | unsigned type : 15; /* 528 = ctr, 16 = lr */ | |
132 | unsigned lk : 1; | |
133 | } bclr; | |
134 | } variant; | |
135 | } inst; | |
136 | }; | |
137 | ||
138 | static LONG saved_inst; | |
8edf0016 | 139 | static LONG *saved_inst_pc = 0; |
b7da2494 | 140 | static LONG saved_target_inst; |
8edf0016 | 141 | static LONG *saved_target_inst_pc = 0; |
b7da2494 SG |
142 | |
143 | void | |
144 | set_step_traps (frame) | |
145 | struct StackFrame *frame; | |
146 | { | |
147 | union inst inst; | |
8edf0016 | 148 | LONG *target; |
b7da2494 SG |
149 | int opcode; |
150 | int ra, rb; | |
8edf0016 | 151 | LONG *pc = (LONG *)frame->ExceptionPC; |
b7da2494 | 152 | |
8edf0016 | 153 | inst.l = *pc++; |
b7da2494 SG |
154 | |
155 | opcode = inst.inst.variant.b.opcode; | |
156 | ||
8edf0016 SG |
157 | target = pc; |
158 | ||
b7da2494 SG |
159 | switch (opcode) |
160 | { | |
161 | case 18: /* Unconditional branch */ | |
b7da2494 | 162 | |
8edf0016 SG |
163 | if (inst.inst.variant.b.aa) /* Absolute? */ |
164 | target = 0; | |
165 | target += inst.inst.variant.b.li; | |
b7da2494 SG |
166 | |
167 | break; | |
168 | case 16: /* Conditional branch */ | |
b7da2494 | 169 | |
8edf0016 SG |
170 | if (!inst.inst.variant.bc.aa) /* Absolute? */ |
171 | target = 0; | |
172 | target += inst.inst.variant.bc.bd; | |
b7da2494 SG |
173 | |
174 | break; | |
175 | case 19: /* Cond. branch via ctr or lr reg */ | |
176 | switch (inst.inst.variant.bclr.type) | |
177 | { | |
178 | case 528: /* ctr */ | |
8edf0016 | 179 | target = (LONG *)frame->ExceptionState.u.SpecialRegistersEnumerated.CsavedCTR; |
b7da2494 SG |
180 | break; |
181 | case 16: /* lr */ | |
8edf0016 | 182 | target = (LONG *)frame->ExceptionState.u.SpecialRegistersEnumerated.CsavedLR; |
b7da2494 | 183 | break; |
b7da2494 SG |
184 | } |
185 | break; | |
b7da2494 SG |
186 | } |
187 | ||
8edf0016 | 188 | saved_inst = *pc; |
b7da2494 SG |
189 | mem_write (pc, breakpoint_insn, BREAKPOINT_SIZE); |
190 | saved_inst_pc = pc; | |
191 | ||
192 | if (target != pc) | |
193 | { | |
8edf0016 | 194 | saved_target_inst = *target; |
b7da2494 SG |
195 | mem_write (target, breakpoint_insn, BREAKPOINT_SIZE); |
196 | saved_target_inst_pc = target; | |
197 | } | |
198 | } | |
199 | ||
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 | |
202 | set. */ | |
203 | ||
204 | int | |
205 | clear_step_traps (frame) | |
206 | struct StackFrame *frame; | |
207 | { | |
208 | int retcode; | |
8edf0016 | 209 | LONG *pc = (LONG *)frame->ExceptionPC; |
b7da2494 SG |
210 | |
211 | if (saved_inst_pc == pc || saved_target_inst_pc == pc) | |
212 | retcode = 1; | |
213 | else | |
214 | retcode = 0; | |
215 | ||
216 | if (saved_inst_pc) | |
217 | { | |
218 | mem_write (saved_inst_pc, saved_inst, BREAKPOINT_SIZE); | |
219 | saved_inst_pc = 0; | |
220 | } | |
221 | ||
222 | if (saved_target_inst_pc) | |
223 | { | |
224 | mem_write (saved_target_inst_pc, saved_target_inst, BREAKPOINT_SIZE); | |
225 | saved_target_inst_pc = 0; | |
226 | } | |
227 | ||
228 | return retcode; | |
229 | } | |
230 | ||
231 | void | |
232 | do_status (ptr, frame) | |
233 | char *ptr; | |
234 | struct StackFrame *frame; | |
235 | { | |
236 | int sigval; | |
237 | ||
238 | sigval = computeSignal (frame->ExceptionNumber); | |
239 | ||
240 | sprintf (ptr, "T%02x", sigval); | |
241 | ptr += 3; | |
242 | ||
243 | sprintf (ptr, "%02x:", PC_REGNUM); | |
244 | ptr = mem2hex (&frame->ExceptionPC, ptr + 3, 4, 0); | |
245 | *ptr++ = ';'; | |
246 | ||
247 | sprintf (ptr, "%02x:", SP_REGNUM); | |
248 | ptr = mem2hex (&frame->ExceptionState.CsavedRegs[SP_REGNUM], ptr + 3, 4, 0); | |
249 | *ptr++ = ';'; | |
250 | ||
251 | sprintf (ptr, "%02x:", LR_REGNUM); | |
252 | ptr = mem2hex (&frame->ExceptionState.CsavedRegs[LR_REGNUM], ptr + 3, 4, 0); | |
253 | *ptr++ = ';'; | |
254 | ||
255 | *ptr = '\000'; | |
256 | } | |
257 | ||
b7da2494 | 258 | void |
9db29b17 | 259 | StopBell() |
b7da2494 | 260 | { |
b7da2494 | 261 | } |