Skip to content

Commit 32ea218

Browse files
MuhammadHammad001UmerShahidengrjamesbeyond
authored
Physical Memory Protection (32/64) Tests and Covergroups (#462)
* PMP32 and PMP64 Covergroups added * YAML basedHeaders/Macros file for the coverpoints added * Added PMP32 and PMP64 ACTs * Added Changelog entry * PMP Macros added in Header file, PMP tests updated to support byte and half word access, PMP Coverpoints updated to a new pattern * 64 bit PMP Tests and coverpoints updated * 32 bit PMP Coverpoints updated to more compact version * Changelog entry removed for the PMP Tests and Coverpoints * Update rv32_pmp.cgf Updated pmp_cfg_locked_write_unrelated coverpoint based on Allen comment Signed-off-by: Umer Shahid <umer.shahid@10xengineers.ai> * Update rv64_pmp.cgf Updated pmp_cfg_locked_write_unrelated coverpoint in rv64 to update a minor bug Signed-off-by: Umer Shahid <umer.shahid@10xengineers.ai> * Changed the CI to see the artifacts * Reverted the change in CI * Removed __pycache__ folders * removed riscof work folder * RISCOF work folder in rv64 removed --------- Signed-off-by: Muhammad Hammad Bashir <139617104+MuhammadHammad001@users.noreply.github.com> Signed-off-by: Umer Shahid <umer.shahid@10xengineers.ai> Co-authored-by: umershahidengr <umer.shahid@10xengineers.ai> Co-authored-by: James Shi <shiqinghao.sqh@alibaba-inc.com>
1 parent 956b77e commit 32ea218

File tree

95 files changed

+21128
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+21128
-0
lines changed

coverage/header_file.yaml

Lines changed: 935 additions & 0 deletions
Large diffs are not rendered by default.

coverage/rv32_pmp.cgf

Lines changed: 836 additions & 0 deletions
Large diffs are not rendered by default.

coverage/rv64_pmp.cgf

Lines changed: 836 additions & 0 deletions
Large diffs are not rendered by default.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// -----------
2+
// Copyright (c) 2020. RISC-V International. All rights reserved.
3+
// SPDX-License-Identifier: BSD-3-Clause
4+
// -----------
5+
//
6+
// This test belongs to the test plan for RISC-V Privilege Arch Compliance developed by 10xEngineers
7+
// which can be found here: https://docs.google.com/spreadsheets/d/1p13gic7BD6aq7n_dHrqti4QmlGpxY7FkF17RVbG4DC0/edit?usp=sharing
8+
//
9+
// This assembly file tests access of pmp registers in M, S, and U mode.
10+
// pmp csrs are accessable only in M-mode so it should trap in S, and U mode.
11+
//
12+
/* COVERPOINTS: (Explanation of updates in /coverage/rv32i_priv.cgf)
13+
pmpcfg0 & 0x20 == 0 : 0 // CHECK IF pmpcfg0[5]==0 (Hard wired zero bit)
14+
pmpcfg0 & 0x40 == 0 : 0 // CHECK IF pmpcfg0[6]==0 (Hard wired zero bit)
15+
pmpcfg0 & 0x80 == 0x80 : 0 // CHECK IF pmpcfg0[7]==1 (Lock bit)
16+
(pmpcfg0 >> 8) & 0x20 == 0 : 0 // CHECK IF pmpcfg0[13]==0 (Hard wired zero bit)
17+
(pmpcfg0 >> 8) & 0x40 == 0 : 0 // CHECK IF pmpcfg0[14]==0 (Hard wired zero bit)
18+
(pmpcfg0 >> 8) & 0x80 == 0x80 : 0 // CHECK IF pmpcfg0[15]==1 (Lock bit)
19+
(pmpcfg0 >> 16) & 0x20 == 0 : 0 // CHECK IF pmpcfg0[21]==0 (Hard wired zero bit)
20+
(pmpcfg0 >> 16) & 0x40 == 0 : 0 // CHECK IF pmpcfg0[22]==0 (Hard wired zero bit)
21+
(pmpcfg0 >> 16) & 0x80 == 0x80 : 0 // CHECK IF pmpcfg0[23]==1 (Lock bit)
22+
(pmpcfg0 >> 24) & 0x20 == 0 : 0 // CHECK IF pmpcfg0[29]==0 (Hard wired zero bit)
23+
(pmpcfg0 >> 24) & 0x40 == 0 : 0 // CHECK IF pmpcfg0[30]==0 (Hard wired zero bit)
24+
(pmpcfg0 >> 24) & 0x80 == 0x80 : 0 // CHECK IF pmpcfg0[31]==1 (Lock bit)
25+
// Same coverpoints are defined for pmpcfg1, pmpcfg2, and pmpcfg3
26+
// Details are given in /coverage/rv32i_priv.cgf
27+
*/
28+
#include "model_test.h"
29+
#include "arch_test.h"
30+
RVTEST_ISA("RV32I_Zicsr")
31+
# Test code region
32+
.section .text.init
33+
.globl rvtest_entry_point
34+
rvtest_entry_point:
35+
RVMODEL_BOOT
36+
RVTEST_CODE_BEGIN
37+
38+
#ifdef TEST_CASE_1
39+
RVTEST_CASE(1,"//check ISA:=regex(.*32.*); check ISA:=regex(.*I.*Zicsr.*); def rvtest_mtrap_routine=True; def rvtest_strap_routine=True; def TEST_CASE_1=True; mac PMP_MACROS; mac PMP_helper_Coverpoints",pmp_cfg_locked_write_unrelated)
40+
RVTEST_SIGBASE( x3,signature_x3_1)
41+
42+
.attribute unaligned_access, 0
43+
.attribute stack_align, 16
44+
.align 2
45+
.option norvc
46+
#define PMPCFG0 0x3A0 // Address of pmpcfg0 (HAS BEEN USED WHILE ITERATING THE LOOP)
47+
#define PMPADDR0 0x3B0 // Address of pmpaddr0 (HAS BEEN USED WHILE ITERATING THE LOOP)
48+
main:
49+
//////////////////////// INITIAL VALUES ////////////////////////////////
50+
LI(a5, -1) // SEtting up All locked bits (including everyother non-zero bit, which is redundent for this test)
51+
LI(x9,0) // The register to carry offset value
52+
LI(x5, 100) // A rondom number, to check if pmp regs get update after lock bit enable
53+
// Loop to SET ALL pmpcfg REGs to zero
54+
.set pmpcfgi, PMPCFG0 // Initialize an iterating variable with the address of pmpcfg0
55+
.rept 4 // START OF LOOP
56+
csrc pmpcfgi , a5 // Set all pmpcfg regs to zero (initial value)
57+
.set pmpcfgi, pmpcfgi+1 // increment variable to next pmpcfg reg
58+
.endr // END OF LOOP BODY
59+
// Loop to SET ALL pmpaddr REGs to zero
60+
.set pmpaddri, PMPADDR0 // Initialize an iterating variable with the address of pmpaddr0
61+
.rept 16 // START OF LOOP
62+
csrc pmpaddri, a5 // Set all pmpaddr regs to zero (initial value)
63+
.set pmpaddri, pmpaddri+1 // increment variable pmpaddri to the next pmpaddr reg
64+
.endr // END OF LOOP BODY
65+
66+
//////////////////// Locked bit TEST 1 /////////////////////////////////////////////
67+
.set pmpcfgi, PMPCFG0 // Initialize an iterating variable with the address of pmpcfg0
68+
.rept 4 // START OF LOOP
69+
csrw pmpcfgi, a5 // WRITE pmpcfgi with ALL 1s, Locked the lock-bit [7,15,23,31]
70+
nop // Added nop in case of trap
71+
csrr a4, pmpcfgi // READ pmpcfgi
72+
// THIS READ WILL ALSO CONFIRM THE ZERO BITs OF PMPCFGi REG.
73+
// BIT 5-6, BIT 13-14, BIT 21-22, BIT 29-30 must be hardwired to zero
74+
// Verify that LOCKED bits are HIGH, and ZERO bits are zero
75+
RVTEST_SIGUPD(x3,a4)
76+
// TRY TO WRITE CFG REGISTER AGAIN (TRAP in case of LOCKED bit is HIGH)
77+
csrw pmpcfgi, x5 // WRITE pmpcfgi with some other values
78+
nop // Added nop in case of trap
79+
csrr a4, pmpcfgi // READ pmpcfgi
80+
// Since Locked bit is high, so this should return the old value!!!
81+
RVTEST_SIGUPD(x3,a4)
82+
83+
.set pmpaddri, PMPADDR0+4*(pmpcfgi-PMPCFG0)
84+
// Initialize an iterating variable with the address of pmpaddr0 in 1st iteration (when pmpcfgi=pmpcfg0)
85+
// Initialize an iterating variable with the address of pmpaddr4 in 2nd iteration (when pmpcfgi=pmpcfg1)
86+
// Initialize an iterating variable with the address of pmpaddr8 in 3rd iteration (when pmpcfgi=pmpcfg2)
87+
// Initialize an iterating variable with the address of pmpaddr12 in 4th iteration (when pmpcfgi=pmpcfg3)
88+
.rept 4 // START OF LOOP
89+
// TRY TO WRITE ADDRESS REGISTER.
90+
csrw pmpaddri, a5 // WRITE pmpaddri with some other values
91+
// The updated write will give a trap!!!
92+
nop // Added nop in case of trap
93+
csrr a4, pmpaddri // READ pmpaddr0, value should not have been changed
94+
nop // Added nop in case of trap
95+
RVTEST_SIGUPD(x3,a4)
96+
.set pmpaddri, pmpaddri+1 // increment variable pmpaddri to the next pmpaddr reg
97+
.endr // END OF INNER LOOP BODY
98+
99+
.set pmpcfgi, pmpcfgi+1 // increment variable to next pmpcfg reg
100+
.endr // END OF OUTER LOOP BODY
101+
#endif
102+
# ---------------------------------------------------------------------------------------------
103+
# HALT
104+
RVTEST_CODE_END
105+
RVMODEL_HALT
106+
107+
RVTEST_DATA_BEGIN
108+
.align 4
109+
110+
rvtest_data:
111+
.word 0xbabecafe
112+
.word 0xbabecafe
113+
.word 0xbabecafe
114+
.word 0xbabecafe
115+
RVTEST_DATA_END
116+
117+
118+
RVMODEL_DATA_BEGIN
119+
rvtest_sig_begin:
120+
sig_begin_canary:
121+
CANARY;
122+
signature_x3_1:
123+
.fill 32*(XLEN/32),4,0xdeadbeef
124+
125+
#ifdef rvtest_mtrap_routine
126+
127+
tsig_begin_canary:
128+
CANARY;
129+
mtrap_sigptr:
130+
.fill 64*(XLEN/32),4,0xdeadbeef
131+
tsig_end_canary:
132+
CANARY;
133+
134+
#endif
135+
136+
#ifdef rvtest_gpr_save
137+
138+
gpr_save:
139+
.fill 32*(XLEN/32),4,0xdeadbeef
140+
141+
#endif
142+
143+
sig_end_canary:
144+
CANARY;
145+
rvtest_sig_end:
146+
RVMODEL_DATA_END
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
// -----------
2+
// Copyright (c) 2020. RISC-V International. All rights reserved.
3+
// SPDX-License-Identifier: BSD-3-Clause
4+
// -----------
5+
//
6+
// This test belongs to the test plan for RISC-V Privilege Arch Compliance developed by 10xEngineers
7+
// which can be found here: https://docs.google.com/spreadsheets/d/1p13gic7BD6aq7n_dHrqti4QmlGpxY7FkF17RVbG4DC0/edit?usp=sharing
8+
//
9+
// This assembly file tests access of pmp registers in M, S, and U mode.
10+
// pmp csrs are accessable only in M-mode so it should trap in S, and U mode.
11+
//
12+
/* COVERPOINTS: (Explanation of updates in /coverage/rv32i_priv.cgf)
13+
14+
// Details are given in /coverage/rv32i_priv.cgf
15+
*/
16+
//
17+
#define rvtest_strap_routine
18+
#include "model_test.h"
19+
#include "arch_test.h"
20+
RVTEST_ISA("RV32I_Zicsr")
21+
# Test code region
22+
.section .text.init
23+
.globl rvtest_entry_point
24+
rvtest_entry_point:
25+
RVMODEL_BOOT
26+
RVTEST_CODE_BEGIN
27+
#ifdef TEST_CASE_1
28+
RVTEST_CASE(1,"//check ISA:=regex(.*32.*); check ISA:=regex(.*I.*Zicsr.*); def rvtest_mtrap_routine=True; def TEST_CASE_1=True",PMP_access_permission)
29+
RVTEST_SIGBASE( x13,signature_x13_1)
30+
.option nopic
31+
.attribute unaligned_access, 0
32+
.attribute stack_align, 16
33+
.align 2
34+
main:
35+
#define PMPCFG0 0x3A0 // Address of pmpcfg0 (HAS BEEN USED WHILE ITERATING THE LOOP)
36+
#define PMPADDR0 0x3B0 // Address of pmpaddr0 (HAS BEEN USED WHILE ITERATING THE LOOP)
37+
main:
38+
//////////////////////// INITIAL VALUES ////////////////////////////////
39+
LI(a5, -1) // SEtting up All locked bits (including everyother non-zero bit, which is redundent for this test)
40+
LI(x5, 100) // A rondom number, to check if pmp regs get update after lock bit enable
41+
// Loop to SET ALL pmpcfg REGs to zero
42+
.set pmpcfgi, PMPCFG0 // Initialize an iterating variable with the address of pmpcfg0
43+
.rept 4 // START OF LOOP
44+
csrc pmpcfgi , a5 // Set all pmpcfg regs to zero (initial value)
45+
.set pmpcfgi, pmpcfgi+1 // increment variable to next pmpcfg reg
46+
.endr // END OF LOOP BODY
47+
// Loop to SET ALL pmpaddr REGs to zero
48+
// Loop to SET ALL pmpaddr REGs to zero
49+
.set pmpaddri, PMPADDR0 // Initialize an iterating variable with the address of pmpaddr0
50+
.rept 16 // START OF LOOP
51+
csrc pmpaddri, a5 // Set all pmpaddr regs to zero (initial value)
52+
.set pmpaddri, pmpaddri+1 // increment variable pmpaddri to the next pmpaddr reg
53+
.endr // END OF LOOP BODY
54+
.set pmpaddri, PMPADDR0 // Initialize an iterating variable with the address of pmpaddr0
55+
.rept 16 // START OF LOOP
56+
csrs pmpaddri, a5 // Set all pmpaddr regs to zero (initial value)
57+
.set pmpaddri, pmpaddri+1 // increment variable pmpaddri to the next pmpaddr reg
58+
.endr // END OF LOOP BODY
59+
//////////////// VERIFICATION /////////////////////////////////////////
60+
// READING pmpaddr in M-mode /////////////////////////////////////////
61+
.set pmpaddri, PMPADDR0 // Initialize an iterating variable with the address of pmpaddr0
62+
.rept 16 // START OF LOOP
63+
csrr a4, pmpaddri // READING pmpaddri (i is from 0-15)
64+
nop // Added nop in case of trap
65+
RVTEST_SIGUPD(x13,a4) // Storing into signature file
66+
.set pmpaddri, pmpaddri+1 // increment variable pmpaddri to the next pmpaddr reg
67+
.endr // END OF LOOP BODY
68+
// WRITING pmpcfg registers //////////////////////////////////////////
69+
// Write in M-mode will be valid, Write in other modes will cause trap
70+
LI(a5, PMP_R| PMP_W | PMP_X | PMP_TOR) // LOCKED BIT IS NOT SET
71+
// Loop to Write ALL pmpcfg regs
72+
.set pmpcfgi, PMPCFG0 // Initialize an iterating variable with the address of pmpcfg0
73+
.rept 4 // START OF LOOP
74+
csrw pmpcfgi, a5 // Write pmpcfgi
75+
nop // Added nop in case of trap
76+
.set pmpcfgi, pmpcfgi+1 // increment variable to next pmpcfg reg
77+
.endr // END OF LOOP BODY
78+
//////////////// VERIFICATION /////////////////////////////////////////
79+
// READING pmpcfg in M-mode /////////////////////////////////////////
80+
// Loop to verify the contents of pmpcfg regs
81+
.set pmpcfgi, PMPCFG0 // Initialize an iterating variable with the address of pmpcfg0
82+
.rept 4 // START OF LOOP
83+
csrr a4, pmpcfg0 // Read pmpcfg0
84+
nop // Added nop in case of trap
85+
RVTEST_SIGUPD(x13,a4)
86+
.set pmpcfgi, pmpcfgi+1 // increment variable to next pmpcfg reg
87+
.endr // END OF LOOP BODY
88+
/////////////////// Switch to S-mode ////////////////////////////////////////////
89+
csrw satp, zero // Disable address translation.
90+
LI(t2, -1)
91+
csrw pmpaddr0, t2 // Updated pmpaddr0 to define PMP region consisting
92+
// of whole physical memory
93+
csrr t0, pmpaddr0 // Verify its value by reading back
94+
nop // Added nop in case of trap
95+
RVTEST_SIGUPD(x13,t0)
96+
nop // Added nop in case of trap
97+
LI(a5, PMP_L| PMP_R| PMP_W | PMP_X | PMP_TOR) // LOCKED BIT IS SET
98+
csrw pmpcfg0, a5
99+
100+
RVTEST_GOTO_LOWER_MODE Smode // GO into S mode
101+
// REPEATING THE SAME TEST //////////////////////////////////////////
102+
// IN Smode now
103+
/////////////////// TEST 01 ////////////////////////////////////////////
104+
// WRITING pmpaddr registers //////////////////////////////////////////
105+
// Write in M-mode will be valid, Write in other modes will cause trap
106+
csrw pmpaddr0, x2 // Write pmpaddr0 in S mode (TRAP)
107+
nop // Added nop in case of trap
108+
// READING pmpaddr in S-mode /////////////////////////////////////////
109+
csrr a4, pmpaddr0 // Reading pmpaddr0 in S mode (TRAP)
110+
nop // Added nop in case of trap
111+
/////////////////// Switch back to M-mode ////////////////////////////////////////////
112+
RVTEST_GOTO_MMODE
113+
csrr a4, mstatus // VERIFICATION of M-mode
114+
nop // Added nop in case of trap
115+
RVTEST_SIGUPD(x13,a4)
116+
/////////////////// Switch to U-mode ////////////////////////////////////////////
117+
csrw satp, zero // Disable address translation.
118+
LI(t2, -1)
119+
csrw pmpaddr0, t2 // Updated pmpaddr0 to define PMP region consisting
120+
// of whole physical memory
121+
csrr t0, pmpaddr0 // Verify its value by reading back
122+
nop // Added nop in case of trap
123+
RVTEST_SIGUPD(x13,t0)
124+
nop // Added nop in case of trap
125+
LI(a5, PMP_L| PMP_R| PMP_W | PMP_X | PMP_TOR) // LOCKED BIT IS SET
126+
csrw pmpcfg0, a5
127+
// These steps are repeated and can be removed but it will make sure that you will switch mode
128+
// with full access on physical memory
129+
RVTEST_GOTO_LOWER_MODE Umode
130+
// REPEATING THE SAME TEST //////////////////////////////////////////
131+
// IN U-mode now
132+
/////////////////// TEST 01 ////////////////////////////////////////////
133+
// WRITING pmpaddr registers //////////////////////////////////////////
134+
// Write in M-mode will be valid, Write in other modes will cause trap
135+
csrw pmpaddr0, x2 // Write pmpaddr0 in u mode (TRAP)
136+
nop // Added nop in case of trap
137+
//////////////// VERIFICATION /////////////////////////////////////////
138+
// READING pmpaddr in S-mode /////////////////////////////////////////
139+
csrr a4, pmpaddr0 // Reading pmpaddr0 in U mode (TRAP)
140+
nop // Added nop in case of trap
141+
142+
#endif
143+
144+
# ---------------------------------------------------------------------------------------------
145+
# HALT
146+
RVTEST_CODE_END
147+
RVMODEL_HALT
148+
149+
RVTEST_DATA_BEGIN
150+
.align 4
151+
152+
rvtest_data:
153+
.word 0xbabecafe
154+
.word 0xbabecafe
155+
.word 0xbabecafe
156+
.word 0xbabecafe
157+
RVTEST_DATA_END
158+
159+
160+
RVMODEL_DATA_BEGIN
161+
rvtest_sig_begin:
162+
sig_begin_canary:
163+
CANARY;
164+
signature_x13_1:
165+
.fill 32*(XLEN/32),4,0xdeadbeef
166+
167+
#ifdef rvtest_mtrap_routine
168+
169+
tsig_begin_canary:
170+
CANARY;
171+
mtrap_sigptr:
172+
.fill 64*(XLEN/32),4,0xdeadbeef
173+
tsig_end_canary:
174+
CANARY;
175+
176+
#endif
177+
178+
#ifdef rvtest_gpr_save
179+
180+
gpr_save:
181+
.fill 32*(XLEN/32),4,0xdeadbeef
182+
183+
#endif
184+
185+
sig_end_canary:
186+
CANARY;
187+
rvtest_sig_end:
188+
RVMODEL_DATA_END

0 commit comments

Comments
 (0)