]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/i386v-nat.c
* i386v-nat.c: Remove space from front of #endif.
[thirdparty/binutils-gdb.git] / gdb / i386v-nat.c
1 /* Intel 386 native support.
2 Copyright (C) 1988, 1989, 1991, 1992 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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. */
19
20 #include "defs.h"
21 #include "frame.h"
22 #include "inferior.h"
23 #include "language.h"
24 #include "gdbcore.h"
25
26 #ifdef USG
27 #include <sys/types.h>
28 #endif
29
30 #include <sys/param.h>
31 #include <sys/dir.h>
32 #include <signal.h>
33 #include <sys/user.h>
34 #include <sys/ioctl.h>
35 #include <fcntl.h>
36
37 #include <sys/file.h>
38 #include <sys/stat.h>
39
40 #include <sys/reg.h>
41 #include "ieee-float.h"
42
43 #include "target.h"
44
45 extern struct ext_format ext_format_i387;
46 \f
47 /* this table must line up with REGISTER_NAMES in tm-i386v.h */
48 /* symbols like 'EAX' come from <sys/reg.h> */
49 static int regmap[] =
50 {
51 EAX, ECX, EDX, EBX,
52 UESP, EBP, ESI, EDI,
53 EIP, EFL, CS, SS,
54 DS, ES, FS, GS,
55 };
56
57 /* blockend is the value of u.u_ar0, and points to the
58 * place where GS is stored
59 */
60
61 int
62 i386_register_u_addr (blockend, regnum)
63 int blockend;
64 int regnum;
65 {
66 #if 0
67 /* this will be needed if fp registers are reinstated */
68 /* for now, you can look at them with 'info float'
69 * sys5 wont let you change them with ptrace anyway
70 */
71 if (regnum >= FP0_REGNUM && regnum <= FP7_REGNUM)
72 {
73 int ubase, fpstate;
74 struct user u;
75 ubase = blockend + 4 * (SS + 1) - KSTKSZ;
76 fpstate = ubase + ((char *)&u.u_fpstate - (char *)&u);
77 return (fpstate + 0x1c + 10 * (regnum - FP0_REGNUM));
78 }
79 else
80 #endif
81 return (blockend + 4 * regmap[regnum]);
82
83 }
84
85 #if 0
86 /* using FLOAT_INFO as is would be a problem. FLOAT_INFO is called
87 via a command xxx and eventually calls ptrace without ever having
88 traversed the target vector. This would be terribly impolite
89 behaviour for a sun4 hosted remote gdb.
90
91 A fix might be to move this code into the "info registers" command.
92 rich@cygnus.com 15 Sept 92. */
93 i386_float_info ()
94 {
95 struct user u; /* just for address computations */
96 int i;
97 /* fpstate defined in <sys/user.h> */
98 struct fpstate *fpstatep;
99 char buf[sizeof (struct fpstate) + 2 * sizeof (int)];
100 unsigned int uaddr;
101 char fpvalid = 0;
102 unsigned int rounded_addr;
103 unsigned int rounded_size;
104 extern int corechan;
105 int skip;
106
107 uaddr = (char *)&u.u_fpvalid - (char *)&u;
108 if (target_has_execution)
109 {
110 unsigned int data;
111 unsigned int mask;
112
113 rounded_addr = uaddr & -sizeof (int);
114 data = ptrace (3, inferior_pid, (PTRACE_ARG3_TYPE) rounded_addr, 0);
115 mask = 0xff << ((uaddr - rounded_addr) * 8);
116
117 fpvalid = ((data & mask) != 0);
118 }
119 #if 0
120 else
121 {
122 if (lseek (corechan, uaddr, 0) < 0)
123 perror ("seek on core file");
124 if (myread (corechan, &fpvalid, 1) < 0)
125 perror ("read on core file");
126
127 }
128 #endif /* no core support yet */
129
130 if (fpvalid == 0)
131 {
132 printf ("no floating point status saved\n");
133 return;
134 }
135
136 uaddr = (char *)&U_FPSTATE(u) - (char *)&u;
137 if (target_has_execution)
138 {
139 int *ip;
140
141 rounded_addr = uaddr & -sizeof (int);
142 rounded_size = (((uaddr + sizeof (struct fpstate)) - uaddr) +
143 sizeof (int) - 1) / sizeof (int);
144 skip = uaddr - rounded_addr;
145
146 ip = (int *)buf;
147 for (i = 0; i < rounded_size; i++)
148 {
149 *ip++ = ptrace (3, inferior_pid, (PTRACE_ARG3_TYPE) rounded_addr, 0);
150 rounded_addr += sizeof (int);
151 }
152 }
153 #if 0
154 else
155 {
156 if (lseek (corechan, uaddr, 0) < 0)
157 perror_with_name ("seek on core file");
158 if (myread (corechan, buf, sizeof (struct fpstate)) < 0)
159 perror_with_name ("read from core file");
160 skip = 0;
161 }
162 #endif /* 0 */
163
164 fpstatep = (struct fpstate *)(buf + skip);
165 print_387_status (fpstatep->status, (struct env387 *)fpstatep->state);
166 }
167
168 #endif /* never */