1 /* Functions specific to running gdb native on a SPARC running SunOS4.
2 Copyright 1989, 1992, 1993, 1994, 1996, 1997, 1998, 1999, 2000, 2001,
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
29 #ifdef HAVE_SYS_PARAM_H
30 #include <sys/param.h>
33 #include <sys/ptrace.h>
38 #include <machine/reg.h>
42 /* We don't store all registers immediately when requested, since they
43 get sent over in large chunks anyway. Instead, we accumulate most
44 of the changes and send them over once. "deferred_stores" keeps
45 track of which sets of registers we have locally-changed copies of,
46 so we only need send the groups that have changed. */
52 /* Fetch one or more registers from the inferior. REGNO == -1 to get
53 them all. We actually fetch more than requested, when convenient,
54 marking them as valid so we won't fetch them again. */
57 fetch_inferior_registers (int regno
)
59 struct regs inferior_registers
;
60 struct fp_status inferior_fp_registers
;
64 /* NOTE: cagney/2002-12-03: This code assumes that the currently
65 selected light weight processes' registers can be written
66 directly into the selected thread's register cache. This works
67 fine when given an 1:1 LWP:thread model (such as found on
68 GNU/Linux) but will, likely, have problems when used on an N:1
69 (userland threads) or N:M (userland multiple LWP) model. In the
70 case of the latter two, the LWP's registers do not necessarily
71 belong to the selected thread (the LWP could be in the middle of
72 executing the thread switch code).
74 These functions should instead be paramaterized with an explicit
75 object (struct regcache, struct thread_info?) into which the LWPs
76 registers can be written. */
78 fetch_pid
= TIDGET (inferior_ptid
);
80 fetch_pid
= PIDGET (inferior_ptid
);
82 /* We should never be called with deferred stores, because a prerequisite
83 for writing regs is to have fetched them all (PREPARE_TO_STORE), sigh. */
85 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
89 /* Global and Out regs are fetched directly, as well as the control
90 registers. If we're getting one of the in or local regs,
91 and the stack pointer has not yet been fetched,
92 we have to do that first, since they're found in memory relative
93 to the stack pointer. */
94 if (regno
< O7_REGNUM
/* including -1 */
96 || (!deprecated_register_valid
[SP_REGNUM
] && regno
< I7_REGNUM
))
98 if (0 != ptrace (PTRACE_GETREGS
, fetch_pid
,
99 (PTRACE_ARG3_TYPE
) & inferior_registers
, 0))
100 perror ("ptrace_getregs");
102 deprecated_registers
[REGISTER_BYTE (0)] = 0;
103 memcpy (&deprecated_registers
[REGISTER_BYTE (1)],
104 &inferior_registers
.r_g1
, 15 * REGISTER_RAW_SIZE (G0_REGNUM
));
105 *(int *) &deprecated_registers
[REGISTER_BYTE (PS_REGNUM
)]
106 = inferior_registers
.r_ps
;
107 *(int *) &deprecated_registers
[REGISTER_BYTE (PC_REGNUM
)]
108 = inferior_registers
.r_pc
;
109 *(int *) &deprecated_registers
[REGISTER_BYTE (NPC_REGNUM
)]
110 = inferior_registers
.r_npc
;
111 *(int *) ®isters
[REGISTER_BYTE (Y_REGNUM
)] = inferior_registers
.r_y
;
113 for (i
= G0_REGNUM
; i
<= O7_REGNUM
; i
++)
114 deprecated_register_valid
[i
] = 1;
115 deprecated_register_valid
[Y_REGNUM
] = 1;
116 deprecated_register_valid
[PS_REGNUM
] = 1;
117 deprecated_register_valid
[PC_REGNUM
] = 1;
118 deprecated_register_valid
[NPC_REGNUM
] = 1;
119 /* If we don't set these valid, read_register_bytes() rereads
120 all the regs every time it is called! FIXME. */
121 deprecated_register_valid
[WIM_REGNUM
] = 1; /* Not true yet, FIXME */
122 deprecated_register_valid
[TBR_REGNUM
] = 1; /* Not true yet, FIXME */
123 deprecated_register_valid
[CPS_REGNUM
] = 1; /* Not true yet, FIXME */
126 /* Floating point registers */
128 regno
== FPS_REGNUM
||
129 (regno
>= FP0_REGNUM
&& regno
<= FP0_REGNUM
+ 31))
131 if (0 != ptrace (PTRACE_GETFPREGS
, fetch_pid
,
132 (PTRACE_ARG3_TYPE
) & inferior_fp_registers
,
134 perror ("ptrace_getfpregs");
135 memcpy (&deprecated_registers
[REGISTER_BYTE (FP0_REGNUM
)],
136 &inferior_fp_registers
, sizeof inferior_fp_registers
.fpu_fr
);
137 memcpy (&deprecated_registers
[REGISTER_BYTE (FPS_REGNUM
)],
138 &inferior_fp_registers
.Fpu_fsr
, sizeof (FPU_FSR_TYPE
));
139 for (i
= FP0_REGNUM
; i
<= FP0_REGNUM
+ 31; i
++)
140 deprecated_register_valid
[i
] = 1;
141 deprecated_register_valid
[FPS_REGNUM
] = 1;
144 /* These regs are saved on the stack by the kernel. Only read them
145 all (16 ptrace calls!) if we really need them. */
148 CORE_ADDR sp
= *(unsigned int *) & deprecated_registers
[REGISTER_BYTE (SP_REGNUM
)];
149 target_read_memory (sp
, &deprecated_registers
[REGISTER_BYTE (L0_REGNUM
)],
150 16 * REGISTER_RAW_SIZE (L0_REGNUM
));
151 for (i
= L0_REGNUM
; i
<= I7_REGNUM
; i
++)
152 deprecated_register_valid
[i
] = 1;
154 else if (regno
>= L0_REGNUM
&& regno
<= I7_REGNUM
)
156 CORE_ADDR sp
= *(unsigned int *) & deprecated_registers
[REGISTER_BYTE (SP_REGNUM
)];
157 i
= REGISTER_BYTE (regno
);
158 if (deprecated_register_valid
[regno
])
159 printf_unfiltered ("register %d valid and read\n", regno
);
160 target_read_memory (sp
+ i
- REGISTER_BYTE (L0_REGNUM
),
161 &deprecated_registers
[i
], REGISTER_RAW_SIZE (regno
));
162 deprecated_register_valid
[regno
] = 1;
166 /* Store our register values back into the inferior.
167 If REGNO is -1, do this for all registers.
168 Otherwise, REGNO specifies which register (so we can save time). */
171 store_inferior_registers (int regno
)
173 struct regs inferior_registers
;
174 struct fp_status inferior_fp_registers
;
175 int wanna_store
= INT_REGS
+ STACK_REGS
+ FP_REGS
;
178 /* NOTE: cagney/2002-12-02: See comment in fetch_inferior_registers
179 about threaded assumptions. */
180 store_pid
= TIDGET (inferior_ptid
);
182 store_pid
= PIDGET (inferior_ptid
);
184 /* First decide which pieces of machine-state we need to modify.
185 Default for regno == -1 case is all pieces. */
188 if (FP0_REGNUM
<= regno
&& regno
< FP0_REGNUM
+ 32)
190 wanna_store
= FP_REGS
;
194 if (regno
== SP_REGNUM
)
195 wanna_store
= INT_REGS
+ STACK_REGS
;
196 else if (regno
< L0_REGNUM
|| regno
> I7_REGNUM
)
197 wanna_store
= INT_REGS
;
198 else if (regno
== FPS_REGNUM
)
199 wanna_store
= FP_REGS
;
201 wanna_store
= STACK_REGS
;
205 /* See if we're forcing the stores to happen now, or deferring. */
208 wanna_store
= deferred_stores
;
213 if (wanna_store
== STACK_REGS
)
215 /* Fall through and just store one stack reg. If we deferred
216 it, we'd have to store them all, or remember more info. */
220 deferred_stores
|= wanna_store
;
225 if (wanna_store
& STACK_REGS
)
227 CORE_ADDR sp
= *(unsigned int *) & deprecated_registers
[REGISTER_BYTE (SP_REGNUM
)];
229 if (regno
< 0 || regno
== SP_REGNUM
)
231 if (!deprecated_register_valid
[L0_REGNUM
+ 5])
232 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
233 target_write_memory (sp
,
234 &deprecated_registers
[REGISTER_BYTE (L0_REGNUM
)],
235 16 * REGISTER_RAW_SIZE (L0_REGNUM
));
239 if (!deprecated_register_valid
[regno
])
240 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
241 target_write_memory (sp
+ REGISTER_BYTE (regno
) - REGISTER_BYTE (L0_REGNUM
),
242 &deprecated_registers
[REGISTER_BYTE (regno
)],
243 REGISTER_RAW_SIZE (regno
));
248 if (wanna_store
& INT_REGS
)
250 if (!deprecated_register_valid
[G1_REGNUM
])
251 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
253 memcpy (&inferior_registers
.r_g1
,
254 &deprecated_registers
[REGISTER_BYTE (G1_REGNUM
)],
255 15 * REGISTER_RAW_SIZE (G1_REGNUM
));
257 inferior_registers
.r_ps
=
258 *(int *) &deprecated_registers
[REGISTER_BYTE (PS_REGNUM
)];
259 inferior_registers
.r_pc
=
260 *(int *) &deprecated_registers
[REGISTER_BYTE (PC_REGNUM
)];
261 inferior_registers
.r_npc
=
262 *(int *) &deprecated_registers
[REGISTER_BYTE (NPC_REGNUM
)];
263 inferior_registers
.r_y
=
264 *(int *) &deprecated_registers
[REGISTER_BYTE (Y_REGNUM
)];
266 if (0 != ptrace (PTRACE_SETREGS
, store_pid
,
267 (PTRACE_ARG3_TYPE
) & inferior_registers
, 0))
268 perror ("ptrace_setregs");
271 if (wanna_store
& FP_REGS
)
273 if (!deprecated_register_valid
[FP0_REGNUM
+ 9])
274 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
275 memcpy (&inferior_fp_registers
,
276 &deprecated_registers
[REGISTER_BYTE (FP0_REGNUM
)],
277 sizeof inferior_fp_registers
.fpu_fr
);
278 memcpy (&inferior_fp_registers
.Fpu_fsr
,
279 &deprecated_registers
[REGISTER_BYTE (FPS_REGNUM
)],
280 sizeof (FPU_FSR_TYPE
));
282 ptrace (PTRACE_SETFPREGS
, store_pid
,
283 (PTRACE_ARG3_TYPE
) & inferior_fp_registers
, 0))
284 perror ("ptrace_setfpregs");
288 /* Provide registers to GDB from a core file.
290 CORE_REG_SECT points to an array of bytes, which are the contents
291 of a `note' from a core file which BFD thinks might contain
292 register contents. CORE_REG_SIZE is its size.
294 WHICH says which register set corelow suspects this is:
295 0 --- the general-purpose register set
296 2 --- the floating-point register set
301 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
,
302 int which
, CORE_ADDR ignore
)
308 /* Integer registers */
310 #define gregs ((struct regs *)core_reg_sect)
311 /* G0 *always* holds 0. */
312 *(int *) &deprecated_registers
[REGISTER_BYTE (0)] = 0;
314 /* The globals and output registers. */
315 memcpy (&deprecated_registers
[REGISTER_BYTE (G1_REGNUM
)], &gregs
->r_g1
,
316 15 * REGISTER_RAW_SIZE (G1_REGNUM
));
317 *(int *) &deprecated_registers
[REGISTER_BYTE (PS_REGNUM
)] = gregs
->r_ps
;
318 *(int *) &deprecated_registers
[REGISTER_BYTE (PC_REGNUM
)] = gregs
->r_pc
;
319 *(int *) &deprecated_registers
[REGISTER_BYTE (NPC_REGNUM
)] = gregs
->r_npc
;
320 *(int *) &deprecated_registers
[REGISTER_BYTE (Y_REGNUM
)] = gregs
->r_y
;
322 /* My best guess at where to get the locals and input
323 registers is exactly where they usually are, right above
324 the stack pointer. If the core dump was caused by a bus error
325 from blowing away the stack pointer (as is possible) then this
326 won't work, but it's worth the try. */
330 sp
= *(int *) &deprecated_registers
[REGISTER_BYTE (SP_REGNUM
)];
331 if (0 != target_read_memory (sp
,
332 &deprecated_registers
[REGISTER_BYTE (L0_REGNUM
)],
333 16 * REGISTER_RAW_SIZE (L0_REGNUM
)))
335 /* fprintf_unfiltered so user can still use gdb */
336 fprintf_unfiltered (gdb_stderr
,
337 "Couldn't read input and local registers from core file\n");
344 /* Floating point registers */
346 #define fpuregs ((struct fpu *) core_reg_sect)
347 if (core_reg_size
>= sizeof (struct fpu
))
349 memcpy (&deprecated_registers
[REGISTER_BYTE (FP0_REGNUM
)],
350 fpuregs
->fpu_regs
, sizeof (fpuregs
->fpu_regs
));
351 memcpy (&deprecated_registers
[REGISTER_BYTE (FPS_REGNUM
)],
352 &fpuregs
->fpu_fsr
, sizeof (FPU_FSR_TYPE
));
355 fprintf_unfiltered (gdb_stderr
, "Couldn't read float regs from core file\n");
362 return (sizeof (struct user
));
366 /* Register that we are able to handle sparc core file formats.
367 FIXME: is this really bfd_target_unknown_flavour? */
369 static struct core_fns sparc_core_fns
=
371 bfd_target_unknown_flavour
, /* core_flavour */
372 default_check_format
, /* check_format */
373 default_core_sniffer
, /* core_sniffer */
374 fetch_core_registers
, /* core_read_registers */
379 _initialize_core_sparc (void)
381 add_core_fns (&sparc_core_fns
);