1 # Copyright 2018-2020 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This file is part of the gdb testsuite.
18 # Test initial values of x87 control registers, before any x87
19 # instructions have been executed in the inferior.
21 if ![is_amd64_regs_target] then {
27 set options [list debug \
28 additional_flags=-static \
29 additional_flags=-nostartfiles]
30 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $options] } {
34 # Start the test file, and check the x87 control registers (and
35 # mxcsr), we expect the default values in all registers.
37 # Step forward until the x87 unit is enabled, recheck the register
38 # values; they should still have the default values.
40 # Finally, step forward until the x87 state has changed, and then
41 # recheck the register state to view the changes.
42 proc_with_prefix check_x87_regs_around_init {} {
45 clean_restart ${binfile}
48 if ![runto_main] then {
49 fail "can't run to main"
53 # Check initial values of x87 control registers. The MXCSR isn't part
54 # of the x87 set, it belongs with SSE/AVX, however we test it here
55 # too, it should have its default value in both cases.
56 foreach {regname regvalue} { "fctrl" "0x37f" \
65 gdb_test "p/x \$${regname}" " = ${regvalue}" "check initial value of \$${regname}"
68 # No x87 instructions have been executed yet. Step up to FWAIT
69 # instruction. Executing this instruction will enable the x87 unit,
70 # causing the kernel to place the default values into all registers.
71 # After this GDB will no longer supply the default values itself but
72 # will instread read the values out of the xsave buffer.
73 gdb_test "stepi" "fwait" "step to FWAIT instruction"
74 gdb_test "stepi" "nop" "step past FWAIT instruction"
76 # The x87 unit is now enabled, but the register values should be
78 foreach {regname regvalue} { "fctrl" "0x37f" \
87 gdb_test "p/x \$${regname}" " = ${regvalue}" "check post FWAIT value of \$${regname}"
90 # Now step to an x87 instruction that modifies some state.
91 gdb_test "stepi" "fld1" "step to FLD1 instruction"
93 # Grab the address of this instruction, it will appear in later
95 set addr [get_hexadecimal_valueof "\$pc" "0"]
97 # Step past the FLD1 instruction.
98 gdb_test "stepi" "nop" "step past FLD1 instruction"
100 # Check new values of x87 control registers (and MXCSR).
101 foreach {regname regvalue} [list "fctrl" "0x37f" \
110 gdb_test "p/x \$${regname}" " = ${regvalue}" "check post FLD1 value of \$${regname}"
114 # Start the test file, all FP features will be disabled. Set a new
115 # value into the MXCSR register, then step forward one instruction (a
116 # nop that does not enable any FP features). Finally check that the
117 # mxcsr register still has the value we set.
118 proc_with_prefix check_setting_mxcsr_before_enable {} {
119 global binfile gdb_prompt
121 clean_restart ${binfile}
123 if ![runto_main] then {
124 fail "can't run to main"
128 gdb_test_no_output "set \$mxcsr=0x9f80" "set a new value for MXCSR"
129 gdb_test "stepi" "fwait" "step forward one instruction for mxcsr test"
131 set test "check new value of MXCSR is still in place"
132 set pass_pattern " = 0x9f80"
133 # Pre-4.14 kernels have a bug (fixed by commit 0852b374173b "x86/fpu:
134 # Add FPU state copying quirk to handle XRSTOR failure on Intel Skylake
135 # CPUs") that causes mxcsr not to be copied, in which case we get 0 instead of
136 # the just saved value.
137 set xfail_pattern " = 0x0"
138 gdb_test_multiple "p/x \$mxcsr" $test {
139 -re "\[\r\n\]*(?:$pass_pattern)\[\r\n\]+$gdb_prompt $" {
142 -re "\[\r\n\]*(?:$xfail_pattern)\[\r\n\]+$gdb_prompt $" {
148 # Start the test file, all FP features will be disabled. Set new
149 # values into the x87 control-registers, then step forward one
150 # instruction (a nop that does not enable any FP features). Finally
151 # check that all the x87 control-registers still have the values we
153 proc_with_prefix check_setting_x87_regs_before_enable {} {
156 clean_restart ${binfile}
158 if ![runto_main] then {
159 fail "can't run to main"
163 foreach {regname regvalue} [list "fctrl" "0x37f" \
171 gdb_test_no_output "set \$$regname=$regvalue" "set a new value for $regname"
174 gdb_test "stepi" "fwait" "step forward one instruction for x87 test"
176 foreach {regname regvalue} [list "fctrl" "0x37f" \
184 gdb_test "p/x \$$regname" "= $regvalue" "check new value of $regname"
188 check_x87_regs_around_init
189 check_setting_mxcsr_before_enable
190 check_setting_x87_regs_before_enable