1 /* i387-specific utility functions, for the remote server for GDB.
2 Copyright (C) 2000, 2001, 2002, 2005, 2007 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
24 int num_xmm_registers
= 8;
26 /* Note: These functions preserve the reserved bits in control registers.
27 However, gdbserver promptly throws away that information. */
29 /* These structs should have the proper sizes and alignment on both
30 i386 and x86-64 machines. */
33 /* All these are only sixteen bits, plus padding, except for fop (which
34 is only eleven bits), and fooff / fioff (which are 32 bits each). */
48 /* Space for eight 80-bit FP values. */
49 unsigned char st_space
[80];
53 /* All these are only sixteen bits, plus padding, except for fop (which
54 is only eleven bits), and fooff / fioff (which are 32 bits each). */
69 /* Space for eight 80-bit FP values in 128-bit spaces. */
70 unsigned char st_space
[128];
72 /* Space for eight 128-bit XMM values, or 16 on x86-64. */
73 unsigned char xmm_space
[256];
77 i387_cache_to_fsave (void *buf
)
79 struct i387_fsave
*fp
= (struct i387_fsave
*) buf
;
81 int st0_regnum
= find_regno ("st0");
82 unsigned long val
, val2
;
84 for (i
= 0; i
< 8; i
++)
85 collect_register (i
+ st0_regnum
, ((char *) &fp
->st_space
[0]) + i
* 10);
87 collect_register_by_name ("fioff", &fp
->fioff
);
88 collect_register_by_name ("fooff", &fp
->fooff
);
90 /* This one's 11 bits... */
91 collect_register_by_name ("fop", &val2
);
92 fp
->fop
= (val2
& 0x7FF) | (fp
->fop
& 0xF800);
94 /* Some registers are 16-bit. */
95 collect_register_by_name ("fctrl", &val
);
98 collect_register_by_name ("fstat", &val
);
102 collect_register_by_name ("ftag", &val
);
106 collect_register_by_name ("fiseg", &val
);
110 collect_register_by_name ("foseg", &val
);
116 i387_fsave_to_cache (const void *buf
)
118 struct i387_fsave
*fp
= (struct i387_fsave
*) buf
;
120 int st0_regnum
= find_regno ("st0");
123 for (i
= 0; i
< 8; i
++)
124 supply_register (i
+ st0_regnum
, ((char *) &fp
->st_space
[0]) + i
* 10);
126 supply_register_by_name ("fioff", &fp
->fioff
);
127 supply_register_by_name ("fooff", &fp
->fooff
);
129 /* Some registers are 16-bit. */
130 val
= fp
->fctrl
& 0xFFFF;
131 supply_register_by_name ("fctrl", &val
);
133 val
= fp
->fstat
& 0xFFFF;
134 supply_register_by_name ("fstat", &val
);
136 val
= fp
->ftag
& 0xFFFF;
137 supply_register_by_name ("ftag", &val
);
139 val
= fp
->fiseg
& 0xFFFF;
140 supply_register_by_name ("fiseg", &val
);
142 val
= fp
->foseg
& 0xFFFF;
143 supply_register_by_name ("foseg", &val
);
145 /* fop has only 11 valid bits. */
146 val
= (fp
->fop
) & 0x7FF;
147 supply_register_by_name ("fop", &val
);
151 i387_cache_to_fxsave (void *buf
)
153 struct i387_fxsave
*fp
= (struct i387_fxsave
*) buf
;
155 int st0_regnum
= find_regno ("st0");
156 int xmm0_regnum
= find_regno ("xmm0");
157 unsigned long val
, val2
;
159 for (i
= 0; i
< 8; i
++)
160 collect_register (i
+ st0_regnum
, ((char *) &fp
->st_space
[0]) + i
* 16);
161 for (i
= 0; i
< num_xmm_registers
; i
++)
162 collect_register (i
+ xmm0_regnum
, ((char *) &fp
->xmm_space
[0]) + i
* 16);
164 collect_register_by_name ("fioff", &fp
->fioff
);
165 collect_register_by_name ("fooff", &fp
->fooff
);
166 collect_register_by_name ("mxcsr", &fp
->mxcsr
);
168 /* This one's 11 bits... */
169 collect_register_by_name ("fop", &val2
);
170 fp
->fop
= (val2
& 0x7FF) | (fp
->fop
& 0xF800);
172 /* Some registers are 16-bit. */
173 collect_register_by_name ("fctrl", &val
);
176 collect_register_by_name ("fstat", &val
);
179 /* Convert to the simplifed tag form stored in fxsave data. */
180 collect_register_by_name ("ftag", &val
);
183 for (i
= 7; i
>= 0; i
--)
185 int tag
= (val
>> (i
* 2)) & 3;
192 collect_register_by_name ("fiseg", &val
);
195 collect_register_by_name ("foseg", &val
);
200 i387_ftag (struct i387_fxsave
*fp
, int regno
)
202 unsigned char *raw
= &fp
->st_space
[regno
* 16];
203 unsigned int exponent
;
204 unsigned long fraction
[2];
207 integer
= raw
[7] & 0x80;
208 exponent
= (((raw
[9] & 0x7f) << 8) | raw
[8]);
209 fraction
[0] = ((raw
[3] << 24) | (raw
[2] << 16) | (raw
[1] << 8) | raw
[0]);
210 fraction
[1] = (((raw
[7] & 0x7f) << 24) | (raw
[6] << 16)
211 | (raw
[5] << 8) | raw
[4]);
213 if (exponent
== 0x7fff)
218 else if (exponent
== 0x0000)
220 if (fraction
[0] == 0x0000 && fraction
[1] == 0x0000 && !integer
)
247 i387_fxsave_to_cache (const void *buf
)
249 struct i387_fxsave
*fp
= (struct i387_fxsave
*) buf
;
251 int st0_regnum
= find_regno ("st0");
252 int xmm0_regnum
= find_regno ("xmm0");
255 for (i
= 0; i
< 8; i
++)
256 supply_register (i
+ st0_regnum
, ((char *) &fp
->st_space
[0]) + i
* 16);
257 for (i
= 0; i
< num_xmm_registers
; i
++)
258 supply_register (i
+ xmm0_regnum
, ((char *) &fp
->xmm_space
[0]) + i
* 16);
260 supply_register_by_name ("fioff", &fp
->fioff
);
261 supply_register_by_name ("fooff", &fp
->fooff
);
262 supply_register_by_name ("mxcsr", &fp
->mxcsr
);
264 /* Some registers are 16-bit. */
265 val
= fp
->fctrl
& 0xFFFF;
266 supply_register_by_name ("fctrl", &val
);
268 val
= fp
->fstat
& 0xFFFF;
269 supply_register_by_name ("fstat", &val
);
271 /* Generate the form of ftag data that GDB expects. */
272 top
= (fp
->fstat
>> 11) & 0x7;
274 for (i
= 7; i
>= 0; i
--)
277 if (fp
->ftag
& (1 << i
))
278 tag
= i387_ftag (fp
, (i
+ 8 - top
) % 8);
281 val
|= tag
<< (2 * i
);
283 supply_register_by_name ("ftag", &val
);
285 val
= fp
->fiseg
& 0xFFFF;
286 supply_register_by_name ("fiseg", &val
);
288 val
= fp
->foseg
& 0xFFFF;
289 supply_register_by_name ("foseg", &val
);
291 val
= (fp
->fop
) & 0x7FF;
292 supply_register_by_name ("fop", &val
);
This page took 0.035398 seconds and 4 git commands to generate.