-Subproject commit 104ce71726ee9ae95f920b42462afb30baeeb36c
+Subproject commit fe2bd085aaef12c043672b2bb07fc1daab9ce598
include $(isa_src_dir)/rv64uv/Makefrag
include $(isa_src_dir)/rv64si/Makefrag
include $(isa_src_dir)/rv64sv/Makefrag
+include $(isa_src_dir)/rv64mi/Makefrag
include $(isa_src_dir)/rv32ui/Makefrag
include $(isa_src_dir)/rv32si/Makefrag
+include $(isa_src_dir)/rv32mi/Makefrag
default: all
$(eval $(call compile_template,rv32ui,-m32))
$(eval $(call compile_template,rv32si,-m32))
+$(eval $(call compile_template,rv32mi,-m32))
$(eval $(call compile_template,rv64ui))
$(eval $(call compile_template,rv64uf))
$(eval $(call compile_template,rv64uv))
$(eval $(call compile_template,rv64si))
$(eval $(call compile_template,rv64sv))
+$(eval $(call compile_template,rv64mi))
tests_dump = $(addsuffix .dump, $(tests))
tests_hex = $(addsuffix .hex, $(tests))
--- /dev/null
+#=======================================================================
+# Makefrag for rv32mi tests
+#-----------------------------------------------------------------------
+
+rv32mi_sc_tests = \
+ csr \
+ illegal \
+ ma_fetch \
+ ma_addr \
+ scall \
+ sbreak \
+ timer \
+
+rv32mi_mc_tests = \
+ ipi \
+
+rv32mi_p_tests = $(addprefix rv32mi-p-, $(rv32mi_sc_tests))
+rv32mi_pm_tests = $(addprefix rv32mi-pm-, $(rv32mi_mc_tests))
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64S
+#define RVTEST_RV64S RVTEST_RV32M
+#define __MACHINE_MODE
+
+#include "../rv64si/csr.S"
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64S
+#define RVTEST_RV64S RVTEST_RV32M
+#define __MACHINE_MODE
+
+#include "../rv64si/illegal.S"
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64M
+#define RVTEST_RV64M RVTEST_RV32M
+
+#include "../rv64mi/ipi.S"
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64S
+#define RVTEST_RV64S RVTEST_RV32M
+#define __MACHINE_MODE
+
+#include "../rv64si/ma_addr.S"
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64S
+#define RVTEST_RV64S RVTEST_RV32M
+#define __MACHINE_MODE
+
+#include "../rv64si/ma_fetch.S"
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64S
+#define RVTEST_RV64S RVTEST_RV32M
+#define __MACHINE_MODE
+
+#include "../rv64si/sbreak.S"
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64S
+#define RVTEST_RV64S RVTEST_RV32M
+#define __MACHINE_MODE
+
+#include "../rv64si/scall.S"
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64S
+#define RVTEST_RV64S RVTEST_RV32M
+#define __MACHINE_MODE
+
+#include "../rv64si/timer.S"
ma_addr \
timer \
-rv32si_mc_tests = \
- ipi \
-
rv32si_p_tests = $(addprefix rv32si-p-, $(rv32si_sc_tests))
-rv32si_pm_tests = $(addprefix rv32si-pm-, $(rv32si_mc_tests))
-
-spike_tests += $(rv32si_p_tests) $(rv32si_pm_tests)
+++ /dev/null
-# See LICENSE for license details.
-
-#include "riscv_test.h"
-#undef RVTEST_RV64S
-#define RVTEST_RV64S RVTEST_RV32S
-
-#include "../rv64si/ipi.S"
--- /dev/null
+#=======================================================================
+# Makefrag for rv64mi tests
+#-----------------------------------------------------------------------
+
+rv64mi_sc_tests = \
+ dirty \
+ csr \
+ illegal \
+ ma_fetch \
+ ma_addr \
+ scall \
+ sbreak \
+ timer \
+
+rv64mi_mc_tests = \
+ ipi \
+
+rv64mi_p_tests = $(addprefix rv64mi-p-, $(rv64mi_sc_tests))
+rv64mi_pm_tests = $(addprefix rv64mi-pm-, $(rv64mi_mc_tests))
+
+spike_tests += $(rv64mi_p_tests) $(rv64mi_pm_tests)
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64S
+#define RVTEST_RV64S RVTEST_RV64M
+#define __MACHINE_MODE
+
+#include "../rv64si/csr.S"
--- /dev/null
+# See LICENSE for license details.
+
+#*****************************************************************************
+# dirty.S
+#-----------------------------------------------------------------------------
+#
+# Test VM referenced and dirty bits.
+#
+
+#include "riscv_test.h"
+#include "test_macros.h"
+
+RVTEST_RV64M
+RVTEST_CODE_BEGIN
+
+ # Turn on VM with superpage identity mapping
+ la a1, page_table_1
+ csrw sptbr, a1
+ sfence.vm
+ li a1, ((MSTATUS_VM & ~(MSTATUS_VM<<1)) * VM_SV43) | ((MSTATUS_PRV1 & ~(MSTATUS_PRV1<<1)) * PRV_S)
+ csrs mstatus, a1
+ la a1, 1f
+ csrw mepc, a1
+ eret
+1:
+
+ # Try a faulting store to make sure dirty bit is not set
+ li TESTNUM, 2
+ li t0, 1
+ sd t0, dummy, t1
+
+ # Load new page table
+ li TESTNUM, 3
+ la t0, page_table_2
+ csrw sptbr, t0
+ sfence.vm
+
+ # Try a non-faulting store to make sure dirty bit is set
+ sd t0, dummy, t1
+
+ # Make sure R and D bits are set
+ lw t0, page_table_2
+ li t1, PTE_R | PTE_D
+ and t0, t0, t1
+ bne t0, t1, die
+
+ RVTEST_PASS
+
+ TEST_PASSFAIL
+
+stvec_handler:
+ csrr t0, scause
+ li t1, 2
+ bne TESTNUM, t1, 1f
+ # Make sure R bit is set
+ lw t0, page_table_1
+ li t1, PTE_R
+ and t0, t0, t1
+ bne t0, t1, die
+
+ # Make sure D bit is clear
+ lw t0, page_table_1
+ li t1, PTE_D
+ and t0, t0, t1
+ beq t0, t1, die
+
+ csrr t0, sepc
+ add t0, t0, 4
+ csrw sepc, t0
+ sret
+
+die:
+ RVTEST_FAIL
+
+.data
+.align 13
+page_table_1: .dword PTE_V | PTE_SX | PTE_SR
+dummy: .dword 0
+.align 13
+page_table_2: .dword PTE_V | PTE_SX | PTE_SR | PTE_SW
+
+RVTEST_CODE_END
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64S
+#define RVTEST_RV64S RVTEST_RV64M
+#define __MACHINE_MODE
+
+#include "../rv64si/illegal.S"
--- /dev/null
+# See LICENSE for license details.
+
+#*****************************************************************************
+# ipi.S
+#-----------------------------------------------------------------------------
+#
+# Test interprocessor interrupts.
+#
+
+#include "riscv_test.h"
+#include "test_macros.h"
+
+RVTEST_RV64M
+RVTEST_CODE_BEGIN
+
+ # enable interrupts
+ csrs mstatus, MSTATUS_IE
+
+ # get a unique core id
+ la a0, coreid
+ li a1, 1
+ amoadd.w a2, a1, (a0)
+
+ # for now, only run this on core 0
+ 1:li a3, 1
+ bgeu a2, a3, 1b
+
+ # wait for all cores to boot
+ 1: lw a1, (a0)
+ bltu a1, a3, 1b
+
+ # IPI dominoes
+ csrr a0, hartid
+ 1: bnez a0, 1b
+ add a0, a0, 1
+ rem a0, a0, a3
+ csrw send_ipi, a0
+ 1: j 1b
+
+mtvec_handler:
+ csrr a0, hartid
+ bnez a0, 2f
+ RVTEST_PASS
+
+ TEST_PASSFAIL
+
+ 2: add a0, a0, 1
+ rem a0, a0, a3
+ csrw send_ipi, a0
+ 1: j 1b
+
+RVTEST_CODE_END
+
+ .data
+RVTEST_DATA_BEGIN
+
+ TEST_DATA
+
+coreid: .word 0
+foo: .word 0
+
+RVTEST_DATA_END
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64S
+#define RVTEST_RV64S RVTEST_RV64M
+#define __MACHINE_MODE
+
+#include "../rv64si/ma_addr.S"
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64S
+#define RVTEST_RV64S RVTEST_RV64M
+#define __MACHINE_MODE
+
+#include "../rv64si/ma_fetch.S"
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64S
+#define RVTEST_RV64S RVTEST_RV64M
+#define __MACHINE_MODE
+
+#include "../rv64si/sbreak.S"
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64S
+#define RVTEST_RV64S RVTEST_RV64M
+#define __MACHINE_MODE
+
+#include "../rv64si/scall.S"
--- /dev/null
+# See LICENSE for license details.
+
+#include "riscv_test.h"
+#undef RVTEST_RV64S
+#define RVTEST_RV64S RVTEST_RV64M
+#define __MACHINE_MODE
+
+#include "../rv64si/timer.S"
scall \
sbreak \
timer \
- dirty \
-
-rv64si_mc_tests = \
- ipi \
rv64si_p_tests = $(addprefix rv64si-p-, $(rv64si_sc_tests))
-rv64si_pm_tests = $(addprefix rv64si-pm-, $(rv64si_mc_tests))
-spike_tests += $(rv64si_p_tests) $(rv64si_pm_tests)
+spike_tests += $(rv64si_p_tests)
RVTEST_RV64S
RVTEST_CODE_BEGIN
- # Set up stvec in case we trap.
- la t0, stvec
- csrw stvec, t0
+#ifdef __MACHINE_MODE
+ #define sscratch mscratch
+ #define sstatus mstatus
+ #define scause mcause
+ #define sepc mepc
+ #define stvec_handler mtvec_handler
+ #undef SSTATUS_PS
+ #define SSTATUS_PS MSTATUS_PRV1
+#endif
+
csrwi scycle, 0
csrwi sscratch, 3
# Make sure writing the cycle counter causes an exception.
TEST_CASE(10, a0, 255, li a0, 255; csrrw a0, cycle, x0);
- # Enter user mode
+ # jump to user land
li t0, SSTATUS_PS
csrc sstatus, t0
la t0, 1f
# We should only fall through to this if scall failed.
TEST_PASSFAIL
-stvec:
+stvec_handler:
# Trapping on tests 10, 11, and 13 is usually good news.
# Note that since the test didn't complete, TESTNUM is smaller by 1.
li t0, 9
j fail
privileged:
- # Make sure CAUSE indicates a lack of privilege.
+ # Make sure scause indicates a lack of privilege.
csrr t0, scause
li t1, CAUSE_ILLEGAL_INSTRUCTION
bne t0, t1, fail
sret
syscall:
- # Make sure CAUSE indicates a syscall.
+ # Make sure scause indicates a syscall.
csrr t0, scause
li t1, CAUSE_ECALL
bne t0, t1, fail
+++ /dev/null
-# See LICENSE for license details.
-
-#*****************************************************************************
-# dirty.S
-#-----------------------------------------------------------------------------
-#
-# Test VM referenced and dirty bits.
-#
-
-#include "riscv_test.h"
-#include "test_macros.h"
-
-RVTEST_RV64M
-RVTEST_CODE_BEGIN
-
- # Turn on VM with superpage identity mapping
- la a1, handler
- csrw stvec, a1
- la a1, page_table_1
- csrw sptbr, a1
- sfence.vm
- li a1, ((MSTATUS_VM & ~(MSTATUS_VM<<1)) * VM_SV43) | ((MSTATUS_PRV1 & ~(MSTATUS_PRV1<<1)) * PRV_S)
- csrs mstatus, a1
- la a1, 1f
- csrw mepc, a1
- eret
-1:
-
- # Try a faulting store to make sure dirty bit is not set
- li TESTNUM, 2
- li t0, 1
- sd t0, dummy, t1
-
- # Load new page table
- li TESTNUM, 3
- la t0, page_table_2
- csrw sptbr, t0
- sfence.vm
-
- # Try a non-faulting store to make sure dirty bit is set
- sd t0, dummy, t1
-
- # Make sure R and D bits are set
- lw t0, page_table_2
- li t1, PTE_R | PTE_D
- and t0, t0, t1
- bne t0, t1, die
-
- RVTEST_PASS
-
- TEST_PASSFAIL
-
-handler:
- csrr t0, scause
- li t1, 2
- bne TESTNUM, t1, 1f
- # Make sure R bit is set
- lw t0, page_table_1
- li t1, PTE_R
- and t0, t0, t1
- bne t0, t1, die
-
- # Make sure D bit is clear
- lw t0, page_table_1
- li t1, PTE_D
- and t0, t0, t1
- beq t0, t1, die
-
- csrr t0, sepc
- add t0, t0, 4
- csrw sepc, t0
- sret
-
-die:
- RVTEST_FAIL
-
-.data
-.align 13
-page_table_1: .dword PTE_V | PTE_SX | PTE_SR
-dummy: .dword 0
-.align 13
-page_table_2: .dword PTE_V | PTE_SX | PTE_SR | PTE_SW
-
-RVTEST_CODE_END
RVTEST_RV64S
RVTEST_CODE_BEGIN
- la t0, stvec
- csrw stvec, t0
+#ifdef __MACHINE_MODE
+ #define sscratch mscratch
+ #define sstatus mstatus
+ #define scause mcause
+ #define sepc mepc
+ #define stvec_handler mtvec_handler
+#endif
li TESTNUM, 2
.word 0
TEST_PASSFAIL
-stvec:
+stvec_handler:
li t1, CAUSE_ILLEGAL_INSTRUCTION
csrr t0, scause
bne t0, t1, fail
+++ /dev/null
-# See LICENSE for license details.
-
-#*****************************************************************************
-# ipi.S
-#-----------------------------------------------------------------------------
-#
-# Test interprocessor interrupts.
-#
-
-#include "riscv_test.h"
-#include "test_macros.h"
-
-RVTEST_RV64M
-RVTEST_CODE_BEGIN
-
- # enable interrupts
- csrs mstatus, MSTATUS_IE
-
- # get a unique core id
- la a0, coreid
- li a1, 1
- amoadd.w a2, a1, (a0)
-
- # for now, only run this on core 0
- 1:li a3, 1
- bgeu a2, a3, 1b
-
- # wait for all cores to boot
- 1: lw a1, (a0)
- bltu a1, a3, 1b
-
- # IPI dominoes
- csrr a0, hartid
- 1: bnez a0, 1b
- add a0, a0, 1
- rem a0, a0, a3
- csrw send_ipi, a0
- 1: j 1b
-
-mtvec:
- csrr a0, hartid
- bnez a0, 2f
- RVTEST_PASS
-
- TEST_PASSFAIL
-
- 2: add a0, a0, 1
- rem a0, a0, a3
- csrw send_ipi, a0
- 1: j 1b
-
-RVTEST_CODE_END
-
- .data
-RVTEST_DATA_BEGIN
-
- TEST_DATA
-
-coreid: .word 0
-foo: .word 0
-
-RVTEST_DATA_END
RVTEST_RV64S
RVTEST_CODE_BEGIN
- la s0, stvec_load
+#ifdef __MACHINE_MODE
+ #define sscratch mscratch
+ #define sstatus mstatus
+ #define scause mcause
+ #define sepc mepc
+ #define stvec_handler mtvec_handler
+#endif
+
+ la s0, stvec_handler
- la t0, stvec_load
- csrw stvec, t0
+ # indicate it's a load test
+ li s1, 0
#define MISALIGNED_LDST_TEST(testnum, insn, base, offset) \
li TESTNUM, testnum; \
MISALIGNED_LDST_TEST(16, ld, s0, 7)
#endif
- la t0, stvec_store
- csrw stvec, t0
+ # indicate it's a store test
+ li s1, 1
MISALIGNED_LDST_TEST(22, sh, s0, 1)
MISALIGNED_LDST_TEST(23, sw, s0, 1)
TEST_PASSFAIL
.align 3
-stvec_load:
+stvec_handler:
+ bnez s1, test_store
+
+test_load:
li t1, CAUSE_MISALIGNED_LOAD
csrr t0, scause
bne t0, t1, fail
csrw sepc, t0
sret
-stvec_store:
+test_store:
li t1, CAUSE_MISALIGNED_STORE
csrr t0, scause
bne t0, t1, fail
RVTEST_RV64S
RVTEST_CODE_BEGIN
- la t0, stvec
- csrw stvec, t0
+#ifdef __MACHINE_MODE
+ #define sscratch mscratch
+ #define sstatus mstatus
+ #define scause mcause
+ #define sepc mepc
+ #define stvec_handler mtvec_handler
+#endif
#ifndef __rvc
li TESTNUM, 2
TEST_PASSFAIL
-stvec:
+stvec_handler:
# tests 2 and 4 should trap
li a0, 2
beq TESTNUM, a0, 1f
RVTEST_RV64S
RVTEST_CODE_BEGIN
- la t0, stvec
- csrw stvec, t0
+#ifdef __MACHINE_MODE
+ #define sscratch mscratch
+ #define sstatus mstatus
+ #define scause mcause
+ #define sepc mepc
+ #define stvec_handler mtvec_handler
+#endif
li TESTNUM, 2
sbreak
TEST_PASSFAIL
-stvec:
+stvec_handler:
li t1, CAUSE_BREAKPOINT
csrr t0, scause
bne t0, t1, fail
RVTEST_RV64S
RVTEST_CODE_BEGIN
- la t0, stvec
- csrw stvec, t0
+#ifdef __MACHINE_MODE
+ #define sscratch mscratch
+ #define sstatus mstatus
+ #define scause mcause
+ #define sepc mepc
+ #define stvec_handler mtvec_handler
+#endif
li TESTNUM, 2
scall
TEST_PASSFAIL
-stvec:
+stvec_handler:
li t1, CAUSE_ECALL
csrr t0, scause
bne t0, t1, fail
# See LICENSE for license details.
#*****************************************************************************
-# ipi.S
+# timer.S
#-----------------------------------------------------------------------------
#
-# Test interprocessor interrupts.
+# Test timer interrupts.
#
#include "riscv_test.h"
RVTEST_RV64S
RVTEST_CODE_BEGIN
- # clear pending IPIs then enable interrupts
+#ifdef __MACHINE_MODE
+ #define sscratch mscratch
+ #define sstatus mstatus
+ #define scause mcause
+ #define sepc mepc
+ #define stvec_handler mtvec_handler
+ #undef SSTATUS_PS
+ #define SSTATUS_PS MSTATUS_PRV1
+ #undef SSTATUS_IE
+ #define SSTATUS_IE MSTATUS_IE
+ #undef SSTATUS_TIE
+ #define SSTATUS_TIE MSTATUS_STIE
+#endif
+
li s8, 0 # number of taken timer interrupts
li s9, 10 # how many interrupts to run for
- la a0, handler
- csrw stvec, a0
csrw stimecmp, 1
csrw stime, 0
li a0, SSTATUS_IE | SSTATUS_TIE
csrs sstatus, a0
+ # jump to user land
+ li t0, SSTATUS_PS
+ csrc sstatus, t0
+ la t0, 1f
+ csrw sepc, t0
+ sret
+ 1:
+
# advance an LFSR 1000 times
li s0, 1023
li s4, 0
add s4, s4, 1
bltu s8, s9, 1b
- csrc sstatus, SSTATUS_IE
-
# make sure the LFSR was computed correctly
li s1, 1023
remu s4, s4, s1
TEST_PASSFAIL
-handler:
+stvec_handler:
li TESTNUM, 3
csrr t0, scause
bgez t0, fail
csrw stimecmp, t0
add s8, s8, 1
+ bltu s8, s9, stvec_return
+
+ li t0, SSTATUS_PS
+ csrs sstatus, t0
+ csrc sstatus, SSTATUS_IE
+stvec_return:
sret
.data
RVTEST_RV64SV
RVTEST_CODE_BEGIN
- la a3,handler
- csrw stvec,a3 # set exception handler
-
li a0,33
slli a0,a0,6
vsetcfg a0
add x2,x2,x3
stop
-handler:
+stvec_handler:
vxcptkill
li TESTNUM,2
RVTEST_RV64SV
RVTEST_CODE_BEGIN
- la a3,handler
- csrw stvec,a3 # set exception handler
-
li a0,33
vsetcfg a0
add x2,x2,x3
stop
-handler:
+stvec_handler:
vxcptkill
li TESTNUM,2
RVTEST_RV64SV
RVTEST_CODE_BEGIN
- la a3,handler
- csrw stvec,a3 # set exception handler
-
.word 0xff00002b
vsetcfg 32,0
add x2,x2,x3
stop
-handler:
+stvec_handler:
vxcptkill
li TESTNUM,2
TEST_PASSFAIL
+# the handler gets rewritten for every test, but need this for the framework
+stvec_handler:
+ j fail
+
RVTEST_CODE_END
.data
RVTEST_RV64SV
RVTEST_CODE_BEGIN
- la a3,handler
- csrw stvec,a3 # set exception handler
-
vsetcfg 32,0
li a3,4
vsetvl a3,a3
add x2,x2,x3
stop
-handler:
+stvec_handler:
vxcptkill
li TESTNUM,2
TEST_PASSFAIL
+# the handler gets rewritten for every test, but need this for the framework
+stvec_handler:
+ j fail
+
RVTEST_CODE_END
.data
RVTEST_RV64SV
RVTEST_CODE_BEGIN
- la a3,handler
- csrw stvec,a3 # set exception handler
-
vsetcfg 32,0
li a3,4
vsetvl a3,a3
add x2,x2,x3
stop
-handler:
+stvec_handler:
vxcptkill
li TESTNUM,2
RVTEST_RV64SV
RVTEST_CODE_BEGIN
- la a3,handler
- csrw stvec,a3 # set exception handler
-
vsetcfg 32,0
li a3,4
vsetvl a3,a3
add x2,x2,x3
stop
-handler:
+stvec_handler:
vxcptkill
li TESTNUM,2
RVTEST_RV64SV
RVTEST_CODE_BEGIN
- la a3,handler
- csrw stvec,a3 # set exception handler
-
vsetcfg 32,0
li a3,4
vsetvl a3,a3
add x2,x2,x3
stop
-handler:
+stvec_handler:
vxcptkill
li TESTNUM,2
RVTEST_RV64SV
RVTEST_CODE_BEGIN
- la a3,handler
- csrw stvec,a3 # set exception handler
-
vsetcfg 32,0
li a3,4
vsetvl a3,a3
add x2,x2,x3
stop
-handler:
+stvec_handler:
vxcptkill
li TESTNUM,2
RVTEST_RV64SV
RVTEST_CODE_BEGIN
- la a3,handler
- csrw stvec,a3 # set exception handler
-
vsetcfg 32,0
li a3,4
vsetvl a3,a3
add x2,x2,x3
stop
-handler:
+stvec_handler:
vxcptkill
li TESTNUM,2
RVTEST_RV64SV
RVTEST_CODE_BEGIN
- la a3,handler
- csrw stvec,a3 # set exception handler
-
li a3, SSTATUS_PS
csrc sstatus, a3
la t0, 1f
add x2,x2,x3
stop
-handler:
+stvec_handler:
vxcptkill
li TESTNUM,2