* scripttempl/h8300.sc: Use all 64K for ram.
[deliverable/binutils-gdb.git] / gdb / i386b-nat.c
CommitLineData
ede9d8a7 1/* Native-dependent code for BSD Unix running on i386's, for GDB.
84f652b1 2 Copyright 1988, 1989, 1991, 1992, 1994 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"
6d685882
JG
21#include <machine/reg.h>
22
6d685882
JG
23/* this table must line up with REGISTER_NAMES in tm-i386.h */
24/* symbols like 'tEAX' come from <machine/reg.h> */
25static int tregmap[] =
26{
27 tEAX, tECX, tEDX, tEBX,
28 tESP, tEBP, tESI, tEDI,
29 tEIP, tEFLAGS, tCS, tSS
30};
11ebf939
JK
31
32#ifdef sEAX
6d685882
JG
33static int sregmap[] =
34{
35 sEAX, sECX, sEDX, sEBX,
36 sESP, sEBP, sESI, sEDI,
37 sEIP, sEFLAGS, sCS, sSS
38};
11ebf939
JK
39#else /* No sEAX */
40
41/* NetBSD has decided to collapse the s* and t* symbols. So if the s*
42 ones aren't around, use the t* ones for sregmap too. */
43
44static int sregmap[] =
45{
46 tEAX, tECX, tEDX, tEBX,
47 tESP, tEBP, tESI, tEDI,
48 tEIP, tEFLAGS, tCS, tSS
49};
50#endif /* No sEAX */
6d685882
JG
51
52/* blockend is the value of u.u_ar0, and points to the
53 place where ES is stored. */
54
55int
56i386_register_u_addr (blockend, regnum)
57 int blockend;
58 int regnum;
59{
60 /* The following condition is a kludge to get at the proper register map
61 depending upon the state of pcb_flag.
62 The proper condition would be
63 if (u.u_pcb.pcb_flag & FM_TRAP)
64 but that would require a ptrace call here and wouldn't work
65 for corefiles. */
66
67 if (blockend < 0x1fcc)
68 return (blockend + 4 * tregmap[regnum]);
69 else
70 return (blockend + 4 * sregmap[regnum]);
71}
84f652b1
C
72
73
74#ifdef FLOAT_INFO
1a494973 75#include "language.h" /* for local_hex_string */
84f652b1
C
76#include "floatformat.h"
77
78#include <sys/param.h>
79#include <sys/dir.h>
80#include <signal.h>
81#include <sys/ioctl.h>
82#include <fcntl.h>
83
84#include <a.out.h>
85
86#include <sys/time.h>
87#include <sys/resource.h>
88#include <sys/uio.h>
89#define curpcb Xcurpcb /* XXX avoid leaking declaration from pcb.h */
90#include <sys/user.h>
91#undef curpcb
92#include <sys/file.h>
2b576293 93#include "gdb_stat.h"
84f652b1
C
94#include <sys/ptrace.h>
95
96extern void print_387_control_word (); /* i387-tdep.h */
97extern void print_387_status_word ();
98
99#define fpstate save87
100#define U_FPSTATE(u) u.u_pcb.pcb_savefpu
101
102struct env387
103{
104 unsigned short control;
105 unsigned short r0;
106 unsigned short status;
107 unsigned short r1;
108 unsigned short tag;
109 unsigned short r2;
110 unsigned long eip;
111 unsigned short code_seg;
112 unsigned short opcode;
113 unsigned long operand;
114 unsigned short operand_seg;
115 unsigned short r3;
116 unsigned char regs[8][10];
117};
118
1a494973 119static void
84f652b1
C
120print_387_status (status, ep)
121 unsigned short status;
122 struct env387 *ep;
123{
124 int i;
125 int bothstatus;
126 int top;
127 int fpreg;
84f652b1
C
128
129 bothstatus = ((status != 0) && (ep->status != 0));
130 if (status != 0)
131 {
132 if (bothstatus)
133 printf_unfiltered ("u: ");
134 print_387_status_word ((unsigned int)status);
135 }
136
137 if (ep->status != 0)
138 {
139 if (bothstatus)
140 printf_unfiltered ("e: ");
141 print_387_status_word ((unsigned int)ep->status);
142 }
143
144 print_387_control_word ((unsigned int)ep->control);
145 printf_unfiltered ("last exception: ");
146 printf_unfiltered ("opcode %s; ", local_hex_string(ep->opcode));
147 printf_unfiltered ("pc %s:", local_hex_string(ep->code_seg));
148 printf_unfiltered ("%s; ", local_hex_string(ep->eip));
149 printf_unfiltered ("operand %s", local_hex_string(ep->operand_seg));
150 printf_unfiltered (":%s\n", local_hex_string(ep->operand));
151
152 top = (ep->status >> 11) & 7;
153
154 printf_unfiltered ("regno tag msb lsb value\n");
155 for (fpreg = 7; fpreg >= 0; fpreg--)
156 {
157 double val;
158
159 printf_unfiltered ("%s %d: ", fpreg == top ? "=>" : " ", fpreg);
160
161 switch ((ep->tag >> (fpreg * 2)) & 3)
162 {
163 case 0: printf_unfiltered ("valid "); break;
164 case 1: printf_unfiltered ("zero "); break;
165 case 2: printf_unfiltered ("trap "); break;
166 case 3: printf_unfiltered ("empty "); break;
167 }
168 for (i = 9; i >= 0; i--)
169 printf_unfiltered ("%02x", ep->regs[fpreg][i]);
170
171 floatformat_to_double(&floatformat_i387_ext, (char *) ep->regs[fpreg],
172 &val);
173 printf_unfiltered (" %g\n", val);
174 }
175}
176
177i386_float_info ()
178{
179 struct user u; /* just for address computations */
180 int i;
181 /* fpstate defined in <sys/user.h> */
182 struct fpstate *fpstatep;
183 char buf[sizeof (struct fpstate) + 2 * sizeof (int)];
184 unsigned int uaddr;
185 char fpvalid;
186 unsigned int rounded_addr;
187 unsigned int rounded_size;
188 /*extern int corechan;*/
189 int skip;
190 extern int inferior_pid;
191
192 uaddr = (char *)&U_FPSTATE(u) - (char *)&u;
193 if (inferior_pid)
194 {
195 int *ip;
196
197 rounded_addr = uaddr & -sizeof (int);
198 rounded_size = (((uaddr + sizeof (struct fpstate)) - uaddr) +
199 sizeof (int) - 1) / sizeof (int);
200 skip = uaddr - rounded_addr;
201
202 ip = (int *)buf;
203 for (i = 0; i < rounded_size; i++)
204 {
205 *ip++ = ptrace (PT_READ_U, inferior_pid, (caddr_t)rounded_addr, 0);
206 rounded_addr += sizeof (int);
207 }
208 }
209 else
210 {
211 printf("float info: can't do a core file (yet)\n");
212 return;
213#if 0
214 if (lseek (corechan, uaddr, 0) < 0)
215 perror_with_name ("seek on core file");
216 if (myread (corechan, buf, sizeof (struct fpstate)) < 0)
217 perror_with_name ("read from core file");
218 skip = 0;
219#endif
220 }
221
222 print_387_status (0, (struct env387 *)buf);
223}
224
225#endif
This page took 0.187805 seconds and 4 git commands to generate.