1 /* Intel 386 native support.
2 Copyright 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999,
3 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
30 #include <sys/types.h>
33 #include <sys/param.h>
37 #include <sys/ioctl.h>
44 #include <sys/ptrace.h>
46 /* Does AIX define this in <errno.h>? */
53 #include "floatformat.h"
57 static void fetch_core_registers (char *, unsigned, int, CORE_ADDR
);
60 /* this table must line up with REGISTER_NAMES in tm-i386v.h */
61 /* symbols like 'EAX' come from <sys/reg.h> */
70 /* blockend is the value of u.u_ar0, and points to the
71 * place where GS is stored
75 i386_register_u_addr (int blockend
, int regnum
)
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
82 if (regnum
>= FP0_REGNUM
&& regnum
<= FP7_REGNUM
)
86 ubase
= blockend
+ 4 * (SS
+ 1) - KSTKSZ
;
87 fpstate
= ubase
+ ((char *) &u
.u_fpstate
- (char *) &u
);
88 return (fpstate
+ 0x1c + 10 * (regnum
- FP0_REGNUM
));
92 return (blockend
+ 4 * regmap
[regnum
]);
96 /* The code below only work on the aix ps/2 (i386-ibm-aix) -
97 * mtranle@paris - Sat Apr 11 10:34:12 1992
102 unsigned short control
;
104 unsigned short status
;
109 unsigned short code_seg
;
110 unsigned short opcode
;
111 unsigned long operand
;
112 unsigned short operand_seg
;
114 unsigned char regs
[8][10];
118 print_387_status (unsigned short status
, struct env387
*ep
)
126 bothstatus
= ((status
!= 0) && (ep
->status
!= 0));
130 printf_unfiltered ("u: ");
131 print_387_status_word (status
);
137 printf_unfiltered ("e: ");
138 print_387_status_word (ep
->status
);
141 print_387_control_word (ep
->control
);
142 printf_unfiltered ("last exception: ");
143 printf_unfiltered ("opcode %s; ", local_hex_string (ep
->opcode
));
144 printf_unfiltered ("pc %s:", local_hex_string (ep
->code_seg
));
145 printf_unfiltered ("%s; ", local_hex_string (ep
->eip
));
146 printf_unfiltered ("operand %s", local_hex_string (ep
->operand_seg
));
147 printf_unfiltered (":%s\n", local_hex_string (ep
->operand
));
149 top
= ((ep
->status
>> 11) & 7);
151 printf_unfiltered ("regno tag msb lsb value\n");
152 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
156 printf_unfiltered ("%s %d: ", fpreg
== top
? "=>" : " ", fpreg
);
158 switch ((ep
->tag
>> ((7 - fpreg
) * 2)) & 3)
161 printf_unfiltered ("valid ");
164 printf_unfiltered ("zero ");
167 printf_unfiltered ("trap ");
170 printf_unfiltered ("empty ");
173 for (i
= 9; i
>= 0; i
--)
174 printf_unfiltered ("%02x", ep
->regs
[fpreg
][i
]);
176 i387_to_double ((char *) ep
->regs
[fpreg
], (char *) &val
);
177 printf_unfiltered (" %#g\n", val
);
181 static struct env387 core_env387
;
184 i386_float_info (void)
188 /* We need to reverse the order of the registers. Apparently AIX stores
189 the highest-numbered ones first. */
190 struct env387 fps_fixed
;
196 unsigned short status
;
198 ptrace (PT_READ_FPR
, inferior_pid
, buf
, offsetof (struct env387
, status
));
199 memcpy (&status
, buf
, sizeof (status
));
204 if ((fpsaved
= core_env387
.status
) != 0)
205 memcpy (&fps
, &core_env387
, sizeof (fps
));
210 printf_unfiltered ("no floating point status saved\n");
217 for (offset
= 0; offset
< sizeof (fps
); offset
+= 10)
220 ptrace (PT_READ_FPR
, inferior_pid
, buf
, offset
);
221 memcpy ((char *) &fps
.control
+ offset
, buf
,
222 MIN (10, sizeof (fps
) - offset
));
226 for (i
= 0; i
< 8; ++i
)
227 memcpy (fps_fixed
.regs
[i
], fps
.regs
[7 - i
], 10);
228 print_387_status (0, &fps_fixed
);
231 /* Fetch one register. */
233 fetch_register (int regno
)
235 char buf
[MAX_REGISTER_RAW_SIZE
];
236 if (regno
< FP0_REGNUM
)
237 *(int *) buf
= ptrace (PT_READ_GPR
, inferior_pid
,
238 PT_REG (regmap
[regno
]), 0, 0);
240 ptrace (PT_READ_FPR
, inferior_pid
, buf
,
241 (regno
- FP0_REGNUM
) * 10 + offsetof (struct env387
, regs
));
242 supply_register (regno
, buf
);
246 fetch_inferior_registers (int regno
)
249 for (regno
= 0; regno
< NUM_REGS
; regno
++)
250 fetch_register (regno
);
252 fetch_register (regno
);
255 /* store one register */
257 store_register (int regno
)
261 if (regno
< FP0_REGNUM
)
262 ptrace (PT_WRITE_GPR
, inferior_pid
, PT_REG (regmap
[regno
]),
263 *(int *) ®isters
[REGISTER_BYTE (regno
)], 0);
265 ptrace (PT_WRITE_FPR
, inferior_pid
, ®isters
[REGISTER_BYTE (regno
)],
266 (regno
- FP0_REGNUM
) * 10 + offsetof (struct env387
, regs
));
270 sprintf (buf
, "writing register number %d", regno
);
271 perror_with_name (buf
);
275 /* Store our register values back into the inferior.
276 If REGNO is -1, do this for all registers.
277 Otherwise, REGNO specifies which register (so we can save time). */
279 store_inferior_registers (int regno
)
282 for (regno
= 0; regno
< NUM_REGS
; regno
++)
283 store_register (regno
);
285 store_register (regno
);
288 #ifndef CD_AX /* defined in sys/i386/coredump.h */
308 * The order here in core_regmap[] has to be the same as in
311 static int core_regmap
[] =
313 CD_AX
, CD_CX
, CD_DX
, CD_BX
,
314 CD_SP
, CD_BP
, CD_SI
, CD_DI
,
315 CD_IP
, CD_FL
, CD_CS
, CD_SS
,
316 CD_DS
, CD_ES
, CD_FS
, CD_GS
,
319 /* Provide registers to GDB from a core file.
321 CORE_REG_SECT points to an array of bytes, which were obtained from
322 a core file which BFD thinks might contain register contents.
323 CORE_REG_SIZE is its size.
325 WHICH says which register set corelow suspects this is:
326 0 --- the general-purpose register set
327 2 --- the floating-point register set
329 REG_ADDR isn't used. */
332 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
,
333 int which
, CORE_ADDR reg_addr
)
338 /* Integer registers */
340 #define cd_regs(n) ((int *)core_reg_sect)[n]
341 #define regs(n) *((int *) ®isters[REGISTER_BYTE (n)])
344 for (i
= 0; i
< FP0_REGNUM
; i
++)
345 regs (i
) = cd_regs (core_regmap
[i
]);
349 /* Floating point registers */
351 if (core_reg_size
>= sizeof (core_env387
))
352 memcpy (&core_env387
, core_reg_sect
, core_reg_size
);
354 fprintf_unfiltered (gdb_stderr
, "Couldn't read float regs from core file\n");
359 /* Register that we are able to handle i386aix core file formats.
360 FIXME: is this really bfd_target_unknown_flavour? */
362 static struct core_fns i386aix_core_fns
=
364 bfd_target_unknown_flavour
, /* core_flavour */
365 default_check_format
, /* check_format */
366 default_core_sniffer
, /* core_sniffer */
367 fetch_core_registers
, /* core_read_registers */
372 _initialize_core_i386aix (void)
374 add_core_fns (&i386aix_core_fns
);