Commit | Line | Data |
---|---|---|
d6e9fb05 JK |
1 | /* Low level interface to ptrace, for the remote server for GDB. |
2 | Copyright (C) 1986, 1987, 1993, 2000 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
19 | ||
f29d9b6d | 20 | #include "server.h" |
d6e9fb05 JK |
21 | #include <sys/types.h> |
22 | #include <sys/wait.h> | |
23 | #include "frame.h" | |
24 | #include "inferior.h" | |
25 | ||
26 | #include <stdio.h> | |
27 | #include <errno.h> | |
28 | ||
29 | /***************Begin MY defs*********************/ | |
d6e9fb05 JK |
30 | static char my_registers[REGISTER_BYTES]; |
31 | char *registers = my_registers; | |
d6e9fb05 JK |
32 | /***************End MY defs*********************/ |
33 | ||
34 | #include <sys/ptrace.h> | |
35 | #include <machine/reg.h> | |
36 | ||
9cebe72f C |
37 | #define RF(dst, src) \ |
38 | memcpy(®isters[REGISTER_BYTE(dst)], &src, sizeof(src)) | |
39 | ||
40 | #define RS(src, dst) \ | |
41 | memcpy(&dst, ®isters[REGISTER_BYTE(src)], sizeof(dst)) | |
42 | ||
43 | #ifdef __i386__ | |
44 | struct env387 | |
45 | { | |
46 | unsigned short control; | |
47 | unsigned short r0; | |
48 | unsigned short status; | |
49 | unsigned short r1; | |
50 | unsigned short tag; | |
51 | unsigned short r2; | |
52 | unsigned long eip; | |
53 | unsigned short code_seg; | |
54 | unsigned short opcode; | |
55 | unsigned long operand; | |
56 | unsigned short operand_seg; | |
57 | unsigned short r3; | |
58 | unsigned char regs[8][10]; | |
59 | }; | |
60 | ||
d6e9fb05 JK |
61 | /* i386_register_raw_size[i] is the number of bytes of storage in the |
62 | actual machine representation for register i. */ | |
63 | int i386_register_raw_size[MAX_NUM_REGS] = { | |
64 | 4, 4, 4, 4, | |
65 | 4, 4, 4, 4, | |
66 | 4, 4, 4, 4, | |
67 | 4, 4, 4, 4, | |
68 | 10, 10, 10, 10, | |
69 | 10, 10, 10, 10, | |
70 | 4, 4, 4, 4, | |
71 | 4, 4, 4, 4, | |
72 | 16, 16, 16, 16, | |
73 | 16, 16, 16, 16, | |
74 | 4 | |
75 | }; | |
76 | ||
77 | int i386_register_byte[MAX_NUM_REGS]; | |
78 | ||
79 | static void | |
fba45db2 | 80 | initialize_arch (void) |
d6e9fb05 JK |
81 | { |
82 | /* Initialize the table saying where each register starts in the | |
83 | register file. */ | |
84 | { | |
85 | int i, offset; | |
86 | ||
87 | offset = 0; | |
88 | for (i = 0; i < MAX_NUM_REGS; i++) | |
89 | { | |
90 | i386_register_byte[i] = offset; | |
91 | offset += i386_register_raw_size[i]; | |
92 | } | |
93 | } | |
94 | } | |
9cebe72f | 95 | #endif /* !__i386__ */ |
d6e9fb05 | 96 | |
bd2fa4f6 C |
97 | #ifdef __m68k__ |
98 | static void | |
99 | initialize_arch (void) | |
100 | { | |
101 | } | |
102 | #endif /* !__m68k__ */ | |
103 | ||
104 | #ifdef __ns32k__ | |
105 | static void | |
106 | initialize_arch (void) | |
107 | { | |
108 | } | |
109 | #endif /* !__ns32k__ */ | |
110 | ||
9cebe72f | 111 | #ifdef __powerpc__ |
22c72081 C |
112 | #include "ppc-tdep.h" |
113 | ||
9cebe72f | 114 | static void |
fba45db2 | 115 | initialize_arch (void) |
9cebe72f C |
116 | { |
117 | } | |
118 | #endif /* !__powerpc__ */ | |
d6e9fb05 JK |
119 | |
120 | ||
121 | /* Start an inferior process and returns its pid. | |
bd2fa4f6 | 122 | ALLARGS is a vector of program-name and args. */ |
d6e9fb05 JK |
123 | |
124 | int | |
fba45db2 | 125 | create_inferior (char *program, char **allargs) |
d6e9fb05 JK |
126 | { |
127 | int pid; | |
128 | ||
129 | pid = fork (); | |
130 | if (pid < 0) | |
131 | perror_with_name ("fork"); | |
132 | ||
133 | if (pid == 0) | |
134 | { | |
135 | ptrace (PT_TRACE_ME, 0, 0, 0); | |
136 | ||
137 | execv (program, allargs); | |
138 | ||
139 | fprintf (stderr, "Cannot exec %s: %s.\n", program, | |
140 | errno < sys_nerr ? sys_errlist[errno] : "unknown error"); | |
141 | fflush (stderr); | |
142 | _exit (0177); | |
143 | } | |
144 | ||
145 | return pid; | |
146 | } | |
147 | ||
148 | /* Kill the inferior process. Make us have no inferior. */ | |
149 | ||
150 | void | |
fba45db2 | 151 | kill_inferior (void) |
d6e9fb05 JK |
152 | { |
153 | if (inferior_pid == 0) | |
154 | return; | |
155 | ptrace (PT_KILL, inferior_pid, 0, 0); | |
156 | wait (0); | |
157 | /*************inferior_died ();****VK**************/ | |
158 | } | |
159 | ||
160 | /* Return nonzero if the given thread is still alive. */ | |
161 | int | |
fba45db2 | 162 | mythread_alive (int pid) |
d6e9fb05 JK |
163 | { |
164 | return 1; | |
165 | } | |
166 | ||
167 | /* Wait for process, returns status */ | |
168 | ||
169 | unsigned char | |
fba45db2 | 170 | mywait (char *status) |
d6e9fb05 JK |
171 | { |
172 | int pid; | |
173 | int w; | |
174 | ||
175 | pid = wait (&w); | |
176 | if (pid != inferior_pid) | |
177 | perror_with_name ("wait"); | |
178 | ||
179 | if (WIFEXITED (w)) | |
180 | { | |
181 | fprintf (stderr, "\nChild exited with retcode = %x \n", WEXITSTATUS (w)); | |
182 | *status = 'W'; | |
183 | return ((unsigned char) WEXITSTATUS (w)); | |
184 | } | |
185 | else if (!WIFSTOPPED (w)) | |
186 | { | |
187 | fprintf (stderr, "\nChild terminated with signal = %x \n", WTERMSIG (w)); | |
188 | *status = 'X'; | |
189 | return ((unsigned char) WTERMSIG (w)); | |
190 | } | |
191 | ||
192 | fetch_inferior_registers (0); | |
193 | ||
194 | *status = 'T'; | |
195 | return ((unsigned char) WSTOPSIG (w)); | |
196 | } | |
197 | ||
198 | /* Resume execution of the inferior process. | |
199 | If STEP is nonzero, single-step it. | |
200 | If SIGNAL is nonzero, give it that signal. */ | |
201 | ||
202 | void | |
fba45db2 | 203 | myresume (int step, int signal) |
d6e9fb05 JK |
204 | { |
205 | errno = 0; | |
206 | ptrace (step ? PT_STEP : PT_CONTINUE, inferior_pid, | |
207 | (PTRACE_ARG3_TYPE) 1, signal); | |
208 | if (errno) | |
209 | perror_with_name ("ptrace"); | |
210 | } | |
211 | ||
9cebe72f C |
212 | |
213 | #ifdef __i386__ | |
d6e9fb05 JK |
214 | /* Fetch one or more registers from the inferior. REGNO == -1 to get |
215 | them all. We actually fetch more than requested, when convenient, | |
216 | marking them as valid so we won't fetch them again. */ | |
217 | ||
218 | void | |
fba45db2 | 219 | fetch_inferior_registers (int ignored) |
d6e9fb05 JK |
220 | { |
221 | struct reg inferior_registers; | |
9cebe72f | 222 | struct env387 inferior_fp_registers; |
d6e9fb05 JK |
223 | |
224 | ptrace (PT_GETREGS, inferior_pid, | |
225 | (PTRACE_ARG3_TYPE) &inferior_registers, 0); | |
d6e9fb05 JK |
226 | ptrace (PT_GETFPREGS, inferior_pid, |
227 | (PTRACE_ARG3_TYPE) &inferior_fp_registers, 0); | |
9cebe72f C |
228 | |
229 | RF ( 0, inferior_registers.r_eax); | |
230 | RF ( 1, inferior_registers.r_ecx); | |
231 | RF ( 2, inferior_registers.r_edx); | |
232 | RF ( 3, inferior_registers.r_ebx); | |
233 | RF ( 4, inferior_registers.r_esp); | |
234 | RF ( 5, inferior_registers.r_ebp); | |
235 | RF ( 6, inferior_registers.r_esi); | |
236 | RF ( 7, inferior_registers.r_edi); | |
237 | RF ( 8, inferior_registers.r_eip); | |
238 | RF ( 9, inferior_registers.r_eflags); | |
239 | RF (10, inferior_registers.r_cs); | |
240 | RF (11, inferior_registers.r_ss); | |
241 | RF (12, inferior_registers.r_ds); | |
242 | RF (13, inferior_registers.r_es); | |
243 | RF (14, inferior_registers.r_fs); | |
244 | RF (15, inferior_registers.r_gs); | |
245 | ||
0c9f8a69 C |
246 | RF (FP0_REGNUM, inferior_fp_registers.regs[0]); |
247 | RF (FP0_REGNUM + 1, inferior_fp_registers.regs[1]); | |
248 | RF (FP0_REGNUM + 2, inferior_fp_registers.regs[2]); | |
249 | RF (FP0_REGNUM + 3, inferior_fp_registers.regs[3]); | |
250 | RF (FP0_REGNUM + 4, inferior_fp_registers.regs[4]); | |
251 | RF (FP0_REGNUM + 5, inferior_fp_registers.regs[5]); | |
252 | RF (FP0_REGNUM + 6, inferior_fp_registers.regs[6]); | |
253 | RF (FP0_REGNUM + 7, inferior_fp_registers.regs[7]); | |
9cebe72f | 254 | |
0c9f8a69 C |
255 | RF (FCTRL_REGNUM, inferior_fp_registers.control); |
256 | RF (FSTAT_REGNUM, inferior_fp_registers.status); | |
257 | RF (FTAG_REGNUM, inferior_fp_registers.tag); | |
258 | RF (FCS_REGNUM, inferior_fp_registers.code_seg); | |
259 | RF (FCOFF_REGNUM, inferior_fp_registers.eip); | |
260 | RF (FDS_REGNUM, inferior_fp_registers.operand_seg); | |
261 | RF (FDOFF_REGNUM, inferior_fp_registers.operand); | |
262 | RF (FOP_REGNUM, inferior_fp_registers.opcode); | |
d6e9fb05 JK |
263 | } |
264 | ||
265 | /* Store our register values back into the inferior. | |
266 | If REGNO is -1, do this for all registers. | |
267 | Otherwise, REGNO specifies which register (so we can save time). */ | |
268 | ||
269 | void | |
fba45db2 | 270 | store_inferior_registers (int ignored) |
d6e9fb05 JK |
271 | { |
272 | struct reg inferior_registers; | |
9cebe72f C |
273 | struct env387 inferior_fp_registers; |
274 | ||
275 | RS ( 0, inferior_registers.r_eax); | |
276 | RS ( 1, inferior_registers.r_ecx); | |
277 | RS ( 2, inferior_registers.r_edx); | |
278 | RS ( 3, inferior_registers.r_ebx); | |
279 | RS ( 4, inferior_registers.r_esp); | |
280 | RS ( 5, inferior_registers.r_ebp); | |
281 | RS ( 6, inferior_registers.r_esi); | |
282 | RS ( 7, inferior_registers.r_edi); | |
283 | RS ( 8, inferior_registers.r_eip); | |
284 | RS ( 9, inferior_registers.r_eflags); | |
285 | RS (10, inferior_registers.r_cs); | |
286 | RS (11, inferior_registers.r_ss); | |
287 | RS (12, inferior_registers.r_ds); | |
288 | RS (13, inferior_registers.r_es); | |
289 | RS (14, inferior_registers.r_fs); | |
290 | RS (15, inferior_registers.r_gs); | |
291 | ||
0c9f8a69 C |
292 | RS (FP0_REGNUM, inferior_fp_registers.regs[0]); |
293 | RS (FP0_REGNUM + 1, inferior_fp_registers.regs[1]); | |
294 | RS (FP0_REGNUM + 2, inferior_fp_registers.regs[2]); | |
295 | RS (FP0_REGNUM + 3, inferior_fp_registers.regs[3]); | |
296 | RS (FP0_REGNUM + 4, inferior_fp_registers.regs[4]); | |
297 | RS (FP0_REGNUM + 5, inferior_fp_registers.regs[5]); | |
298 | RS (FP0_REGNUM + 6, inferior_fp_registers.regs[6]); | |
299 | RS (FP0_REGNUM + 7, inferior_fp_registers.regs[7]); | |
9cebe72f | 300 | |
0c9f8a69 C |
301 | RS (FCTRL_REGNUM, inferior_fp_registers.control); |
302 | RS (FSTAT_REGNUM, inferior_fp_registers.status); | |
303 | RS (FTAG_REGNUM, inferior_fp_registers.tag); | |
304 | RS (FCS_REGNUM, inferior_fp_registers.code_seg); | |
305 | RS (FCOFF_REGNUM, inferior_fp_registers.eip); | |
306 | RS (FDS_REGNUM, inferior_fp_registers.operand_seg); | |
307 | RS (FDOFF_REGNUM, inferior_fp_registers.operand); | |
308 | RS (FOP_REGNUM, inferior_fp_registers.opcode); | |
d6e9fb05 | 309 | |
d6e9fb05 JK |
310 | ptrace (PT_SETREGS, inferior_pid, |
311 | (PTRACE_ARG3_TYPE) &inferior_registers, 0); | |
d6e9fb05 JK |
312 | ptrace (PT_SETFPREGS, inferior_pid, |
313 | (PTRACE_ARG3_TYPE) &inferior_fp_registers, 0); | |
d6e9fb05 | 314 | } |
9cebe72f C |
315 | #endif /* !__i386__ */ |
316 | ||
bd2fa4f6 C |
317 | #ifdef __m68k__ |
318 | /* Fetch one or more registers from the inferior. REGNO == -1 to get | |
319 | them all. We actually fetch more than requested, when convenient, | |
320 | marking them as valid so we won't fetch them again. */ | |
321 | ||
322 | void | |
323 | fetch_inferior_registers (int regno) | |
324 | { | |
325 | struct reg inferior_registers; | |
326 | struct fpreg inferior_fp_registers; | |
327 | ||
328 | ptrace (PT_GETREGS, inferior_pid, | |
329 | (PTRACE_ARG3_TYPE) & inferior_registers, 0); | |
330 | memcpy (®isters[REGISTER_BYTE (0)], &inferior_registers, | |
331 | sizeof (inferior_registers)); | |
332 | ||
333 | ptrace (PT_GETFPREGS, inferior_pid, | |
334 | (PTRACE_ARG3_TYPE) & inferior_fp_registers, 0); | |
335 | memcpy (®isters[REGISTER_BYTE (FP0_REGNUM)], &inferior_fp_registers, | |
336 | sizeof (inferior_fp_registers)); | |
337 | } | |
338 | ||
339 | /* Store our register values back into the inferior. | |
340 | If REGNO is -1, do this for all registers. | |
341 | Otherwise, REGNO specifies which register (so we can save time). */ | |
342 | ||
343 | void | |
344 | store_inferior_registers (int regno) | |
345 | { | |
346 | struct reg inferior_registers; | |
347 | struct fpreg inferior_fp_registers; | |
348 | ||
349 | memcpy (&inferior_registers, ®isters[REGISTER_BYTE (0)], | |
350 | sizeof (inferior_registers)); | |
351 | ptrace (PT_SETREGS, inferior_pid, | |
352 | (PTRACE_ARG3_TYPE) & inferior_registers, 0); | |
353 | ||
354 | memcpy (&inferior_fp_registers, ®isters[REGISTER_BYTE (FP0_REGNUM)], | |
355 | sizeof (inferior_fp_registers)); | |
356 | ptrace (PT_SETFPREGS, inferior_pid, | |
357 | (PTRACE_ARG3_TYPE) & inferior_fp_registers, 0); | |
358 | } | |
359 | #endif /* !__m68k__ */ | |
360 | ||
361 | ||
362 | #ifdef __ns32k__ | |
363 | /* Fetch one or more registers from the inferior. REGNO == -1 to get | |
364 | them all. We actually fetch more than requested, when convenient, | |
365 | marking them as valid so we won't fetch them again. */ | |
366 | ||
367 | void | |
368 | fetch_inferior_registers (int regno) | |
369 | { | |
370 | struct reg inferior_registers; | |
371 | struct fpreg inferior_fpregisters; | |
372 | ||
373 | ptrace (PT_GETREGS, inferior_pid, | |
374 | (PTRACE_ARG3_TYPE) & inferior_registers, 0); | |
375 | ptrace (PT_GETFPREGS, inferior_pid, | |
376 | (PTRACE_ARG3_TYPE) & inferior_fpregisters, 0); | |
377 | ||
378 | RF (R0_REGNUM + 0, inferior_registers.r_r0); | |
379 | RF (R0_REGNUM + 1, inferior_registers.r_r1); | |
380 | RF (R0_REGNUM + 2, inferior_registers.r_r2); | |
381 | RF (R0_REGNUM + 3, inferior_registers.r_r3); | |
382 | RF (R0_REGNUM + 4, inferior_registers.r_r4); | |
383 | RF (R0_REGNUM + 5, inferior_registers.r_r5); | |
384 | RF (R0_REGNUM + 6, inferior_registers.r_r6); | |
385 | RF (R0_REGNUM + 7, inferior_registers.r_r7); | |
386 | ||
387 | RF (SP_REGNUM, inferior_registers.r_sp); | |
388 | RF (FP_REGNUM, inferior_registers.r_fp); | |
389 | RF (PC_REGNUM, inferior_registers.r_pc); | |
390 | RF (PS_REGNUM, inferior_registers.r_psr); | |
391 | ||
392 | RF (FPS_REGNUM, inferior_fpregisters.r_fsr); | |
393 | RF (FP0_REGNUM + 0, inferior_fpregisters.r_freg[0]); | |
394 | RF (FP0_REGNUM + 2, inferior_fpregisters.r_freg[2]); | |
395 | RF (FP0_REGNUM + 4, inferior_fpregisters.r_freg[4]); | |
396 | RF (FP0_REGNUM + 6, inferior_fpregisters.r_freg[6]); | |
397 | RF (LP0_REGNUM + 1, inferior_fpregisters.r_freg[1]); | |
398 | RF (LP0_REGNUM + 3, inferior_fpregisters.r_freg[3]); | |
399 | RF (LP0_REGNUM + 5, inferior_fpregisters.r_freg[5]); | |
400 | RF (LP0_REGNUM + 7, inferior_fpregisters.r_freg[7]); | |
401 | } | |
402 | ||
403 | /* Store our register values back into the inferior. | |
404 | If REGNO is -1, do this for all registers. | |
405 | Otherwise, REGNO specifies which register (so we can save time). */ | |
406 | ||
407 | void | |
408 | store_inferior_registers (int regno) | |
409 | { | |
410 | struct reg inferior_registers; | |
411 | struct fpreg inferior_fpregisters; | |
412 | ||
413 | RS (R0_REGNUM + 0, inferior_registers.r_r0); | |
414 | RS (R0_REGNUM + 1, inferior_registers.r_r1); | |
415 | RS (R0_REGNUM + 2, inferior_registers.r_r2); | |
416 | RS (R0_REGNUM + 3, inferior_registers.r_r3); | |
417 | RS (R0_REGNUM + 4, inferior_registers.r_r4); | |
418 | RS (R0_REGNUM + 5, inferior_registers.r_r5); | |
419 | RS (R0_REGNUM + 6, inferior_registers.r_r6); | |
420 | RS (R0_REGNUM + 7, inferior_registers.r_r7); | |
421 | ||
422 | RS (SP_REGNUM, inferior_registers.r_sp); | |
423 | RS (FP_REGNUM, inferior_registers.r_fp); | |
424 | RS (PC_REGNUM, inferior_registers.r_pc); | |
425 | RS (PS_REGNUM, inferior_registers.r_psr); | |
426 | ||
427 | RS (FPS_REGNUM, inferior_fpregisters.r_fsr); | |
428 | RS (FP0_REGNUM + 0, inferior_fpregisters.r_freg[0]); | |
429 | RS (FP0_REGNUM + 2, inferior_fpregisters.r_freg[2]); | |
430 | RS (FP0_REGNUM + 4, inferior_fpregisters.r_freg[4]); | |
431 | RS (FP0_REGNUM + 6, inferior_fpregisters.r_freg[6]); | |
432 | RS (LP0_REGNUM + 1, inferior_fpregisters.r_freg[1]); | |
433 | RS (LP0_REGNUM + 3, inferior_fpregisters.r_freg[3]); | |
434 | RS (LP0_REGNUM + 5, inferior_fpregisters.r_freg[5]); | |
435 | RS (LP0_REGNUM + 7, inferior_fpregisters.r_freg[7]); | |
436 | ||
437 | ptrace (PT_SETREGS, inferior_pid, | |
438 | (PTRACE_ARG3_TYPE) & inferior_registers, 0); | |
439 | ptrace (PT_SETFPREGS, inferior_pid, | |
440 | (PTRACE_ARG3_TYPE) & inferior_fpregisters, 0); | |
441 | ||
442 | } | |
443 | #endif /* !__ns32k__ */ | |
444 | ||
9cebe72f C |
445 | #ifdef __powerpc__ |
446 | /* Fetch one or more registers from the inferior. REGNO == -1 to get | |
447 | them all. We actually fetch more than requested, when convenient, | |
448 | marking them as valid so we won't fetch them again. */ | |
449 | ||
450 | void | |
fba45db2 | 451 | fetch_inferior_registers (int regno) |
9cebe72f C |
452 | { |
453 | struct reg inferior_registers; | |
22c72081 | 454 | #ifdef PT_GETFPREGS |
9cebe72f | 455 | struct fpreg inferior_fp_registers; |
22c72081 | 456 | #endif |
9cebe72f C |
457 | int i; |
458 | ||
459 | ptrace (PT_GETREGS, inferior_pid, | |
460 | (PTRACE_ARG3_TYPE) & inferior_registers, 0); | |
9cebe72f C |
461 | for (i = 0; i < 32; i++) |
462 | RF (i, inferior_registers.fixreg[i]); | |
22c72081 C |
463 | RF (PPC_LR_REGNUM, inferior_registers.lr); |
464 | RF (PPC_CR_REGNUM, inferior_registers.cr); | |
465 | RF (PPC_XER_REGNUM, inferior_registers.xer); | |
466 | RF (PPC_CTR_REGNUM, inferior_registers.ctr); | |
9cebe72f C |
467 | RF (PC_REGNUM, inferior_registers.pc); |
468 | ||
22c72081 C |
469 | #ifdef PT_GETFPREGS |
470 | ptrace (PT_GETFPREGS, inferior_pid, | |
471 | (PTRACE_ARG3_TYPE) & inferior_fp_registers, 0); | |
9cebe72f C |
472 | for (i = 0; i < 32; i++) |
473 | RF (FP0_REGNUM + i, inferior_fp_registers.r_regs[i]); | |
22c72081 | 474 | #endif |
9cebe72f C |
475 | } |
476 | ||
477 | /* Store our register values back into the inferior. | |
478 | If REGNO is -1, do this for all registers. | |
479 | Otherwise, REGNO specifies which register (so we can save time). */ | |
480 | ||
481 | void | |
fba45db2 | 482 | store_inferior_registers (int regno) |
9cebe72f C |
483 | { |
484 | struct reg inferior_registers; | |
22c72081 | 485 | #ifdef PT_SETFPREGS |
9cebe72f | 486 | struct fpreg inferior_fp_registers; |
22c72081 | 487 | #endif |
9cebe72f C |
488 | int i; |
489 | ||
490 | for (i = 0; i < 32; i++) | |
491 | RS (i, inferior_registers.fixreg[i]); | |
22c72081 C |
492 | RS (PPC_LR_REGNUM, inferior_registers.lr); |
493 | RS (PPC_CR_REGNUM, inferior_registers.cr); | |
494 | RS (PPC_XER_REGNUM, inferior_registers.xer); | |
495 | RS (PPC_CTR_REGNUM, inferior_registers.ctr); | |
9cebe72f | 496 | RS (PC_REGNUM, inferior_registers.pc); |
22c72081 C |
497 | ptrace (PT_SETREGS, inferior_pid, |
498 | (PTRACE_ARG3_TYPE) & inferior_registers, 0); | |
9cebe72f | 499 | |
22c72081 | 500 | #ifdef PT_SETFPREGS |
9cebe72f C |
501 | for (i = 0; i < 32; i++) |
502 | RS (FP0_REGNUM + i, inferior_fp_registers.r_regs[i]); | |
9cebe72f C |
503 | ptrace (PT_SETFPREGS, inferior_pid, |
504 | (PTRACE_ARG3_TYPE) & inferior_fp_registers, 0); | |
22c72081 | 505 | #endif |
9cebe72f C |
506 | } |
507 | #endif /* !__powerpc__ */ | |
d6e9fb05 JK |
508 | |
509 | /* NOTE! I tried using PTRACE_READDATA, etc., to read and write memory | |
510 | in the NEW_SUN_PTRACE case. | |
511 | It ought to be straightforward. But it appears that writing did | |
512 | not write the data that I specified. I cannot understand where | |
513 | it got the data that it actually did write. */ | |
514 | ||
515 | /* Copy LEN bytes from inferior's memory starting at MEMADDR | |
516 | to debugger memory starting at MYADDR. */ | |
517 | ||
fba45db2 | 518 | read_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len) |
d6e9fb05 JK |
519 | { |
520 | register int i; | |
521 | /* Round starting address down to longword boundary. */ | |
522 | register CORE_ADDR addr = memaddr & -sizeof (int); | |
523 | /* Round ending address up; get number of longwords that makes. */ | |
524 | register int count | |
525 | = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int); | |
526 | /* Allocate buffer of that many longwords. */ | |
527 | register int *buffer = (int *) alloca (count * sizeof (int)); | |
528 | ||
529 | /* Read all the longwords */ | |
530 | for (i = 0; i < count; i++, addr += sizeof (int)) | |
531 | { | |
532 | buffer[i] = ptrace (PT_READ_D, inferior_pid, (PTRACE_ARG3_TYPE) addr, 0); | |
533 | } | |
534 | ||
535 | /* Copy appropriate bytes out of the buffer. */ | |
536 | memcpy (myaddr, (char *) buffer + (memaddr & (sizeof (int) - 1)), len); | |
537 | } | |
538 | ||
539 | /* Copy LEN bytes of data from debugger memory at MYADDR | |
540 | to inferior's memory at MEMADDR. | |
541 | On failure (cannot write the inferior) | |
542 | returns the value of errno. */ | |
543 | ||
544 | int | |
fba45db2 | 545 | write_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len) |
d6e9fb05 JK |
546 | { |
547 | register int i; | |
548 | /* Round starting address down to longword boundary. */ | |
549 | register CORE_ADDR addr = memaddr & -sizeof (int); | |
550 | /* Round ending address up; get number of longwords that makes. */ | |
551 | register int count | |
552 | = (((memaddr + len) - addr) + sizeof (int) - 1) / sizeof (int); | |
553 | /* Allocate buffer of that many longwords. */ | |
554 | register int *buffer = (int *) alloca (count * sizeof (int)); | |
555 | extern int errno; | |
556 | ||
557 | /* Fill start and end extra bytes of buffer with existing memory data. */ | |
558 | ||
559 | buffer[0] = ptrace (PT_READ_D, inferior_pid, (PTRACE_ARG3_TYPE) addr, 0); | |
560 | ||
561 | if (count > 1) | |
562 | { | |
563 | buffer[count - 1] | |
564 | = ptrace (PT_READ_D, inferior_pid, | |
565 | (PTRACE_ARG3_TYPE) addr + (count - 1) * sizeof (int), 0); | |
566 | } | |
567 | ||
568 | /* Copy data to be written over corresponding part of buffer */ | |
569 | ||
570 | memcpy ((char *) buffer + (memaddr & (sizeof (int) - 1)), myaddr, len); | |
571 | ||
572 | /* Write the entire buffer. */ | |
573 | ||
574 | for (i = 0; i < count; i++, addr += sizeof (int)) | |
575 | { | |
576 | errno = 0; | |
577 | ptrace (PT_WRITE_D, inferior_pid, (PTRACE_ARG3_TYPE) addr, buffer[i]); | |
578 | if (errno) | |
579 | return errno; | |
580 | } | |
581 | ||
582 | return 0; | |
583 | } | |
584 | \f | |
585 | void | |
fba45db2 | 586 | initialize_low (void) |
d6e9fb05 JK |
587 | { |
588 | initialize_arch (); | |
589 | } |