1 /* IBM RS/6000 native-dependent code for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include <sys/ptrace.h>
28 #include <sys/param.h>
32 #include <sys/ioctl.h>
43 exec_one_dummy_insn
PARAMS ((void));
45 /* Conversion from gdb-to-system special purpose register numbers.. */
47 static int special_regs
[] = {
58 fetch_inferior_registers (regno
)
62 extern char registers
[];
64 if (regno
< 0) { /* for all registers */
66 /* read 32 general purpose registers. */
68 for (ii
=0; ii
< 32; ++ii
)
69 *(int*)®isters
[REGISTER_BYTE (ii
)] =
70 ptrace (PT_READ_GPR
, inferior_pid
, (PTRACE_ARG3_TYPE
) ii
, 0, 0);
72 /* read general purpose floating point registers. */
74 for (ii
=0; ii
< 32; ++ii
)
75 ptrace (PT_READ_FPR
, inferior_pid
,
76 (PTRACE_ARG3_TYPE
) ®isters
[REGISTER_BYTE (FP0_REGNUM
+ii
)],
79 /* read special registers. */
80 for (ii
=0; ii
<= LAST_SP_REGNUM
-FIRST_SP_REGNUM
; ++ii
)
81 *(int*)®isters
[REGISTER_BYTE (FIRST_SP_REGNUM
+ii
)] =
82 ptrace (PT_READ_GPR
, inferior_pid
, (PTRACE_ARG3_TYPE
) special_regs
[ii
],
89 /* else an individual register is addressed. */
91 else if (regno
< FP0_REGNUM
) { /* a GPR */
92 *(int*)®isters
[REGISTER_BYTE (regno
)] =
93 ptrace (PT_READ_GPR
, inferior_pid
, (PTRACE_ARG3_TYPE
) regno
, 0, 0);
95 else if (regno
<= FPLAST_REGNUM
) { /* a FPR */
96 ptrace (PT_READ_FPR
, inferior_pid
,
97 (PTRACE_ARG3_TYPE
) ®isters
[REGISTER_BYTE (regno
)],
98 (regno
-FP0_REGNUM
+FPR0
), 0);
100 else if (regno
<= LAST_SP_REGNUM
) { /* a special register */
101 *(int*)®isters
[REGISTER_BYTE (regno
)] =
102 ptrace (PT_READ_GPR
, inferior_pid
,
103 (PTRACE_ARG3_TYPE
) special_regs
[regno
-FIRST_SP_REGNUM
], 0, 0);
106 fprintf (stderr
, "gdb error: register no %d not implemented.\n", regno
);
108 register_valid
[regno
] = 1;
111 /* Store our register values back into the inferior.
112 If REGNO is -1, do this for all registers.
113 Otherwise, REGNO specifies which register (so we can save time). */
116 store_inferior_registers (regno
)
119 extern char registers
[];
123 if (regno
== -1) { /* for all registers.. */
126 /* execute one dummy instruction (which is a breakpoint) in inferior
127 process. So give kernel a chance to do internal house keeping.
128 Otherwise the following ptrace(2) calls will mess up user stack
129 since kernel will get confused about the bottom of the stack (%sp) */
131 exec_one_dummy_insn ();
133 /* write general purpose registers first! */
134 for ( ii
=GPR0
; ii
<=GPR31
; ++ii
) {
135 ptrace (PT_WRITE_GPR
, inferior_pid
, (PTRACE_ARG3_TYPE
) ii
,
136 *(int*)®isters
[REGISTER_BYTE (ii
)], 0);
138 perror ("ptrace write_gpr"); errno
= 0;
142 /* write floating point registers now. */
143 for ( ii
=0; ii
< 32; ++ii
) {
144 ptrace (PT_WRITE_FPR
, inferior_pid
,
145 (PTRACE_ARG3_TYPE
) ®isters
[REGISTER_BYTE (FP0_REGNUM
+ii
)],
148 perror ("ptrace write_fpr"); errno
= 0;
152 /* write special registers. */
153 for (ii
=0; ii
<= LAST_SP_REGNUM
-FIRST_SP_REGNUM
; ++ii
) {
154 ptrace (PT_WRITE_GPR
, inferior_pid
,
155 (PTRACE_ARG3_TYPE
) special_regs
[ii
],
156 *(int*)®isters
[REGISTER_BYTE (FIRST_SP_REGNUM
+ii
)], 0);
158 perror ("ptrace write_gpr"); errno
= 0;
163 /* else, a specific register number is given... */
165 else if (regno
< FP0_REGNUM
) { /* a GPR */
167 ptrace (PT_WRITE_GPR
, inferior_pid
, (PTRACE_ARG3_TYPE
) regno
,
168 *(int*)®isters
[REGISTER_BYTE (regno
)], 0);
171 else if (regno
<= FPLAST_REGNUM
) { /* a FPR */
172 ptrace (PT_WRITE_FPR
, inferior_pid
,
173 (PTRACE_ARG3_TYPE
) ®isters
[REGISTER_BYTE (regno
)],
174 regno
-FP0_REGNUM
+FPR0
, 0);
177 else if (regno
<= LAST_SP_REGNUM
) { /* a special register */
179 ptrace (PT_WRITE_GPR
, inferior_pid
,
180 (PTRACE_ARG3_TYPE
) special_regs
[regno
-FIRST_SP_REGNUM
],
181 *(int*)®isters
[REGISTER_BYTE (regno
)], 0);
185 fprintf (stderr
, "Gdb error: register no %d not implemented.\n", regno
);
188 perror ("ptrace write"); errno
= 0;
192 /* Execute one dummy breakpoint instruction. This way we give the kernel
193 a chance to do some housekeeping and update inferior's internal data,
196 exec_one_dummy_insn ()
198 #define DUMMY_INSN_ADDR (TEXT_SEGMENT_BASE)+0x200
200 unsigned long shadow
;
201 unsigned int status
, pid
;
203 /* We plant one dummy breakpoint into DUMMY_INSN_ADDR address. We assume that
204 this address will never be executed again by the real code. */
206 target_insert_breakpoint (DUMMY_INSN_ADDR
, &shadow
);
209 ptrace (PT_CONTINUE
, inferior_pid
, (PTRACE_ARG3_TYPE
) DUMMY_INSN_ADDR
, 0, 0);
211 perror ("pt_continue");
214 pid
= wait (&status
);
215 } while (pid
!= inferior_pid
);
217 target_remove_breakpoint (DUMMY_INSN_ADDR
, &shadow
);
221 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
223 unsigned core_reg_size
;
225 unsigned int reg_addr
; /* Unused in this version */
227 /* fetch GPRs and special registers from the first register section
231 /* copy GPRs first. */
232 bcopy (core_reg_sect
, registers
, 32 * 4);
234 /* gdb's internal register template and bfd's register section layout
235 should share a common include file. FIXMEmgo */
236 /* then comes special registes. They are supposed to be in the same
237 order in gdb template and bfd `.reg' section. */
238 core_reg_sect
+= (32 * 4);
239 bcopy (core_reg_sect
, ®isters
[REGISTER_BYTE (FIRST_SP_REGNUM
)],
240 (LAST_SP_REGNUM
- FIRST_SP_REGNUM
+ 1) * 4);
243 /* fetch floating point registers from register section 2 in core bfd. */
245 bcopy (core_reg_sect
, ®isters
[REGISTER_BYTE (FP0_REGNUM
)], 32 * 8);
248 fprintf (stderr
, "Gdb error: unknown parameter to fetch_core_registers().\n");
This page took 0.03415 seconds and 4 git commands to generate.