From 55a74fd3153053b6851eb4bf7f87335ed45ad5c5 Mon Sep 17 00:00:00 2001 From: Alexa Wright Date: Tue, 25 Apr 2023 17:06:57 -0700 Subject: [PATCH 1/2] Excluded and added coverage for WFI test case. --- src/privileged/privdec.sv | 3 +++ tests/coverage/priv.S | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/privileged/privdec.sv b/src/privileged/privdec.sv index 21239dc9..3c33c8b5 100644 --- a/src/privileged/privdec.sv +++ b/src/privileged/privdec.sv @@ -69,7 +69,10 @@ module privdec ( logic [`WFI_TIMEOUT_BIT:0] WFICount, WFICountPlus1; assign WFICountPlus1 = WFICount + 1; floprc #(`WFI_TIMEOUT_BIT+1) wficountreg(clk, reset, ~wfiM, WFICountPlus1, WFICount); // count while in WFI + // coverage off -item e 1 -fecexprrow 1 + // Excluding test case where we need to test WFI in a condition where it will never trap assign WFITimeoutM = ((STATUS_TW & PrivilegeModeW != `M_MODE) | (`S_SUPPORTED & PrivilegeModeW == `U_MODE)) & WFICount[`WFI_TIMEOUT_BIT]; + // coverage on end else assign WFITimeoutM = 0; /////////////////////////////////////////// diff --git a/tests/coverage/priv.S b/tests/coverage/priv.S index 5e187866..d311f2a0 100644 --- a/tests/coverage/priv.S +++ b/tests/coverage/priv.S @@ -169,6 +169,24 @@ main: csrw mcounteren, t0 csrw scounteren, t0 + #getting the remainder of PMD instructions + + #go to user mode + li a0, 0 + ecall + #set status TVM to 0 by writing to bit 20 of mstatus as 0 + #bseti t0, zero, 20 + sfence.vma zero, zero + + # Go to supervisor mode + li a0, 1 + ecall + + sfence.vma zero, zero + + li a0, 3 + ecall + # Write to satp when status.TVM is 1 from machine mode bseti t0, zero, 20 csrs mstatus, t0 @@ -203,6 +221,30 @@ main: csrr t0, hpmcounter22 + #getting the mpp and mstatus Mpriv condition met + #go to machine mode + li a0, 3 + ecall + # set bit 17 of mstatus to enable STATUS_MPRV + bseti t1, zero, 17 + csrs mstatus, t1 + + li a0, 3 + ecall + + # set bit 21 of mstatus to 0 to disable STATUS_TW + csrr t1, mstatus + bseti t2, zero, 21 + not t2, t2 + and t1, t1, t2 + csrs mstatus, t1 + + # go to user mode + li a0, 0 + ecall + + wfi + j done From 79031e3de0d88464fc873b919eb66af359fb9b4f Mon Sep 17 00:00:00 2001 From: Alexa Wright Date: Wed, 26 Apr 2023 16:25:55 -0700 Subject: [PATCH 2/2] Added better comment for the exclusion in privdec.sv --- src/privileged/privdec.sv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/privileged/privdec.sv b/src/privileged/privdec.sv index 3c33c8b5..9aaa9979 100644 --- a/src/privileged/privdec.sv +++ b/src/privileged/privdec.sv @@ -70,7 +70,7 @@ module privdec ( assign WFICountPlus1 = WFICount + 1; floprc #(`WFI_TIMEOUT_BIT+1) wficountreg(clk, reset, ~wfiM, WFICountPlus1, WFICount); // count while in WFI // coverage off -item e 1 -fecexprrow 1 - // Excluding test case where we need to test WFI in a condition where it will never trap + // WFI Timout trap will not occur when STATUS_TW is low while in supervisor mode, so the system gets stuck waiting for an interrupt and triggers a watchdog timeout. assign WFITimeoutM = ((STATUS_TW & PrivilegeModeW != `M_MODE) | (`S_SUPPORTED & PrivilegeModeW == `U_MODE)) & WFICount[`WFI_TIMEOUT_BIT]; // coverage on end else assign WFITimeoutM = 0;