From e3ef7a629360b1a5bb486fd8f4dbdc8d579552c4 Mon Sep 17 00:00:00 2001 From: Ved Shanbhogue Date: Thu, 3 Aug 2023 18:15:29 -0500 Subject: [PATCH] make PMP setup a common macro --- riscv-test-suite/env/test_macros.h | 20 +++++++++++++++++++ .../rv32i_m/Svadu/src/svadu_sv32.S | 10 +++------- .../rv64i_m/Svadu/src/svadu_sv39.S | 12 ++++------- .../rv64i_m/Svadu/src/svadu_sv48.S | 12 ++++------- .../rv64i_m/Svadu/src/svadu_sv57.S | 12 ++++------- 5 files changed, 35 insertions(+), 31 deletions(-) diff --git a/riscv-test-suite/env/test_macros.h b/riscv-test-suite/env/test_macros.h index fd44eb166..7b48bdbee 100644 --- a/riscv-test-suite/env/test_macros.h +++ b/riscv-test-suite/env/test_macros.h @@ -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 ;\ diff --git a/riscv-test-suite/rv32i_m/Svadu/src/svadu_sv32.S b/riscv-test-suite/rv32i_m/Svadu/src/svadu_sv32.S index 823df8bdf..b4c502d8d 100644 --- a/riscv-test-suite/rv32i_m/Svadu/src/svadu_sv32.S +++ b/riscv-test-suite/rv32i_m/Svadu/src/svadu_sv32.S @@ -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) @@ -39,7 +36,6 @@ RVTEST_CODE_BEGIN # test svadu TEST_SVADU(x1, s2, page_4k, offset, 0x31a, MENVCFGH_HADE) - RVMODEL_HALT #endif diff --git a/riscv-test-suite/rv64i_m/Svadu/src/svadu_sv39.S b/riscv-test-suite/rv64i_m/Svadu/src/svadu_sv39.S index e1f53e8bf..c4fd3ed1b 100644 --- a/riscv-test-suite/rv64i_m/Svadu/src/svadu_sv39.S +++ b/riscv-test-suite/rv64i_m/Svadu/src/svadu_sv39.S @@ -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 diff --git a/riscv-test-suite/rv64i_m/Svadu/src/svadu_sv48.S b/riscv-test-suite/rv64i_m/Svadu/src/svadu_sv48.S index 1cd356e16..0011da4dc 100644 --- a/riscv-test-suite/rv64i_m/Svadu/src/svadu_sv48.S +++ b/riscv-test-suite/rv64i_m/Svadu/src/svadu_sv48.S @@ -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 diff --git a/riscv-test-suite/rv64i_m/Svadu/src/svadu_sv57.S b/riscv-test-suite/rv64i_m/Svadu/src/svadu_sv57.S index 38ff9f9ec..b6e18d429 100644 --- a/riscv-test-suite/rv64i_m/Svadu/src/svadu_sv57.S +++ b/riscv-test-suite/rv64i_m/Svadu/src/svadu_sv57.S @@ -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