GDB (xrefs)

/tmp/gdb-8.1/gdb/i386-v4-nat.c
Go to the documentation of this file.
1 /* Native-dependent code for Unix SVR4 running on i386's.
2
3 Copyright (C) 1988-2018 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "value.h"
22 #include "inferior.h"
23 #include "regcache.h"
24
25 #ifdef HAVE_SYS_REG_H
26 #include <sys/reg.h>
27 #endif
28
29 #include "i386-tdep.h"
30 #include "i387-tdep.h"
31
32 #ifdef HAVE_SYS_PROCFS_H
33
34 #include <sys/procfs.h>
35
36 /* We must not compile this code for 64-bit Solaris x86. */
37 #if !defined (PR_MODEL_NATIVE) || (PR_MODEL_NATIVE == PR_MODEL_ILP32)
38
39 #include "gregset.h"
40
41 /* The `/proc' interface divides the target machine's register set up
42 into two different sets, the general purpose register set (gregset)
43 and the floating-point register set (fpregset). For each set,
44 there is an ioctl to get the current register set and another ioctl
45 to set the current values.
46
47 The actual structure passed through the ioctl interface is, of
48 course, naturally machine dependent, and is different for each set
49 of registers. For the i386 for example, the general-purpose
50 register set is typically defined by:
51
52 typedef int gregset_t[19]; (in <sys/regset.h>)
53
54 #define GS 0 (in <sys/reg.h>)
55 #define FS 1
56 ...
57 #define UESP 17
58 #define SS 18
59
60 and the floating-point set by:
61
62 typedef struct fpregset {
63 union {
64 struct fpchip_state // fp extension state //
65 {
66 int state[27]; // 287/387 saved state //
67 int status; // status word saved at //
68 // exception //
69 } fpchip_state;
70 struct fp_emul_space // for emulators //
71 {
72 char fp_emul[246];
73 char fp_epad[2];
74 } fp_emul_space;
75 int f_fpregs[62]; // union of the above //
76 } fp_reg_set;
77 long f_wregs[33]; // saved weitek state //
78 } fpregset_t;
79
80 Incidentally fpchip_state contains the FPU state in the same format
81 as used by the "fsave" instruction, and that's the only thing we
82 support here. I don't know how the emulator stores it state. The
83 Weitek stuff definitely isn't supported.
84
85 The routines defined here, provide the packing and unpacking of
86 gregset_t and fpregset_t formatted data. */
87
88 #ifdef HAVE_GREGSET_T
89
90 /* Mapping between the general-purpose registers in `/proc'
91 format and GDB's register array layout. */
92 static int regmap[] =
93 {
94 EAX, ECX, EDX, EBX,
95 UESP, EBP, ESI, EDI,
96 EIP, EFL, CS, SS,
97 DS, ES, FS, GS
98 };
99
100 /* Fill GDB's register array with the general-purpose register values
101 in *GREGSETP. */
102
103 void
104 supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
105 {
106 const greg_t *regp = (const greg_t *) gregsetp;
107 int regnum;
108
109 for (regnum = 0; regnum < I386_NUM_GREGS; regnum++)
110 regcache_raw_supply (regcache, regnum, regp + regmap[regnum]);
111 }
112
113 /* Fill register REGNUM (if it is a general-purpose register) in
114 *GREGSETPS with the value in GDB's register array. If REGNUM is -1,
115 do this for all registers. */
116
117 void
118 fill_gregset (const struct regcache *regcache,
119 gregset_t *gregsetp, int regnum)
120 {
121 greg_t *regp = (greg_t *) gregsetp;
122 int i;
123
124 for (i = 0; i < I386_NUM_GREGS; i++)
125 if (regnum == -1 || regnum == i)
126 regcache_raw_collect (regcache, i, regp + regmap[i]);
127 }
128
129 #endif /* HAVE_GREGSET_T */
130
131 #ifdef HAVE_FPREGSET_T
132
133 /* Fill GDB's register array with the floating-point register values in
134 *FPREGSETP. */
135
136 void
137 supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
138 {
139 if (gdbarch_fp0_regnum (regcache->arch ()) == 0)
140 return;
141
142 i387_supply_fsave (regcache, -1, fpregsetp);
143 }
144
145 /* Fill register REGNO (if it is a floating-point register) in
146 *FPREGSETP with the value in GDB's register array. If REGNO is -1,
147 do this for all registers. */
148
149 void
150 fill_fpregset (const struct regcache *regcache,
151 fpregset_t *fpregsetp, int regno)
152 {
153 if (gdbarch_fp0_regnum (regcache->arch ()) == 0)
154 return;
155
156 i387_collect_fsave (regcache, regno, fpregsetp);
157 }
158
159 #endif /* HAVE_FPREGSET_T */
160
161 #endif /* not 64-bit. */
162
163 #endif /* HAVE_SYS_PROCFS_H */
i387_collect_fsave
void i387_collect_fsave(const struct regcache *regcache, int regnum, void *fsave)
Definition: i387-tdep.c:493
I386_NUM_GREGS
#define I386_NUM_GREGS
Definition: i386-tdep.h:332
fill_gregset
void fill_gregset(const struct regcache *regcache, gdb_gregset_t *gregsetp, int regno)
Definition: aarch64-linux-nat.c:386
i387_supply_fsave
void i387_supply_fsave(struct regcache *regcache, int regnum, const void *fsave)
Definition: i387-tdep.c:438
regmap
static int regmap[]
Definition: m32r-linux-nat.c:45
defs.h
fill_fpregset
void fill_fpregset(const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regno)
Definition: aarch64-linux-nat.c:410
regcache.h
fpregset_t
struct fpreg fpregset_t
Definition: alpha-bsd-nat.c:41
supply_gregset
void supply_gregset(struct regcache *regcache, const gdb_gregset_t *gregsetp)
Definition: aarch64-linux-nat.c:398
inferior.h
regnum
int regnum
Definition: aarch64-tdep.c:77
gregset.h
reg
Definition: regdef.h:22
gdbarch_fp0_regnum
int gdbarch_fp0_regnum(struct gdbarch *gdbarch)
Definition: gdbarch.c:2197
regcache::arch
gdbarch * arch() const
Definition: regcache.c:221
value.h
regcache_raw_supply
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1004
regcache
Definition: regcache.h:232
regcache_raw_collect
void regcache_raw_collect(const struct regcache *regcache, int regnum, void *buf)
Definition: regcache.c:1085
i386-tdep.h
i387-tdep.h
supply_fpregset
void supply_fpregset(struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
Definition: aarch64-linux-nat.c:422