Commit | Line | Data |
---|---|---|
58caa3dc | 1 | /* i387-specific utility functions, for the remote server for GDB. |
ecd75fc8 | 2 | Copyright (C) 2000-2014 Free Software Foundation, Inc. |
58caa3dc DJ |
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 | |
a9762ec7 | 8 | the Free Software Foundation; either version 3 of the License, or |
58caa3dc DJ |
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 | |
a9762ec7 | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
58caa3dc DJ |
18 | |
19 | #include "server.h" | |
0d62e5e8 | 20 | #include "i387-fp.h" |
1570b33e | 21 | #include "i386-xstate.h" |
58caa3dc | 22 | |
a196ebeb WT |
23 | static const int num_mpx_bnd_registers = 4; |
24 | static const int num_mpx_cfg_registers = 2; | |
25 | ||
58caa3dc DJ |
26 | /* Note: These functions preserve the reserved bits in control registers. |
27 | However, gdbserver promptly throws away that information. */ | |
28 | ||
29 | /* These structs should have the proper sizes and alignment on both | |
30 | i386 and x86-64 machines. */ | |
31 | ||
32 | struct i387_fsave { | |
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). */ | |
0c2ead7e DJ |
35 | unsigned short fctrl; |
36 | unsigned short pad1; | |
37 | unsigned short fstat; | |
38 | unsigned short pad2; | |
39 | unsigned short ftag; | |
40 | unsigned short pad3; | |
58caa3dc DJ |
41 | unsigned int fioff; |
42 | unsigned short fiseg; | |
43 | unsigned short fop; | |
44 | unsigned int fooff; | |
0c2ead7e DJ |
45 | unsigned short foseg; |
46 | unsigned short pad4; | |
58caa3dc DJ |
47 | |
48 | /* Space for eight 80-bit FP values. */ | |
f450004a | 49 | unsigned char st_space[80]; |
58caa3dc DJ |
50 | }; |
51 | ||
52 | struct i387_fxsave { | |
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). */ | |
55 | unsigned short fctrl; | |
56 | unsigned short fstat; | |
57 | unsigned short ftag; | |
58 | unsigned short fop; | |
59 | unsigned int fioff; | |
0c2ead7e DJ |
60 | unsigned short fiseg; |
61 | unsigned short pad1; | |
58caa3dc | 62 | unsigned int fooff; |
0c2ead7e DJ |
63 | unsigned short foseg; |
64 | unsigned short pad12; | |
58caa3dc DJ |
65 | |
66 | unsigned int mxcsr; | |
0c2ead7e | 67 | unsigned int pad3; |
58caa3dc DJ |
68 | |
69 | /* Space for eight 80-bit FP values in 128-bit spaces. */ | |
f450004a | 70 | unsigned char st_space[128]; |
58caa3dc DJ |
71 | |
72 | /* Space for eight 128-bit XMM values, or 16 on x86-64. */ | |
f450004a | 73 | unsigned char xmm_space[256]; |
58caa3dc DJ |
74 | }; |
75 | ||
1570b33e L |
76 | struct i387_xsave { |
77 | /* All these are only sixteen bits, plus padding, except for fop (which | |
78 | is only eleven bits), and fooff / fioff (which are 32 bits each). */ | |
79 | unsigned short fctrl; | |
80 | unsigned short fstat; | |
81 | unsigned short ftag; | |
82 | unsigned short fop; | |
83 | unsigned int fioff; | |
84 | unsigned short fiseg; | |
85 | unsigned short pad1; | |
86 | unsigned int fooff; | |
87 | unsigned short foseg; | |
88 | unsigned short pad12; | |
89 | ||
90 | unsigned int mxcsr; | |
91 | unsigned int mxcsr_mask; | |
92 | ||
93 | /* Space for eight 80-bit FP values in 128-bit spaces. */ | |
94 | unsigned char st_space[128]; | |
95 | ||
96 | /* Space for eight 128-bit XMM values, or 16 on x86-64. */ | |
97 | unsigned char xmm_space[256]; | |
98 | ||
99 | unsigned char reserved1[48]; | |
100 | ||
101 | /* The extended control register 0 (the XFEATURE_ENABLED_MASK | |
102 | register). */ | |
103 | unsigned long long xcr0; | |
104 | ||
105 | unsigned char reserved2[40]; | |
106 | ||
107 | /* The XSTATE_BV bit vector. */ | |
108 | unsigned long long xstate_bv; | |
109 | ||
110 | unsigned char reserved3[56]; | |
111 | ||
112 | /* Space for eight upper 128-bit YMM values, or 16 on x86-64. */ | |
113 | unsigned char ymmh_space[256]; | |
a196ebeb WT |
114 | |
115 | unsigned char reserved4[128]; | |
116 | ||
117 | /* Space for 4 bound registers values of 128 bits. */ | |
118 | unsigned char mpx_bnd_space[64]; | |
119 | ||
120 | /* Space for 2 MPX configuration registers of 64 bits | |
121 | plus reserved space. */ | |
122 | unsigned char mpx_cfg_space[16]; | |
1570b33e L |
123 | }; |
124 | ||
58caa3dc | 125 | void |
442ea881 | 126 | i387_cache_to_fsave (struct regcache *regcache, void *buf) |
58caa3dc DJ |
127 | { |
128 | struct i387_fsave *fp = (struct i387_fsave *) buf; | |
129 | int i; | |
3aee8918 | 130 | int st0_regnum = find_regno (regcache->tdesc, "st0"); |
58caa3dc DJ |
131 | unsigned long val, val2; |
132 | ||
133 | for (i = 0; i < 8; i++) | |
442ea881 PA |
134 | collect_register (regcache, i + st0_regnum, |
135 | ((char *) &fp->st_space[0]) + i * 10); | |
58caa3dc | 136 | |
442ea881 PA |
137 | collect_register_by_name (regcache, "fioff", &fp->fioff); |
138 | collect_register_by_name (regcache, "fooff", &fp->fooff); | |
58caa3dc DJ |
139 | |
140 | /* This one's 11 bits... */ | |
442ea881 | 141 | collect_register_by_name (regcache, "fop", &val2); |
58caa3dc DJ |
142 | fp->fop = (val2 & 0x7FF) | (fp->fop & 0xF800); |
143 | ||
144 | /* Some registers are 16-bit. */ | |
442ea881 | 145 | collect_register_by_name (regcache, "fctrl", &val); |
0c2ead7e | 146 | fp->fctrl = val; |
58caa3dc | 147 | |
442ea881 | 148 | collect_register_by_name (regcache, "fstat", &val); |
58caa3dc | 149 | val &= 0xFFFF; |
0c2ead7e | 150 | fp->fstat = val; |
58caa3dc | 151 | |
442ea881 | 152 | collect_register_by_name (regcache, "ftag", &val); |
58caa3dc | 153 | val &= 0xFFFF; |
0c2ead7e | 154 | fp->ftag = val; |
58caa3dc | 155 | |
442ea881 | 156 | collect_register_by_name (regcache, "fiseg", &val); |
58caa3dc | 157 | val &= 0xFFFF; |
0c2ead7e | 158 | fp->fiseg = val; |
58caa3dc | 159 | |
442ea881 | 160 | collect_register_by_name (regcache, "foseg", &val); |
58caa3dc | 161 | val &= 0xFFFF; |
0c2ead7e | 162 | fp->foseg = val; |
58caa3dc DJ |
163 | } |
164 | ||
165 | void | |
442ea881 | 166 | i387_fsave_to_cache (struct regcache *regcache, const void *buf) |
58caa3dc DJ |
167 | { |
168 | struct i387_fsave *fp = (struct i387_fsave *) buf; | |
169 | int i; | |
3aee8918 | 170 | int st0_regnum = find_regno (regcache->tdesc, "st0"); |
58caa3dc DJ |
171 | unsigned long val; |
172 | ||
173 | for (i = 0; i < 8; i++) | |
442ea881 PA |
174 | supply_register (regcache, i + st0_regnum, |
175 | ((char *) &fp->st_space[0]) + i * 10); | |
58caa3dc | 176 | |
442ea881 PA |
177 | supply_register_by_name (regcache, "fioff", &fp->fioff); |
178 | supply_register_by_name (regcache, "fooff", &fp->fooff); | |
1b3f6016 | 179 | |
58caa3dc DJ |
180 | /* Some registers are 16-bit. */ |
181 | val = fp->fctrl & 0xFFFF; | |
442ea881 | 182 | supply_register_by_name (regcache, "fctrl", &val); |
58caa3dc DJ |
183 | |
184 | val = fp->fstat & 0xFFFF; | |
442ea881 | 185 | supply_register_by_name (regcache, "fstat", &val); |
58caa3dc DJ |
186 | |
187 | val = fp->ftag & 0xFFFF; | |
442ea881 | 188 | supply_register_by_name (regcache, "ftag", &val); |
58caa3dc DJ |
189 | |
190 | val = fp->fiseg & 0xFFFF; | |
442ea881 | 191 | supply_register_by_name (regcache, "fiseg", &val); |
58caa3dc DJ |
192 | |
193 | val = fp->foseg & 0xFFFF; | |
442ea881 | 194 | supply_register_by_name (regcache, "foseg", &val); |
58caa3dc | 195 | |
0c2ead7e | 196 | /* fop has only 11 valid bits. */ |
58caa3dc | 197 | val = (fp->fop) & 0x7FF; |
442ea881 | 198 | supply_register_by_name (regcache, "fop", &val); |
58caa3dc DJ |
199 | } |
200 | ||
201 | void | |
442ea881 | 202 | i387_cache_to_fxsave (struct regcache *regcache, void *buf) |
58caa3dc DJ |
203 | { |
204 | struct i387_fxsave *fp = (struct i387_fxsave *) buf; | |
205 | int i; | |
3aee8918 PA |
206 | int st0_regnum = find_regno (regcache->tdesc, "st0"); |
207 | int xmm0_regnum = find_regno (regcache->tdesc, "xmm0"); | |
58caa3dc | 208 | unsigned long val, val2; |
3aee8918 PA |
209 | /* Amd64 has 16 xmm regs; I386 has 8 xmm regs. */ |
210 | int num_xmm_registers = register_size (regcache->tdesc, 0) == 8 ? 16 : 8; | |
58caa3dc DJ |
211 | |
212 | for (i = 0; i < 8; i++) | |
442ea881 PA |
213 | collect_register (regcache, i + st0_regnum, |
214 | ((char *) &fp->st_space[0]) + i * 16); | |
58caa3dc | 215 | for (i = 0; i < num_xmm_registers; i++) |
442ea881 PA |
216 | collect_register (regcache, i + xmm0_regnum, |
217 | ((char *) &fp->xmm_space[0]) + i * 16); | |
58caa3dc | 218 | |
442ea881 PA |
219 | collect_register_by_name (regcache, "fioff", &fp->fioff); |
220 | collect_register_by_name (regcache, "fooff", &fp->fooff); | |
221 | collect_register_by_name (regcache, "mxcsr", &fp->mxcsr); | |
1b3f6016 | 222 | |
58caa3dc | 223 | /* This one's 11 bits... */ |
442ea881 | 224 | collect_register_by_name (regcache, "fop", &val2); |
58caa3dc DJ |
225 | fp->fop = (val2 & 0x7FF) | (fp->fop & 0xF800); |
226 | ||
227 | /* Some registers are 16-bit. */ | |
442ea881 | 228 | collect_register_by_name (regcache, "fctrl", &val); |
0c2ead7e | 229 | fp->fctrl = val; |
58caa3dc | 230 | |
442ea881 | 231 | collect_register_by_name (regcache, "fstat", &val); |
0c2ead7e | 232 | fp->fstat = val; |
58caa3dc DJ |
233 | |
234 | /* Convert to the simplifed tag form stored in fxsave data. */ | |
442ea881 | 235 | collect_register_by_name (regcache, "ftag", &val); |
58caa3dc | 236 | val &= 0xFFFF; |
73725ff3 | 237 | val2 = 0; |
58caa3dc DJ |
238 | for (i = 7; i >= 0; i--) |
239 | { | |
240 | int tag = (val >> (i * 2)) & 3; | |
241 | ||
242 | if (tag != 3) | |
243 | val2 |= (1 << i); | |
244 | } | |
0c2ead7e | 245 | fp->ftag = val2; |
58caa3dc | 246 | |
442ea881 | 247 | collect_register_by_name (regcache, "fiseg", &val); |
0c2ead7e | 248 | fp->fiseg = val; |
58caa3dc | 249 | |
442ea881 | 250 | collect_register_by_name (regcache, "foseg", &val); |
0c2ead7e | 251 | fp->foseg = val; |
58caa3dc DJ |
252 | } |
253 | ||
1570b33e L |
254 | void |
255 | i387_cache_to_xsave (struct regcache *regcache, void *buf) | |
256 | { | |
257 | struct i387_xsave *fp = (struct i387_xsave *) buf; | |
258 | int i; | |
259 | unsigned long val, val2; | |
260 | unsigned int clear_bv; | |
261 | unsigned long long xstate_bv = 0; | |
262 | char raw[16]; | |
263 | char *p; | |
3aee8918 PA |
264 | /* Amd64 has 16 xmm regs; I386 has 8 xmm regs. */ |
265 | int num_xmm_registers = register_size (regcache->tdesc, 0) == 8 ? 16 : 8; | |
1570b33e L |
266 | |
267 | /* The supported bits in `xstat_bv' are 1 byte. Clear part in | |
268 | vector registers if its bit in xstat_bv is zero. */ | |
269 | clear_bv = (~fp->xstate_bv) & x86_xcr0; | |
270 | ||
271 | /* Clear part in x87 and vector registers if its bit in xstat_bv is | |
272 | zero. */ | |
273 | if (clear_bv) | |
274 | { | |
275 | if ((clear_bv & I386_XSTATE_X87)) | |
276 | for (i = 0; i < 8; i++) | |
277 | memset (((char *) &fp->st_space[0]) + i * 16, 0, 10); | |
278 | ||
279 | if ((clear_bv & I386_XSTATE_SSE)) | |
280 | for (i = 0; i < num_xmm_registers; i++) | |
281 | memset (((char *) &fp->xmm_space[0]) + i * 16, 0, 16); | |
282 | ||
283 | if ((clear_bv & I386_XSTATE_AVX)) | |
284 | for (i = 0; i < num_xmm_registers; i++) | |
285 | memset (((char *) &fp->ymmh_space[0]) + i * 16, 0, 16); | |
a196ebeb WT |
286 | |
287 | if ((clear_bv & I386_XSTATE_BNDREGS)) | |
288 | for (i = 0; i < num_mpx_bnd_registers; i++) | |
289 | memset (((char *) &fp->mpx_bnd_space[0]) + i * 16, 0, 16); | |
290 | ||
291 | if ((clear_bv & I386_XSTATE_BNDCFG)) | |
292 | for (i = 0; i < num_mpx_cfg_registers; i++) | |
293 | memset (((char *) &fp->mpx_cfg_space[0]) + i * 8, 0, 8); | |
1570b33e L |
294 | } |
295 | ||
296 | /* Check if any x87 registers are changed. */ | |
297 | if ((x86_xcr0 & I386_XSTATE_X87)) | |
298 | { | |
3aee8918 | 299 | int st0_regnum = find_regno (regcache->tdesc, "st0"); |
1570b33e L |
300 | |
301 | for (i = 0; i < 8; i++) | |
302 | { | |
303 | collect_register (regcache, i + st0_regnum, raw); | |
304 | p = ((char *) &fp->st_space[0]) + i * 16; | |
305 | if (memcmp (raw, p, 10)) | |
306 | { | |
307 | xstate_bv |= I386_XSTATE_X87; | |
308 | memcpy (p, raw, 10); | |
309 | } | |
310 | } | |
311 | } | |
312 | ||
313 | /* Check if any SSE registers are changed. */ | |
314 | if ((x86_xcr0 & I386_XSTATE_SSE)) | |
315 | { | |
3aee8918 | 316 | int xmm0_regnum = find_regno (regcache->tdesc, "xmm0"); |
1570b33e L |
317 | |
318 | for (i = 0; i < num_xmm_registers; i++) | |
319 | { | |
320 | collect_register (regcache, i + xmm0_regnum, raw); | |
321 | p = ((char *) &fp->xmm_space[0]) + i * 16; | |
322 | if (memcmp (raw, p, 16)) | |
323 | { | |
324 | xstate_bv |= I386_XSTATE_SSE; | |
325 | memcpy (p, raw, 16); | |
326 | } | |
327 | } | |
328 | } | |
329 | ||
330 | /* Check if any AVX registers are changed. */ | |
331 | if ((x86_xcr0 & I386_XSTATE_AVX)) | |
332 | { | |
3aee8918 | 333 | int ymm0h_regnum = find_regno (regcache->tdesc, "ymm0h"); |
1570b33e L |
334 | |
335 | for (i = 0; i < num_xmm_registers; i++) | |
336 | { | |
337 | collect_register (regcache, i + ymm0h_regnum, raw); | |
338 | p = ((char *) &fp->ymmh_space[0]) + i * 16; | |
339 | if (memcmp (raw, p, 16)) | |
340 | { | |
341 | xstate_bv |= I386_XSTATE_AVX; | |
342 | memcpy (p, raw, 16); | |
343 | } | |
344 | } | |
345 | } | |
346 | ||
a196ebeb WT |
347 | /* Check if any bound register has changed. */ |
348 | if ((x86_xcr0 & I386_XSTATE_BNDREGS)) | |
349 | { | |
350 | int bnd0r_regnum = find_regno (regcache->tdesc, "bnd0raw"); | |
351 | ||
352 | for (i = 0; i < num_mpx_bnd_registers; i++) | |
353 | { | |
354 | collect_register (regcache, i + bnd0r_regnum, raw); | |
355 | p = ((char *) &fp->mpx_bnd_space[0]) + i * 16; | |
356 | if (memcmp (raw, p, 16)) | |
357 | { | |
358 | xstate_bv |= I386_XSTATE_BNDREGS; | |
359 | memcpy (p, raw, 16); | |
360 | } | |
361 | } | |
362 | } | |
363 | ||
364 | /* Check if any status register has changed. */ | |
365 | if ((x86_xcr0 & I386_XSTATE_BNDCFG)) | |
366 | { | |
367 | int bndcfg_regnum = find_regno (regcache->tdesc, "bndcfgu"); | |
368 | ||
369 | for (i = 0; i < num_mpx_cfg_registers; i++) | |
370 | { | |
371 | collect_register (regcache, i + bndcfg_regnum, raw); | |
372 | p = ((char *) &fp->mpx_cfg_space[0]) + i * 8; | |
373 | if (memcmp (raw, p, 8)) | |
374 | { | |
375 | xstate_bv |= I386_XSTATE_BNDCFG; | |
376 | memcpy (p, raw, 8); | |
377 | } | |
378 | } | |
379 | } | |
380 | ||
1570b33e L |
381 | /* Update the corresponding bits in xstate_bv if any SSE/AVX |
382 | registers are changed. */ | |
383 | fp->xstate_bv |= xstate_bv; | |
384 | ||
385 | collect_register_by_name (regcache, "fioff", &fp->fioff); | |
386 | collect_register_by_name (regcache, "fooff", &fp->fooff); | |
387 | collect_register_by_name (regcache, "mxcsr", &fp->mxcsr); | |
388 | ||
389 | /* This one's 11 bits... */ | |
390 | collect_register_by_name (regcache, "fop", &val2); | |
391 | fp->fop = (val2 & 0x7FF) | (fp->fop & 0xF800); | |
392 | ||
393 | /* Some registers are 16-bit. */ | |
394 | collect_register_by_name (regcache, "fctrl", &val); | |
395 | fp->fctrl = val; | |
396 | ||
397 | collect_register_by_name (regcache, "fstat", &val); | |
398 | fp->fstat = val; | |
399 | ||
400 | /* Convert to the simplifed tag form stored in fxsave data. */ | |
401 | collect_register_by_name (regcache, "ftag", &val); | |
402 | val &= 0xFFFF; | |
403 | val2 = 0; | |
404 | for (i = 7; i >= 0; i--) | |
405 | { | |
406 | int tag = (val >> (i * 2)) & 3; | |
407 | ||
408 | if (tag != 3) | |
409 | val2 |= (1 << i); | |
410 | } | |
411 | fp->ftag = val2; | |
412 | ||
413 | collect_register_by_name (regcache, "fiseg", &val); | |
414 | fp->fiseg = val; | |
415 | ||
416 | collect_register_by_name (regcache, "foseg", &val); | |
417 | fp->foseg = val; | |
418 | } | |
419 | ||
58caa3dc DJ |
420 | static int |
421 | i387_ftag (struct i387_fxsave *fp, int regno) | |
422 | { | |
423 | unsigned char *raw = &fp->st_space[regno * 16]; | |
424 | unsigned int exponent; | |
425 | unsigned long fraction[2]; | |
426 | int integer; | |
427 | ||
428 | integer = raw[7] & 0x80; | |
429 | exponent = (((raw[9] & 0x7f) << 8) | raw[8]); | |
430 | fraction[0] = ((raw[3] << 24) | (raw[2] << 16) | (raw[1] << 8) | raw[0]); | |
431 | fraction[1] = (((raw[7] & 0x7f) << 24) | (raw[6] << 16) | |
1b3f6016 | 432 | | (raw[5] << 8) | raw[4]); |
58caa3dc DJ |
433 | |
434 | if (exponent == 0x7fff) | |
435 | { | |
436 | /* Special. */ | |
437 | return (2); | |
438 | } | |
439 | else if (exponent == 0x0000) | |
440 | { | |
441 | if (fraction[0] == 0x0000 && fraction[1] == 0x0000 && !integer) | |
1b3f6016 PA |
442 | { |
443 | /* Zero. */ | |
444 | return (1); | |
445 | } | |
58caa3dc | 446 | else |
1b3f6016 PA |
447 | { |
448 | /* Special. */ | |
449 | return (2); | |
450 | } | |
58caa3dc DJ |
451 | } |
452 | else | |
453 | { | |
454 | if (integer) | |
1b3f6016 PA |
455 | { |
456 | /* Valid. */ | |
457 | return (0); | |
458 | } | |
58caa3dc | 459 | else |
1b3f6016 PA |
460 | { |
461 | /* Special. */ | |
462 | return (2); | |
463 | } | |
58caa3dc DJ |
464 | } |
465 | } | |
466 | ||
467 | void | |
442ea881 | 468 | i387_fxsave_to_cache (struct regcache *regcache, const void *buf) |
58caa3dc DJ |
469 | { |
470 | struct i387_fxsave *fp = (struct i387_fxsave *) buf; | |
471 | int i, top; | |
3aee8918 PA |
472 | int st0_regnum = find_regno (regcache->tdesc, "st0"); |
473 | int xmm0_regnum = find_regno (regcache->tdesc, "xmm0"); | |
58caa3dc | 474 | unsigned long val; |
3aee8918 PA |
475 | /* Amd64 has 16 xmm regs; I386 has 8 xmm regs. */ |
476 | int num_xmm_registers = register_size (regcache->tdesc, 0) == 8 ? 16 : 8; | |
58caa3dc DJ |
477 | |
478 | for (i = 0; i < 8; i++) | |
442ea881 PA |
479 | supply_register (regcache, i + st0_regnum, |
480 | ((char *) &fp->st_space[0]) + i * 16); | |
58caa3dc | 481 | for (i = 0; i < num_xmm_registers; i++) |
442ea881 PA |
482 | supply_register (regcache, i + xmm0_regnum, |
483 | ((char *) &fp->xmm_space[0]) + i * 16); | |
58caa3dc | 484 | |
442ea881 PA |
485 | supply_register_by_name (regcache, "fioff", &fp->fioff); |
486 | supply_register_by_name (regcache, "fooff", &fp->fooff); | |
487 | supply_register_by_name (regcache, "mxcsr", &fp->mxcsr); | |
1b3f6016 | 488 | |
58caa3dc DJ |
489 | /* Some registers are 16-bit. */ |
490 | val = fp->fctrl & 0xFFFF; | |
442ea881 | 491 | supply_register_by_name (regcache, "fctrl", &val); |
58caa3dc DJ |
492 | |
493 | val = fp->fstat & 0xFFFF; | |
442ea881 | 494 | supply_register_by_name (regcache, "fstat", &val); |
58caa3dc DJ |
495 | |
496 | /* Generate the form of ftag data that GDB expects. */ | |
497 | top = (fp->fstat >> 11) & 0x7; | |
498 | val = 0; | |
499 | for (i = 7; i >= 0; i--) | |
500 | { | |
501 | int tag; | |
73725ff3 | 502 | if (fp->ftag & (1 << i)) |
58caa3dc DJ |
503 | tag = i387_ftag (fp, (i + 8 - top) % 8); |
504 | else | |
505 | tag = 3; | |
506 | val |= tag << (2 * i); | |
507 | } | |
442ea881 | 508 | supply_register_by_name (regcache, "ftag", &val); |
58caa3dc DJ |
509 | |
510 | val = fp->fiseg & 0xFFFF; | |
442ea881 | 511 | supply_register_by_name (regcache, "fiseg", &val); |
58caa3dc DJ |
512 | |
513 | val = fp->foseg & 0xFFFF; | |
442ea881 | 514 | supply_register_by_name (regcache, "foseg", &val); |
58caa3dc DJ |
515 | |
516 | val = (fp->fop) & 0x7FF; | |
442ea881 | 517 | supply_register_by_name (regcache, "fop", &val); |
58caa3dc | 518 | } |
1570b33e L |
519 | |
520 | void | |
521 | i387_xsave_to_cache (struct regcache *regcache, const void *buf) | |
522 | { | |
523 | struct i387_xsave *fp = (struct i387_xsave *) buf; | |
524 | struct i387_fxsave *fxp = (struct i387_fxsave *) buf; | |
525 | int i, top; | |
526 | unsigned long val; | |
527 | unsigned int clear_bv; | |
85724a0e | 528 | gdb_byte *p; |
3aee8918 PA |
529 | /* Amd64 has 16 xmm regs; I386 has 8 xmm regs. */ |
530 | int num_xmm_registers = register_size (regcache->tdesc, 0) == 8 ? 16 : 8; | |
1570b33e L |
531 | |
532 | /* The supported bits in `xstat_bv' are 1 byte. Clear part in | |
533 | vector registers if its bit in xstat_bv is zero. */ | |
534 | clear_bv = (~fp->xstate_bv) & x86_xcr0; | |
535 | ||
536 | /* Check if any x87 registers are changed. */ | |
85724a0e | 537 | if ((x86_xcr0 & I386_XSTATE_X87) != 0) |
1570b33e | 538 | { |
3aee8918 | 539 | int st0_regnum = find_regno (regcache->tdesc, "st0"); |
1570b33e | 540 | |
85724a0e PA |
541 | if ((clear_bv & I386_XSTATE_X87) != 0) |
542 | { | |
543 | for (i = 0; i < 8; i++) | |
1c79eb8a | 544 | supply_register_zeroed (regcache, i + st0_regnum); |
85724a0e | 545 | } |
1570b33e | 546 | else |
1570b33e | 547 | { |
85724a0e PA |
548 | p = (gdb_byte *) &fp->st_space[0]; |
549 | for (i = 0; i < 8; i++) | |
550 | supply_register (regcache, i + st0_regnum, p + i * 16); | |
1570b33e L |
551 | } |
552 | } | |
553 | ||
85724a0e | 554 | if ((x86_xcr0 & I386_XSTATE_SSE) != 0) |
1570b33e | 555 | { |
3aee8918 | 556 | int xmm0_regnum = find_regno (regcache->tdesc, "xmm0"); |
1570b33e L |
557 | |
558 | if ((clear_bv & I386_XSTATE_SSE)) | |
85724a0e PA |
559 | { |
560 | for (i = 0; i < num_xmm_registers; i++) | |
1c79eb8a | 561 | supply_register_zeroed (regcache, i + xmm0_regnum); |
85724a0e | 562 | } |
1570b33e | 563 | else |
1570b33e | 564 | { |
85724a0e PA |
565 | p = (gdb_byte *) &fp->xmm_space[0]; |
566 | for (i = 0; i < num_xmm_registers; i++) | |
567 | supply_register (regcache, i + xmm0_regnum, p + i * 16); | |
1570b33e L |
568 | } |
569 | } | |
570 | ||
85724a0e | 571 | if ((x86_xcr0 & I386_XSTATE_AVX) != 0) |
1570b33e | 572 | { |
3aee8918 | 573 | int ymm0h_regnum = find_regno (regcache->tdesc, "ymm0h"); |
1570b33e | 574 | |
85724a0e PA |
575 | if ((clear_bv & I386_XSTATE_AVX) != 0) |
576 | { | |
577 | for (i = 0; i < num_xmm_registers; i++) | |
1c79eb8a | 578 | supply_register_zeroed (regcache, i + ymm0h_regnum); |
85724a0e | 579 | } |
1570b33e | 580 | else |
1570b33e | 581 | { |
85724a0e PA |
582 | p = (gdb_byte *) &fp->ymmh_space[0]; |
583 | for (i = 0; i < num_xmm_registers; i++) | |
584 | supply_register (regcache, i + ymm0h_regnum, p + i * 16); | |
1570b33e L |
585 | } |
586 | } | |
587 | ||
a196ebeb WT |
588 | if ((x86_xcr0 & I386_XSTATE_BNDREGS)) |
589 | { | |
590 | int bnd0r_regnum = find_regno (regcache->tdesc, "bnd0raw"); | |
591 | ||
592 | ||
593 | if ((clear_bv & I386_XSTATE_BNDREGS) != 0) | |
594 | { | |
595 | for (i = 0; i < num_mpx_bnd_registers; i++) | |
596 | supply_register_zeroed (regcache, i + bnd0r_regnum); | |
597 | } | |
598 | else | |
599 | { | |
600 | p = (gdb_byte *) &fp->mpx_bnd_space[0]; | |
601 | for (i = 0; i < num_mpx_bnd_registers; i++) | |
602 | supply_register (regcache, i + bnd0r_regnum, p + i * 16); | |
603 | } | |
604 | ||
605 | } | |
606 | ||
607 | if ((x86_xcr0 & I386_XSTATE_BNDCFG)) | |
608 | { | |
609 | int bndcfg_regnum = find_regno (regcache->tdesc, "bndcfgu"); | |
610 | ||
611 | if ((clear_bv & I386_XSTATE_BNDCFG) != 0) | |
612 | { | |
613 | for (i = 0; i < num_mpx_cfg_registers; i++) | |
614 | supply_register_zeroed (regcache, i + bndcfg_regnum); | |
615 | } | |
616 | else | |
617 | { | |
618 | p = (gdb_byte *) &fp->mpx_cfg_space[0]; | |
619 | for (i = 0; i < num_mpx_cfg_registers; i++) | |
620 | supply_register (regcache, i + bndcfg_regnum, p + i * 8); | |
621 | } | |
622 | } | |
623 | ||
1570b33e L |
624 | supply_register_by_name (regcache, "fioff", &fp->fioff); |
625 | supply_register_by_name (regcache, "fooff", &fp->fooff); | |
626 | supply_register_by_name (regcache, "mxcsr", &fp->mxcsr); | |
627 | ||
628 | /* Some registers are 16-bit. */ | |
629 | val = fp->fctrl & 0xFFFF; | |
630 | supply_register_by_name (regcache, "fctrl", &val); | |
631 | ||
632 | val = fp->fstat & 0xFFFF; | |
633 | supply_register_by_name (regcache, "fstat", &val); | |
634 | ||
635 | /* Generate the form of ftag data that GDB expects. */ | |
636 | top = (fp->fstat >> 11) & 0x7; | |
637 | val = 0; | |
638 | for (i = 7; i >= 0; i--) | |
639 | { | |
640 | int tag; | |
641 | if (fp->ftag & (1 << i)) | |
642 | tag = i387_ftag (fxp, (i + 8 - top) % 8); | |
643 | else | |
644 | tag = 3; | |
645 | val |= tag << (2 * i); | |
646 | } | |
647 | supply_register_by_name (regcache, "ftag", &val); | |
648 | ||
649 | val = fp->fiseg & 0xFFFF; | |
650 | supply_register_by_name (regcache, "fiseg", &val); | |
651 | ||
652 | val = fp->foseg & 0xFFFF; | |
653 | supply_register_by_name (regcache, "foseg", &val); | |
654 | ||
655 | val = (fp->fop) & 0x7FF; | |
656 | supply_register_by_name (regcache, "fop", &val); | |
657 | } | |
658 | ||
659 | /* Default to SSE. */ | |
660 | unsigned long long x86_xcr0 = I386_XSTATE_SSE_MASK; |