* sunos.c (sunos_scan_ext_relocs): If not making a shared library,
[deliverable/binutils-gdb.git] / gdb / i386b-nat.c
CommitLineData
ede9d8a7 1/* Native-dependent code for BSD Unix running on i386's, for GDB.
7531f36e 2 Copyright 1988, 1989, 1991, 1992, 1994, 1996 Free Software Foundation, Inc.
6d685882
JG
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
6c9638b4 18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
6d685882
JG
19
20#include "defs.h"
48d27324
C
21
22#ifdef FETCH_INFERIOR_REGISTERS
23#include <sys/types.h>
24#include <sys/ptrace.h>
25#include <machine/reg.h>
26#include <machine/frame.h>
27#include "inferior.h"
28
29void
30fetch_inferior_registers(regno)
31 int regno;
32{
33 struct reg inferior_registers;
34
35 ptrace (PT_GETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &inferior_registers, 0);
36 memcpy (&registers[REGISTER_BYTE (0)], &inferior_registers, 4*NUM_REGS);
37 registers_fetched ();
38}
39
40void
41store_inferior_registers(regno)
42 int regno;
43{
44 struct reg inferior_registers;
45
46 memcpy (&inferior_registers, &registers[REGISTER_BYTE (0)], 4*NUM_REGS);
47 ptrace (PT_SETREGS, inferior_pid, (PTRACE_ARG3_TYPE) &inferior_registers, 0);
48}
49
50void
51fetch_core_registers (core_reg_sect, core_reg_size, which, ignore)
52 char *core_reg_sect;
53 unsigned core_reg_size;
54 int which;
55 unsigned int ignore;
56{
57 abort();
58}
59
60#else
61
6d685882
JG
62#include <machine/reg.h>
63
6d685882
JG
64/* this table must line up with REGISTER_NAMES in tm-i386.h */
65/* symbols like 'tEAX' come from <machine/reg.h> */
66static int tregmap[] =
67{
68 tEAX, tECX, tEDX, tEBX,
69 tESP, tEBP, tESI, tEDI,
70 tEIP, tEFLAGS, tCS, tSS
71};
11ebf939 72
6d685882
JG
73static int sregmap[] =
74{
75 sEAX, sECX, sEDX, sEBX,
76 sESP, sEBP, sESI, sEDI,
77 sEIP, sEFLAGS, sCS, sSS
78};
79
80/* blockend is the value of u.u_ar0, and points to the
81 place where ES is stored. */
82
83int
84i386_register_u_addr (blockend, regnum)
85 int blockend;
86 int regnum;
87{
88 /* The following condition is a kludge to get at the proper register map
89 depending upon the state of pcb_flag.
90 The proper condition would be
91 if (u.u_pcb.pcb_flag & FM_TRAP)
92 but that would require a ptrace call here and wouldn't work
93 for corefiles. */
94
95 if (blockend < 0x1fcc)
96 return (blockend + 4 * tregmap[regnum]);
97 else
98 return (blockend + 4 * sregmap[regnum]);
99}
84f652b1 100
48d27324 101#endif /* !FETCH_INFERIOR_REGISTERS */
84f652b1
C
102
103#ifdef FLOAT_INFO
1a494973 104#include "language.h" /* for local_hex_string */
84f652b1
C
105#include "floatformat.h"
106
107#include <sys/param.h>
108#include <sys/dir.h>
109#include <signal.h>
110#include <sys/ioctl.h>
111#include <fcntl.h>
112
113#include <a.out.h>
114
115#include <sys/time.h>
116#include <sys/resource.h>
117#include <sys/uio.h>
118#define curpcb Xcurpcb /* XXX avoid leaking declaration from pcb.h */
119#include <sys/user.h>
120#undef curpcb
121#include <sys/file.h>
2b576293 122#include "gdb_stat.h"
84f652b1
C
123#include <sys/ptrace.h>
124
125extern void print_387_control_word (); /* i387-tdep.h */
126extern void print_387_status_word ();
127
128#define fpstate save87
129#define U_FPSTATE(u) u.u_pcb.pcb_savefpu
130
131struct env387
132{
133 unsigned short control;
134 unsigned short r0;
135 unsigned short status;
136 unsigned short r1;
137 unsigned short tag;
138 unsigned short r2;
139 unsigned long eip;
140 unsigned short code_seg;
141 unsigned short opcode;
142 unsigned long operand;
143 unsigned short operand_seg;
144 unsigned short r3;
145 unsigned char regs[8][10];
146};
147
1a494973 148static void
84f652b1
C
149print_387_status (status, ep)
150 unsigned short status;
151 struct env387 *ep;
152{
153 int i;
154 int bothstatus;
155 int top;
156 int fpreg;
84f652b1
C
157
158 bothstatus = ((status != 0) && (ep->status != 0));
159 if (status != 0)
160 {
161 if (bothstatus)
162 printf_unfiltered ("u: ");
163 print_387_status_word ((unsigned int)status);
164 }
165
166 if (ep->status != 0)
167 {
168 if (bothstatus)
169 printf_unfiltered ("e: ");
170 print_387_status_word ((unsigned int)ep->status);
171 }
172
173 print_387_control_word ((unsigned int)ep->control);
174 printf_unfiltered ("last exception: ");
175 printf_unfiltered ("opcode %s; ", local_hex_string(ep->opcode));
176 printf_unfiltered ("pc %s:", local_hex_string(ep->code_seg));
177 printf_unfiltered ("%s; ", local_hex_string(ep->eip));
178 printf_unfiltered ("operand %s", local_hex_string(ep->operand_seg));
179 printf_unfiltered (":%s\n", local_hex_string(ep->operand));
180
181 top = (ep->status >> 11) & 7;
182
183 printf_unfiltered ("regno tag msb lsb value\n");
184 for (fpreg = 7; fpreg >= 0; fpreg--)
185 {
186 double val;
187
188 printf_unfiltered ("%s %d: ", fpreg == top ? "=>" : " ", fpreg);
189
190 switch ((ep->tag >> (fpreg * 2)) & 3)
191 {
192 case 0: printf_unfiltered ("valid "); break;
193 case 1: printf_unfiltered ("zero "); break;
194 case 2: printf_unfiltered ("trap "); break;
195 case 3: printf_unfiltered ("empty "); break;
196 }
197 for (i = 9; i >= 0; i--)
198 printf_unfiltered ("%02x", ep->regs[fpreg][i]);
199
200 floatformat_to_double(&floatformat_i387_ext, (char *) ep->regs[fpreg],
201 &val);
202 printf_unfiltered (" %g\n", val);
203 }
204}
205
206i386_float_info ()
207{
208 struct user u; /* just for address computations */
209 int i;
210 /* fpstate defined in <sys/user.h> */
211 struct fpstate *fpstatep;
212 char buf[sizeof (struct fpstate) + 2 * sizeof (int)];
213 unsigned int uaddr;
214 char fpvalid;
215 unsigned int rounded_addr;
216 unsigned int rounded_size;
217 /*extern int corechan;*/
218 int skip;
219 extern int inferior_pid;
220
221 uaddr = (char *)&U_FPSTATE(u) - (char *)&u;
222 if (inferior_pid)
223 {
224 int *ip;
225
226 rounded_addr = uaddr & -sizeof (int);
227 rounded_size = (((uaddr + sizeof (struct fpstate)) - uaddr) +
228 sizeof (int) - 1) / sizeof (int);
229 skip = uaddr - rounded_addr;
230
231 ip = (int *)buf;
232 for (i = 0; i < rounded_size; i++)
233 {
234 *ip++ = ptrace (PT_READ_U, inferior_pid, (caddr_t)rounded_addr, 0);
235 rounded_addr += sizeof (int);
236 }
237 }
238 else
239 {
240 printf("float info: can't do a core file (yet)\n");
241 return;
242#if 0
243 if (lseek (corechan, uaddr, 0) < 0)
244 perror_with_name ("seek on core file");
245 if (myread (corechan, buf, sizeof (struct fpstate)) < 0)
246 perror_with_name ("read from core file");
247 skip = 0;
248#endif
249 }
250
251 print_387_status (0, (struct env387 *)buf);
252}
253
7531f36e
FF
254int
255kernel_u_size ()
256{
257 return (sizeof (struct user));
258}
259
84f652b1 260#endif
This page took 0.212123 seconds and 4 git commands to generate.