* config/tc-cris.c: Correct comment typos.
[deliverable/binutils-gdb.git] / gdb / i386aix-nat.c
CommitLineData
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>? */
45extern 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
a14ed312 55static void fetch_core_registers (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 60static 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
72int
fba45db2 73i386_register_u_addr (int blockend, int regnum)
c906108c
SS
74{
75#if 0
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
79 */
c5aa993b 80 if (regnum >= FP0_REGNUM && regnum <= FP7_REGNUM)
c906108c
SS
81 {
82 int ubase, fpstate;
83 struct user u;
84 ubase = blockend + 4 * (SS + 1) - KSTKSZ;
c5aa993b 85 fpstate = ubase + ((char *) &u.u_fpstate - (char *) &u);
c906108c 86 return (fpstate + 0x1c + 10 * (regnum - FP0_REGNUM));
c5aa993b 87 }
c906108c
SS
88 else
89#endif
90 return (blockend + 4 * regmap[regnum]);
c5aa993b 91
c906108c
SS
92}
93
94/* The code below only work on the aix ps/2 (i386-ibm-aix) -
95 * mtranle@paris - Sat Apr 11 10:34:12 1992
96 */
97
c5aa993b 98struct env387
c906108c
SS
99{
100 unsigned short control;
101 unsigned short r0;
102 unsigned short status;
103 unsigned short r1;
104 unsigned short tag;
105 unsigned short r2;
106 unsigned long eip;
107 unsigned short code_seg;
108 unsigned short opcode;
109 unsigned long operand;
110 unsigned short operand_seg;
111 unsigned short r3;
112 unsigned char regs[8][10];
113};
114
115static
fba45db2 116print_387_status (unsigned short status, struct env387 *ep)
c906108c
SS
117{
118 int i;
119 int bothstatus;
120 int top;
121 int fpreg;
122 unsigned char *p;
c5aa993b 123
c906108c 124 bothstatus = ((status != 0) && (ep->status != 0));
c5aa993b 125 if (status != 0)
c906108c
SS
126 {
127 if (bothstatus)
128 printf_unfiltered ("u: ");
129 print_387_status_word (status);
130 }
c5aa993b
JM
131
132 if (ep->status != 0)
c906108c
SS
133 {
134 if (bothstatus)
135 printf_unfiltered ("e: ");
136 print_387_status_word (ep->status);
137 }
c5aa993b 138
c906108c
SS
139 print_387_control_word (ep->control);
140 printf_unfiltered ("last exception: ");
c5aa993b
JM
141 printf_unfiltered ("opcode %s; ", local_hex_string (ep->opcode));
142 printf_unfiltered ("pc %s:", local_hex_string (ep->code_seg));
143 printf_unfiltered ("%s; ", local_hex_string (ep->eip));
144 printf_unfiltered ("operand %s", local_hex_string (ep->operand_seg));
145 printf_unfiltered (":%s\n", local_hex_string (ep->operand));
c906108c
SS
146
147 top = ((ep->status >> 11) & 7);
148
149 printf_unfiltered ("regno tag msb lsb value\n");
c5aa993b 150 for (fpreg = 7; fpreg >= 0; fpreg--)
c906108c
SS
151 {
152 double val;
153
154 printf_unfiltered ("%s %d: ", fpreg == top ? "=>" : " ", fpreg);
155
c5aa993b 156 switch ((ep->tag >> ((7 - fpreg) * 2)) & 3)
c906108c 157 {
c5aa993b
JM
158 case 0:
159 printf_unfiltered ("valid ");
160 break;
161 case 1:
162 printf_unfiltered ("zero ");
163 break;
164 case 2:
165 printf_unfiltered ("trap ");
166 break;
167 case 3:
168 printf_unfiltered ("empty ");
169 break;
c906108c
SS
170 }
171 for (i = 9; i >= 0; i--)
172 printf_unfiltered ("%02x", ep->regs[fpreg][i]);
c5aa993b
JM
173
174 i387_to_double ((char *) ep->regs[fpreg], (char *) &val);
c906108c
SS
175 printf_unfiltered (" %#g\n", val);
176 }
177}
178
179static struct env387 core_env387;
180
181void
fba45db2 182i386_float_info (void)
c906108c
SS
183{
184 struct env387 fps;
185 int fpsaved = 0;
186 /* We need to reverse the order of the registers. Apparently AIX stores
187 the highest-numbered ones first. */
188 struct env387 fps_fixed;
189 int i;
190
191 if (inferior_pid)
192 {
193 char buf[10];
194 unsigned short status;
195
c5aa993b 196 ptrace (PT_READ_FPR, inferior_pid, buf, offsetof (struct env387, status));
c906108c
SS
197 memcpy (&status, buf, sizeof (status));
198 fpsaved = status;
199 }
200 else
201 {
202 if ((fpsaved = core_env387.status) != 0)
c5aa993b 203 memcpy (&fps, &core_env387, sizeof (fps));
c906108c 204 }
c5aa993b
JM
205
206 if (fpsaved == 0)
c906108c
SS
207 {
208 printf_unfiltered ("no floating point status saved\n");
209 return;
210 }
211
212 if (inferior_pid)
213 {
214 int offset;
c5aa993b 215 for (offset = 0; offset < sizeof (fps); offset += 10)
c906108c
SS
216 {
217 char buf[10];
218 ptrace (PT_READ_FPR, inferior_pid, buf, offset);
c5aa993b
JM
219 memcpy ((char *) &fps.control + offset, buf,
220 MIN (10, sizeof (fps) - offset));
c906108c 221 }
c5aa993b 222 }
c906108c
SS
223 fps_fixed = fps;
224 for (i = 0; i < 8; ++i)
225 memcpy (fps_fixed.regs[i], fps.regs[7 - i], 10);
226 print_387_status (0, &fps_fixed);
227}
228
229/* Fetch one register. */
230static void
fba45db2 231fetch_register (int regno)
c906108c
SS
232{
233 char buf[MAX_REGISTER_RAW_SIZE];
234 if (regno < FP0_REGNUM)
c5aa993b
JM
235 *(int *) buf = ptrace (PT_READ_GPR, inferior_pid,
236 PT_REG (regmap[regno]), 0, 0);
c906108c
SS
237 else
238 ptrace (PT_READ_FPR, inferior_pid, buf,
c5aa993b 239 (regno - FP0_REGNUM) * 10 + offsetof (struct env387, regs));
c906108c
SS
240 supply_register (regno, buf);
241}
242
243void
fba45db2 244fetch_inferior_registers (int regno)
c906108c
SS
245{
246 if (regno < 0)
247 for (regno = 0; regno < NUM_REGS; regno++)
248 fetch_register (regno);
249 else
250 fetch_register (regno);
251}
252
253/* store one register */
254static void
fba45db2 255store_register (int regno)
c906108c
SS
256{
257 char buf[80];
c906108c
SS
258 errno = 0;
259 if (regno < FP0_REGNUM)
c5aa993b 260 ptrace (PT_WRITE_GPR, inferior_pid, PT_REG (regmap[regno]),
c906108c
SS
261 *(int *) &registers[REGISTER_BYTE (regno)], 0);
262 else
263 ptrace (PT_WRITE_FPR, inferior_pid, &registers[REGISTER_BYTE (regno)],
c5aa993b 264 (regno - FP0_REGNUM) * 10 + offsetof (struct env387, regs));
c906108c
SS
265
266 if (errno != 0)
267 {
268 sprintf (buf, "writing register number %d", regno);
269 perror_with_name (buf);
270 }
271}
272
273/* Store our register values back into the inferior.
274 If REGNO is -1, do this for all registers.
275 Otherwise, REGNO specifies which register (so we can save time). */
276void
fba45db2 277store_inferior_registers (int regno)
c906108c
SS
278{
279 if (regno < 0)
280 for (regno = 0; regno < NUM_REGS; regno++)
281 store_register (regno);
282 else
283 store_register (regno);
284}
285
286#ifndef CD_AX /* defined in sys/i386/coredump.h */
c5aa993b
JM
287#define CD_AX 0
288#define CD_BX 1
289#define CD_CX 2
290#define CD_DX 3
291#define CD_SI 4
292#define CD_DI 5
293#define CD_BP 6
294#define CD_SP 7
295#define CD_FL 8
296#define CD_IP 9
297#define CD_CS 10
298#define CD_DS 11
299#define CD_ES 12
300#define CD_FS 13
301#define CD_GS 14
302#define CD_SS 15
c906108c
SS
303#endif
304
305/*
306 * The order here in core_regmap[] has to be the same as in
307 * regmap[] above.
308 */
c5aa993b 309static int core_regmap[] =
c906108c
SS
310{
311 CD_AX, CD_CX, CD_DX, CD_BX,
312 CD_SP, CD_BP, CD_SI, CD_DI,
313 CD_IP, CD_FL, CD_CS, CD_SS,
314 CD_DS, CD_ES, CD_FS, CD_GS,
315};
316
317static void
318fetch_core_registers (core_reg_sect, core_reg_size, which, reg_addr)
319 char *core_reg_sect;
320 unsigned core_reg_size;
321 int which;
322 CORE_ADDR reg_addr; /* ignored */
323{
324
325 if (which == 0)
326 {
327 /* Integer registers */
328
329#define cd_regs(n) ((int *)core_reg_sect)[n]
330#define regs(n) *((int *) &registers[REGISTER_BYTE (n)])
331
332 int i;
333 for (i = 0; i < FP0_REGNUM; i++)
c5aa993b 334 regs (i) = cd_regs (core_regmap[i]);
c906108c
SS
335 }
336 else if (which == 2)
337 {
338 /* Floating point registers */
339
340 if (core_reg_size >= sizeof (core_env387))
341 memcpy (&core_env387, core_reg_sect, core_reg_size);
342 else
343 fprintf_unfiltered (gdb_stderr, "Couldn't read float regs from core file\n");
344 }
345}
c906108c 346\f
c5aa993b 347
c906108c
SS
348/* Register that we are able to handle i386aix core file formats.
349 FIXME: is this really bfd_target_unknown_flavour? */
350
351static struct core_fns i386aix_core_fns =
352{
2acceee2
JM
353 bfd_target_unknown_flavour, /* core_flavour */
354 default_check_format, /* check_format */
355 default_core_sniffer, /* core_sniffer */
356 fetch_core_registers, /* core_read_registers */
357 NULL /* next */
c906108c
SS
358};
359
360void
fba45db2 361_initialize_core_i386aix (void)
c906108c
SS
362{
363 add_core_fns (&i386aix_core_fns);
364}
This page took 0.08045 seconds and 4 git commands to generate.