1 /* i387-specific utility functions, for the remote server for GDB.
2 Copyright 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of GDB.
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 2 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 int num_xmm_registers
= 8;
27 /* Note: These functions preserve the reserved bits in control registers.
28 However, gdbserver promptly throws away that information. */
30 /* These structs should have the proper sizes and alignment on both
31 i386 and x86-64 machines. */
34 /* All these are only sixteen bits, plus padding, except for fop (which
35 is only eleven bits), and fooff / fioff (which are 32 bits each). */
45 /* Space for eight 80-bit FP values. */
50 /* All these are only sixteen bits, plus padding, except for fop (which
51 is only eleven bits), and fooff / fioff (which are 32 bits each). */
65 /* Space for eight 80-bit FP values in 128-bit spaces. */
68 /* Space for eight 128-bit XMM values, or 16 on x86-64. */
73 i387_cache_to_fsave (void *buf
)
75 struct i387_fsave
*fp
= (struct i387_fsave
*) buf
;
77 int st0_regnum
= find_regno ("st0");
78 unsigned long val
, val2
;
80 for (i
= 0; i
< 8; i
++)
81 collect_register (i
+ st0_regnum
, ((char *) &fp
->st_space
[0]) + i
* 10);
83 collect_register_by_name ("fioff", &fp
->fioff
);
84 collect_register_by_name ("fooff", &fp
->fooff
);
86 /* This one's 11 bits... */
87 collect_register_by_name ("fop", &val2
);
88 fp
->fop
= (val2
& 0x7FF) | (fp
->fop
& 0xF800);
90 /* Some registers are 16-bit. */
91 collect_register_by_name ("fctrl", &val
);
92 *(unsigned short *) &fp
->fctrl
= val
;
94 collect_register_by_name ("fstat", &val
);
96 *(unsigned short *) &fp
->fstat
= val
;
98 collect_register_by_name ("ftag", &val
);
100 *(unsigned short *) &fp
->ftag
= val
;
102 collect_register_by_name ("fiseg", &val
);
104 *(unsigned short *) &fp
->fiseg
= val
;
106 collect_register_by_name ("foseg", &val
);
108 *(unsigned short *) &fp
->foseg
= val
;
112 i387_fsave_to_cache (const void *buf
)
114 struct i387_fsave
*fp
= (struct i387_fsave
*) buf
;
116 int st0_regnum
= find_regno ("st0");
119 for (i
= 0; i
< 8; i
++)
120 supply_register (i
+ st0_regnum
, ((char *) &fp
->st_space
[0]) + i
* 10);
122 supply_register_by_name ("fioff", &fp
->fioff
);
123 supply_register_by_name ("fooff", &fp
->fooff
);
125 /* Some registers are 16-bit. */
126 val
= fp
->fctrl
& 0xFFFF;
127 supply_register_by_name ("fctrl", &val
);
129 val
= fp
->fstat
& 0xFFFF;
130 supply_register_by_name ("fstat", &val
);
132 val
= fp
->ftag
& 0xFFFF;
133 supply_register_by_name ("ftag", &val
);
135 val
= fp
->fiseg
& 0xFFFF;
136 supply_register_by_name ("fiseg", &val
);
138 val
= fp
->foseg
& 0xFFFF;
139 supply_register_by_name ("foseg", &val
);
141 val
= (fp
->fop
) & 0x7FF;
142 supply_register_by_name ("fop", &val
);
146 i387_cache_to_fxsave (void *buf
)
148 struct i387_fxsave
*fp
= (struct i387_fxsave
*) buf
;
150 int st0_regnum
= find_regno ("st0");
151 int xmm0_regnum
= find_regno ("xmm0");
152 unsigned long val
, val2
;
154 for (i
= 0; i
< 8; i
++)
155 collect_register (i
+ st0_regnum
, ((char *) &fp
->st_space
[0]) + i
* 16);
156 for (i
= 0; i
< num_xmm_registers
; i
++)
157 collect_register (i
+ xmm0_regnum
, ((char *) &fp
->xmm_space
[0]) + i
* 16);
159 collect_register_by_name ("fioff", &fp
->fioff
);
160 collect_register_by_name ("fooff", &fp
->fooff
);
161 collect_register_by_name ("mxcsr", &fp
->mxcsr
);
163 /* This one's 11 bits... */
164 collect_register_by_name ("fop", &val2
);
165 fp
->fop
= (val2
& 0x7FF) | (fp
->fop
& 0xF800);
167 /* Some registers are 16-bit. */
168 collect_register_by_name ("fctrl", &val
);
169 *(unsigned short *) &fp
->fctrl
= val
;
171 collect_register_by_name ("fstat", &val
);
173 *(unsigned short *) &fp
->fstat
= val
;
175 /* Convert to the simplifed tag form stored in fxsave data. */
176 collect_register_by_name ("ftag", &val
);
178 for (i
= 7; i
>= 0; i
--)
180 int tag
= (val
>> (i
* 2)) & 3;
185 *(unsigned short *) &fp
->ftag
= val2
;
187 collect_register_by_name ("fiseg", &val
);
189 *(unsigned short *) &fp
->fiseg
= val
;
191 collect_register_by_name ("foseg", &val
);
193 *(unsigned short *) &fp
->foseg
= val
;
197 i387_ftag (struct i387_fxsave
*fp
, int regno
)
199 unsigned char *raw
= &fp
->st_space
[regno
* 16];
200 unsigned int exponent
;
201 unsigned long fraction
[2];
204 integer
= raw
[7] & 0x80;
205 exponent
= (((raw
[9] & 0x7f) << 8) | raw
[8]);
206 fraction
[0] = ((raw
[3] << 24) | (raw
[2] << 16) | (raw
[1] << 8) | raw
[0]);
207 fraction
[1] = (((raw
[7] & 0x7f) << 24) | (raw
[6] << 16)
208 | (raw
[5] << 8) | raw
[4]);
210 if (exponent
== 0x7fff)
215 else if (exponent
== 0x0000)
217 if (fraction
[0] == 0x0000 && fraction
[1] == 0x0000 && !integer
)
244 i387_fxsave_to_cache (const void *buf
)
246 struct i387_fxsave
*fp
= (struct i387_fxsave
*) buf
;
248 int st0_regnum
= find_regno ("st0");
249 int xmm0_regnum
= find_regno ("xmm0");
252 for (i
= 0; i
< 8; i
++)
253 supply_register (i
+ st0_regnum
, ((char *) &fp
->st_space
[0]) + i
* 16);
254 for (i
= 0; i
< num_xmm_registers
; i
++)
255 supply_register (i
+ xmm0_regnum
, ((char *) &fp
->xmm_space
[0]) + i
* 16);
257 supply_register_by_name ("fioff", &fp
->fioff
);
258 supply_register_by_name ("fooff", &fp
->fooff
);
259 supply_register_by_name ("mxcsr", &fp
->mxcsr
);
261 /* Some registers are 16-bit. */
262 val
= fp
->fctrl
& 0xFFFF;
263 supply_register_by_name ("fctrl", &val
);
265 val
= fp
->fstat
& 0xFFFF;
266 supply_register_by_name ("fstat", &val
);
268 /* Generate the form of ftag data that GDB expects. */
269 top
= (fp
->fstat
>> 11) & 0x7;
271 for (i
= 7; i
>= 0; i
--)
275 tag
= i387_ftag (fp
, (i
+ 8 - top
) % 8);
278 val
|= tag
<< (2 * i
);
280 supply_register_by_name ("ftag", &val
);
282 val
= fp
->fiseg
& 0xFFFF;
283 supply_register_by_name ("fiseg", &val
);
285 val
= fp
->foseg
& 0xFFFF;
286 supply_register_by_name ("foseg", &val
);
288 val
= (fp
->fop
) & 0x7FF;
289 supply_register_by_name ("fop", &val
);
This page took 0.035888 seconds and 4 git commands to generate.