1 /* Intel 386 native support.
2 Copyright (C) 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
28 #include <sys/types.h>
31 #include <sys/param.h>
35 #include <sys/ioctl.h>
42 #include <sys/ptrace.h>
44 /* Does AIX define this in <errno.h>? */
51 #include "floatformat.h"
55 static void fetch_core_registers PARAMS ((char *, unsigned, int, CORE_ADDR));
58 /* this table must line up with REGISTER_NAMES in tm-i386v.h */
59 /* symbols like 'EAX' come from <sys/reg.h> */
68 /* blockend is the value of u.u_ar0, and points to the
69 * place where GS is stored
73 i386_register_u_addr (blockend, 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 (status, ep)
119 unsigned short status;
128 bothstatus = ((status != 0) && (ep->status != 0));
132 printf_unfiltered ("u: ");
133 print_387_status_word (status);
139 printf_unfiltered ("e: ");
140 print_387_status_word (ep->status);
143 print_387_control_word (ep->control);
144 printf_unfiltered ("last exception: ");
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));
151 top = ((ep->status >> 11) & 7);
153 printf_unfiltered ("regno tag msb lsb value\n");
154 for (fpreg = 7; fpreg >= 0; fpreg--)
158 printf_unfiltered ("%s %d: ", fpreg == top ? "=>" : " ", fpreg);
160 switch ((ep->tag >> ((7 - fpreg) * 2)) & 3)
163 printf_unfiltered ("valid ");
166 printf_unfiltered ("zero ");
169 printf_unfiltered ("trap ");
172 printf_unfiltered ("empty ");
175 for (i = 9; i >= 0; i--)
176 printf_unfiltered ("%02x", ep->regs[fpreg][i]);
178 i387_to_double ((char *) ep->regs[fpreg], (char *) &val);
179 printf_unfiltered (" %#g\n", val);
183 static struct env387 core_env387;
190 /* We need to reverse the order of the registers. Apparently AIX stores
191 the highest-numbered ones first. */
192 struct env387 fps_fixed;
198 unsigned short status;
200 ptrace (PT_READ_FPR, inferior_pid, buf, offsetof (struct env387, status));
201 memcpy (&status, buf, sizeof (status));
206 if ((fpsaved = core_env387.status) != 0)
207 memcpy (&fps, &core_env387, sizeof (fps));
212 printf_unfiltered ("no floating point status saved\n");
219 for (offset = 0; offset < sizeof (fps); offset += 10)
222 ptrace (PT_READ_FPR, inferior_pid, buf, offset);
223 memcpy ((char *) &fps.control + offset, buf,
224 MIN (10, sizeof (fps) - offset));
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);
233 /* Fetch one register. */
235 fetch_register (regno)
238 char buf[MAX_REGISTER_RAW_SIZE];
239 if (regno < FP0_REGNUM)
240 *(int *) buf = ptrace (PT_READ_GPR, inferior_pid,
241 PT_REG (regmap[regno]), 0, 0);
243 ptrace (PT_READ_FPR, inferior_pid, buf,
244 (regno - FP0_REGNUM) * 10 + offsetof (struct env387, regs));
245 supply_register (regno, buf);
249 fetch_inferior_registers (regno)
253 for (regno = 0; regno < NUM_REGS; regno++)
254 fetch_register (regno);
256 fetch_register (regno);
259 /* store one register */
261 store_register (regno)
266 if (regno < FP0_REGNUM)
267 ptrace (PT_WRITE_GPR, inferior_pid, PT_REG (regmap[regno]),
268 *(int *) ®isters[REGISTER_BYTE (regno)], 0);
270 ptrace (PT_WRITE_FPR, inferior_pid, ®isters[REGISTER_BYTE (regno)],
271 (regno - FP0_REGNUM) * 10 + offsetof (struct env387, regs));
275 sprintf (buf, "writing register number %d", regno);
276 perror_with_name (buf);
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). */
284 store_inferior_registers (regno)
288 for (regno = 0; regno < NUM_REGS; regno++)
289 store_register (regno);
291 store_register (regno);
294 #ifndef CD_AX /* defined in sys/i386/coredump.h */
314 * The order here in core_regmap[] has to be the same as in
317 static int core_regmap[] =
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,
326 fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
328 unsigned core_reg_size;
330 CORE_ADDR reg_addr; /* ignored */
335 /* Integer registers */
337 #define cd_regs(n) ((int *)core_reg_sect)[n]
338 #define regs(n) *((int *) ®isters[REGISTER_BYTE (n)])
341 for (i = 0; i < FP0_REGNUM; i++)
342 regs (i) = cd_regs (core_regmap[i]);
346 /* Floating point registers */
348 if (core_reg_size >= sizeof (core_env387))
349 memcpy (&core_env387, core_reg_sect, core_reg_size);
351 fprintf_unfiltered (gdb_stderr, "Couldn't read float regs from core file\n");
356 /* Register that we are able to handle i386aix core file formats.
357 FIXME: is this really bfd_target_unknown_flavour? */
359 static struct core_fns i386aix_core_fns =
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 */
369 _initialize_core_i386aix ()
371 add_core_fns (&i386aix_core_fns);