Commit | Line | Data |
---|---|---|
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 | |
34 | typedef struct reg gregset_t; | |
35 | #endif | |
36 | ||
37 | #ifndef HAVE_FPREGSET_T | |
38 | typedef struct fpreg fpregset_t; | |
39 | #endif | |
40 | ||
b051bfa4 MK |
41 | #include "gregset.h" |
42 | \f | |
43 | ||
e6031aeb MK |
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. */ | |
48 | ||
49 | /* Registers we shouldn't try to fetch. */ | |
50 | #if !defined (CANNOT_FETCH_REGISTER) | |
51 | #define CANNOT_FETCH_REGISTER(regno) cannot_fetch_register (regno) | |
52 | #endif | |
53 | ||
54 | /* Registers we shouldn't try to store. */ | |
55 | #if !defined (CANNOT_STORE_REGISTER) | |
b051bfa4 | 56 | #define CANNOT_STORE_REGISTER(regno) cannot_fetch_register (regno) |
e6031aeb MK |
57 | #endif |
58 | ||
59 | /* Offset to the gregset_t location where REG is stored. */ | |
60 | #define REG_OFFSET(reg) offsetof (gregset_t, reg) | |
61 | ||
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[] = | |
66 | { | |
67 | REG_OFFSET (r_eax), | |
68 | REG_OFFSET (r_ecx), | |
69 | REG_OFFSET (r_edx), | |
70 | REG_OFFSET (r_edx), | |
71 | REG_OFFSET (r_esp), | |
72 | REG_OFFSET (r_ebp), | |
73 | REG_OFFSET (r_esi), | |
74 | REG_OFFSET (r_edi), | |
75 | REG_OFFSET (r_eip), | |
76 | REG_OFFSET (r_eflags), | |
77 | REG_OFFSET (r_cs), | |
78 | REG_OFFSET (r_ss), | |
79 | REG_OFFSET (r_ds), | |
80 | REG_OFFSET (r_es), | |
422ea4b8 | 81 | #ifdef HAVE_STRUCT_REG_R_FS |
e6031aeb MK |
82 | REG_OFFSET (r_fs), |
83 | #else | |
84 | -1, | |
85 | #endif | |
422ea4b8 | 86 | #ifdef HAVE_STRUCT_REG_R_GS |
e6031aeb MK |
87 | REG_OFFSET (r_gs) |
88 | #else | |
89 | -1 | |
90 | #endif | |
91 | }; | |
92 | ||
93 | #define REG_ADDR(regset, regno) ((char *) (regset) + reg_offset[regno]) | |
94 | ||
95 | /* Return nonzero if we shouldn't try to fetch register REGNO. */ | |
96 | ||
97 | static int | |
98 | cannot_fetch_register (int regno) | |
99 | { | |
100 | return (reg_offset[regno] == -1); | |
101 | } | |
102 | \f | |
103 | ||
104 | /* Transfering the registers between GDB, inferiors and core files. */ | |
105 | ||
106 | /* Fill GDB's register array with the genereal-purpose register values | |
107 | in *GREGSETP. */ | |
108 | ||
109 | void | |
110 | supply_gregset (gregset_t *gregsetp) | |
111 | { | |
e6031aeb MK |
112 | int i; |
113 | ||
114 | for (i = 0; i < NUM_GREGS; i++) | |
115 | { | |
116 | if (CANNOT_FETCH_REGISTER (i)) | |
b051bfa4 | 117 | supply_register (i, NULL); |
e6031aeb MK |
118 | else |
119 | supply_register (i, REG_ADDR (gregsetp, i)); | |
120 | } | |
121 | } | |
122 | ||
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. */ | |
126 | ||
127 | void | |
128 | fill_gregset (gregset_t *gregsetp, int regno) | |
129 | { | |
130 | int i; | |
131 | ||
132 | for (i = 0; i < NUM_GREGS; i++) | |
133 | if ((regno == -1 || regno == i) && ! CANNOT_STORE_REGISTER (i)) | |
b051bfa4 | 134 | memcpy (REG_ADDR (gregsetp, i), ®isters[REGISTER_BYTE (i)], |
e6031aeb MK |
135 | REGISTER_RAW_SIZE (i)); |
136 | } | |
137 | ||
138 | #include "i387-nat.h" | |
139 | ||
140 | /* Fill GDB's register array with the floating-point register values | |
141 | in *FPREGSETP. */ | |
142 | ||
143 | void | |
144 | supply_fpregset (fpregset_t *fpregsetp) | |
145 | { | |
146 | i387_supply_fsave ((char *) fpregsetp); | |
147 | } | |
148 | ||
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. */ | |
152 | ||
153 | void | |
154 | fill_fpregset (fpregset_t *fpregsetp, int regno) | |
155 | { | |
156 | i387_fill_fsave ((char *) fpregsetp, regno); | |
157 | } | |
158 | ||
159 | /* Fetch register REGNO from the inferior. If REGNO is -1, do this | |
160 | for all registers (including the floating point registers). */ | |
161 | ||
162 | void | |
163 | fetch_inferior_registers (int regno) | |
164 | { | |
165 | gregset_t gregs; | |
166 | ||
167 | if (ptrace (PT_GETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &gregs, 0) == -1) | |
168 | perror_with_name ("Couldn't get registers"); | |
169 | ||
170 | supply_gregset (&gregs); | |
171 | ||
172 | if (regno == -1 || regno >= FP0_REGNUM) | |
173 | { | |
174 | fpregset_t fpregs; | |
175 | ||
176 | if (ptrace (PT_GETFPREGS, inferior_pid, | |
177 | (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) | |
178 | perror_with_name ("Couldn't get floating point status"); | |
179 | ||
180 | supply_fpregset (&fpregs); | |
181 | } | |
b051bfa4 | 182 | } |
e6031aeb MK |
183 | |
184 | /* Store register REGNO back into the inferior. If REGNO is -1, do | |
185 | this for all registers (including the floating point registers). */ | |
186 | ||
187 | void | |
188 | store_inferior_registers (int regno) | |
189 | { | |
190 | gregset_t gregs; | |
191 | ||
192 | if (ptrace (PT_GETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &gregs, 0) == -1) | |
193 | perror_with_name ("Couldn't get registers"); | |
194 | ||
195 | fill_gregset (&gregs, regno); | |
196 | ||
197 | if (ptrace (PT_SETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &gregs, 0) == -1) | |
198 | perror_with_name ("Couldn't write registers"); | |
199 | ||
200 | if (regno == -1 || regno >= FP0_REGNUM) | |
201 | { | |
202 | fpregset_t fpregs; | |
203 | ||
204 | if (ptrace (PT_GETFPREGS, inferior_pid, | |
205 | (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) | |
206 | perror_with_name ("Couldn't get floating point status"); | |
207 | ||
208 | fill_fpregset (&fpregs, regno); | |
209 | ||
210 | if (ptrace (PT_SETFPREGS, inferior_pid, | |
211 | (PTRACE_ARG3_TYPE) &fpregs, 0) == -1) | |
212 | perror_with_name ("Couldn't write floating point status"); | |
213 | } | |
214 | } | |
215 | \f | |
216 | ||
217 | /* Support for the user struct. */ | |
218 | ||
219 | /* Return the address register REGNO. BLOCKEND is the value of | |
220 | u.u_ar0, which should point to the registers. */ | |
221 | ||
222 | CORE_ADDR | |
223 | register_u_addr (CORE_ADDR blockend, int regno) | |
224 | { | |
225 | return (CORE_ADDR) REG_ADDR (blockend, regno); | |
226 | } | |
227 | ||
228 | #include <sys/param.h> | |
229 | #include <sys/user.h> | |
230 | ||
231 | /* Return the size of the user struct. */ | |
232 | ||
233 | int | |
234 | kernel_u_size (void) | |
235 | { | |
236 | return (sizeof (struct user)); | |
237 | } |