]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.arch/amd64-init-x87-values.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.arch / amd64-init-x87-values.exp
1 # Copyright 2018-2023 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # This file is part of the gdb testsuite.
17
18 # Test initial values of x87 control registers, before any x87
19 # instructions have been executed in the inferior.
20
21 if {![is_amd64_regs_target]} {
22 return
23 }
24
25 standard_testfile .S
26
27 set options [list debug \
28 additional_flags=-static \
29 additional_flags=-nostartfiles]
30 if { [build_executable "failed to prepare" ${testfile} ${srcfile} $options] } {
31 return -1
32 }
33
34 # Start the test file, and check the x87 control registers (and
35 # mxcsr), we expect the default values in all registers.
36 #
37 # Step forward until the x87 unit is enabled, recheck the register
38 # values; they should still have the default values.
39 #
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 {} {
43 global binfile
44
45 clean_restart ${binfile}
46
47 # Get things started.
48 if {![runto_main]} {
49 return 0
50 }
51
52 # Check initial values of x87 control registers. The MXCSR isn't part
53 # of the x87 set, it belongs with SSE/AVX, however we test it here
54 # too, it should have its default value in both cases.
55 foreach {regname regvalue} { "fctrl" "0x37f" \
56 "fstat" "0x0" \
57 "ftag" "0xffff" \
58 "fiseg" "0x0" \
59 "fioff" "0x0" \
60 "foseg" "0x0" \
61 "fooff" "0x0" \
62 "fop" "0x0" \
63 "mxcsr" "0x1f80"} {
64 gdb_test "p/x \$${regname}" " = ${regvalue}" "check initial value of \$${regname}"
65 }
66
67 # No x87 instructions have been executed yet. Step up to FWAIT
68 # instruction. Executing this instruction will enable the x87 unit,
69 # causing the kernel to place the default values into all registers.
70 # After this GDB will no longer supply the default values itself but
71 # will instread read the values out of the xsave buffer.
72 gdb_test "stepi" "fwait" "step to FWAIT instruction"
73 gdb_test "stepi" "nop" "step past FWAIT instruction"
74
75 # The x87 unit is now enabled, but the register values should be
76 # unchanged.
77 foreach {regname regvalue} { "fctrl" "0x37f" \
78 "fstat" "0x0" \
79 "ftag" "0xffff" \
80 "fiseg" "0x0" \
81 "fioff" "0x0" \
82 "foseg" "0x0" \
83 "fooff" "0x0" \
84 "fop" "0x0" \
85 "mxcsr" "0x1f80"} {
86 gdb_test "p/x \$${regname}" " = ${regvalue}" "check post FWAIT value of \$${regname}"
87 }
88
89 # Now step to an x87 instruction that modifies some state.
90 gdb_test "stepi" "fld1" "step to FLD1 instruction"
91
92 # Grab the address of this instruction, it will appear in later
93 # results.
94 set addr [get_hexadecimal_valueof "\$pc" "0"]
95
96 # Step past the FLD1 instruction.
97 gdb_test "stepi" "nop" "step past FLD1 instruction"
98
99 # Check new values of x87 control registers (and MXCSR).
100 foreach {regname regvalue} [list "fctrl" "0x37f" \
101 "fstat" "0x3800" \
102 "ftag" "0x3fff" \
103 "fiseg" "0x0" \
104 "fioff" $addr \
105 "foseg" "0x0" \
106 "fooff" "0x0" \
107 "fop" "0x0" \
108 "mxcsr" "0x1f80" ] {
109 gdb_test "p/x \$${regname}" " = ${regvalue}" "check post FLD1 value of \$${regname}"
110 }
111 }
112
113 # Start the test file, all FP features will be disabled. Set a new
114 # value into the MXCSR register, then step forward one instruction (a
115 # nop that does not enable any FP features). Finally check that the
116 # mxcsr register still has the value we set.
117 proc_with_prefix check_setting_mxcsr_before_enable {} {
118 global binfile gdb_prompt
119
120 clean_restart ${binfile}
121
122 if {![runto_main]} {
123 return 0
124 }
125
126 gdb_test_no_output "set \$mxcsr=0x9f80" "set a new value for MXCSR"
127 gdb_test "stepi" "fwait" "step forward one instruction for mxcsr test"
128
129 set test "check new value of MXCSR is still in place"
130 set pass_pattern " = 0x9f80"
131 # Pre-4.14 kernels have a bug (fixed by commit 0852b374173b "x86/fpu:
132 # Add FPU state copying quirk to handle XRSTOR failure on Intel Skylake
133 # CPUs") that causes mxcsr not to be copied, in which case we get 0 instead of
134 # the just saved value.
135 set xfail_pattern " = 0x0"
136 gdb_test_multiple "p/x \$mxcsr" $test {
137 -re "\[\r\n\]*(?:$pass_pattern)\[\r\n\]+$gdb_prompt $" {
138 pass $test
139 }
140 -re "\[\r\n\]*(?:$xfail_pattern)\[\r\n\]+$gdb_prompt $" {
141 xfail $test
142 }
143 }
144 }
145
146 # Start the test file, all FP features will be disabled. Set new
147 # values into the x87 control-registers, then step forward one
148 # instruction (a nop that does not enable any FP features). Finally
149 # check that all the x87 control-registers still have the values we
150 # set.
151 proc_with_prefix check_setting_x87_regs_before_enable {} {
152 global binfile
153
154 clean_restart ${binfile}
155
156 if {![runto_main]} {
157 return 0
158 }
159
160 foreach {regname regvalue} [list "fctrl" "0x37f" \
161 "fstat" "0x3800" \
162 "ftag" "0x7777" \
163 "fiseg" "0x12" \
164 "fioff" "0x2418" \
165 "foseg" "0x24" \
166 "fooff" "0x36" \
167 "fop" "0x100" ] {
168 gdb_test_no_output "set \$$regname=$regvalue" "set a new value for $regname"
169 }
170
171 gdb_test "stepi" "fwait" "step forward one instruction for x87 test"
172
173 foreach {regname regvalue} [list "fctrl" "0x37f" \
174 "fstat" "0x3800" \
175 "ftag" "0x7777" \
176 "fiseg" "0x12" \
177 "fioff" "0x2418" \
178 "foseg" "0x24" \
179 "fooff" "0x36" \
180 "fop" "0x100" ] {
181 gdb_test "p/x \$$regname" "= $regvalue" "check new value of $regname"
182 }
183 }
184
185 check_x87_regs_around_init
186 check_setting_mxcsr_before_enable
187 check_setting_x87_regs_before_enable