1 /* Intel 387 floating point stuff.
3 Copyright (C) 1988-2024 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 3 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, see <http://www.gnu.org/licenses/>. */
20 #include "extract-store-integer.h"
26 #include "target-float.h"
29 #include "i386-tdep.h"
30 #include "i387-tdep.h"
31 #include "gdbsupport/x86-xstate.h"
33 /* Print the floating point number specified by RAW. */
36 print_i387_value (struct gdbarch
*gdbarch
,
37 const gdb_byte
*raw
, struct ui_file
*file
)
39 /* We try to print 19 digits. The last digit may or may not contain
40 garbage, but we'd better print one too many. We need enough room
41 to print the value, 1 position for the sign, 1 for the decimal
42 point, 19 for the digits and 6 for the exponent adds up to 27. */
43 const struct type
*type
= i387_ext_type (gdbarch
);
44 std::string str
= target_float_to_string (raw
, type
, " %-+27.19g");
45 gdb_printf (file
, "%s", str
.c_str ());
48 /* Print the classification for the register contents RAW. */
51 print_i387_ext (struct gdbarch
*gdbarch
,
52 const gdb_byte
*raw
, struct ui_file
*file
)
56 unsigned int exponent
;
57 unsigned long fraction
[2];
60 integer
= raw
[7] & 0x80;
61 exponent
= (((raw
[9] & 0x7f) << 8) | raw
[8]);
62 fraction
[0] = ((raw
[3] << 24) | (raw
[2] << 16) | (raw
[1] << 8) | raw
[0]);
63 fraction
[1] = (((raw
[7] & 0x7f) << 24) | (raw
[6] << 16)
64 | (raw
[5] << 8) | raw
[4]);
66 if (exponent
== 0x7fff && integer
)
68 if (fraction
[0] == 0x00000000 && fraction
[1] == 0x00000000)
70 gdb_printf (file
, " %cInf", (sign
? '-' : '+'));
71 else if (sign
&& fraction
[0] == 0x00000000 && fraction
[1] == 0x40000000)
72 /* Real Indefinite (QNaN). */
73 gdb_puts (" Real Indefinite (QNaN)", file
);
74 else if (fraction
[1] & 0x40000000)
76 gdb_puts (" QNaN", file
);
79 gdb_puts (" SNaN", file
);
81 else if (exponent
< 0x7fff && exponent
> 0x0000 && integer
)
83 print_i387_value (gdbarch
, raw
, file
);
84 else if (exponent
== 0x0000)
86 /* Denormal or zero. */
87 print_i387_value (gdbarch
, raw
, file
);
90 /* Pseudo-denormal. */
91 gdb_puts (" Pseudo-denormal", file
);
92 else if (fraction
[0] || fraction
[1])
94 gdb_puts (" Denormal", file
);
98 gdb_puts (" Unsupported", file
);
101 /* Print the status word STATUS. If STATUS_P is false, then STATUS
105 print_i387_status_word (int status_p
,
106 unsigned int status
, struct ui_file
*file
)
108 gdb_printf (file
, "Status Word: ");
111 gdb_printf (file
, "%s\n", _("<unavailable>"));
115 gdb_printf (file
, "%s", hex_string_custom (status
, 4));
116 gdb_puts (" ", file
);
117 gdb_printf (file
, " %s", (status
& 0x0001) ? "IE" : " ");
118 gdb_printf (file
, " %s", (status
& 0x0002) ? "DE" : " ");
119 gdb_printf (file
, " %s", (status
& 0x0004) ? "ZE" : " ");
120 gdb_printf (file
, " %s", (status
& 0x0008) ? "OE" : " ");
121 gdb_printf (file
, " %s", (status
& 0x0010) ? "UE" : " ");
122 gdb_printf (file
, " %s", (status
& 0x0020) ? "PE" : " ");
123 gdb_puts (" ", file
);
124 gdb_printf (file
, " %s", (status
& 0x0080) ? "ES" : " ");
125 gdb_puts (" ", file
);
126 gdb_printf (file
, " %s", (status
& 0x0040) ? "SF" : " ");
127 gdb_puts (" ", file
);
128 gdb_printf (file
, " %s", (status
& 0x0100) ? "C0" : " ");
129 gdb_printf (file
, " %s", (status
& 0x0200) ? "C1" : " ");
130 gdb_printf (file
, " %s", (status
& 0x0400) ? "C2" : " ");
131 gdb_printf (file
, " %s", (status
& 0x4000) ? "C3" : " ");
133 gdb_puts ("\n", file
);
136 " TOP: %d\n", ((status
>> 11) & 7));
139 /* Print the control word CONTROL. If CONTROL_P is false, then
140 CONTROL was unavailable. */
143 print_i387_control_word (int control_p
,
144 unsigned int control
, struct ui_file
*file
)
146 gdb_printf (file
, "Control Word: ");
149 gdb_printf (file
, "%s\n", _("<unavailable>"));
153 gdb_printf (file
, "%s", hex_string_custom (control
, 4));
154 gdb_puts (" ", file
);
155 gdb_printf (file
, " %s", (control
& 0x0001) ? "IM" : " ");
156 gdb_printf (file
, " %s", (control
& 0x0002) ? "DM" : " ");
157 gdb_printf (file
, " %s", (control
& 0x0004) ? "ZM" : " ");
158 gdb_printf (file
, " %s", (control
& 0x0008) ? "OM" : " ");
159 gdb_printf (file
, " %s", (control
& 0x0010) ? "UM" : " ");
160 gdb_printf (file
, " %s", (control
& 0x0020) ? "PM" : " ");
162 gdb_puts ("\n", file
);
164 gdb_puts (" PC: ", file
);
165 switch ((control
>> 8) & 3)
168 gdb_puts ("Single Precision (24-bits)\n", file
);
171 gdb_puts ("Reserved\n", file
);
174 gdb_puts ("Double Precision (53-bits)\n", file
);
177 gdb_puts ("Extended Precision (64-bits)\n", file
);
181 gdb_puts (" RC: ", file
);
182 switch ((control
>> 10) & 3)
185 gdb_puts ("Round to nearest\n", file
);
188 gdb_puts ("Round down\n", file
);
191 gdb_puts ("Round up\n", file
);
194 gdb_puts ("Round toward zero\n", file
);
199 /* Print out the i387 floating point state. Note that we ignore FRAME
200 in the code below. That's OK since floating-point registers are
201 never saved on the stack. */
204 i387_print_float_info (struct gdbarch
*gdbarch
, struct ui_file
*file
,
205 const frame_info_ptr
&frame
, const char *args
)
207 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
227 gdb_assert (gdbarch
== get_frame_arch (frame
));
229 fctrl_p
= read_frame_register_unsigned (frame
,
230 I387_FCTRL_REGNUM (tdep
), &fctrl
);
231 fstat_p
= read_frame_register_unsigned (frame
,
232 I387_FSTAT_REGNUM (tdep
), &fstat
);
233 ftag_p
= read_frame_register_unsigned (frame
,
234 I387_FTAG_REGNUM (tdep
), &ftag
);
235 fiseg_p
= read_frame_register_unsigned (frame
,
236 I387_FISEG_REGNUM (tdep
), &fiseg
);
237 fioff_p
= read_frame_register_unsigned (frame
,
238 I387_FIOFF_REGNUM (tdep
), &fioff
);
239 foseg_p
= read_frame_register_unsigned (frame
,
240 I387_FOSEG_REGNUM (tdep
), &foseg
);
241 fooff_p
= read_frame_register_unsigned (frame
,
242 I387_FOOFF_REGNUM (tdep
), &fooff
);
243 fop_p
= read_frame_register_unsigned (frame
,
244 I387_FOP_REGNUM (tdep
), &fop
);
248 top
= ((fstat
>> 11) & 7);
250 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
252 struct value
*regval
;
257 gdb_printf (file
, "%sR%d: ", fpreg
== top
? "=>" : " ", fpreg
);
261 tag
= (ftag
>> (fpreg
* 2)) & 3;
266 gdb_puts ("Valid ", file
);
269 gdb_puts ("Zero ", file
);
272 gdb_puts ("Special ", file
);
275 gdb_puts ("Empty ", file
);
280 gdb_puts ("Unknown ", file
);
282 regnum
= (fpreg
+ 8 - top
) % 8 + I387_ST0_REGNUM (tdep
);
283 regval
= get_frame_register_value (frame
, regnum
);
285 if (regval
->entirely_available ())
287 const gdb_byte
*raw
= regval
->contents ().data ();
289 gdb_puts ("0x", file
);
290 for (i
= 9; i
>= 0; i
--)
291 gdb_printf (file
, "%02x", raw
[i
]);
293 if (tag
!= -1 && tag
!= 3)
294 print_i387_ext (gdbarch
, raw
, file
);
297 gdb_printf (file
, "%s", _("<unavailable>"));
299 gdb_puts ("\n", file
);
303 gdb_puts ("\n", file
);
304 print_i387_status_word (fstat_p
, fstat
, file
);
305 print_i387_control_word (fctrl_p
, fctrl
, file
);
306 gdb_printf (file
, "Tag Word: %s\n",
307 ftag_p
? hex_string_custom (ftag
, 4) : _("<unavailable>"));
308 gdb_printf (file
, "Instruction Pointer: %s:",
309 fiseg_p
? hex_string_custom (fiseg
, 2) : _("<unavailable>"));
310 gdb_printf (file
, "%s\n",
311 fioff_p
? hex_string_custom (fioff
, 8) : _("<unavailable>"));
312 gdb_printf (file
, "Operand Pointer: %s:",
313 foseg_p
? hex_string_custom (foseg
, 2) : _("<unavailable>"));
314 gdb_printf (file
, "%s\n",
315 fooff_p
? hex_string_custom (fooff
, 8) : _("<unavailable>"));
316 gdb_printf (file
, "Opcode: %s\n",
318 ? (hex_string_custom (fop
? (fop
| 0xd800) : 0, 4))
319 : _("<unavailable>"));
323 /* Return nonzero if a value of type TYPE stored in register REGNUM
324 needs any special handling. */
327 i387_convert_register_p (struct gdbarch
*gdbarch
, int regnum
,
330 if (i386_fp_regnum_p (gdbarch
, regnum
))
332 /* Floating point registers must be converted unless we are
333 accessing them in their hardware type or TYPE is not float. */
334 if (type
== i387_ext_type (gdbarch
)
335 || type
->code () != TYPE_CODE_FLT
)
344 /* Read a value of type TYPE from register REGNUM in frame FRAME, and
345 return its contents in TO. */
348 i387_register_to_value (const frame_info_ptr
&frame
, int regnum
,
349 struct type
*type
, gdb_byte
*to
,
350 int *optimizedp
, int *unavailablep
)
352 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
353 gdb_byte from
[I386_MAX_REGISTER_SIZE
];
355 gdb_assert (i386_fp_regnum_p (gdbarch
, regnum
));
357 /* We only support floating-point values. */
358 if (type
->code () != TYPE_CODE_FLT
)
360 warning (_("Cannot convert floating-point register value "
361 "to non-floating-point type."));
362 *optimizedp
= *unavailablep
= 0;
366 /* Convert to TYPE. */
368 = gdb::make_array_view (from
, register_size (gdbarch
, regnum
));
369 frame_info_ptr next_frame
= get_next_frame_sentinel_okay (frame
);
370 if (!get_frame_register_bytes (next_frame
, regnum
, 0, from_view
, optimizedp
,
374 target_float_convert (from
, i387_ext_type (gdbarch
), to
, type
);
375 *optimizedp
= *unavailablep
= 0;
379 /* Write the contents FROM of a value of type TYPE into register
380 REGNUM in frame FRAME. */
383 i387_value_to_register (const frame_info_ptr
&frame
, int regnum
,
384 struct type
*type
, const gdb_byte
*from
)
386 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
387 gdb_byte to
[I386_MAX_REGISTER_SIZE
];
389 gdb_assert (i386_fp_regnum_p (gdbarch
, regnum
));
391 /* We only support floating-point values. */
392 if (type
->code () != TYPE_CODE_FLT
)
394 warning (_("Cannot convert non-floating-point type "
395 "to floating-point register value."));
399 /* Convert from TYPE. */
400 struct type
*to_type
= i387_ext_type (gdbarch
);
401 target_float_convert (from
, type
, to
, to_type
);
402 auto to_view
= gdb::make_array_view (to
, to_type
->length ());
403 put_frame_register (get_next_frame_sentinel_okay (frame
), regnum
, to_view
);
407 /* Handle FSAVE and FXSAVE formats. */
409 /* At fsave_offset[REGNUM] you'll find the offset to the location in
410 the data structure used by the "fsave" instruction where GDB
411 register REGNUM is stored. */
413 static int fsave_offset
[] =
415 28 + 0 * 10, /* %st(0) ... */
422 28 + 7 * 10, /* ... %st(7). */
423 0, /* `fctrl' (16 bits). */
424 4, /* `fstat' (16 bits). */
425 8, /* `ftag' (16 bits). */
426 16, /* `fiseg' (16 bits). */
428 24, /* `foseg' (16 bits). */
430 18 /* `fop' (bottom 11 bits). */
433 #define FSAVE_ADDR(tdep, fsave, regnum) \
434 (fsave + fsave_offset[regnum - I387_ST0_REGNUM (tdep)])
437 /* Fill register REGNUM in REGCACHE with the appropriate value from
438 *FSAVE. This function masks off any of the reserved bits in
442 i387_supply_fsave (struct regcache
*regcache
, int regnum
, const void *fsave
)
444 struct gdbarch
*gdbarch
= regcache
->arch ();
445 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
446 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
447 const gdb_byte
*regs
= (const gdb_byte
*) fsave
;
450 gdb_assert (tdep
->st0_regnum
>= I386_ST0_REGNUM
);
452 for (i
= I387_ST0_REGNUM (tdep
); i
< I387_XMM0_REGNUM (tdep
); i
++)
453 if (regnum
== -1 || regnum
== i
)
457 regcache
->raw_supply (i
, NULL
);
461 /* Most of the FPU control registers occupy only 16 bits in the
462 fsave area. Give those a special treatment. */
463 if (i
>= I387_FCTRL_REGNUM (tdep
)
464 && i
!= I387_FIOFF_REGNUM (tdep
) && i
!= I387_FOOFF_REGNUM (tdep
))
468 memcpy (val
, FSAVE_ADDR (tdep
, regs
, i
), 2);
470 if (i
== I387_FOP_REGNUM (tdep
))
471 val
[1] &= ((1 << 3) - 1);
472 regcache
->raw_supply (i
, val
);
475 regcache
->raw_supply (i
, FSAVE_ADDR (tdep
, regs
, i
));
478 /* Provide dummy values for the SSE registers. */
479 for (i
= I387_XMM0_REGNUM (tdep
); i
< I387_MXCSR_REGNUM (tdep
); i
++)
480 if (regnum
== -1 || regnum
== i
)
481 regcache
->raw_supply (i
, NULL
);
482 if (regnum
== -1 || regnum
== I387_MXCSR_REGNUM (tdep
))
486 store_unsigned_integer (buf
, 4, byte_order
, I387_MXCSR_INIT_VAL
);
487 regcache
->raw_supply (I387_MXCSR_REGNUM (tdep
), buf
);
491 /* Fill register REGNUM (if it is a floating-point register) in *FSAVE
492 with the value from REGCACHE. If REGNUM is -1, do this for all
493 registers. This function doesn't touch any of the reserved bits in
497 i387_collect_fsave (const struct regcache
*regcache
, int regnum
, void *fsave
)
499 gdbarch
*arch
= regcache
->arch ();
500 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (arch
);
501 gdb_byte
*regs
= (gdb_byte
*) fsave
;
504 gdb_assert (tdep
->st0_regnum
>= I386_ST0_REGNUM
);
506 for (i
= I387_ST0_REGNUM (tdep
); i
< I387_XMM0_REGNUM (tdep
); i
++)
507 if (regnum
== -1 || regnum
== i
)
509 /* Most of the FPU control registers occupy only 16 bits in
510 the fsave area. Give those a special treatment. */
511 if (i
>= I387_FCTRL_REGNUM (tdep
)
512 && i
!= I387_FIOFF_REGNUM (tdep
) && i
!= I387_FOOFF_REGNUM (tdep
))
516 regcache
->raw_collect (i
, buf
);
518 if (i
== I387_FOP_REGNUM (tdep
))
520 /* The opcode occupies only 11 bits. Make sure we
521 don't touch the other bits. */
522 buf
[1] &= ((1 << 3) - 1);
523 buf
[1] |= ((FSAVE_ADDR (tdep
, regs
, i
))[1] & ~((1 << 3) - 1));
525 memcpy (FSAVE_ADDR (tdep
, regs
, i
), buf
, 2);
528 regcache
->raw_collect (i
, FSAVE_ADDR (tdep
, regs
, i
));
533 /* At fxsave_offset[REGNUM] you'll find the offset to the location in
534 the data structure used by the "fxsave" instruction where GDB
535 register REGNUM is stored. */
537 static int fxsave_offset
[] =
539 32, /* %st(0) through ... */
546 144, /* ... %st(7) (80 bits each). */
547 0, /* `fctrl' (16 bits). */
548 2, /* `fstat' (16 bits). */
549 4, /* `ftag' (16 bits). */
550 12, /* `fiseg' (16 bits). */
552 20, /* `foseg' (16 bits). */
554 6, /* `fop' (bottom 11 bits). */
555 160 + 0 * 16, /* %xmm0 through ... */
570 160 + 15 * 16, /* ... %xmm15 (128 bits each). */
573 #define FXSAVE_ADDR(tdep, fxsave, regnum) \
574 (fxsave + fxsave_offset[regnum - I387_ST0_REGNUM (tdep)])
576 /* We made an unfortunate choice in putting %mxcsr after the SSE
577 registers %xmm0-%xmm7 instead of before, since it makes supporting
578 the registers %xmm8-%xmm15 on AMD64 a bit involved. Therefore we
579 don't include the offset for %mxcsr here above. */
581 #define FXSAVE_MXCSR_ADDR(fxsave) (fxsave + 24)
583 static int i387_tag (const gdb_byte
*raw
);
586 /* Fill register REGNUM in REGCACHE with the appropriate
587 floating-point or SSE register value from *FXSAVE. This function
588 masks off any of the reserved bits in *FXSAVE. */
591 i387_supply_fxsave (struct regcache
*regcache
, int regnum
, const void *fxsave
)
593 gdbarch
*arch
= regcache
->arch ();
594 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (arch
);
595 const gdb_byte
*regs
= (const gdb_byte
*) fxsave
;
598 gdb_assert (tdep
->st0_regnum
>= I386_ST0_REGNUM
);
599 gdb_assert (tdep
->num_xmm_regs
> 0);
601 for (i
= I387_ST0_REGNUM (tdep
); i
< I387_MXCSR_REGNUM (tdep
); i
++)
602 if (regnum
== -1 || regnum
== i
)
606 regcache
->raw_supply (i
, NULL
);
610 /* Most of the FPU control registers occupy only 16 bits in
611 the fxsave area. Give those a special treatment. */
612 if (i
>= I387_FCTRL_REGNUM (tdep
) && i
< I387_XMM0_REGNUM (tdep
)
613 && i
!= I387_FIOFF_REGNUM (tdep
) && i
!= I387_FOOFF_REGNUM (tdep
))
617 memcpy (val
, FXSAVE_ADDR (tdep
, regs
, i
), 2);
619 if (i
== I387_FOP_REGNUM (tdep
))
620 val
[1] &= ((1 << 3) - 1);
621 else if (i
== I387_FTAG_REGNUM (tdep
))
623 /* The fxsave area contains a simplified version of
624 the tag word. We have to look at the actual 80-bit
625 FP data to recreate the traditional i387 tag word. */
627 unsigned long ftag
= 0;
631 top
= ((FXSAVE_ADDR (tdep
, regs
,
632 I387_FSTAT_REGNUM (tdep
)))[1] >> 3);
635 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
639 if (val
[0] & (1 << fpreg
))
641 int thisreg
= (fpreg
+ 8 - top
) % 8
642 + I387_ST0_REGNUM (tdep
);
643 tag
= i387_tag (FXSAVE_ADDR (tdep
, regs
, thisreg
));
648 ftag
|= tag
<< (2 * fpreg
);
650 val
[0] = ftag
& 0xff;
651 val
[1] = (ftag
>> 8) & 0xff;
653 regcache
->raw_supply (i
, val
);
656 regcache
->raw_supply (i
, FXSAVE_ADDR (tdep
, regs
, i
));
659 if (regnum
== I387_MXCSR_REGNUM (tdep
) || regnum
== -1)
662 regcache
->raw_supply (I387_MXCSR_REGNUM (tdep
), NULL
);
664 regcache
->raw_supply (I387_MXCSR_REGNUM (tdep
),
665 FXSAVE_MXCSR_ADDR (regs
));
669 /* Fill register REGNUM (if it is a floating-point or SSE register) in
670 *FXSAVE with the value from REGCACHE. If REGNUM is -1, do this for
671 all registers. This function doesn't touch any of the reserved
675 i387_collect_fxsave (const struct regcache
*regcache
, int regnum
, void *fxsave
)
677 gdbarch
*arch
= regcache
->arch ();
678 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (arch
);
679 gdb_byte
*regs
= (gdb_byte
*) fxsave
;
682 gdb_assert (tdep
->st0_regnum
>= I386_ST0_REGNUM
);
683 gdb_assert (tdep
->num_xmm_regs
> 0);
685 for (i
= I387_ST0_REGNUM (tdep
); i
< I387_MXCSR_REGNUM (tdep
); i
++)
686 if (regnum
== -1 || regnum
== i
)
688 /* Most of the FPU control registers occupy only 16 bits in
689 the fxsave area. Give those a special treatment. */
690 if (i
>= I387_FCTRL_REGNUM (tdep
) && i
< I387_XMM0_REGNUM (tdep
)
691 && i
!= I387_FIOFF_REGNUM (tdep
) && i
!= I387_FOOFF_REGNUM (tdep
))
695 regcache
->raw_collect (i
, buf
);
697 if (i
== I387_FOP_REGNUM (tdep
))
699 /* The opcode occupies only 11 bits. Make sure we
700 don't touch the other bits. */
701 buf
[1] &= ((1 << 3) - 1);
702 buf
[1] |= ((FXSAVE_ADDR (tdep
, regs
, i
))[1] & ~((1 << 3) - 1));
704 else if (i
== I387_FTAG_REGNUM (tdep
))
706 /* Converting back is much easier. */
711 ftag
= (buf
[1] << 8) | buf
[0];
715 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
717 int tag
= (ftag
>> (fpreg
* 2)) & 3;
720 buf
[0] |= (1 << fpreg
);
723 memcpy (FXSAVE_ADDR (tdep
, regs
, i
), buf
, 2);
726 regcache
->raw_collect (i
, FXSAVE_ADDR (tdep
, regs
, i
));
729 if (regnum
== I387_MXCSR_REGNUM (tdep
) || regnum
== -1)
730 regcache
->raw_collect (I387_MXCSR_REGNUM (tdep
),
731 FXSAVE_MXCSR_ADDR (regs
));
734 /* `xstate_bv' is at byte offset 512. */
735 #define XSAVE_XSTATE_BV_ADDR(xsave) (xsave + 512)
737 /* At xsave_avxh_offset[REGNUM] you'll find the relative offset within
738 the AVX region of the XSAVE extended state where the upper 128bits
739 of GDB register YMM0 + REGNUM is stored. */
741 static int xsave_avxh_offset
[] =
743 0 * 16, /* Upper 128bit of %ymm0 through ... */
758 15 * 16 /* Upper 128bit of ... %ymm15 (128 bits each). */
761 #define XSAVE_AVXH_ADDR(tdep, xsave, regnum) \
762 (xsave + (tdep)->xsave_layout.avx_offset \
763 + xsave_avxh_offset[regnum - I387_YMM0H_REGNUM (tdep)])
765 /* At xsave_ymm_avx512_offset[REGNUM] you'll find the relative offset
766 within the ZMM region of the XSAVE extended state where the second
767 128bits of GDB register YMM16 + REGNUM is stored. */
769 static int xsave_ymm_avx512_offset
[] =
771 16 + 0 * 64, /* %ymm16 through... */
786 16 + 15 * 64 /* ... %ymm31 (128 bits each). */
789 #define XSAVE_YMM_AVX512_ADDR(tdep, xsave, regnum) \
790 (xsave + (tdep)->xsave_layout.zmm_offset \
791 + xsave_ymm_avx512_offset[regnum - I387_YMM16H_REGNUM (tdep)])
793 /* At xsave_xmm_avx512_offset[REGNUM] you'll find the relative offset
794 within the ZMM region of the XSAVE extended state where the first
795 128bits of GDB register XMM16 + REGNUM is stored. */
797 static int xsave_xmm_avx512_offset
[] =
799 0 * 64, /* %xmm16 through... */
814 15 * 64 /* ... %xmm31 (128 bits each). */
817 #define XSAVE_XMM_AVX512_ADDR(tdep, xsave, regnum) \
818 (xsave + (tdep)->xsave_layout.zmm_offset \
819 + xsave_xmm_avx512_offset[regnum - I387_XMM16_REGNUM (tdep)])
821 /* At xsave_bndregs_offset[REGNUM] you'll find the relative offset
822 within the BNDREGS region of the XSAVE extended state where the GDB
823 register BND0R + REGNUM is stored. */
825 static int xsave_bndregs_offset
[] = {
826 0 * 16, /* bnd0r...bnd3r registers. */
832 #define XSAVE_BNDREGS_ADDR(tdep, xsave, regnum) \
833 (xsave + (tdep)->xsave_layout.bndregs_offset \
834 + xsave_bndregs_offset[regnum - I387_BND0R_REGNUM (tdep)])
836 static int xsave_bndcfg_offset
[] = {
837 0 * 8, /* bndcfg ... bndstatus. */
841 #define XSAVE_BNDCFG_ADDR(tdep, xsave, regnum) \
842 (xsave + (tdep)->xsave_layout.bndcfg_offset \
843 + xsave_bndcfg_offset[regnum - I387_BNDCFGU_REGNUM (tdep)])
845 /* At xsave_avx512_k_offset[REGNUM] you'll find the relative offset
846 within the K region of the XSAVE extended state where the AVX512
847 opmask register K0 + REGNUM is stored. */
849 static int xsave_avx512_k_offset
[] =
851 0 * 8, /* %k0 through... */
858 7 * 8 /* %k7 (64 bits each). */
861 #define XSAVE_AVX512_K_ADDR(tdep, xsave, regnum) \
862 (xsave + (tdep)->xsave_layout.k_offset \
863 + xsave_avx512_k_offset[regnum - I387_K0_REGNUM (tdep)])
866 /* At xsave_avx512_zmm0_h_offset[REGNUM] you find the relative offset
867 within the ZMM_H region of the XSAVE extended state where the upper
868 256bits of the GDB register ZMM0 + REGNUM is stored. */
870 static int xsave_avx512_zmm0_h_offset
[] =
872 0 * 32, /* Upper 256bit of %zmmh0 through... */
887 15 * 32 /* Upper 256bit of... %zmmh15 (256 bits each). */
890 #define XSAVE_AVX512_ZMM0_H_ADDR(tdep, xsave, regnum) \
891 (xsave + (tdep)->xsave_layout.zmm_h_offset \
892 + xsave_avx512_zmm0_h_offset[regnum - I387_ZMM0H_REGNUM (tdep)])
894 /* At xsave_avx512_zmm16_h_offset[REGNUM] you find the relative offset
895 within the ZMM_H region of the XSAVE extended state where the upper
896 256bits of the GDB register ZMM16 + REGNUM is stored. */
898 static int xsave_avx512_zmm16_h_offset
[] =
900 32 + 0 * 64, /* Upper 256bit of... %zmmh16 (256 bits each). */
915 32 + 15 * 64 /* Upper 256bit of... %zmmh31 (256 bits each). */
918 #define XSAVE_AVX512_ZMM16_H_ADDR(tdep, xsave, regnum) \
919 (xsave + (tdep)->xsave_layout.zmm_offset \
920 + xsave_avx512_zmm16_h_offset[regnum - I387_ZMM16H_REGNUM (tdep)])
922 /* At xsave_pkeys_offset[REGNUM] you'll find the relative offset
923 within the PKEYS region of the XSAVE extended state where the PKRU
924 register is stored. */
926 static int xsave_pkeys_offset
[] =
928 0 * 8 /* %pkru (64 bits in XSTATE, 32-bit actually used by
929 instructions and applications). */
932 #define XSAVE_PKEYS_ADDR(tdep, xsave, regnum) \
933 (xsave + (tdep)->xsave_layout.pkru_offset \
934 + xsave_pkeys_offset[regnum - I387_PKRU_REGNUM (tdep)])
937 /* See i387-tdep.h. */
940 i387_guess_xsave_layout (uint64_t xcr0
, size_t xsave_size
,
941 x86_xsave_layout
&layout
)
943 if (HAS_PKRU (xcr0
) && xsave_size
== 2696)
945 /* Intel CPUs supporting PKRU. */
946 layout
.avx_offset
= 576;
947 layout
.bndregs_offset
= 960;
948 layout
.bndcfg_offset
= 1024;
949 layout
.k_offset
= 1088;
950 layout
.zmm_h_offset
= 1152;
951 layout
.zmm_offset
= 1664;
952 layout
.pkru_offset
= 2688;
954 else if (HAS_PKRU (xcr0
) && xsave_size
== 2440)
956 /* AMD CPUs supporting PKRU. */
957 layout
.avx_offset
= 576;
958 layout
.k_offset
= 832;
959 layout
.zmm_h_offset
= 896;
960 layout
.zmm_offset
= 1408;
961 layout
.pkru_offset
= 2432;
963 else if (HAS_AVX512 (xcr0
) && xsave_size
== 2688)
965 /* Intel CPUs supporting AVX512. */
966 layout
.avx_offset
= 576;
967 layout
.bndregs_offset
= 960;
968 layout
.bndcfg_offset
= 1024;
969 layout
.k_offset
= 1088;
970 layout
.zmm_h_offset
= 1152;
971 layout
.zmm_offset
= 1664;
973 else if (HAS_MPX (xcr0
) && xsave_size
== 1088)
975 /* Intel CPUs supporting MPX. */
976 layout
.avx_offset
= 576;
977 layout
.bndregs_offset
= 960;
978 layout
.bndcfg_offset
= 1024;
980 else if (HAS_AVX (xcr0
) && xsave_size
== 832)
982 /* Intel and AMD CPUs supporting AVX. */
983 layout
.avx_offset
= 576;
988 layout
.sizeof_xsave
= xsave_size
;
992 /* See i387-tdep.h. */
995 i387_fallback_xsave_layout (uint64_t xcr0
)
997 x86_xsave_layout layout
;
1001 /* Intel CPUs supporting PKRU. */
1002 layout
.avx_offset
= 576;
1003 layout
.bndregs_offset
= 960;
1004 layout
.bndcfg_offset
= 1024;
1005 layout
.k_offset
= 1088;
1006 layout
.zmm_h_offset
= 1152;
1007 layout
.zmm_offset
= 1664;
1008 layout
.pkru_offset
= 2688;
1009 layout
.sizeof_xsave
= 2696;
1011 else if (HAS_AVX512 (xcr0
))
1013 /* Intel CPUs supporting AVX512. */
1014 layout
.avx_offset
= 576;
1015 layout
.bndregs_offset
= 960;
1016 layout
.bndcfg_offset
= 1024;
1017 layout
.k_offset
= 1088;
1018 layout
.zmm_h_offset
= 1152;
1019 layout
.zmm_offset
= 1664;
1020 layout
.sizeof_xsave
= 2688;
1022 else if (HAS_MPX (xcr0
))
1024 /* Intel CPUs supporting MPX. */
1025 layout
.avx_offset
= 576;
1026 layout
.bndregs_offset
= 960;
1027 layout
.bndcfg_offset
= 1024;
1028 layout
.sizeof_xsave
= 1088;
1030 else if (HAS_AVX (xcr0
))
1032 /* Intel and AMD CPUs supporting AVX. */
1033 layout
.avx_offset
= 576;
1034 layout
.sizeof_xsave
= 832;
1040 /* Extract from XSAVE a bitset of the features that are available on the
1041 target, but which have not yet been enabled. */
1044 i387_xsave_get_clear_bv (struct gdbarch
*gdbarch
, const void *xsave
)
1046 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1047 const gdb_byte
*regs
= (const gdb_byte
*) xsave
;
1048 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
1050 /* Get `xstat_bv'. The supported bits in `xstat_bv' are 8 bytes. */
1051 ULONGEST xstate_bv
= extract_unsigned_integer (XSAVE_XSTATE_BV_ADDR (regs
),
1054 /* Clear part in vector registers if its bit in xstat_bv is zero. */
1055 ULONGEST clear_bv
= (~(xstate_bv
)) & tdep
->xcr0
;
1060 /* Similar to i387_supply_fxsave, but use XSAVE extended state. */
1063 i387_supply_xsave (struct regcache
*regcache
, int regnum
,
1066 struct gdbarch
*gdbarch
= regcache
->arch ();
1067 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1068 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
1069 const gdb_byte
*regs
= (const gdb_byte
*) xsave
;
1071 /* In 64-bit mode the split between "low" and "high" ZMM registers is at
1072 ZMM16. Outside of 64-bit mode there are no "high" ZMM registers at all.
1073 Precalculate the number to be used for the split point, with the all
1074 registers in the "low" portion outside of 64-bit mode. */
1075 unsigned int zmm_endlo_regnum
= I387_ZMM0H_REGNUM (tdep
)
1076 + std::min (tdep
->num_zmm_regs
, 16);
1078 static const gdb_byte zero
[I386_MAX_REGISTER_SIZE
] = { 0 };
1088 avx512_zmm0_h
= 0x40,
1089 avx512_zmm16_h
= 0x80,
1090 avx512_ymmh_avx512
= 0x100,
1091 avx512_xmm_avx512
= 0x200,
1093 all
= x87
| sse
| avxh
| bndregs
| bndcfg
| avx512_k
| avx512_zmm0_h
1094 | avx512_zmm16_h
| avx512_ymmh_avx512
| avx512_xmm_avx512
| pkeys
1097 gdb_assert (regs
!= NULL
);
1098 gdb_assert (tdep
->st0_regnum
>= I386_ST0_REGNUM
);
1099 gdb_assert (tdep
->num_xmm_regs
> 0);
1103 else if (regnum
>= I387_PKRU_REGNUM (tdep
)
1104 && regnum
< I387_PKEYSEND_REGNUM (tdep
))
1106 else if (regnum
>= I387_ZMM0H_REGNUM (tdep
)
1107 && regnum
< I387_ZMM16H_REGNUM (tdep
))
1108 regclass
= avx512_zmm0_h
;
1109 else if (regnum
>= I387_ZMM16H_REGNUM (tdep
)
1110 && regnum
< I387_ZMMENDH_REGNUM (tdep
))
1111 regclass
= avx512_zmm16_h
;
1112 else if (regnum
>= I387_K0_REGNUM (tdep
)
1113 && regnum
< I387_KEND_REGNUM (tdep
))
1114 regclass
= avx512_k
;
1115 else if (regnum
>= I387_YMM16H_REGNUM (tdep
)
1116 && regnum
< I387_YMMH_AVX512_END_REGNUM (tdep
))
1117 regclass
= avx512_ymmh_avx512
;
1118 else if (regnum
>= I387_XMM16_REGNUM (tdep
)
1119 && regnum
< I387_XMM_AVX512_END_REGNUM (tdep
))
1120 regclass
= avx512_xmm_avx512
;
1121 else if (regnum
>= I387_YMM0H_REGNUM (tdep
)
1122 && regnum
< I387_YMMENDH_REGNUM (tdep
))
1124 else if (regnum
>= I387_BND0R_REGNUM (tdep
)
1125 && regnum
< I387_BNDCFGU_REGNUM (tdep
))
1127 else if (regnum
>= I387_BNDCFGU_REGNUM (tdep
)
1128 && regnum
< I387_MPXEND_REGNUM (tdep
))
1130 else if (regnum
>= I387_XMM0_REGNUM (tdep
)
1131 && regnum
< I387_MXCSR_REGNUM (tdep
))
1133 else if (regnum
>= I387_ST0_REGNUM (tdep
)
1134 && regnum
< I387_FCTRL_REGNUM (tdep
))
1139 clear_bv
= i387_xsave_get_clear_bv (gdbarch
, xsave
);
1141 /* With the delayed xsave mechanism, in between the program
1142 starting, and the program accessing the vector registers for the
1143 first time, the register's values are invalid. The kernel
1144 initializes register states to zero when they are set the first
1145 time in a program. This means that from the user-space programs'
1146 perspective, it's the same as if the registers have always been
1147 zero from the start of the program. Therefore, the debugger
1148 should provide the same illusion to the user. */
1156 if ((clear_bv
& X86_XSTATE_PKRU
))
1157 regcache
->raw_supply (regnum
, zero
);
1159 regcache
->raw_supply (regnum
, XSAVE_PKEYS_ADDR (tdep
, regs
, regnum
));
1163 if ((clear_bv
& X86_XSTATE_ZMM_H
))
1164 regcache
->raw_supply (regnum
, zero
);
1166 regcache
->raw_supply (regnum
,
1167 XSAVE_AVX512_ZMM0_H_ADDR (tdep
, regs
, regnum
));
1170 case avx512_zmm16_h
:
1171 if ((clear_bv
& X86_XSTATE_ZMM
))
1172 regcache
->raw_supply (regnum
, zero
);
1174 regcache
->raw_supply (regnum
,
1175 XSAVE_AVX512_ZMM16_H_ADDR (tdep
, regs
, regnum
));
1179 if ((clear_bv
& X86_XSTATE_K
))
1180 regcache
->raw_supply (regnum
, zero
);
1182 regcache
->raw_supply (regnum
, XSAVE_AVX512_K_ADDR (tdep
, regs
, regnum
));
1185 case avx512_ymmh_avx512
:
1186 if ((clear_bv
& X86_XSTATE_ZMM
))
1187 regcache
->raw_supply (regnum
, zero
);
1189 regcache
->raw_supply (regnum
,
1190 XSAVE_YMM_AVX512_ADDR (tdep
, regs
, regnum
));
1193 case avx512_xmm_avx512
:
1194 if ((clear_bv
& X86_XSTATE_ZMM
))
1195 regcache
->raw_supply (regnum
, zero
);
1197 regcache
->raw_supply (regnum
,
1198 XSAVE_XMM_AVX512_ADDR (tdep
, regs
, regnum
));
1202 if ((clear_bv
& X86_XSTATE_AVX
))
1203 regcache
->raw_supply (regnum
, zero
);
1205 regcache
->raw_supply (regnum
, XSAVE_AVXH_ADDR (tdep
, regs
, regnum
));
1209 if ((clear_bv
& X86_XSTATE_BNDCFG
))
1210 regcache
->raw_supply (regnum
, zero
);
1212 regcache
->raw_supply (regnum
, XSAVE_BNDCFG_ADDR (tdep
, regs
, regnum
));
1216 if ((clear_bv
& X86_XSTATE_BNDREGS
))
1217 regcache
->raw_supply (regnum
, zero
);
1219 regcache
->raw_supply (regnum
, XSAVE_BNDREGS_ADDR (tdep
, regs
, regnum
));
1223 if ((clear_bv
& X86_XSTATE_SSE
))
1224 regcache
->raw_supply (regnum
, zero
);
1226 regcache
->raw_supply (regnum
, FXSAVE_ADDR (tdep
, regs
, regnum
));
1230 if ((clear_bv
& X86_XSTATE_X87
))
1231 regcache
->raw_supply (regnum
, zero
);
1233 regcache
->raw_supply (regnum
, FXSAVE_ADDR (tdep
, regs
, regnum
));
1237 /* Handle PKEYS registers. */
1238 if ((tdep
->xcr0
& X86_XSTATE_PKRU
))
1240 if ((clear_bv
& X86_XSTATE_PKRU
))
1242 for (i
= I387_PKRU_REGNUM (tdep
);
1243 i
< I387_PKEYSEND_REGNUM (tdep
);
1245 regcache
->raw_supply (i
, zero
);
1249 for (i
= I387_PKRU_REGNUM (tdep
);
1250 i
< I387_PKEYSEND_REGNUM (tdep
);
1252 regcache
->raw_supply (i
, XSAVE_PKEYS_ADDR (tdep
, regs
, i
));
1256 /* Handle the upper halves of the low 8/16 ZMM registers. */
1257 if ((tdep
->xcr0
& X86_XSTATE_ZMM_H
))
1259 if ((clear_bv
& X86_XSTATE_ZMM_H
))
1261 for (i
= I387_ZMM0H_REGNUM (tdep
); i
< zmm_endlo_regnum
; i
++)
1262 regcache
->raw_supply (i
, zero
);
1266 for (i
= I387_ZMM0H_REGNUM (tdep
); i
< zmm_endlo_regnum
; i
++)
1267 regcache
->raw_supply (i
,
1268 XSAVE_AVX512_ZMM0_H_ADDR (tdep
, regs
, i
));
1272 /* Handle AVX512 OpMask registers. */
1273 if ((tdep
->xcr0
& X86_XSTATE_K
))
1275 if ((clear_bv
& X86_XSTATE_K
))
1277 for (i
= I387_K0_REGNUM (tdep
);
1278 i
< I387_KEND_REGNUM (tdep
);
1280 regcache
->raw_supply (i
, zero
);
1284 for (i
= I387_K0_REGNUM (tdep
);
1285 i
< I387_KEND_REGNUM (tdep
);
1287 regcache
->raw_supply (i
, XSAVE_AVX512_K_ADDR (tdep
, regs
, i
));
1291 /* Handle the upper 16 ZMM/YMM/XMM registers (if any). */
1292 if ((tdep
->xcr0
& X86_XSTATE_ZMM
))
1294 if ((clear_bv
& X86_XSTATE_ZMM
))
1296 for (i
= I387_ZMM16H_REGNUM (tdep
);
1297 i
< I387_ZMMENDH_REGNUM (tdep
); i
++)
1298 regcache
->raw_supply (i
, zero
);
1299 for (i
= I387_YMM16H_REGNUM (tdep
);
1300 i
< I387_YMMH_AVX512_END_REGNUM (tdep
);
1302 regcache
->raw_supply (i
, zero
);
1303 for (i
= I387_XMM16_REGNUM (tdep
);
1304 i
< I387_XMM_AVX512_END_REGNUM (tdep
);
1306 regcache
->raw_supply (i
, zero
);
1310 for (i
= I387_ZMM16H_REGNUM (tdep
);
1311 i
< I387_ZMMENDH_REGNUM (tdep
); i
++)
1312 regcache
->raw_supply (i
,
1313 XSAVE_AVX512_ZMM16_H_ADDR (tdep
, regs
, i
));
1314 for (i
= I387_YMM16H_REGNUM (tdep
);
1315 i
< I387_YMMH_AVX512_END_REGNUM (tdep
);
1317 regcache
->raw_supply (i
, XSAVE_YMM_AVX512_ADDR (tdep
, regs
, i
));
1318 for (i
= I387_XMM16_REGNUM (tdep
);
1319 i
< I387_XMM_AVX512_END_REGNUM (tdep
);
1321 regcache
->raw_supply (i
, XSAVE_XMM_AVX512_ADDR (tdep
, regs
, i
));
1324 /* Handle the upper YMM registers. */
1325 if ((tdep
->xcr0
& X86_XSTATE_AVX
))
1327 if ((clear_bv
& X86_XSTATE_AVX
))
1329 for (i
= I387_YMM0H_REGNUM (tdep
);
1330 i
< I387_YMMENDH_REGNUM (tdep
);
1332 regcache
->raw_supply (i
, zero
);
1336 for (i
= I387_YMM0H_REGNUM (tdep
);
1337 i
< I387_YMMENDH_REGNUM (tdep
);
1339 regcache
->raw_supply (i
, XSAVE_AVXH_ADDR (tdep
, regs
, i
));
1343 /* Handle the MPX registers. */
1344 if ((tdep
->xcr0
& X86_XSTATE_BNDREGS
))
1346 if (clear_bv
& X86_XSTATE_BNDREGS
)
1348 for (i
= I387_BND0R_REGNUM (tdep
);
1349 i
< I387_BNDCFGU_REGNUM (tdep
); i
++)
1350 regcache
->raw_supply (i
, zero
);
1354 for (i
= I387_BND0R_REGNUM (tdep
);
1355 i
< I387_BNDCFGU_REGNUM (tdep
); i
++)
1356 regcache
->raw_supply (i
, XSAVE_BNDREGS_ADDR (tdep
, regs
, i
));
1360 /* Handle the MPX registers. */
1361 if ((tdep
->xcr0
& X86_XSTATE_BNDCFG
))
1363 if (clear_bv
& X86_XSTATE_BNDCFG
)
1365 for (i
= I387_BNDCFGU_REGNUM (tdep
);
1366 i
< I387_MPXEND_REGNUM (tdep
); i
++)
1367 regcache
->raw_supply (i
, zero
);
1371 for (i
= I387_BNDCFGU_REGNUM (tdep
);
1372 i
< I387_MPXEND_REGNUM (tdep
); i
++)
1373 regcache
->raw_supply (i
, XSAVE_BNDCFG_ADDR (tdep
, regs
, i
));
1377 /* Handle the XMM registers. */
1378 if ((tdep
->xcr0
& X86_XSTATE_SSE
))
1380 if ((clear_bv
& X86_XSTATE_SSE
))
1382 for (i
= I387_XMM0_REGNUM (tdep
);
1383 i
< I387_MXCSR_REGNUM (tdep
);
1385 regcache
->raw_supply (i
, zero
);
1389 for (i
= I387_XMM0_REGNUM (tdep
);
1390 i
< I387_MXCSR_REGNUM (tdep
); i
++)
1391 regcache
->raw_supply (i
, FXSAVE_ADDR (tdep
, regs
, i
));
1395 /* Handle the x87 registers. */
1396 if ((tdep
->xcr0
& X86_XSTATE_X87
))
1398 if ((clear_bv
& X86_XSTATE_X87
))
1400 for (i
= I387_ST0_REGNUM (tdep
);
1401 i
< I387_FCTRL_REGNUM (tdep
);
1403 regcache
->raw_supply (i
, zero
);
1407 for (i
= I387_ST0_REGNUM (tdep
);
1408 i
< I387_FCTRL_REGNUM (tdep
);
1410 regcache
->raw_supply (i
, FXSAVE_ADDR (tdep
, regs
, i
));
1416 /* Only handle x87 control registers. */
1417 for (i
= I387_FCTRL_REGNUM (tdep
); i
< I387_XMM0_REGNUM (tdep
); i
++)
1418 if (regnum
== -1 || regnum
== i
)
1420 if (clear_bv
& X86_XSTATE_X87
)
1422 if (i
== I387_FCTRL_REGNUM (tdep
))
1426 store_unsigned_integer (buf
, 4, byte_order
,
1427 I387_FCTRL_INIT_VAL
);
1428 regcache
->raw_supply (i
, buf
);
1430 else if (i
== I387_FTAG_REGNUM (tdep
))
1434 store_unsigned_integer (buf
, 4, byte_order
, 0xffff);
1435 regcache
->raw_supply (i
, buf
);
1438 regcache
->raw_supply (i
, zero
);
1440 /* Most of the FPU control registers occupy only 16 bits in
1441 the xsave extended state. Give those a special treatment. */
1442 else if (i
!= I387_FIOFF_REGNUM (tdep
)
1443 && i
!= I387_FOOFF_REGNUM (tdep
))
1447 memcpy (val
, FXSAVE_ADDR (tdep
, regs
, i
), 2);
1448 val
[2] = val
[3] = 0;
1449 if (i
== I387_FOP_REGNUM (tdep
))
1450 val
[1] &= ((1 << 3) - 1);
1451 else if (i
== I387_FTAG_REGNUM (tdep
))
1453 /* The fxsave area contains a simplified version of
1454 the tag word. We have to look at the actual 80-bit
1455 FP data to recreate the traditional i387 tag word. */
1457 unsigned long ftag
= 0;
1461 top
= ((FXSAVE_ADDR (tdep
, regs
,
1462 I387_FSTAT_REGNUM (tdep
)))[1] >> 3);
1465 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
1469 if (val
[0] & (1 << fpreg
))
1471 int thisreg
= (fpreg
+ 8 - top
) % 8
1472 + I387_ST0_REGNUM (tdep
);
1473 tag
= i387_tag (FXSAVE_ADDR (tdep
, regs
, thisreg
));
1476 tag
= 3; /* Empty */
1478 ftag
|= tag
<< (2 * fpreg
);
1480 val
[0] = ftag
& 0xff;
1481 val
[1] = (ftag
>> 8) & 0xff;
1483 regcache
->raw_supply (i
, val
);
1486 regcache
->raw_supply (i
, FXSAVE_ADDR (tdep
, regs
, i
));
1489 if (regnum
== I387_MXCSR_REGNUM (tdep
) || regnum
== -1)
1491 /* The MXCSR register is placed into the xsave buffer if either the
1492 AVX or SSE features are enabled. */
1493 if ((clear_bv
& (X86_XSTATE_AVX
| X86_XSTATE_SSE
))
1494 == (X86_XSTATE_AVX
| X86_XSTATE_SSE
))
1498 store_unsigned_integer (buf
, 4, byte_order
, I387_MXCSR_INIT_VAL
);
1499 regcache
->raw_supply (I387_MXCSR_REGNUM (tdep
), buf
);
1502 regcache
->raw_supply (I387_MXCSR_REGNUM (tdep
),
1503 FXSAVE_MXCSR_ADDR (regs
));
1507 /* Similar to i387_collect_fxsave, but use XSAVE extended state. */
1510 i387_collect_xsave (const struct regcache
*regcache
, int regnum
,
1511 void *xsave
, int gcore
)
1513 struct gdbarch
*gdbarch
= regcache
->arch ();
1514 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1515 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
1516 gdb_byte
*p
, *regs
= (gdb_byte
*) xsave
;
1517 gdb_byte raw
[I386_MAX_REGISTER_SIZE
];
1518 ULONGEST initial_xstate_bv
, clear_bv
, xstate_bv
= 0;
1520 /* See the comment in i387_supply_xsave(). */
1521 unsigned int zmm_endlo_regnum
= I387_ZMM0H_REGNUM (tdep
)
1522 + std::min (tdep
->num_zmm_regs
, 16);
1525 x87_ctrl_or_mxcsr
= 0x1,
1532 avx512_zmm0_h
= 0x80,
1533 avx512_zmm16_h
= 0x100,
1534 avx512_ymmh_avx512
= 0x200,
1535 avx512_xmm_avx512
= 0x400,
1537 all
= x87
| sse
| avxh
| bndregs
| bndcfg
| avx512_k
| avx512_zmm0_h
1538 | avx512_zmm16_h
| avx512_ymmh_avx512
| avx512_xmm_avx512
| pkeys
1541 gdb_assert (tdep
->st0_regnum
>= I386_ST0_REGNUM
);
1542 gdb_assert (tdep
->num_xmm_regs
> 0);
1546 else if (regnum
>= I387_PKRU_REGNUM (tdep
)
1547 && regnum
< I387_PKEYSEND_REGNUM (tdep
))
1549 else if (regnum
>= I387_ZMM0H_REGNUM (tdep
)
1550 && regnum
< I387_ZMM16H_REGNUM (tdep
))
1551 regclass
= avx512_zmm0_h
;
1552 else if (regnum
>= I387_ZMM16H_REGNUM (tdep
)
1553 && regnum
< I387_ZMMENDH_REGNUM (tdep
))
1554 regclass
= avx512_zmm16_h
;
1555 else if (regnum
>= I387_K0_REGNUM (tdep
)
1556 && regnum
< I387_KEND_REGNUM (tdep
))
1557 regclass
= avx512_k
;
1558 else if (regnum
>= I387_YMM16H_REGNUM (tdep
)
1559 && regnum
< I387_YMMH_AVX512_END_REGNUM (tdep
))
1560 regclass
= avx512_ymmh_avx512
;
1561 else if (regnum
>= I387_XMM16_REGNUM (tdep
)
1562 && regnum
< I387_XMM_AVX512_END_REGNUM (tdep
))
1563 regclass
= avx512_xmm_avx512
;
1564 else if (regnum
>= I387_YMM0H_REGNUM (tdep
)
1565 && regnum
< I387_YMMENDH_REGNUM (tdep
))
1567 else if (regnum
>= I387_BND0R_REGNUM (tdep
)
1568 && regnum
< I387_BNDCFGU_REGNUM (tdep
))
1570 else if (regnum
>= I387_BNDCFGU_REGNUM (tdep
)
1571 && regnum
< I387_MPXEND_REGNUM (tdep
))
1573 else if (regnum
>= I387_XMM0_REGNUM (tdep
)
1574 && regnum
< I387_MXCSR_REGNUM (tdep
))
1576 else if (regnum
>= I387_ST0_REGNUM (tdep
)
1577 && regnum
< I387_FCTRL_REGNUM (tdep
))
1579 else if ((regnum
>= I387_FCTRL_REGNUM (tdep
)
1580 && regnum
< I387_XMM0_REGNUM (tdep
))
1581 || regnum
== I387_MXCSR_REGNUM (tdep
))
1582 regclass
= x87_ctrl_or_mxcsr
;
1584 internal_error (_("invalid i387 regnum %d"), regnum
);
1588 /* Clear XSAVE extended state. */
1589 memset (regs
, 0, tdep
->xsave_layout
.sizeof_xsave
);
1591 /* Update XCR0 and `xstate_bv' with XCR0 for gcore. */
1592 if (tdep
->xsave_xcr0_offset
!= -1)
1593 memcpy (regs
+ tdep
->xsave_xcr0_offset
, &tdep
->xcr0
, 8);
1594 memcpy (XSAVE_XSTATE_BV_ADDR (regs
), &tdep
->xcr0
, 8);
1597 /* The supported bits in `xstat_bv' are 8 bytes. */
1598 initial_xstate_bv
= extract_unsigned_integer (XSAVE_XSTATE_BV_ADDR (regs
),
1600 clear_bv
= (~(initial_xstate_bv
)) & tdep
->xcr0
;
1602 /* The XSAVE buffer was filled lazily by the kernel. Only those
1603 features that are enabled were written into the buffer, disabled
1604 features left the buffer uninitialised. In order to identify if any
1605 registers have changed we will be comparing the register cache
1606 version to the version in the XSAVE buffer, it is important then that
1607 at this point we initialise to the default values any features in
1608 XSAVE that are not yet initialised.
1610 This could be made more efficient, we know which features (from
1611 REGNUM) we will be potentially updating, and could limit ourselves to
1612 only clearing that feature. However, the extra complexity does not
1613 seem justified at this point. */
1616 if ((clear_bv
& X86_XSTATE_PKRU
))
1617 for (i
= I387_PKRU_REGNUM (tdep
);
1618 i
< I387_PKEYSEND_REGNUM (tdep
); i
++)
1619 memset (XSAVE_PKEYS_ADDR (tdep
, regs
, i
), 0, 4);
1621 if ((clear_bv
& X86_XSTATE_BNDREGS
))
1622 for (i
= I387_BND0R_REGNUM (tdep
);
1623 i
< I387_BNDCFGU_REGNUM (tdep
); i
++)
1624 memset (XSAVE_BNDREGS_ADDR (tdep
, regs
, i
), 0, 16);
1626 if ((clear_bv
& X86_XSTATE_BNDCFG
))
1627 for (i
= I387_BNDCFGU_REGNUM (tdep
);
1628 i
< I387_MPXEND_REGNUM (tdep
); i
++)
1629 memset (XSAVE_BNDCFG_ADDR (tdep
, regs
, i
), 0, 8);
1631 if ((clear_bv
& X86_XSTATE_ZMM_H
))
1632 for (i
= I387_ZMM0H_REGNUM (tdep
); i
< zmm_endlo_regnum
; i
++)
1633 memset (XSAVE_AVX512_ZMM0_H_ADDR (tdep
, regs
, i
), 0, 32);
1635 if ((clear_bv
& X86_XSTATE_K
))
1636 for (i
= I387_K0_REGNUM (tdep
);
1637 i
< I387_KEND_REGNUM (tdep
); i
++)
1638 memset (XSAVE_AVX512_K_ADDR (tdep
, regs
, i
), 0, 8);
1640 if ((clear_bv
& X86_XSTATE_ZMM
))
1642 for (i
= I387_ZMM16H_REGNUM (tdep
); i
< I387_ZMMENDH_REGNUM (tdep
);
1644 memset (XSAVE_AVX512_ZMM16_H_ADDR (tdep
, regs
, i
), 0, 32);
1645 for (i
= I387_YMM16H_REGNUM (tdep
);
1646 i
< I387_YMMH_AVX512_END_REGNUM (tdep
); i
++)
1647 memset (XSAVE_YMM_AVX512_ADDR (tdep
, regs
, i
), 0, 16);
1648 for (i
= I387_XMM16_REGNUM (tdep
);
1649 i
< I387_XMM_AVX512_END_REGNUM (tdep
); i
++)
1650 memset (XSAVE_XMM_AVX512_ADDR (tdep
, regs
, i
), 0, 16);
1653 if ((clear_bv
& X86_XSTATE_AVX
))
1654 for (i
= I387_YMM0H_REGNUM (tdep
);
1655 i
< I387_YMMENDH_REGNUM (tdep
); i
++)
1656 memset (XSAVE_AVXH_ADDR (tdep
, regs
, i
), 0, 16);
1658 if ((clear_bv
& X86_XSTATE_SSE
))
1659 for (i
= I387_XMM0_REGNUM (tdep
);
1660 i
< I387_MXCSR_REGNUM (tdep
); i
++)
1661 memset (FXSAVE_ADDR (tdep
, regs
, i
), 0, 16);
1663 /* The mxcsr register is written into the xsave buffer if either AVX
1664 or SSE is enabled, so only clear it if both of those features
1665 require clearing. */
1666 if ((clear_bv
& (X86_XSTATE_AVX
| X86_XSTATE_SSE
))
1667 == (X86_XSTATE_AVX
| X86_XSTATE_SSE
))
1668 store_unsigned_integer (FXSAVE_MXCSR_ADDR (regs
), 2, byte_order
,
1669 I387_MXCSR_INIT_VAL
);
1671 if ((clear_bv
& X86_XSTATE_X87
))
1673 for (i
= I387_ST0_REGNUM (tdep
);
1674 i
< I387_FCTRL_REGNUM (tdep
); i
++)
1675 memset (FXSAVE_ADDR (tdep
, regs
, i
), 0, 10);
1677 for (i
= I387_FCTRL_REGNUM (tdep
);
1678 i
< I387_XMM0_REGNUM (tdep
); i
++)
1680 if (i
== I387_FCTRL_REGNUM (tdep
))
1681 store_unsigned_integer (FXSAVE_ADDR (tdep
, regs
, i
), 2,
1682 byte_order
, I387_FCTRL_INIT_VAL
);
1684 memset (FXSAVE_ADDR (tdep
, regs
, i
), 0,
1685 regcache_register_size (regcache
, i
));
1690 if (regclass
== all
)
1692 /* Check if any PKEYS registers are changed. */
1693 if ((tdep
->xcr0
& X86_XSTATE_PKRU
))
1694 for (i
= I387_PKRU_REGNUM (tdep
);
1695 i
< I387_PKEYSEND_REGNUM (tdep
); i
++)
1697 regcache
->raw_collect (i
, raw
);
1698 p
= XSAVE_PKEYS_ADDR (tdep
, regs
, i
);
1699 if (memcmp (raw
, p
, 4) != 0)
1701 xstate_bv
|= X86_XSTATE_PKRU
;
1706 /* Check if any ZMMH registers are changed. */
1707 if ((tdep
->xcr0
& X86_XSTATE_ZMM
))
1708 for (i
= I387_ZMM16H_REGNUM (tdep
);
1709 i
< I387_ZMMENDH_REGNUM (tdep
); i
++)
1711 regcache
->raw_collect (i
, raw
);
1712 p
= XSAVE_AVX512_ZMM16_H_ADDR (tdep
, regs
, i
);
1713 if (memcmp (raw
, p
, 32) != 0)
1715 xstate_bv
|= X86_XSTATE_ZMM
;
1716 memcpy (p
, raw
, 32);
1720 if ((tdep
->xcr0
& X86_XSTATE_ZMM_H
))
1721 for (i
= I387_ZMM0H_REGNUM (tdep
); i
< zmm_endlo_regnum
; i
++)
1723 regcache
->raw_collect (i
, raw
);
1724 p
= XSAVE_AVX512_ZMM0_H_ADDR (tdep
, regs
, i
);
1725 if (memcmp (raw
, p
, 32) != 0)
1727 xstate_bv
|= X86_XSTATE_ZMM_H
;
1728 memcpy (p
, raw
, 32);
1732 /* Check if any K registers are changed. */
1733 if ((tdep
->xcr0
& X86_XSTATE_K
))
1734 for (i
= I387_K0_REGNUM (tdep
);
1735 i
< I387_KEND_REGNUM (tdep
); i
++)
1737 regcache
->raw_collect (i
, raw
);
1738 p
= XSAVE_AVX512_K_ADDR (tdep
, regs
, i
);
1739 if (memcmp (raw
, p
, 8) != 0)
1741 xstate_bv
|= X86_XSTATE_K
;
1746 /* Check if any XMM or upper YMM registers are changed. */
1747 if ((tdep
->xcr0
& X86_XSTATE_ZMM
))
1749 for (i
= I387_YMM16H_REGNUM (tdep
);
1750 i
< I387_YMMH_AVX512_END_REGNUM (tdep
); i
++)
1752 regcache
->raw_collect (i
, raw
);
1753 p
= XSAVE_YMM_AVX512_ADDR (tdep
, regs
, i
);
1754 if (memcmp (raw
, p
, 16) != 0)
1756 xstate_bv
|= X86_XSTATE_ZMM
;
1757 memcpy (p
, raw
, 16);
1760 for (i
= I387_XMM16_REGNUM (tdep
);
1761 i
< I387_XMM_AVX512_END_REGNUM (tdep
); i
++)
1763 regcache
->raw_collect (i
, raw
);
1764 p
= XSAVE_XMM_AVX512_ADDR (tdep
, regs
, i
);
1765 if (memcmp (raw
, p
, 16) != 0)
1767 xstate_bv
|= X86_XSTATE_ZMM
;
1768 memcpy (p
, raw
, 16);
1773 /* Check if any upper MPX registers are changed. */
1774 if ((tdep
->xcr0
& X86_XSTATE_BNDREGS
))
1775 for (i
= I387_BND0R_REGNUM (tdep
);
1776 i
< I387_BNDCFGU_REGNUM (tdep
); i
++)
1778 regcache
->raw_collect (i
, raw
);
1779 p
= XSAVE_BNDREGS_ADDR (tdep
, regs
, i
);
1780 if (memcmp (raw
, p
, 16))
1782 xstate_bv
|= X86_XSTATE_BNDREGS
;
1783 memcpy (p
, raw
, 16);
1787 /* Check if any upper MPX registers are changed. */
1788 if ((tdep
->xcr0
& X86_XSTATE_BNDCFG
))
1789 for (i
= I387_BNDCFGU_REGNUM (tdep
);
1790 i
< I387_MPXEND_REGNUM (tdep
); i
++)
1792 regcache
->raw_collect (i
, raw
);
1793 p
= XSAVE_BNDCFG_ADDR (tdep
, regs
, i
);
1794 if (memcmp (raw
, p
, 8))
1796 xstate_bv
|= X86_XSTATE_BNDCFG
;
1801 /* Check if any upper YMM registers are changed. */
1802 if ((tdep
->xcr0
& X86_XSTATE_AVX
))
1803 for (i
= I387_YMM0H_REGNUM (tdep
);
1804 i
< I387_YMMENDH_REGNUM (tdep
); i
++)
1806 regcache
->raw_collect (i
, raw
);
1807 p
= XSAVE_AVXH_ADDR (tdep
, regs
, i
);
1808 if (memcmp (raw
, p
, 16))
1810 xstate_bv
|= X86_XSTATE_AVX
;
1811 memcpy (p
, raw
, 16);
1815 /* Check if any SSE registers are changed. */
1816 if ((tdep
->xcr0
& X86_XSTATE_SSE
))
1817 for (i
= I387_XMM0_REGNUM (tdep
);
1818 i
< I387_MXCSR_REGNUM (tdep
); i
++)
1820 regcache
->raw_collect (i
, raw
);
1821 p
= FXSAVE_ADDR (tdep
, regs
, i
);
1822 if (memcmp (raw
, p
, 16))
1824 xstate_bv
|= X86_XSTATE_SSE
;
1825 memcpy (p
, raw
, 16);
1829 if ((tdep
->xcr0
& X86_XSTATE_AVX
) || (tdep
->xcr0
& X86_XSTATE_SSE
))
1831 i
= I387_MXCSR_REGNUM (tdep
);
1832 regcache
->raw_collect (i
, raw
);
1833 p
= FXSAVE_MXCSR_ADDR (regs
);
1834 if (memcmp (raw
, p
, 4))
1836 /* Now, we need to mark one of either SSE of AVX as enabled.
1837 We could pick either. What we do is check to see if one
1838 of the features is already enabled, if it is then we leave
1839 it at that, otherwise we pick SSE. */
1840 if ((xstate_bv
& (X86_XSTATE_SSE
| X86_XSTATE_AVX
)) == 0)
1841 xstate_bv
|= X86_XSTATE_SSE
;
1846 /* Check if any X87 registers are changed. Only the non-control
1847 registers are handled here, the control registers are all handled
1848 later on in this function. */
1849 if ((tdep
->xcr0
& X86_XSTATE_X87
))
1850 for (i
= I387_ST0_REGNUM (tdep
);
1851 i
< I387_FCTRL_REGNUM (tdep
); i
++)
1853 regcache
->raw_collect (i
, raw
);
1854 p
= FXSAVE_ADDR (tdep
, regs
, i
);
1855 if (memcmp (raw
, p
, 10))
1857 xstate_bv
|= X86_XSTATE_X87
;
1858 memcpy (p
, raw
, 10);
1864 /* Check if REGNUM is changed. */
1865 regcache
->raw_collect (regnum
, raw
);
1870 internal_error (_("invalid i387 regclass"));
1873 /* This is a PKEYS register. */
1874 p
= XSAVE_PKEYS_ADDR (tdep
, regs
, regnum
);
1875 if (memcmp (raw
, p
, 4) != 0)
1877 xstate_bv
|= X86_XSTATE_PKRU
;
1882 case avx512_zmm16_h
:
1883 /* This is a ZMM16-31 register. */
1884 p
= XSAVE_AVX512_ZMM16_H_ADDR (tdep
, regs
, regnum
);
1885 if (memcmp (raw
, p
, 32) != 0)
1887 xstate_bv
|= X86_XSTATE_ZMM
;
1888 memcpy (p
, raw
, 32);
1893 /* This is a ZMM0-15 register. */
1894 p
= XSAVE_AVX512_ZMM0_H_ADDR (tdep
, regs
, regnum
);
1895 if (memcmp (raw
, p
, 32) != 0)
1897 xstate_bv
|= X86_XSTATE_ZMM_H
;
1898 memcpy (p
, raw
, 32);
1903 /* This is a AVX512 mask register. */
1904 p
= XSAVE_AVX512_K_ADDR (tdep
, regs
, regnum
);
1905 if (memcmp (raw
, p
, 8) != 0)
1907 xstate_bv
|= X86_XSTATE_K
;
1912 case avx512_ymmh_avx512
:
1913 /* This is an upper YMM16-31 register. */
1914 p
= XSAVE_YMM_AVX512_ADDR (tdep
, regs
, regnum
);
1915 if (memcmp (raw
, p
, 16) != 0)
1917 xstate_bv
|= X86_XSTATE_ZMM
;
1918 memcpy (p
, raw
, 16);
1922 case avx512_xmm_avx512
:
1923 /* This is an upper XMM16-31 register. */
1924 p
= XSAVE_XMM_AVX512_ADDR (tdep
, regs
, regnum
);
1925 if (memcmp (raw
, p
, 16) != 0)
1927 xstate_bv
|= X86_XSTATE_ZMM
;
1928 memcpy (p
, raw
, 16);
1933 /* This is an upper YMM register. */
1934 p
= XSAVE_AVXH_ADDR (tdep
, regs
, regnum
);
1935 if (memcmp (raw
, p
, 16))
1937 xstate_bv
|= X86_XSTATE_AVX
;
1938 memcpy (p
, raw
, 16);
1943 regcache
->raw_collect (regnum
, raw
);
1944 p
= XSAVE_BNDREGS_ADDR (tdep
, regs
, regnum
);
1945 if (memcmp (raw
, p
, 16))
1947 xstate_bv
|= X86_XSTATE_BNDREGS
;
1948 memcpy (p
, raw
, 16);
1953 p
= XSAVE_BNDCFG_ADDR (tdep
, regs
, regnum
);
1954 xstate_bv
|= X86_XSTATE_BNDCFG
;
1959 /* This is an SSE register. */
1960 p
= FXSAVE_ADDR (tdep
, regs
, regnum
);
1961 if (memcmp (raw
, p
, 16))
1963 xstate_bv
|= X86_XSTATE_SSE
;
1964 memcpy (p
, raw
, 16);
1969 /* This is an x87 register. */
1970 p
= FXSAVE_ADDR (tdep
, regs
, regnum
);
1971 if (memcmp (raw
, p
, 10))
1973 xstate_bv
|= X86_XSTATE_X87
;
1974 memcpy (p
, raw
, 10);
1978 case x87_ctrl_or_mxcsr
:
1979 /* We only handle MXCSR here. All other x87 control registers
1980 are handled separately below. */
1981 if (regnum
== I387_MXCSR_REGNUM (tdep
))
1983 p
= FXSAVE_MXCSR_ADDR (regs
);
1984 if (memcmp (raw
, p
, 2))
1986 /* We're only setting MXCSR, so check the initial state
1987 to see if either of AVX or SSE are already enabled.
1988 If they are then we'll attribute this changed MXCSR to
1989 that feature. If neither feature is enabled, then
1990 we'll attribute this change to the SSE feature. */
1991 xstate_bv
|= (initial_xstate_bv
1992 & (X86_XSTATE_AVX
| X86_XSTATE_SSE
));
1993 if ((xstate_bv
& (X86_XSTATE_AVX
| X86_XSTATE_SSE
)) == 0)
1994 xstate_bv
|= X86_XSTATE_SSE
;
2001 /* Only handle x87 control registers. */
2002 for (i
= I387_FCTRL_REGNUM (tdep
); i
< I387_XMM0_REGNUM (tdep
); i
++)
2003 if (regnum
== -1 || regnum
== i
)
2005 /* Most of the FPU control registers occupy only 16 bits in
2006 the xsave extended state. Give those a special treatment. */
2007 if (i
!= I387_FIOFF_REGNUM (tdep
)
2008 && i
!= I387_FOOFF_REGNUM (tdep
))
2012 regcache
->raw_collect (i
, buf
);
2014 if (i
== I387_FOP_REGNUM (tdep
))
2016 /* The opcode occupies only 11 bits. Make sure we
2017 don't touch the other bits. */
2018 buf
[1] &= ((1 << 3) - 1);
2019 buf
[1] |= ((FXSAVE_ADDR (tdep
, regs
, i
))[1] & ~((1 << 3) - 1));
2021 else if (i
== I387_FTAG_REGNUM (tdep
))
2023 /* Converting back is much easier. */
2025 unsigned short ftag
;
2028 ftag
= (buf
[1] << 8) | buf
[0];
2032 for (fpreg
= 7; fpreg
>= 0; fpreg
--)
2034 int tag
= (ftag
>> (fpreg
* 2)) & 3;
2037 buf
[0] |= (1 << fpreg
);
2040 p
= FXSAVE_ADDR (tdep
, regs
, i
);
2041 if (memcmp (p
, buf
, 2))
2043 xstate_bv
|= X86_XSTATE_X87
;
2051 regcache
->raw_collect (i
, raw
);
2052 regsize
= regcache_register_size (regcache
, i
);
2053 p
= FXSAVE_ADDR (tdep
, regs
, i
);
2054 if (memcmp (raw
, p
, regsize
))
2056 xstate_bv
|= X86_XSTATE_X87
;
2057 memcpy (p
, raw
, regsize
);
2062 /* Update the corresponding bits in `xstate_bv' if any
2063 registers are changed. */
2066 /* The supported bits in `xstat_bv' are 8 bytes. */
2067 initial_xstate_bv
|= xstate_bv
;
2068 store_unsigned_integer (XSAVE_XSTATE_BV_ADDR (regs
),
2074 /* Recreate the FTW (tag word) valid bits from the 80-bit FP data in
2078 i387_tag (const gdb_byte
*raw
)
2081 unsigned int exponent
;
2082 unsigned long fraction
[2];
2084 integer
= raw
[7] & 0x80;
2085 exponent
= (((raw
[9] & 0x7f) << 8) | raw
[8]);
2086 fraction
[0] = ((raw
[3] << 24) | (raw
[2] << 16) | (raw
[1] << 8) | raw
[0]);
2087 fraction
[1] = (((raw
[7] & 0x7f) << 24) | (raw
[6] << 16)
2088 | (raw
[5] << 8) | raw
[4]);
2090 if (exponent
== 0x7fff)
2095 else if (exponent
== 0x0000)
2097 if (fraction
[0] == 0x0000 && fraction
[1] == 0x0000 && !integer
)
2123 /* Prepare the FPU stack in REGCACHE for a function return. */
2126 i387_return_value (struct gdbarch
*gdbarch
, struct regcache
*regcache
)
2128 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
2131 /* Set the top of the floating-point register stack to 7. The
2132 actual value doesn't really matter, but 7 is what a normal
2133 function return would end up with if the program started out with
2134 a freshly initialized FPU. */
2135 regcache_raw_read_unsigned (regcache
, I387_FSTAT_REGNUM (tdep
), &fstat
);
2137 regcache_raw_write_unsigned (regcache
, I387_FSTAT_REGNUM (tdep
), fstat
);
2139 /* Mark %st(1) through %st(7) as empty. Since we set the top of the
2140 floating-point register stack to 7, the appropriate value for the
2141 tag word is 0x3fff. */
2142 regcache_raw_write_unsigned (regcache
, I387_FTAG_REGNUM (tdep
), 0x3fff);
2146 /* See i387-tdep.h. */
2149 i387_reset_bnd_regs (struct gdbarch
*gdbarch
, struct regcache
*regcache
)
2151 i386_gdbarch_tdep
*tdep
= gdbarch_tdep
<i386_gdbarch_tdep
> (gdbarch
);
2153 if (I387_BND0R_REGNUM (tdep
) > 0)
2155 gdb_byte bnd_buf
[16];
2157 memset (bnd_buf
, 0, 16);
2158 for (int i
= 0; i
< I387_NUM_BND_REGS
; i
++)
2159 regcache
->raw_write (I387_BND0R_REGNUM (tdep
) + i
, bnd_buf
);