aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.arch/powerpc-htm-regs.exp
blob: 7d21e52260dfcf35e76a574226da7e06d5af54f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# Copyright (C) 2018-2023 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This file is part of the gdb testsuite.

# Test access to HTM (Hardware Transactional Memory) registers.  The
# tests read the values of various registers before stepping the
# inferior through a "tbegin." instruction to start a transaction,
# then the checkpointed versions of the registers are checked against
# the pre-transactional values.  Then, new values are written to some
# of the checkpointed registers, these values are read back and saved,
# the inferior continues until the transaction aborts, and the regular
# registers are then checked against the saved values, because the
# abort should have reverted the registers to these values.

require {istarget "powerpc*-*-linux*"}

standard_testfile .c .gen.c

# First check if our processor and kernel support access to
# the registers we need and to the HTM facility.

proc check_register_access { regname } {
    global gdb_prompt

    set test "$regname register access"
    gdb_test_multiple "info reg $regname" "$test" {
	-re "Invalid register.*\r\n$gdb_prompt $" {
	    unsupported "$test"
	    return 0
	}
	-re "\r\n$regname.*\r\n$gdb_prompt $" {
	    pass "$test"
	    return 1
	}
    }
    return 0
}

proc check_htm_support {} {
    global gdb_prompt
    set test "htm support"

    gdb_test_multiple "stepi" "$test" {
	-re "Illegal instruction.*\r\n$gdb_prompt $" {
	    unsupported $test
	    return 0
	}
	-re "nop.*\r\n$gdb_prompt $"
	{
	    pass $test
	    return 1
	}
    }
    return 0;
}

with_test_prefix "check htm support" {
    set gen_src [standard_output_file $srcfile2]

    gdb_produce_source $gen_src {
	int main () {
	    asm volatile ("tbegin."); // marker
	    asm volatile ("nop");
	    return 0;
	}
    }

    if {[build_executable "compile" $binfile $gen_src {debug}] == -1} {
	return
    }

    clean_restart $binfile

    # Displaced-stepping a tbegin. causes problems,
    # so we make the breakpoint temporary.
    gdb_breakpoint [gdb_get_line_number "marker" "$gen_src"] temporary

    gdb_run_cmd

    # Wait for the prompt.
    if {[gdb_test "" "Temporary breakpoint.*"] != 0 } {
	return
    }

    # Make sure that we stopped at the right place (just before tbegin. is
    # executed).
    if { [gdb_test "x/i \$pc" "=> $hex.*:.*tbegin\\..*" "disassemble tbegin"] != 0} {
	return
    }

    if {![check_register_access "vs0"]} {
	return
    }

    if {![check_register_access "texasr"]} {
	return
    }

    if {![check_register_access "dscr"]} {
	return
    }

    if {![check_register_access "ppr"]} {
	return
    }

    if {![check_register_access "tar"]} {
	return
    }

    if {![check_htm_support]} {
	return
    }
}

# Now do the actual test.
if {[build_executable "compile" $binfile $srcfile {debug}] == -1} {
    return
}

clean_restart $binfile

gdb_breakpoint [gdb_get_line_number "first marker"] temporary

gdb_run_cmd

# Wait for the prompt.
gdb_test "" "Temporary breakpoint.*"

if {[gdb_test "x/i \$pc" "=> $hex.*:.*tbegin\\..*" "disassemble tbegin"] != 0} {
    return
}

# Now we write non-zero values to some registers, then read the values
# of various registers, then stepi to start the transaction.  The
# checkpointed register state should correspond to the values we read.

# Write to the GPRs
for {set i 0} {$i < 32} {incr i 1} {
    gdb_test_no_output "set \$r$i = $i"
}

gdb_test_no_output "set \$xer = 0xc0000000"

# FPRs
gdb_test_no_output "set \$f0 = 0.5"
for {set i 1} {$i < 32} {incr i 1} {
    gdb_test_no_output "set \$f$i = \$f[expr $i - 1] + 1.0"
}

gdb_test_no_output "set \$fpscr = 0x84005000"

# VRs
for {set i 0} {$i < 32} {incr i 1} {
    for {set j 0} {$j < 4} {incr j 1} {
	gdb_test_no_output "set \$vr$i.v4_int32\[$j\] = $i"
    }
}

gdb_test_no_output "set \$dscr = 0x2"
gdb_test_no_output "set \$tar = &main" "set tar"

# Get the pre-transactional value of the registers.
for {set i 0} {$i < 32} {incr i 1} {
    set "r$i" [get_hexadecimal_valueof "\$r$i" "default0"]
}

set cr [get_hexadecimal_valueof "\$cr" "default0"]
set xer [get_hexadecimal_valueof "\$xer" "default0"]
set lr [get_hexadecimal_valueof "\$lr" "default0"]
set ctr [get_hexadecimal_valueof "\$ctr" "default0"]

