Skip to content

Commit

Permalink
make PMP setup a common macro
Browse files Browse the repository at this point in the history
  • Loading branch information
ved-rivos committed Aug 12, 2023
1 parent e3617f3 commit e3ef7a6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 31 deletions.
20 changes: 20 additions & 0 deletions riscv-test-suite/env/test_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,26 @@ RVTEST_SIGUPD_F(swreg,destreg,flagreg)
sub x1,x1,tempreg ;\
RVTEST_SIGUPD(swreg,x1,offset)

#define SETUP_PMP_SVADU_TEST(swreg, offset, TR0, TR1, TR2) \
li TR0, -1 ;\
csrw pmpaddr0, TR0 ;\
j PMP_exist ;\
li TR0, 0 ;\
li TR1, 0 ;\
j Mend_PMP ;\
PMP_exist: ;\
li TR1, PMP_TOR | PMP_X | PMP_W | PMP_R ;\
csrw pmpcfg0, TR1 ;\
csrr TR2, pmpcfg0 ;\
beq TR1, TR2, Mend_PMP ;\
no_TOR_try_NAPOT: ;\
li TR1, PMP_NAPOT | PMP_X | PMP_W | PMP_R ;\
csrw pmpcfg0, TR1 ;\
csrr TR2, pmpcfg0 ;\
Mend_PMP: ;\
RVTEST_SIGUPD(x1,TR0,offset) ;\
RVTEST_SIGUPD(x1,TR1,offset) ;\

#define TEST_SVADU(swreg, PTE_ADDR, VA, offset, menvcfgaddr, hade_bit) \
sfence.vma ;\
la t0, VA ;\
Expand Down
10 changes: 3 additions & 7 deletions riscv-test-suite/rv32i_m/Svadu/src/svadu_sv32.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ RVTEST_CODE_BEGIN

RVTEST_SIGBASE(x1, signature_x1_0)

# enable pmp to cover 4 GiB address space
li t0, -1
csrw pmpaddr0, t0
li t0, PMP_TOR | PMP_X | PMP_W | PMP_R
csrw pmpcfg0, t0
# Setup PMP to cover 4G of address space
SETUP_PMP_SVADU_TEST(x1, offset, t0, t1, t2)

# ID map the page_4k
# Identity map the page_4k
la t1, page_4k
mv t2, t1
PTE_SETUP_SV32(t1, PTE_V, t0, s2, t2, 1)
Expand All @@ -39,7 +36,6 @@ RVTEST_CODE_BEGIN

# test svadu
TEST_SVADU(x1, s2, page_4k, offset, 0x31a, MENVCFGH_HADE)

RVMODEL_HALT

#endif
Expand Down
12 changes: 4 additions & 8 deletions riscv-test-suite/rv64i_m/Svadu/src/svadu_sv39.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,19 @@ RVTEST_CODE_BEGIN

RVTEST_SIGBASE(x1, signature_x1_0)

# enable pmp to cover 4 GiB address space
li t0, -1
csrw pmpaddr0, t0
li t0, PMP_TOR | PMP_X | PMP_W | PMP_R
csrw pmpcfg0, t0
# Setup PMP to cover 4G of address space
SETUP_PMP_SVADU_TEST(x1, offset, t0, t1, t2)

# ID map the page_4k
# Idenity map the page_4k
la t1, page_4k
mv t2, t1
PTE_SETUP_SV39(t1, PTE_V, t0, s2, t2, 2)

# enable virtual memory in Sv32 mode
# enable virtual memory in Sv39 mode
SATP_SETUP(t0, t1, ((SATP_MODE & ~(SATP_MODE<<1)) * SATP_MODE_SV39))

# test svadu
TEST_SVADU(x1, s2, page_4k, offset, 0x30a, MENVCFG_HADE)

RVMODEL_HALT
#endif
RVTEST_CODE_END
Expand Down
12 changes: 4 additions & 8 deletions riscv-test-suite/rv64i_m/Svadu/src/svadu_sv48.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,19 @@ RVTEST_CODE_BEGIN

RVTEST_SIGBASE(x1, signature_x1_0)

# enable pmp to cover 4 GiB address space
li t0, -1
csrw pmpaddr0, t0
li t0, PMP_TOR | PMP_X | PMP_W | PMP_R
csrw pmpcfg0, t0
# Setup PMP to cover 4G of address space
SETUP_PMP_SVADU_TEST(x1, offset, t0, t1, t2)

# ID map the page_4k
# Identity map the page_4k
la t1, page_4k
mv t2, t1
PTE_SETUP_SV48(t1, PTE_V, t0, s2, t2, 3)

# enable virtual memory in Sv32 mode
# enable virtual memory in Sv48 mode
SATP_SETUP(t0, t1, ((SATP_MODE & ~(SATP_MODE<<1)) * SATP_MODE_SV48))

# test svadu
TEST_SVADU(x1, s2, page_4k, offset, 0x30a, MENVCFG_HADE)

RVMODEL_HALT
#endif
RVTEST_CODE_END
Expand Down
12 changes: 4 additions & 8 deletions riscv-test-suite/rv64i_m/Svadu/src/svadu_sv57.S
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,19 @@ RVTEST_CODE_BEGIN

RVTEST_SIGBASE(x1, signature_x1_0)

# enable pmp to cover 4 GiB address space
li t0, -1
csrw pmpaddr0, t0
li t0, PMP_TOR | PMP_X | PMP_W | PMP_R
csrw pmpcfg0, t0
# Setup PMP to cover 4G of address space
SETUP_PMP_SVADU_TEST(x1, offset, t0, t1, t2)

# ID map the page_4k
# Identity map the page_4k
la t1, page_4k
mv t2, t1
PTE_SETUP_SV57(t1, PTE_V, t0, s2, t2, 4)

# enable virtual memory in Sv32 mode
# enable virtual memory in Sv57 mode
SATP_SETUP(t0, t1, ((SATP_MODE & ~(SATP_MODE<<1)) * SATP_MODE_SV57))

# test svadu
TEST_SVADU(x1, s2, page_4k, offset, 0x30a, MENVCFG_HADE)

RVMODEL_HALT
#endif
RVTEST_CODE_END
Expand Down

0 comments on commit e3ef7a6

Please sign in to comment.