From 376ca68cbbc7e3f2b7de1c5cfadd8288779fb684 Mon Sep 17 00:00:00 2001 From: David Harris Date: Wed, 30 Aug 2023 21:04:36 -0700 Subject: [PATCH] Improved NAPOT test coverage --- sim/wave.do | 6 + tests/coverage/WALLY-init-lib.h | 3 + tests/coverage/tlbNAPOT.S | 201 +++++++++++++++++++++++++++++++- 3 files changed, 204 insertions(+), 6 deletions(-) diff --git a/sim/wave.do b/sim/wave.do index 6fd560251..047a0b163 100644 --- a/sim/wave.do +++ b/sim/wave.do @@ -65,14 +65,20 @@ add wave -noupdate -group {Execution Stage} /testbench/dut/core/ifu/PCE add wave -noupdate -group {Execution Stage} /testbench/dut/core/ifu/InstrE add wave -noupdate -group {Execution Stage} /testbench/InstrEName add wave -noupdate -group {Execution Stage} /testbench/dut/core/ieu/c/InstrValidE +add wave -noupdate -group {Execution Stage} /testbench/dut/core/ieu/dp/SrcAE +add wave -noupdate -group {Execution Stage} /testbench/dut/core/ieu/dp/SrcBE +add wave -noupdate -group {Execution Stage} /testbench/dut/core/ieu/dp/ALUResultE add wave -noupdate -expand -group {Memory Stage} /testbench/FunctionName/FunctionName/FunctionName add wave -noupdate -expand -group {Memory Stage} /testbench/dut/core/InstrValidM add wave -noupdate -expand -group {Memory Stage} /testbench/dut/core/PCM add wave -noupdate -expand -group {Memory Stage} /testbench/dut/core/InstrM add wave -noupdate -expand -group {Memory Stage} /testbench/InstrMName add wave -noupdate -expand -group {Memory Stage} /testbench/dut/core/lsu/IEUAdrM +add wave -noupdate -expand -group lsu /testbench/dut/core/lsu/ReadDataM +add wave -noupdate -expand -group lsu /testbench/dut/core/lsu/WriteDataM add wave -noupdate -group {WriteBack stage} /testbench/InstrW add wave -noupdate -group {WriteBack stage} /testbench/InstrWName +add wave -noupdate -group {Execution Stage} /testbench/dut/core/ieu/dp/ResultW add wave -noupdate -group CSRs /testbench/dut/core/priv/priv/csr/csrm/MCAUSE_REGW add wave -noupdate -group CSRs /testbench/dut/core/priv/priv/csr/MCOUNTEREN_REGW add wave -noupdate -group CSRs /testbench/dut/core/priv/priv/csr/MCOUNTINHIBIT_REGW diff --git a/tests/coverage/WALLY-init-lib.h b/tests/coverage/WALLY-init-lib.h index b0f5a9654..55bfcf4e5 100644 --- a/tests/coverage/WALLY-init-lib.h +++ b/tests/coverage/WALLY-init-lib.h @@ -92,7 +92,10 @@ changeprivilege: trap_return: # return from trap handler csrr t0, mepc # get address of instruction that caused exception + li t1, 0x20000 + csrs mstatus, t1 # set mprv bit to fetch instruction with permission of code that trapped lh t0, 0(t0) # get instruction that caused exception + csrc mstatus, t1 # clear mprv bit to restore normal operation li t1, 3 and t0, t0, t1 # mask off upper bits beq t0, t1, instr32 # if lower 2 bits are 11, instruction is uncompresssed diff --git a/tests/coverage/tlbNAPOT.S b/tests/coverage/tlbNAPOT.S index e136f864a..f827d503b 100644 --- a/tests/coverage/tlbNAPOT.S +++ b/tests/coverage/tlbNAPOT.S @@ -41,8 +41,21 @@ main: li a0, 1 ecall - li t0, 0x80215240 + li t0, 0x80215240 # Test NAPOT pages + jal a1, looptest + li t0, 0x80215240 # Test NAPOT pages + jal a1, looptest + li t0, 0xC0215240 # Test ill-formed NAPOT pages + jal a1, looptest + li t0, 0xC0215240 # Test ill-formed NAPOT pages + jal a1, looptest + li t0, 0x40215240 # Test properly formed pages with 1 in PPN[3] that are not NAPOT + jal a1, looptest + li t0, 0x40215240 # Test properly formed pages with 1 in PPN[3] that are not NAPOT + jal a1, looptest + j done +looptest: li t2, 0 # i = 0 li t3, 33 # Max amount of Loops = 32 li t4, 0x200000 @@ -58,7 +71,7 @@ loop: bge t2, t3, finished # exit loop if i >= loops j loop finished: - j done + jr a1 .data @@ -69,9 +82,10 @@ pagetable: # next page table at 0x80011000 .align 12 - .8byte 0x0000000000000000 - .8byte 0x00000000200048C1 - .8byte 0x00000000200048C1 + .8byte 0x0000000000000000 # gigapage at 0x00000000 + .8byte 0x00000000200058C1 # gigapage at 0x40000000 used for non-NAPOT with PPN bit 3 set + .8byte 0x00000000200048C1 # gigapage at 0x80000000 used for testing NAPOT huge pages + .8byte 0x00000000200050C1 # gigapage at 0xC0000000 mapped to ill-formed NAPOT with wrong PPN # Next page table at 0x80012000 @@ -112,7 +126,7 @@ pagetable: .8byte 0x0000000020004CC1 .8byte 0x0000000020004CC1 -# Leaf page table at 0x80013000 +# Leaf page table at 0x80013000 with NAPOT pages .align 12 #80000000 .8byte 0x80000000200020CF @@ -182,3 +196,178 @@ pagetable: .8byte 0x800000002000E0CF .8byte 0x800000002000E0CF + +# Next page table at 0x80014000: mega-sized, pointing to malformed NAPOT +.align 12 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + .8byte 0x00000000200054C1 + +# Leaf page table at 0x80015000 with malformed NAPOT pages (wrong PPN) starting at 0xC0000000 +.align 12 + #80000000 + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + .8byte 0x80000000200000CF + + +# Next page table at 0x80016000: mega-sized, pointing to properly formed PTE with 1 in PPN bit 3 +.align 12 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + .8byte 0x0000000020005CC1 + +# Leaf page table at 0x80017000 with properly formed PTE with bit 4 of PPN set but no NAPOT +.align 12 + #80000000 + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + .8byte 0x00000000200020CF + + \ No newline at end of file