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., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include <sys/types.h>
30 #include <sys/param.h>
34 #include <sys/ioctl.h>
41 #include <sys/ptrace.h>
43 /* Does AIX define this in <errno.h>? */
50 #include "ieee-float.h"
54 extern struct ext_format ext_format_i387;
56 /* this table must line up with REGISTER_NAMES in tm-i386v.h */
57 /* symbols like 'EAX' come from <sys/reg.h> */
66 /* blockend is the value of u.u_ar0, and points to the
67 * place where GS is stored
71 i386_register_u_addr (blockend, regnum)
76 /* this will be needed if fp registers are reinstated */
77 /* for now, you can look at them with 'info float'
78 * sys5 wont let you change them with ptrace anyway
80 if (regnum >= FP0_REGNUM && regnum <= FP7_REGNUM)
84 ubase = blockend + 4 * (SS + 1) - KSTKSZ;
85 fpstate = ubase + ((char *)&u.u_fpstate - (char *)&u);
86 return (fpstate + 0x1c + 10 * (regnum - FP0_REGNUM));
90 return (blockend + 4 * regmap[regnum]);
94 /* The code below only work on the aix ps/2 (i386-ibm-aix) -
95 * mtranle@paris - Sat Apr 11 10:34:12 1992
100 unsigned short control;
102 unsigned short status;
107 unsigned short code_seg;
108 unsigned short opcode;
109 unsigned long operand;
110 unsigned short operand_seg;
112 unsigned char regs[8][10];
116 print_387_status (status, ep)
117 unsigned short status;
126 bothstatus = ((status != 0) && (ep->status != 0));
131 print_387_status_word (status);
138 print_387_status_word (ep->status);
141 print_387_control_word (ep->control);
142 printf ("last exception: ");
143 printf ("opcode %s; ", local_hex_string(ep->opcode));
144 printf ("pc %s:", local_hex_string(ep->code_seg));
145 printf ("%s; ", local_hex_string(ep->eip));
146 printf ("operand %s", local_hex_string(ep->operand_seg));
147 printf (":%s\n", local_hex_string(ep->operand));
149 top = 7- ((ep->status >> 11) & 7);
151 printf ("regno tag msb lsb value\n");
152 for (fpreg = 7; fpreg >= 0; fpreg--)
156 printf ("%s %d: ", fpreg == top ? "=>" : " ", fpreg);
158 switch ((ep->tag >> ((7 - fpreg) * 2)) & 3)
160 case 0: printf ("valid "); break;
161 case 1: printf ("zero "); break;
162 case 2: printf ("trap "); break;
163 case 3: printf ("empty "); break;
165 for (i = 9; i >= 0; i--)
166 printf ("%02x", ep->regs[fpreg][i]);
168 i387_to_double ((char *)ep->regs[fpreg], (char *)&val);
169 printf (" %#g\n", val);
173 static struct env387 core_env387;
184 unsigned short status;
186 ptrace (PT_READ_FPR, inferior_pid, buf, offsetof(struct env387, status));
187 memcpy (&status, buf, sizeof (status));
192 if ((fpsaved = core_env387.status) != 0)
193 memcpy(&fps, &core_env387, sizeof(fps));
198 printf ("no floating point status saved\n");
205 for (offset = 0; offset < sizeof(fps); offset += 10)
208 ptrace (PT_READ_FPR, inferior_pid, buf, offset);
209 memcpy ((char *)&fps.control + offset, buf,
210 MIN(10, sizeof(fps) - offset));
214 print_387_status (0, (struct env387 *)&fps);
217 /* Fetch one register. */
219 fetch_register (regno)
222 char buf[MAX_REGISTER_RAW_SIZE];
223 if (regno < FP0_REGNUM)
224 *(int *)buf = ptrace (PT_READ_GPR, inferior_pid,
225 PT_REG(regmap[regno]), 0, 0);
227 ptrace (PT_READ_FPR, inferior_pid, buf,
228 (regno - FP0_REGNUM)*10 + offsetof(struct env387, regs));
229 supply_register (regno, buf);
233 fetch_inferior_registers (regno)
237 for (regno = 0; regno < NUM_REGS; regno++)
238 fetch_register (regno);
240 fetch_register (regno);
243 /* store one register */
245 store_register (regno)
249 extern char registers[];
251 if (regno < FP0_REGNUM)
252 ptrace (PT_WRITE_GPR, inferior_pid, PT_REG(regmap[regno]),
253 *(int *) ®isters[REGISTER_BYTE (regno)], 0);
255 ptrace (PT_WRITE_FPR, inferior_pid, ®isters[REGISTER_BYTE (regno)],
256 (regno - FP0_REGNUM)*10 + offsetof(struct env387, regs));
260 sprintf (buf, "writing register number %d", regno);
261 perror_with_name (buf);
265 /* Store our register values back into the inferior.
266 If REGNO is -1, do this for all registers.
267 Otherwise, REGNO specifies which register (so we can save time). */
269 store_inferior_registers (regno)
273 for (regno = 0; regno < NUM_REGS; regno++)
274 store_register (regno);
276 store_register (regno);
279 #ifndef CD_AX /* defined in sys/i386/coredump.h */
299 * The order here in core_regmap[] has to be the same as in
302 static int core_regmap[] =
304 CD_AX, CD_CX, CD_DX, CD_BX,
305 CD_SP, CD_BP, CD_SI, CD_DI,
306 CD_IP, CD_FL, CD_CS, CD_SS,
307 CD_DS, CD_ES, CD_FS, CD_GS,
311 fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
313 unsigned core_reg_size;
315 unsigned int reg_addr; /* ignored */
320 /* Integer registers */
322 #define cd_regs(n) ((int *)core_reg_sect)[n]
323 #define regs(n) *((int *) ®isters[REGISTER_BYTE (n)])
326 for (i = 0; i < FP0_REGNUM; i++)
327 regs(i) = cd_regs(core_regmap[i]);
331 /* Floating point registers */
333 if (core_reg_size >= sizeof (core_env387))
334 memcpy (&core_env387, core_reg_sect, core_reg_size);
336 fprintf (stderr, "Couldn't read float regs from core file\n");