Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Native-dependent code for SVR4 Unix running on i386's, for GDB. |
2 | Copyright 1988, 1989, 1991, 1992, 1996, 1998 Free Software Foundation, Inc. | |
3 | ||
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
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. | |
c906108c | 10 | |
c5aa993b JM |
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. | |
c906108c | 15 | |
c5aa993b JM |
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. */ | |
c906108c SS |
20 | |
21 | #include "defs.h" | |
22 | #include "value.h" | |
7a292a7a | 23 | #include "inferior.h" |
c906108c SS |
24 | |
25 | #ifdef HAVE_SYS_REG_H | |
26 | #include <sys/reg.h> | |
27 | #endif | |
28 | ||
29 | ||
30 | #ifdef HAVE_SYS_PROCFS_H | |
31 | ||
32 | #include <sys/procfs.h> | |
33 | ||
c60c0f5f MS |
34 | /* Prototypes for supply_gregset etc. */ |
35 | #include "gregset.h" | |
36 | ||
c906108c | 37 | /* The /proc interface divides the target machine's register set up into |
c5aa993b JM |
38 | two different sets, the general register set (gregset) and the floating |
39 | point register set (fpregset). For each set, there is an ioctl to get | |
40 | the current register set and another ioctl to set the current values. | |
41 | ||
42 | The actual structure passed through the ioctl interface is, of course, | |
43 | naturally machine dependent, and is different for each set of registers. | |
44 | For the i386 for example, the general register set is typically defined | |
45 | by: | |
46 | ||
47 | typedef int gregset_t[19]; (in <sys/regset.h>) | |
48 | ||
49 | #define GS 0 (in <sys/reg.h>) | |
50 | #define FS 1 | |
51 | ... | |
52 | #define UESP 17 | |
53 | #define SS 18 | |
54 | ||
55 | and the floating point set by: | |
56 | ||
57 | typedef struct fpregset | |
58 | { | |
59 | union | |
60 | { | |
61 | struct fpchip_state // fp extension state // | |
62 | { | |
63 | int state[27]; // 287/387 saved state // | |
64 | int status; // status word saved at exception // | |
65 | } fpchip_state; | |
66 | struct fp_emul_space // for emulators // | |
67 | { | |
68 | char fp_emul[246]; | |
69 | char fp_epad[2]; | |
70 | } fp_emul_space; | |
71 | int f_fpregs[62]; // union of the above // | |
72 | } fp_reg_set; | |
73 | long f_wregs[33]; // saved weitek state // | |
74 | } fpregset_t; | |
75 | ||
76 | These routines provide the packing and unpacking of gregset_t and | |
77 | fpregset_t formatted data. | |
c906108c SS |
78 | |
79 | */ | |
80 | ||
81 | #ifdef HAVE_GREGSET_T | |
82 | ||
83 | /* This is a duplicate of the table in i386-xdep.c. */ | |
84 | ||
c5aa993b | 85 | static int regmap[] = |
c906108c SS |
86 | { |
87 | EAX, ECX, EDX, EBX, | |
88 | UESP, EBP, ESI, EDI, | |
89 | EIP, EFL, CS, SS, | |
90 | DS, ES, FS, GS, | |
91 | }; | |
92 | ||
93 | /* Prototypes for local functions */ | |
94 | ||
a14ed312 | 95 | void fill_gregset (gregset_t *, int); |
c906108c | 96 | |
a14ed312 | 97 | void supply_gregset (gregset_t *); |
c906108c | 98 | |
a14ed312 | 99 | void supply_fpregset (fpregset_t *); |
c906108c | 100 | |
a14ed312 | 101 | void fill_fpregset (fpregset_t *, int); |
c906108c SS |
102 | |
103 | ||
104 | /* FIXME: These routine absolutely depends upon (NUM_REGS - NUM_FREGS) | |
c5aa993b JM |
105 | being less than or equal to the number of registers that can be stored |
106 | in a gregset_t. Note that with the current scheme there will typically | |
107 | be more registers actually stored in a gregset_t that what we know | |
108 | about. This is bogus and should be fixed. */ | |
c906108c SS |
109 | |
110 | /* Given a pointer to a general register set in /proc format (gregset_t *), | |
c5aa993b JM |
111 | unpack the register contents and supply them as gdb's idea of the current |
112 | register values. */ | |
c906108c SS |
113 | |
114 | void | |
fba45db2 | 115 | supply_gregset (gregset_t *gregsetp) |
c906108c SS |
116 | { |
117 | register int regi; | |
118 | register greg_t *regp = (greg_t *) gregsetp; | |
119 | extern int regmap[]; | |
120 | ||
c5aa993b | 121 | for (regi = 0; regi < (NUM_REGS - NUM_FREGS); regi++) |
c906108c SS |
122 | { |
123 | supply_register (regi, (char *) (regp + regmap[regi])); | |
124 | } | |
125 | } | |
126 | ||
127 | void | |
fba45db2 | 128 | fill_gregset (gregset_t *gregsetp, int regno) |
c906108c SS |
129 | { |
130 | int regi; | |
131 | register greg_t *regp = (greg_t *) gregsetp; | |
c906108c SS |
132 | extern int regmap[]; |
133 | ||
c5aa993b | 134 | for (regi = 0; regi < (NUM_REGS - NUM_FREGS); regi++) |
c906108c SS |
135 | { |
136 | if ((regno == -1) || (regno == regi)) | |
137 | { | |
138 | *(regp + regmap[regi]) = *(int *) ®isters[REGISTER_BYTE (regi)]; | |
139 | } | |
140 | } | |
141 | } | |
142 | ||
c5aa993b | 143 | #endif /* HAVE_GREGSET_T */ |
c906108c | 144 | |
14164c30 | 145 | #if defined (HAVE_FPREGSET_T) |
c906108c SS |
146 | |
147 | /* Given a pointer to a floating point register set in /proc format | |
c5aa993b JM |
148 | (fpregset_t *), unpack the register contents and supply them as gdb's |
149 | idea of the current floating point register values. */ | |
c906108c | 150 | |
14164c30 PS |
151 | /* FIXME: Assumes that fpregsetp contains an i387 FSAVE area. */ |
152 | static const int freg_offset_map[] = | |
153 | { | |
154 | #if !defined(FPREGSET_FSAVE_OFFSET) | |
155 | #define FPREGSET_FSAVE_OFFSET 0 | |
156 | #endif | |
157 | FPREGSET_FSAVE_OFFSET + 28 + 0 * 10, | |
158 | FPREGSET_FSAVE_OFFSET + 28 + 1 * 10, | |
159 | FPREGSET_FSAVE_OFFSET + 28 + 2 * 10, | |
160 | FPREGSET_FSAVE_OFFSET + 28 + 3 * 10, | |
161 | FPREGSET_FSAVE_OFFSET + 28 + 4 * 10, | |
162 | FPREGSET_FSAVE_OFFSET + 28 + 5 * 10, | |
163 | FPREGSET_FSAVE_OFFSET + 28 + 6 * 10, | |
164 | FPREGSET_FSAVE_OFFSET + 28 + 7 * 10, | |
165 | FPREGSET_FSAVE_OFFSET + 0, | |
166 | FPREGSET_FSAVE_OFFSET + 4, | |
167 | FPREGSET_FSAVE_OFFSET + 8, | |
168 | FPREGSET_FSAVE_OFFSET + 16, | |
169 | FPREGSET_FSAVE_OFFSET + 12, | |
170 | FPREGSET_FSAVE_OFFSET + 24, | |
171 | FPREGSET_FSAVE_OFFSET + 20, | |
172 | FPREGSET_FSAVE_OFFSET + 16 | |
173 | }; | |
174 | ||
c5aa993b | 175 | void |
fba45db2 | 176 | supply_fpregset (fpregset_t *fpregsetp) |
c906108c | 177 | { |
14164c30 PS |
178 | int regi; |
179 | ||
180 | if (NUM_FREGS == 0) | |
181 | return; | |
182 | for (regi = FP0_REGNUM; regi <= LAST_FPU_CTRL_REGNUM; regi++) | |
183 | { | |
184 | char tbuf[4]; | |
185 | ULONGEST tval; | |
186 | char *from = (char *) fpregsetp + freg_offset_map[regi - FP0_REGNUM]; | |
187 | ||
188 | if (regi == FCS_REGNUM) | |
189 | { | |
190 | tval = extract_unsigned_integer (from, 4) & 0xffff; | |
191 | store_unsigned_integer (tbuf, 4, tval); | |
192 | supply_register (regi, tbuf); | |
193 | } | |
194 | else if (regi == FOP_REGNUM) | |
195 | { | |
196 | tval = (extract_unsigned_integer (from, 4) >> 16) & ((1 << 11) - 1); | |
197 | store_unsigned_integer (tbuf, 4, tval); | |
198 | supply_register (regi, tbuf); | |
199 | } | |
200 | else | |
201 | supply_register (regi, from); | |
202 | } | |
c906108c SS |
203 | } |
204 | ||
205 | /* Given a pointer to a floating point register set in /proc format | |
c5aa993b JM |
206 | (fpregset_t *), update the register specified by REGNO from gdb's idea |
207 | of the current floating point register set. If REGNO is -1, update | |
208 | them all. */ | |
c906108c SS |
209 | |
210 | void | |
fba45db2 | 211 | fill_fpregset (fpregset_t *fpregsetp, int regno) |
c906108c | 212 | { |
14164c30 PS |
213 | int regi; |
214 | ||
215 | if (NUM_FREGS == 0) | |
216 | return; | |
217 | for (regi = FP0_REGNUM; regi <= LAST_FPU_CTRL_REGNUM; regi++) | |
218 | { | |
219 | if ((regno == -1) || (regno == regi)) | |
220 | { | |
221 | char *to = (char *) fpregsetp + freg_offset_map[regi - FP0_REGNUM]; | |
222 | char *from = (char *) ®isters[REGISTER_BYTE (regi)]; | |
223 | ULONGEST valto; | |
224 | ULONGEST valfrom; | |
225 | ||
226 | if (regi == FCS_REGNUM) | |
227 | { | |
228 | valto = extract_unsigned_integer (to, 4); | |
229 | valfrom = extract_unsigned_integer (from, 4); | |
230 | valto = (valto & ~0xffff) | (valfrom & 0xffff); | |
231 | store_unsigned_integer (to, 4, valto); | |
232 | } | |
233 | else if (regi == FOP_REGNUM) | |
234 | { | |
235 | valto = extract_unsigned_integer (to, 4); | |
236 | valfrom = extract_unsigned_integer (from, 4); | |
237 | valto = (valto & 0xffff) | ((valfrom & ((1 << 11) - 1)) << 16); | |
238 | store_unsigned_integer (to, 4, valto); | |
239 | } | |
240 | else | |
241 | { | |
242 | memcpy (to, from, REGISTER_RAW_SIZE (regi)); | |
243 | } | |
244 | } | |
245 | } | |
c906108c SS |
246 | } |
247 | ||
14164c30 | 248 | #endif /* defined (HAVE_FPREGSET_T) */ |
c906108c | 249 | |
c5aa993b | 250 | #endif /* HAVE_SYS_PROCFS_H */ |