]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Intel 386 native support. |
2 | Copyright (C) 1988, 1989, 1991, 1992 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 "frame.h" | |
23 | #include "inferior.h" | |
24 | #include "language.h" | |
25 | #include "gdbcore.h" | |
26 | ||
27 | #ifdef USG | |
28 | #include <sys/types.h> | |
29 | #endif | |
30 | ||
31 | #include <sys/param.h> | |
32 | #include <sys/dir.h> | |
33 | #include <signal.h> | |
34 | #include <sys/user.h> | |
35 | #include <sys/ioctl.h> | |
36 | #include <fcntl.h> | |
37 | ||
38 | #include <sys/file.h> | |
39 | #include "gdb_stat.h" | |
40 | ||
41 | #include <stddef.h> | |
42 | #include <sys/ptrace.h> | |
43 | ||
44 | /* Does AIX define this in <errno.h>? */ | |
45 | extern int errno; | |
46 | ||
47 | #ifdef HAVE_SYS_REG_H | |
48 | #include <sys/reg.h> | |
49 | #endif | |
50 | ||
51 | #include "floatformat.h" | |
52 | ||
53 | #include "target.h" | |
54 | ||
55 | static void fetch_core_registers PARAMS ((char *, unsigned, int, CORE_ADDR)); | |
c906108c | 56 | \f |
c5aa993b | 57 | |
c906108c SS |
58 | /* this table must line up with REGISTER_NAMES in tm-i386v.h */ |
59 | /* symbols like 'EAX' come from <sys/reg.h> */ | |
c5aa993b | 60 | static int regmap[] = |
c906108c SS |
61 | { |
62 | EAX, ECX, EDX, EBX, | |
63 | USP, EBP, ESI, EDI, | |
64 | EIP, EFL, CS, SS, | |
65 | DS, ES, FS, GS, | |
66 | }; | |
67 | ||
68 | /* blockend is the value of u.u_ar0, and points to the | |
69 | * place where GS is stored | |
70 | */ | |
71 | ||
72 | int | |
73 | i386_register_u_addr (blockend, regnum) | |
74 | int blockend; | |
75 | int regnum; | |
76 | { | |
77 | #if 0 | |
78 | /* this will be needed if fp registers are reinstated */ | |
79 | /* for now, you can look at them with 'info float' | |
80 | * sys5 wont let you change them with ptrace anyway | |
81 | */ | |
c5aa993b | 82 | if (regnum >= FP0_REGNUM && regnum <= FP7_REGNUM) |
c906108c SS |
83 | { |
84 | int ubase, fpstate; | |
85 | struct user u; | |
86 | ubase = blockend + 4 * (SS + 1) - KSTKSZ; | |
c5aa993b | 87 | fpstate = ubase + ((char *) &u.u_fpstate - (char *) &u); |
c906108c | 88 | return (fpstate + 0x1c + 10 * (regnum - FP0_REGNUM)); |
c5aa993b | 89 | } |
c906108c SS |
90 | else |
91 | #endif | |
92 | return (blockend + 4 * regmap[regnum]); | |
c5aa993b | 93 | |
c906108c SS |
94 | } |
95 | ||
96 | /* The code below only work on the aix ps/2 (i386-ibm-aix) - | |
97 | * mtranle@paris - Sat Apr 11 10:34:12 1992 | |
98 | */ | |
99 | ||
c5aa993b | 100 | struct env387 |
c906108c SS |
101 | { |
102 | unsigned short control; | |
103 | unsigned short r0; | |
104 | unsigned short status; | |
105 | unsigned short r1; | |
106 | unsigned short tag; | |
107 | unsigned short r2; | |
108 | unsigned long eip; | |
109 | unsigned short code_seg; | |
110 | unsigned short opcode; | |
111 | unsigned long operand; | |
112 | unsigned short operand_seg; | |
113 | unsigned short r3; | |
114 | unsigned char regs[8][10]; | |
115 | }; | |
116 | ||
117 | static | |
118 | print_387_status (status, ep) | |
119 | unsigned short status; | |
120 | struct env387 *ep; | |
121 | { | |
122 | int i; | |
123 | int bothstatus; | |
124 | int top; | |
125 | int fpreg; | |
126 | unsigned char *p; | |
c5aa993b | 127 | |
c906108c | 128 | bothstatus = ((status != 0) && (ep->status != 0)); |
c5aa993b | 129 | if (status != 0) |
c906108c SS |
130 | { |
131 | if (bothstatus) | |
132 | printf_unfiltered ("u: "); | |
133 | print_387_status_word (status); | |
134 | } | |
c5aa993b JM |
135 | |
136 | if (ep->status != 0) | |
c906108c SS |
137 | { |
138 | if (bothstatus) | |
139 | printf_unfiltered ("e: "); | |
140 | print_387_status_word (ep->status); | |
141 | } | |
c5aa993b | 142 | |
c906108c SS |
143 | print_387_control_word (ep->control); |
144 | printf_unfiltered ("last exception: "); | |
c5aa993b JM |
145 | printf_unfiltered ("opcode %s; ", local_hex_string (ep->opcode)); |
146 | printf_unfiltered ("pc %s:", local_hex_string (ep->code_seg)); | |
147 | printf_unfiltered ("%s; ", local_hex_string (ep->eip)); | |
148 | printf_unfiltered ("operand %s", local_hex_string (ep->operand_seg)); | |
149 | printf_unfiltered (":%s\n", local_hex_string (ep->operand)); | |
c906108c SS |
150 | |
151 | top = ((ep->status >> 11) & 7); | |
152 | ||
153 | printf_unfiltered ("regno tag msb lsb value\n"); | |
c5aa993b | 154 | for (fpreg = 7; fpreg >= 0; fpreg--) |
c906108c SS |
155 | { |
156 | double val; | |
157 | ||
158 | printf_unfiltered ("%s %d: ", fpreg == top ? "=>" : " ", fpreg); | |
159 | ||
c5aa993b | 160 | switch ((ep->tag >> ((7 - fpreg) * 2)) & 3) |
c906108c | 161 | { |
c5aa993b JM |
162 | case 0: |
163 | printf_unfiltered ("valid "); | |
164 | break; | |
165 | case 1: | |
166 | printf_unfiltered ("zero "); | |
167 | break; | |
168 | case 2: | |
169 | printf_unfiltered ("trap "); | |
170 | break; | |
171 | case 3: | |
172 | printf_unfiltered ("empty "); | |
173 | break; | |
c906108c SS |
174 | } |
175 | for (i = 9; i >= 0; i--) | |
176 | printf_unfiltered ("%02x", ep->regs[fpreg][i]); | |
c5aa993b JM |
177 | |
178 | i387_to_double ((char *) ep->regs[fpreg], (char *) &val); | |
c906108c SS |
179 | printf_unfiltered (" %#g\n", val); |
180 | } | |
181 | } | |
182 | ||
183 | static struct env387 core_env387; | |
184 | ||
185 | void | |
186 | i386_float_info () | |
187 | { | |
188 | struct env387 fps; | |
189 | int fpsaved = 0; | |
190 | /* We need to reverse the order of the registers. Apparently AIX stores | |
191 | the highest-numbered ones first. */ | |
192 | struct env387 fps_fixed; | |
193 | int i; | |
194 | ||
195 | if (inferior_pid) | |
196 | { | |
197 | char buf[10]; | |
198 | unsigned short status; | |
199 | ||
c5aa993b | 200 | ptrace (PT_READ_FPR, inferior_pid, buf, offsetof (struct env387, status)); |
c906108c SS |
201 | memcpy (&status, buf, sizeof (status)); |
202 | fpsaved = status; | |
203 | } | |
204 | else | |
205 | { | |
206 | if ((fpsaved = core_env387.status) != 0) | |
c5aa993b | 207 | memcpy (&fps, &core_env387, sizeof (fps)); |
c906108c | 208 | } |
c5aa993b JM |
209 | |
210 | if (fpsaved == 0) | |
c906108c SS |
211 | { |
212 | printf_unfiltered ("no floating point status saved\n"); | |
213 | return; | |
214 | } | |
215 | ||
216 | if (inferior_pid) | |
217 | { | |
218 | int offset; | |
c5aa993b | 219 | for (offset = 0; offset < sizeof (fps); offset += 10) |
c906108c SS |
220 | { |
221 | char buf[10]; | |
222 | ptrace (PT_READ_FPR, inferior_pid, buf, offset); | |
c5aa993b JM |
223 | memcpy ((char *) &fps.control + offset, buf, |
224 | MIN (10, sizeof (fps) - offset)); | |
c906108c | 225 | } |
c5aa993b | 226 | } |
c906108c SS |
227 | fps_fixed = fps; |
228 | for (i = 0; i < 8; ++i) | |
229 | memcpy (fps_fixed.regs[i], fps.regs[7 - i], 10); | |
230 | print_387_status (0, &fps_fixed); | |
231 | } | |
232 | ||
233 | /* Fetch one register. */ | |
234 | static void | |
235 | fetch_register (regno) | |
236 | int regno; | |
237 | { | |
238 | char buf[MAX_REGISTER_RAW_SIZE]; | |
239 | if (regno < FP0_REGNUM) | |
c5aa993b JM |
240 | *(int *) buf = ptrace (PT_READ_GPR, inferior_pid, |
241 | PT_REG (regmap[regno]), 0, 0); | |
c906108c SS |
242 | else |
243 | ptrace (PT_READ_FPR, inferior_pid, buf, | |
c5aa993b | 244 | (regno - FP0_REGNUM) * 10 + offsetof (struct env387, regs)); |
c906108c SS |
245 | supply_register (regno, buf); |
246 | } | |
247 | ||
248 | void | |
249 | fetch_inferior_registers (regno) | |
250 | int regno; | |
251 | { | |
252 | if (regno < 0) | |
253 | for (regno = 0; regno < NUM_REGS; regno++) | |
254 | fetch_register (regno); | |
255 | else | |
256 | fetch_register (regno); | |
257 | } | |
258 | ||
259 | /* store one register */ | |
260 | static void | |
261 | store_register (regno) | |
262 | int regno; | |
263 | { | |
264 | char buf[80]; | |
c906108c SS |
265 | errno = 0; |
266 | if (regno < FP0_REGNUM) | |
c5aa993b | 267 | ptrace (PT_WRITE_GPR, inferior_pid, PT_REG (regmap[regno]), |
c906108c SS |
268 | *(int *) ®isters[REGISTER_BYTE (regno)], 0); |
269 | else | |
270 | ptrace (PT_WRITE_FPR, inferior_pid, ®isters[REGISTER_BYTE (regno)], | |
c5aa993b | 271 | (regno - FP0_REGNUM) * 10 + offsetof (struct env387, regs)); |
c906108c SS |
272 | |
273 | if (errno != 0) | |
274 | { | |
275 | sprintf (buf, "writing register number %d", regno); | |
276 | perror_with_name (buf); | |
277 | } | |
278 | } | |
279 | ||
280 | /* Store our register values back into the inferior. | |
281 | If REGNO is -1, do this for all registers. | |
282 | Otherwise, REGNO specifies which register (so we can save time). */ | |
283 | void | |
284 | store_inferior_registers (regno) | |
285 | int regno; | |
286 | { | |
287 | if (regno < 0) | |
288 | for (regno = 0; regno < NUM_REGS; regno++) | |
289 | store_register (regno); | |
290 | else | |
291 | store_register (regno); | |
292 | } | |
293 | ||
294 | #ifndef CD_AX /* defined in sys/i386/coredump.h */ | |
c5aa993b JM |
295 | #define CD_AX 0 |
296 | #define CD_BX 1 | |
297 | #define CD_CX 2 | |
298 | #define CD_DX 3 | |
299 | #define CD_SI 4 | |
300 | #define CD_DI 5 | |
301 | #define CD_BP 6 | |
302 | #define CD_SP 7 | |
303 | #define CD_FL 8 | |
304 | #define CD_IP 9 | |
305 | #define CD_CS 10 | |
306 | #define CD_DS 11 | |
307 | #define CD_ES 12 | |
308 | #define CD_FS 13 | |
309 | #define CD_GS 14 | |
310 | #define CD_SS 15 | |
c906108c SS |
311 | #endif |
312 | ||
313 | /* | |
314 | * The order here in core_regmap[] has to be the same as in | |
315 | * regmap[] above. | |
316 | */ | |
c5aa993b | 317 | static int core_regmap[] = |
c906108c SS |
318 | { |
319 | CD_AX, CD_CX, CD_DX, CD_BX, | |
320 | CD_SP, CD_BP, CD_SI, CD_DI, | |
321 | CD_IP, CD_FL, CD_CS, CD_SS, | |
322 | CD_DS, CD_ES, CD_FS, CD_GS, | |
323 | }; | |
324 | ||
325 | static void | |
326 | fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr) | |
327 | char *core_reg_sect; | |
328 | unsigned core_reg_size; | |
329 | int which; | |
330 | CORE_ADDR reg_addr; /* ignored */ | |
331 | { | |
332 | ||
333 | if (which == 0) | |
334 | { | |
335 | /* Integer registers */ | |
336 | ||
337 | #define cd_regs(n) ((int *)core_reg_sect)[n] | |
338 | #define regs(n) *((int *) ®isters[REGISTER_BYTE (n)]) | |
339 | ||
340 | int i; | |
341 | for (i = 0; i < FP0_REGNUM; i++) | |
c5aa993b | 342 | regs (i) = cd_regs (core_regmap[i]); |
c906108c SS |
343 | } |
344 | else if (which == 2) | |
345 | { | |
346 | /* Floating point registers */ | |
347 | ||
348 | if (core_reg_size >= sizeof (core_env387)) | |
349 | memcpy (&core_env387, core_reg_sect, core_reg_size); | |
350 | else | |
351 | fprintf_unfiltered (gdb_stderr, "Couldn't read float regs from core file\n"); | |
352 | } | |
353 | } | |
c906108c | 354 | \f |
c5aa993b | 355 | |
c906108c SS |
356 | /* Register that we are able to handle i386aix core file formats. |
357 | FIXME: is this really bfd_target_unknown_flavour? */ | |
358 | ||
359 | static struct core_fns i386aix_core_fns = | |
360 | { | |
2acceee2 JM |
361 | bfd_target_unknown_flavour, /* core_flavour */ |
362 | default_check_format, /* check_format */ | |
363 | default_core_sniffer, /* core_sniffer */ | |
364 | fetch_core_registers, /* core_read_registers */ | |
365 | NULL /* next */ | |
c906108c SS |
366 | }; |
367 | ||
368 | void | |
369 | _initialize_core_i386aix () | |
370 | { | |
371 | add_core_fns (&i386aix_core_fns); | |
372 | } |