]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2015-2024 Free Software Foundation, Inc. |
51547df6 MS |
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 | standard_testfile | |
17 | ||
c7ccb471 | 18 | require {is_any_target i?86-*-* x86_64-*-*} |
51547df6 | 19 | |
a561456f TV |
20 | set default_pkru_re 0x0 |
21 | if { [istarget *-*-linux*] } { | |
22 | # Starting with v4.9, the linux kernel contains commit acd547b29880 | |
23 | # ("x86/pkeys: Default to a restrictive init PKRU"), which sets the | |
24 | # pkru register to 0x55555554 by default. | |
25 | set default_pkru_re (0x0|0x55555554) | |
26 | } | |
27 | ||
28 | ||
51547df6 MS |
29 | set comp_flags "-I${srcdir}/../nat/" |
30 | ||
31 | if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ | |
32 | [list debug additional_flags=${comp_flags}]] } { | |
1512d3b7 | 33 | untested "failed to compile x86 PKEYS test." |
51547df6 MS |
34 | return -1 |
35 | } | |
36 | ||
37 | if ![runto_main] { | |
51547df6 MS |
38 | return -1 |
39 | } | |
40 | ||
41 | set supports_pkru 0 | |
42 | set test "probe PKRU support" | |
43 | gdb_test_multiple "print have_pkru()" $test { | |
44 | -re ".. = 1\r\n$gdb_prompt $" { | |
45 | pass $test | |
46 | set supports_pkru 1 | |
47 | } | |
25dcbff6 PA |
48 | -re ".. = 0\r\n$gdb_prompt $" { |
49 | pass $test | |
50 | } | |
51547df6 MS |
51 | } |
52 | ||
53 | if { !$supports_pkru } { | |
54 | unsupported "processor does not support protection key feature." | |
55 | return | |
56 | } | |
57 | ||
b46632ca TV |
58 | # Linux kernel versions 5.14.0 to 6.1.x contain a regression related to writing |
59 | # the PKRU using ptrace, see commit 4a804c4f8356 ("x86/fpu: Allow PKRU to be | |
60 | # (once again) written by ptrace."). | |
61 | set have_xfail 0 | |
37d75d45 TV |
62 | set v [linux_kernel_version] |
63 | if { $v != {} } { | |
64 | set have_xfail \ | |
65 | [expr \ | |
66 | [version_compare [list 5 14 0] <= $v] \ | |
67 | && [version_compare $v < [list 6 2 0]]] | |
b46632ca TV |
68 | } |
69 | ||
51547df6 | 70 | # Test pkru register at startup |
a561456f | 71 | gdb_test "print /x \$pkru" "= $default_pkru_re" "pkru register" |
51547df6 MS |
72 | |
73 | # Read values from pseudo registers. | |
74 | gdb_breakpoint [ gdb_get_line_number "break here 1" ] | |
75 | gdb_continue_to_breakpoint "break here 1" ".*break here 1.*" | |
76 | ||
b46632ca TV |
77 | set val1 0x12345678 |
78 | gdb_test "info register pkru" ".*pkru.*$val1.*" "read pkru register" | |
79 | ||
80 | set val2 0x44444444 | |
81 | gdb_test "print /x \$pkru = $val2" "= $val2" "set pkru value" | |
82 | ||
b46632ca TV |
83 | gdb_test_multiple "info register pkru" "read value after setting value" { |
84 | -re -wrap ".*pkru.*$val2.*" { | |
85 | pass $gdb_test_name | |
86 | } | |
87 | -re -wrap ".*pkru.*$val1.*" { | |
88 | if { $have_xfail } { | |
89 | xfail $gdb_test_name | |
90 | } else { | |
91 | fail $gdb_test_name | |
92 | } | |
b46632ca TV |
93 | } |
94 | } | |
51547df6 MS |
95 | |
96 | gdb_breakpoint [ gdb_get_line_number "break here 2" ] | |
97 | gdb_continue_to_breakpoint "break here 2" ".*break here 2.*" | |
98 | ||
7b0d27b6 TV |
99 | gdb_test_multiple "print /x rd_value" "variable after reading pkru" { |
100 | -re -wrap "= $val2" { | |
101 | pass $gdb_test_name | |
102 | } | |
103 | -re -wrap "= $val1" { | |
104 | if { $have_xfail } { | |
105 | xfail $gdb_test_name | |
106 | } else { | |
107 | fail $gdb_test_name | |
108 | } | |
109 | } | |
110 | } |