li t0, MSTATUS_FS; csrs mstatus, t0 # enable FPU
li t0, MSTATUS_XS; csrs mstatus, t0 # enable accelerator
- li t0, ((MSTATUS64_UA & ~(MSTATUS64_UA << 1)) * UA_RV64) >> 31
- sll t0, t0, 31
- li t1, ((MSTATUS64_SA & ~(MSTATUS64_SA << 1)) * UA_RV64) >> 31
- sll t1, t1, 31
#ifdef __riscv64
+ csrr t0, mcpuid
# make sure processor supports RV64 if this was compiled for RV64
- bnez t0, 1f
+ bltz t0, 1f
li a0, 1234
j tohost_exit
1:
- # enable RV64 for user and supervisor
- csrs mstatus, t0
- csrs mstatus, t1
-#else
- # disable RV64 for user and supervisor
- csrc mstatus, t0
- csrc mstatus, t1
#endif
csrr t0, mstatus
and tp, tp, -64
# get core id
- csrr a0, hartid
+ csrr a0, mhartid
# for now, assume only 1 core
li a1, 1
1:bgeu a0, a1, 1b
magic_mem[2] = arg1;
magic_mem[3] = arg2;
__sync_synchronize();
- write_csr(tohost, (long)magic_mem);
- while (swap_csr(fromhost, 0) == 0);
+ write_csr(mtohost, (long)magic_mem);
+ while (swap_csr(mfromhost, 0) == 0);
return magic_mem[0];
}
void tohost_exit(long code)
{
- write_csr(tohost, (code << 1) | 1);
+ write_csr(mtohost, (code << 1) | 1);
while (1);
}
if (cause == CAUSE_ILLEGAL_INSTRUCTION &&
(*(int*)epc & *csr_insn) == *csr_insn)
;
- else if (cause != CAUSE_ECALL)
+ else if (cause != CAUSE_USER_ECALL)
tohost_exit(1337);
else if (regs[17] == SYS_exit)
tohost_exit(regs[10]);
{
/* text: test code section */
- . = 0;
+ . = 0x100;
.text :
{
crt.o(.text)
-Subproject commit 57b1adbf48ad588366c8f88d91e4c165feb3dae1
+Subproject commit 04b236aac5369e4c744796cabf6304324a48fe7d
rv64mi_sc_tests = \
dirty \
csr \
+ mcsr \
illegal \
ma_fetch \
ma_addr \
.data
.align 12
-page_table_1: .dword PTE_TYPE_US_SRX
+page_table_1: .dword PTE_V | PTE_TYPE_URX_SRX
dummy: .dword 0
.align 12
-page_table_2: .dword PTE_TYPE_US_SRWX
+page_table_2: .dword PTE_V | PTE_TYPE_URWX_SRWX
RVTEST_CODE_END
# enable interrupts
csrs mstatus, MSTATUS_IE
+ csrs mie, MIP_MSIP
# get a unique core id
la a0, coreid
bltu a1, a3, 1b
# IPI dominoes
- csrr a0, hartid
+ csrr a0, mhartid
1: bnez a0, 1b
add a0, a0, 1
rem a0, a0, a3
1: j 1b
mtvec_handler:
- csrr a0, hartid
+ csrr a0, mhartid
bnez a0, 2f
RVTEST_PASS
--- /dev/null
+# See LICENSE for license details.
+
+#*****************************************************************************
+# mcsr.S
+#-----------------------------------------------------------------------------
+#
+# Test various M-mode CSRs.
+#
+
+#include "riscv_test.h"
+#include "test_macros.h"
+
+RVTEST_RV64M
+RVTEST_CODE_BEGIN
+
+ # Check that mcpuid reports RV64
+ TEST_CASE(2, a0, 0x2, csrr a0, mcpuid; srl a0, a0, 62)
+
+ # Check that mhartid reports 0
+ TEST_CASE(3, a0, 0x0, csrr a0, mhartid)
+
+ # Check that mimpid reports UC Berkeley
+ TEST_CASE(4, a0, 0x1, csrr a0, mimpid; sll a0, a0, 48; srl a0, a0, 48)
+
+ # Check that mtvec reports DEFAULT_MTVEC
+ TEST_CASE(5, a0, DEFAULT_MTVEC, csrr a0, mtvec)
+
+ TEST_PASSFAIL
+
+RVTEST_CODE_END
#define SSTATUS_PS MSTATUS_PRV1
#endif
- csrwi scycle, 0
+ csrwi cyclew, 0
csrwi sscratch, 3
TEST_CASE( 2, a0, 3, csrr a0, sscratch);
syscall:
# Make sure scause indicates a syscall.
csrr t0, scause
- li t1, CAUSE_ECALL
+ li t1, CAUSE_USER_ECALL
bne t0, t1, fail
# We're done.
#define scause mcause
#define sepc mepc
#define stvec_handler mtvec_handler
+ #undef CAUSE_SUPERVISOR_ECALL
+ #define CAUSE_SUPERVISOR_ECALL CAUSE_MACHINE_ECALL
#endif
li TESTNUM, 2
TEST_PASSFAIL
stvec_handler:
- li t1, CAUSE_ECALL
+ li t1, CAUSE_SUPERVISOR_ECALL
csrr t0, scause
bne t0, t1, fail
csrr t0, sepc
#ifdef __MACHINE_MODE
#define sscratch mscratch
#define sstatus mstatus
+ #define sie mie
#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
+ #undef SIP_STIP
+ #define SIP_STIP MIP_STIP
#endif
+#define DELTA_T 999
+
li s8, 0 # number of taken timer interrupts
li s9, 10 # how many interrupts to run for
- csrw stimecmp, 1
- csrw stime, 0
- li a0, SSTATUS_IE | SSTATUS_TIE
- csrs sstatus, a0
+
+ .align 4
+ csrr a0, stime
+ add a0, a0, DELTA_T
+ csrw stimecmp, a0
+ li a0, SIP_STIP
+ csrs sie, a0
+ csrs sstatus, SSTATUS_IE
# jump to user land
li t0, SSTATUS_PS
bnez t0, fail
csrr t0, stime
- addi t0, t0, 999
+ addi t0, t0, DELTA_T
csrw stimecmp, t0
add s8, s8, 1