for {set i 0} {$i < 32} {incr i 1} {
    set "f$i" [get_valueof "" "\$f$i" "default0"]
}

set fpscr [get_hexadecimal_valueof "\$fpscr" "default0"]

for {set i 0} {$i < 32} {incr i 1} {
    set "vr$i" [get_hexadecimal_valueof "\$vr$i.uint128" "default0"]
}

set vscr [get_hexadecimal_valueof "\$vscr" "default0"]
set vrsave [get_hexadecimal_valueof "\$vrsave" "default0"]

for {set i 0} {$i < 64} {incr i 1} {
    set "vs$i" [get_hexadecimal_valueof "\$vs$i.uint128" "default0"]
}

set dscr [get_hexadecimal_valueof "\$dscr" "default0"]
set ppr [get_hexadecimal_valueof "\$ppr" "default0"]
set tar [get_hexadecimal_valueof "\$tar" "default0"]

gdb_test "stepi" "asm.*bc.*"

proc test_register_match {reg_name reg_var_name hex} {
    set test "$reg_name matches $reg_var_name"

    # In some infrequent cases CXER doesn't match the
    # pre-transactional XER, possibly due to a linux kernel bug.
    set should_xfail 0
    if [istarget "powerpc*-*-linux*" && reg_name == "cxer"] {
	set should_xfail 1
    }

    upvar $reg_var_name expected_val

    if {$hex} {
	set actual_val [get_hexadecimal_valueof "\$$reg_name" "default1"]
    } else {
	set actual_val [get_valueof "" "\$$reg_name" "default1"]
    }

    if { "$expected_val" == "$actual_val" } {
	pass $test
    } else {
	if {$should_xfail} {
	    xfail $test
	} else {
	    fail $test
	}
    }
}

for {set i 0} {$i < 32} {incr i 1} {
    test_register_match "cr$i" "r$i" 1
}

test_register_match "ccr" "cr" 1
test_register_match "cxer" "xer" 1
test_register_match "clr" "lr" 1
test_register_match "cctr" "ctr" 1

for {set i 0} {$i < 32} {incr i 1} {
    test_register_match "cf$i" "f$i" 0
}

test_register_match "cfpscr" "fpscr" 1

for {set i 0} {$i < 32} {incr i 1} {
    test_register_match "cvr$i.uint128" "vr$i" 1
}

test_register_match "cvscr" "vscr" 1
test_register_match "cvrsave" "vrsave" 1

for {set i 0} {$i < 64} {incr i 1} {
    test_register_match "cvs$i.uint128" "vs$i" 1
}

test_register_match "cdscr" "dscr" 1
test_register_match "cppr" "ppr" 1
test_register_match "ctar" "tar" 1

# Support for writing to the checkpointed registers is not
# currently available in the gdbserver stub.
if [target_is_gdbserver] {
    unsupported "write to checkpointed registers"
    return
}

# Now write different values to some of the checkpointed registers and
# check that the transaction abort reverts the register to these
# values.
for {set i 0} {$i < 32} {incr i 1} {
    gdb_test_no_output "set \$cr$i = $i + 0xC00"
}

gdb_test_no_output "set \$cf0 = 0.25"
for {set i 1} {$i < 32} {incr i 1} {
    gdb_test_no_output "set \$cf$i = \$cf[expr $i - 1] + 1.0"
}

for {set i 0} {$i < 32} {incr i 1} {
    for {set j 0} {$j < 4} {incr j 1} {
	gdb_test_no_output "set \$cvr$i.v4_int32\[$j\] = $i + 0xF00"
    }
}

# Read back the values.
with_test_prefix "after write" {
    for {set i 0} {$i < 32} {incr i 1} {
	set "cr$i" [get_hexadecimal_valueof "\$cr$i" "default0"]
    }

    for {set i 0} {$i < 32} {incr i 1} {
	set "cf$i" [get_valueof "" "\$cf$i" "default0"]
    }

    for {set i 0} {$i < 64} {incr i 1} {
	set "cvs$i" [get_hexadecimal_valueof "\$cvs$i.uint128" "default0"]
    }
}

gdb_breakpoint [gdb_get_line_number "second marker"]

gdb_test "continue"

with_test_prefix "after transaction failure" {
    for {set i 0} {$i < 32} {incr i 1} {
	test_register_match "r$i" "cr$i" 1
    }

    for {set i 0} {$i < 32} {incr i 1} {
	test_register_match "f$i" "cf$i" 0
    }

    for {set i 0} {$i < 64} {incr i 1} {
	test_register_match "vs$i.uint128" "cvs$i" 1
    }
}