@samitouri / QOSamiQemu / commits / ce781055ff

tests/tcg/riscv64: add misa write test

Link: https://lore.kernel.org/r/20260321144554.606417-2-npiggin@gmail.com Suggested-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Vladimir Isaev <vvisaev@gmail.com> Message-ID: <20260817150653.40357-3-vvisaev@gmail.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Vladimir Isaev committed Aug 17, 2026 at 18:06 UTC ce781055ff61308df9c4f9546c72e09b6908fe06
2 files changed +92
tests/tcg/riscv64/Makefile.softmmu-target
+4
@@ -67,5 +67,9 @@ EXTRA_RUNS += run-test-zicclsm-off
67 run-test-zicclsm-off: test-zicclsm-off
68 $(call run-test, $<, $(QEMU) -cpu rv64$(comma)v=true$(comma)zfh=true$(comma)zicclsm=false $(QEMU_OPTS)$<)
69
70 +EXTRA_RUNS += run-test-misa-w
71 +run-test-misa-w: test-misa-w
72 + $(call run-test, $<, $(QEMU) -cpu rv64$(comma)x-misa-w=true$(comma)c=true$(comma)v=true $(QEMU_OPTS)$<)
73 +
74 # We don't currently support the multiarch system tests
75 undefine MULTIARCH_TESTS
tests/tcg/riscv64/test-misa-w.S new
+88
@@ -0,0 +1,88 @@
1 +/*
2 + * Test for MISA changing C and related IALIGN alignment cases
3 + *
4 + * This test verifies that the "C" extension can be cleared and set in MISA,
5 + * that a branch to 2-byte aligned instructions can be executed when "C" is
6 + * enabled, and that a write to MISA which would increase IALIGN and cause
7 + * the next instruction to be unaligned is ignored.
8 + *
9 + * SPDX-License-Identifier: GPL-2.0-or-later
10 + */
11 +
12 +#define RVC (1 << ('C'-'A'))
13 +#define RVV (1 << ('V'-'A'))
14 +
15 +.option norvc
16 + .text
17 + .global _start
18 +_start:
19 + lla t0, trap
20 + csrw mtvec, t0
21 +
22 + csrr t0, misa
23 + li t1, RVC
24 + not t1, t1
25 + and t0, t0, t1
26 + csrw misa, t0
27 + csrr t1, misa
28 + li a0, 2 # fail code
29 + bne t0, t1, _exit # Could not clear RVC in MISA
30 +
31 + li t1, RVC
32 + or t0, t0, t1
33 + csrw misa, t0
34 + csrr t1, misa
35 + li a0, 3 # fail code
36 + bne t0, t1, _exit # Could not set RVC in MISA
37 +
38 + j unalign
39 +. = . + 2
40 +unalign:
41 +
42 + li t1, RVC
43 + not t1, t1
44 + and t0, t0, t1
45 + csrw misa, t0
46 + csrr t1, misa
47 + li a0, 4 # fail code
48 + beq t0, t1, _exit # Was able to clear RVC in MISA
49 +
50 + li t0, (RVC|RVV)
51 + not t0, t0
52 + and t0, t0, t1
53 + csrw misa, t0
54 + csrr t0, misa
55 + li a0, 5 # fail code
56 + bne t0, t1, _exit # MISA write was not ignored (RVV was cleared)
57 +
58 + j realign
59 +. = . + 2
60 +realign:
61 +
62 + # Success!
63 + li a0, 0
64 + j _exit
65 +
66 +trap:
67 + # Any trap is a fail code 1
68 + li a0, 1
69 +
70 +# Exit code in a0
71 +_exit:
72 + lla a1, semiargs
73 + li t0, 0x20026 # ADP_Stopped_ApplicationExit
74 + sd t0, 0(a1)
75 + sd a0, 8(a1)
76 + li a0, 0x20 # TARGET_SYS_EXIT_EXTENDED
77 +
78 + # Semihosting call sequence
79 + .balign 16
80 + slli zero, zero, 0x1f
81 + ebreak
82 + srai zero, zero, 0x7
83 + j .
84 +
85 + .data
86 + .balign 16
87 +semiargs:
88 + .space 16