2000-05-29 Philip Blundell <philb@gnu.org>
[deliverable/binutils-gdb.git] / gdb / i386bsd-nat.c
CommitLineData
e6031aeb
MK
1/* Native-dependent code for modern i386 BSD's.
2 Copyright (C) 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,
19 Boston, MA 02111-1307, USA. */
20
21#include "defs.h"
22#include "inferior.h"
23
24#include <sys/types.h>
25#include <sys/ptrace.h>
26#include <machine/reg.h>
27#include <machine/frame.h>
28
29#ifdef HAVE_SYS_PROCFS_H
30#include <sys/procfs.h>
31#endif
32
33#ifndef HAVE_GREGSET_T
34typedef struct reg gregset_t;
35#endif
36
37#ifndef HAVE_FPREGSET_T
38typedef struct fpreg fpregset_t;
39#endif
40
41/* In older BSD versions we cannot get at some of the segment
42 registers. FreeBSD for example didn't support the %fs and %gs
43 registers until the 3.0 release. We have autoconf checks for their
44 presence, and deal gracefully with their absence. */
45
46/* Registers we shouldn't try to fetch. */
47#if !defined (CANNOT_FETCH_REGISTER)
48#define CANNOT_FETCH_REGISTER(regno) cannot_fetch_register (regno)
49#endif
50
51/* Registers we shouldn't try to store. */
52#if !defined (CANNOT_STORE_REGISTER)
53#define CANNOT_STORE_REGISTER(regno) CANNOT_FETCH_REGISTER (regno)
54#endif
55
56/* Offset to the gregset_t location where REG is stored. */
57#define REG_OFFSET(reg) offsetof (gregset_t, reg)
58
59/* At reg_offset[REGNO] you'll find the offset to the gregset_t
60 location where the GDB register REGNO is stored. Unsupported
61 registers are marked with `-1'. */
62static int reg_offset[] =
63{
64 REG_OFFSET (r_eax),
65 REG_OFFSET (r_ecx),
66 REG_OFFSET (r_edx),
67 REG_OFFSET (r_edx),
68 REG_OFFSET (r_esp),
69 REG_OFFSET (r_ebp),
70 REG_OFFSET (r_esi),
71 REG_OFFSET (r_edi),
72 REG_OFFSET (r_eip),
73 REG_OFFSET (r_eflags),
74 REG_OFFSET (r_cs),
75 REG_OFFSET (r_ss),
76 REG_OFFSET (r_ds),
77 REG_OFFSET (r_es),
78#ifdef HAVE_R_FS
79 REG_OFFSET (r_fs),
80#else
81 -1,
82#endif
83#ifdef HAVE_R_GS
84 REG_OFFSET (r_gs)
85#else
86 -1
87#endif
88};
89
90#define REG_ADDR(regset, regno) ((char *) (regset) + reg_offset[regno])
91
92/* Return nonzero if we shouldn't try to fetch register REGNO. */
93
94static int
95cannot_fetch_register (int regno)
96{
97 return (reg_offset[regno] == -1);
98}
99\f
100
101/* Transfering the registers between GDB, inferiors and core files. */
102
103/* Fill GDB's register array with the genereal-purpose register values
104 in *GREGSETP. */
105
106void
107supply_gregset (gregset_t *gregsetp)
108{
109 char buf[MAX_REGISTER_RAW_SIZE];
110 int i;
111
112 for (i = 0; i < NUM_GREGS; i++)
113 {
114 if (CANNOT_FETCH_REGISTER (i))
115 {
116 memset (buf, 0, REGISTER_RAW_SIZE (i));
117 supply_register (i, buf);
118 }
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))
135 memcpy (REG_ADDR (gregsetp, i), &registers[REGISTER_BYTE (regno)],
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 }
183}
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.0445 seconds and 4 git commands to generate.