diff --git a/testbench/tests/pmp_random/main.c b/testbench/tests/pmp_random/main.c index 2a88f2032c7..9313f01515f 100644 --- a/testbench/tests/pmp_random/main.c +++ b/testbench/tests/pmp_random/main.c @@ -220,24 +220,6 @@ uint32_t legalize_config(uint32_t config) { int main () { printf("Hello VeeR (M mode)\n"); - -#if RV_SMEPMP - printf("VeeR has Smepmp\n"); -#else - printf("VeeR does not have Smepmp\n"); -#endif - - // Check if we have user mode support - uint32_t misa = 0; - CSRR_READ(misa, CSR_MISA); - int have_user_mode = (misa & MISA_U) != 0; - -#if RV_SMEPMP - // Set MSECCFG - uint32_t mseccfg = 0; - CSRR_WRITE(mseccfg, 0x747); -#endif - // ....................................................................... // Determine PMP granularity uintptr_t tmp = 0; @@ -262,104 +244,6 @@ int main () { pmp_clear(); - // ....................................................................... - // Check if user mode has access to everything by default when PMP is not - // configured. Just call a simple function. - if (have_user_mode) { - printf("%02d - User mode RWX in default state\n", tid++); - - printf(" testing...\n"); -#if RV_SMEPMP - TRY { - ucall(test_hello); - printf(" fail\n"); - failed++; - } - CATCH { - printf(" pass\n"); - } - END_TRY; -#else - TRY { - ucall(test_hello); - printf(" pass\n"); - } - CATCH { - printf(" fail\n"); - failed++; - } - END_TRY; -#endif - } - - // ....................................................................... - // Configure a single region in PMP and call user mode function. It should - // not have access to code and stack hence it should not execute - if (have_user_mode) { - printf("%02d - User mode RWX with one (any) PMP region enabled\n", tid++); - - // Allow area1 user access - entry.addr = ADDR2PMP(&_area); - entry.addr = (entry.addr & 0xFFFFFC00) | 0x000001FF; // NAPOT, 2^12 - entry.cfg = PMP_NAPOT | PMP_R | PMP_W | PMP_X; - pmp_entry_write(5, &entry); - - printf(" testing...\n"); - TRY { - ucall(test_hello); - printf(" fail\n"); - failed++; - } - CATCH { - printf(" pass\n"); - } - END_TRY; - } - - // ....................................................................... - // Configure PMP to allow user mode access to code and stack - if (have_user_mode) { - printf("%02d - User mode RWX with code, data and stack access allowed\n", tid++); - - // Allow user access to "tohost" and "fromhost" - entry.addr = ADDR2PMP(&tohost); - entry.addr = (entry.addr & 0xFFFFFFFC) | 1; // NAPOT 2^4 - entry.cfg = PMP_NAPOT | PMP_R | PMP_W; - pmp_entry_write(0, &entry); - - // Allow user access to code - entry.addr = ADDR2PMP(&_text); - entry.cfg = 0; - pmp_entry_write(1, &entry); - entry.addr = ADDR2PMP(&_text_end) + 1; // upper bound is not inclusive - entry.cfg = PMP_TOR | PMP_R | PMP_X; - pmp_entry_write(2, &entry); - - // Allow user access to data - entry.addr = ADDR2PMP(&_data); - entry.addr = (entry.addr & 0xFFFFFC00) | 0x000001FF; // NAPOT, 2^12 - entry.cfg = PMP_NAPOT | PMP_R | PMP_W; - pmp_entry_write(3, &entry); - entry.addr = ADDR2PMP(&_data); - - // Allow user access to stack - entry.addr = ADDR2PMP(&_stack_lo); - entry.addr = (entry.addr & 0xFFFFF800) | 0x000003FF; // NAPOT, 2^13 - entry.cfg = PMP_NAPOT | PMP_R | PMP_W; - pmp_entry_write(4, &entry); - - printf(" testing...\n"); - TRY { - ucall(test_hello); - printf(" pass\n"); - } - CATCH { - printf(" fail\n"); - failed++; - } - END_TRY; - } - // ....................................................................... // Test PMP operation for all possible RWX combinations in U and M mode. @@ -373,22 +257,6 @@ int main () { uint8_t test_cases [32]; uint32_t test_count = 0; - // Test cases for all RWX combinations in user mode - if (have_user_mode) { - for (size_t i=0; i<8; ++i) { - uint32_t r = (i & 1) ? PMP_R : 0; - uint32_t w = (i & 2) ? PMP_W : 0; - uint32_t x = (i & 4) ? PMP_X : 0; - -#if RV_SMEPMP - // Skip -W- and -WX combinations - if (!r && w && !x) continue; - if (!r && w && x) continue; -#endif - test_cases[test_count++] = i; - } - } - // Test cases for all RWX combinations in machine mode for (size_t i=0; i<8; ++i) { uint32_t r = (i & 1) ? PMP_R : 0; @@ -403,23 +271,6 @@ int main () { test_cases[test_count++] = TST_M | i; } - // Test cases for all RWX combinations in machine mode with MPRV set - if (have_user_mode) { - for (size_t i=0; i<16; ++i) { - uint32_t r = (i & 1) ? PMP_R : 0; - uint32_t w = (i & 2) ? PMP_W : 0; - uint32_t x = (i & 4) ? PMP_X : 0; - uint32_t mpp = (i & 8) != 0; - -#if RV_SMEPMP - // Skip -W- and -WX combinations - if (!r && w && !x) continue; - if (!r && w && x) continue; -#endif - test_cases[test_count++] = (TST_MPP * mpp) | TST_MPRV | TST_M | i; - } - } - // ................................ // Do the tests @@ -602,20 +453,6 @@ int main () { entry.cfg = PMP_NAPOT | PMP_R | PMP_W | PMP_LOCK; pmp_entry_write(5, &entry); - // Execute from U - if (have_user_mode) { - printf(" testing from U mode...\n"); - TRY { - ucall(test_exec); - printf(" fail\n"); - failed++; - } - CATCH { - printf(" pass\n"); - } - END_TRY; - } - // Execute from M printf(" testing from M mode...\n"); TRY { @@ -636,20 +473,6 @@ int main () { entry.cfg = PMP_NAPOT | PMP_R | PMP_W | PMP_X; pmp_entry_write(5, &entry); - // Execute from U - if (have_user_mode) { - printf(" testing from U mode...\n"); - TRY { - ucall(test_exec); - printf(" fail\n"); - failed++; - } - CATCH { - printf(" pass\n"); - } - END_TRY; - } - // Execute from M printf(" testing from M mode...\n"); TRY {