Obsolete stuff.c and kdb-start.c.
[deliverable/binutils-gdb.git] / gdb / i386bsd-nat.c
CommitLineData
e6031aeb 1/* Native-dependent code for modern i386 BSD's.
4e052eda 2 Copyright 2000, 2001 Free Software Foundation, Inc.
e6031aeb
MK
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,
19 Boston, MA 02111-1307, USA. */
20
21#include "defs.h"
22#include "inferior.h"
4e052eda 23#include "regcache.h"
e6031aeb
MK
24
25#include <sys/types.h>
26#include <sys/ptrace.h>
27#include <machine/reg.h>
28#include <machine/frame.h>
29
30#ifdef HAVE_SYS_PROCFS_H
31#include <sys/procfs.h>
32#endif
33
34#ifndef HAVE_GREGSET_T
35typedef struct reg gregset_t;
36#endif
37
38#ifndef HAVE_FPREGSET_T
39typedef struct fpreg fpregset_t;
40#endif
41
b051bfa4
MK
42#include "gregset.h"
43\f
44
e6031aeb
MK
45/* In older BSD versions we cannot get at some of the segment
46 registers. FreeBSD for example didn't support the %fs and %gs
47 registers until the 3.0 release. We have autoconf checks for their
48 presence, and deal gracefully with their absence. */
49
50/* Registers we shouldn't try to fetch. */
51#if !defined (CANNOT_FETCH_REGISTER)
52#define CANNOT_FETCH_REGISTER(regno) cannot_fetch_register (regno)
53#endif
54
55/* Registers we shouldn't try to store. */
56#if !defined (CANNOT_STORE_REGISTER)
b051bfa4 57#define CANNOT_STORE_REGISTER(regno) cannot_fetch_register (regno)
e6031aeb
MK
58#endif
59
60/* Offset to the gregset_t location where REG is stored. */
61#define REG_OFFSET(reg) offsetof (gregset_t, reg)
62
63/* At reg_offset[REGNO] you'll find the offset to the gregset_t
64 location where the GDB register REGNO is stored. Unsupported
65 registers are marked with `-1'. */
66static int reg_offset[] =
67{
68 REG_OFFSET (r_eax),
69 REG_OFFSET (r_ecx),
70 REG_OFFSET (r_edx),
71 REG_OFFSET (r_edx),
72 REG_OFFSET (r_esp),
73 REG_OFFSET (r_ebp),
74 REG_OFFSET (r_esi),
75 REG_OFFSET (r_edi),
76 REG_OFFSET (r_eip),
77 REG_OFFSET (r_eflags),
78 REG_OFFSET (r_cs),
79 REG_OFFSET (r_ss),
80 REG_OFFSET (r_ds),
81 REG_OFFSET (r_es),
422ea4b8 82#ifdef HAVE_STRUCT_REG_R_FS
e6031aeb
MK
83 REG_OFFSET (r_fs),
84#else
85 -1,
86#endif
422ea4b8 87#ifdef HAVE_STRUCT_REG_R_GS
e6031aeb
MK
88 REG_OFFSET (r_gs)
89#else
90 -1
91#endif
92};
93
94#define REG_ADDR(regset, regno) ((char *) (regset) + reg_offset[regno])
95
96/* Return nonzero if we shouldn't try to fetch register REGNO. */
97
98static int
99cannot_fetch_register (int regno)
100{
101 return (reg_offset[regno] == -1);
102}
103\f
104
105/* Transfering the registers between GDB, inferiors and core files. */
106
ad2a4d09 107/* Fill GDB's register array with the general-purpose register values
e6031aeb
MK
108 in *GREGSETP. */
109
110void
111supply_gregset (gregset_t *gregsetp)
112{
e6031aeb
MK
113 int i;
114
115 for (i = 0; i < NUM_GREGS; i++)
116 {
117 if (CANNOT_FETCH_REGISTER (i))
b051bfa4 118 supply_register (i, NULL);
e6031aeb
MK
119 else
120 supply_register (i, REG_ADDR (gregsetp, i));
121 }
122}
123
124/* Fill register REGNO (if it is a general-purpose register) in
125 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
126 do this for all registers. */
127
128void
129fill_gregset (gregset_t *gregsetp, int regno)
130{
131 int i;
132
133 for (i = 0; i < NUM_GREGS; i++)
134 if ((regno == -1 || regno == i) && ! CANNOT_STORE_REGISTER (i))
b051bfa4 135 memcpy (REG_ADDR (gregsetp, i), &registers[REGISTER_BYTE (i)],
e6031aeb
MK
136 REGISTER_RAW_SIZE (i));
137}
138
139#include "i387-nat.h"
140
141/* Fill GDB's register array with the floating-point register values
142 in *FPREGSETP. */
143
144void
145supply_fpregset (fpregset_t *fpregsetp)
146{
147 i387_supply_fsave ((char *) fpregsetp);
148}
149
150/* Fill register REGNO (if it is a floating-point register) in
151 *FPREGSETP with the value in GDB's register array. If REGNO is -1,
152 do this for all registers. */
153
154void
155fill_fpregset (fpregset_t *fpregsetp, int regno)
156{
157 i387_fill_fsave ((char *) fpregsetp, regno);
158}
159
160/* Fetch register REGNO from the inferior. If REGNO is -1, do this
161 for all registers (including the floating point registers). */
162
163void
164fetch_inferior_registers (int regno)
165{
166 gregset_t gregs;
167
168 if (ptrace (PT_GETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &gregs, 0) == -1)
169 perror_with_name ("Couldn't get registers");
170
171 supply_gregset (&gregs);
172
173 if (regno == -1 || regno >= FP0_REGNUM)
174 {
175 fpregset_t fpregs;
176
177 if (ptrace (PT_GETFPREGS, inferior_pid,
178 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
179 perror_with_name ("Couldn't get floating point status");
180
181 supply_fpregset (&fpregs);
182 }
b051bfa4 183}
e6031aeb
MK
184
185/* Store register REGNO back into the inferior. If REGNO is -1, do
186 this for all registers (including the floating point registers). */
187
188void
189store_inferior_registers (int regno)
190{
191 gregset_t gregs;
192
193 if (ptrace (PT_GETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &gregs, 0) == -1)
194 perror_with_name ("Couldn't get registers");
195
196 fill_gregset (&gregs, regno);
197
198 if (ptrace (PT_SETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &gregs, 0) == -1)
199 perror_with_name ("Couldn't write registers");
200
201 if (regno == -1 || regno >= FP0_REGNUM)
202 {
203 fpregset_t fpregs;
204
205 if (ptrace (PT_GETFPREGS, inferior_pid,
206 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
207 perror_with_name ("Couldn't get floating point status");
208
209 fill_fpregset (&fpregs, regno);
210
211 if (ptrace (PT_SETFPREGS, inferior_pid,
212 (PTRACE_ARG3_TYPE) &fpregs, 0) == -1)
213 perror_with_name ("Couldn't write floating point status");
214 }
215}
216\f
217
218/* Support for the user struct. */
219
220/* Return the address register REGNO. BLOCKEND is the value of
221 u.u_ar0, which should point to the registers. */
222
223CORE_ADDR
224register_u_addr (CORE_ADDR blockend, int regno)
225{
226 return (CORE_ADDR) REG_ADDR (blockend, regno);
227}
228
229#include <sys/param.h>
230#include <sys/user.h>
231
232/* Return the size of the user struct. */
233
234int
235kernel_u_size (void)
236{
237 return (sizeof (struct user));
238}
This page took 0.071018 seconds and 4 git commands to generate.