1 /* Native-dependent code for modern i386 BSD's.
2 Copyright (C) 2000 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., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
24 #include <sys/types.h>
25 #include <sys/ptrace.h>
26 #include <machine/reg.h>
27 #include <machine/frame.h>
29 #ifdef HAVE_SYS_PROCFS_H
30 #include <sys/procfs.h>
33 #ifndef HAVE_GREGSET_T
34 typedef struct reg gregset_t
;
37 #ifndef HAVE_FPREGSET_T
38 typedef struct fpreg fpregset_t
;
44 /* In older BSD versions we cannot get at some of the segment
45 registers. FreeBSD for example didn't support the %fs and %gs
46 registers until the 3.0 release. We have autoconf checks for their
47 presence, and deal gracefully with their absence. */
49 /* Registers we shouldn't try to fetch. */
50 #if !defined (CANNOT_FETCH_REGISTER)
51 #define CANNOT_FETCH_REGISTER(regno) cannot_fetch_register (regno)
54 /* Registers we shouldn't try to store. */
55 #if !defined (CANNOT_STORE_REGISTER)
56 #define CANNOT_STORE_REGISTER(regno) cannot_fetch_register (regno)
59 /* Offset to the gregset_t location where REG is stored. */
60 #define REG_OFFSET(reg) offsetof (gregset_t, reg)
62 /* At reg_offset[REGNO] you'll find the offset to the gregset_t
63 location where the GDB register REGNO is stored. Unsupported
64 registers are marked with `-1'. */
65 static int reg_offset
[] =
76 REG_OFFSET (r_eflags
),
81 #ifdef HAVE_STRUCT_REG_R_FS
86 #ifdef HAVE_STRUCT_REG_R_GS
93 #define REG_ADDR(regset, regno) ((char *) (regset) + reg_offset[regno])
95 /* Return nonzero if we shouldn't try to fetch register REGNO. */
98 cannot_fetch_register (int regno
)
100 return (reg_offset
[regno
] == -1);
104 /* Transfering the registers between GDB, inferiors and core files. */
106 /* Fill GDB's register array with the genereal-purpose register values
110 supply_gregset (gregset_t
*gregsetp
)
114 for (i
= 0; i
< NUM_GREGS
; i
++)
116 if (CANNOT_FETCH_REGISTER (i
))
117 supply_register (i
, NULL
);
119 supply_register (i
, REG_ADDR (gregsetp
, i
));
123 /* Fill register REGNO (if it is a general-purpose register) in
124 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
125 do this for all registers. */
128 fill_gregset (gregset_t
*gregsetp
, int regno
)
132 for (i
= 0; i
< NUM_GREGS
; i
++)
133 if ((regno
== -1 || regno
== i
) && ! CANNOT_STORE_REGISTER (i
))
134 memcpy (REG_ADDR (gregsetp
, i
), ®isters
[REGISTER_BYTE (i
)],
135 REGISTER_RAW_SIZE (i
));
138 #include "i387-nat.h"
140 /* Fill GDB's register array with the floating-point register values
144 supply_fpregset (fpregset_t
*fpregsetp
)
146 i387_supply_fsave ((char *) fpregsetp
);
149 /* Fill register REGNO (if it is a floating-point register) in
150 *FPREGSETP with the value in GDB's register array. If REGNO is -1,
151 do this for all registers. */
154 fill_fpregset (fpregset_t
*fpregsetp
, int regno
)
156 i387_fill_fsave ((char *) fpregsetp
, regno
);
159 /* Fetch register REGNO from the inferior. If REGNO is -1, do this
160 for all registers (including the floating point registers). */
163 fetch_inferior_registers (int regno
)
167 if (ptrace (PT_GETREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) &gregs
, 0) == -1)
168 perror_with_name ("Couldn't get registers");
170 supply_gregset (&gregs
);
172 if (regno
== -1 || regno
>= FP0_REGNUM
)
176 if (ptrace (PT_GETFPREGS
, inferior_pid
,
177 (PTRACE_ARG3_TYPE
) &fpregs
, 0) == -1)
178 perror_with_name ("Couldn't get floating point status");
180 supply_fpregset (&fpregs
);
184 /* Store register REGNO back into the inferior. If REGNO is -1, do
185 this for all registers (including the floating point registers). */
188 store_inferior_registers (int regno
)
192 if (ptrace (PT_GETREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) &gregs
, 0) == -1)
193 perror_with_name ("Couldn't get registers");
195 fill_gregset (&gregs
, regno
);
197 if (ptrace (PT_SETREGS
, inferior_pid
, (PTRACE_ARG3_TYPE
) &gregs
, 0) == -1)
198 perror_with_name ("Couldn't write registers");
200 if (regno
== -1 || regno
>= FP0_REGNUM
)
204 if (ptrace (PT_GETFPREGS
, inferior_pid
,
205 (PTRACE_ARG3_TYPE
) &fpregs
, 0) == -1)
206 perror_with_name ("Couldn't get floating point status");
208 fill_fpregset (&fpregs
, regno
);
210 if (ptrace (PT_SETFPREGS
, inferior_pid
,
211 (PTRACE_ARG3_TYPE
) &fpregs
, 0) == -1)
212 perror_with_name ("Couldn't write floating point status");
217 /* Support for the user struct. */
219 /* Return the address register REGNO. BLOCKEND is the value of
220 u.u_ar0, which should point to the registers. */
223 register_u_addr (CORE_ADDR blockend
, int regno
)
225 return (CORE_ADDR
) REG_ADDR (blockend
, regno
);
228 #include <sys/param.h>
229 #include <sys/user.h>
231 /* Return the size of the user struct. */
236 return (sizeof (struct user
));