Skip to content

Commit

Permalink
Add NAPOT region test
Browse files Browse the repository at this point in the history
  • Loading branch information
dpretet committed Oct 30, 2023
1 parent 79d8c7a commit a12eeeb
Show file tree
Hide file tree
Showing 8 changed files with 416 additions and 360 deletions.
4 changes: 2 additions & 2 deletions rtl/friscv_control.sv
Original file line number Diff line number Diff line change
Expand Up @@ -1220,9 +1220,9 @@ module friscv_control
assign inst_dec_error = dec_error & (cfsm==FETCH) & inst_ready;

// Is fetching instruction on forbidden memory region
assign inst_access_fault = (!mpu_allow[`PMA_X] | !mpu_allow[`PMA_R]) &
assign inst_access_fault = (!mpu_allow[`ALW_X] | !mpu_allow[`ALW_R]) &
(priv_mode == `UMODE ||
priv_mode==`MMODE && mpu_allow[3] /*locked*/);
priv_mode==`MMODE && mpu_allow[`ALW_L]);

//////////////////////////////////////////////////////////////////////
// Stores the incoming excpetions from processing. Can't handle
Expand Down
5 changes: 5 additions & 0 deletions rtl/friscv_h.sv
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@
`define PMA_A 3 // 4:3
`define PMA_L 7

`define ALW_R 0
`define ALW_W 1
`define ALW_X 2
`define ALW_L 3

//////////////////////////////////////////////////////////////////
// Instruction bus feeding ALUs
//////////////////////////////////////////////////////////////////
Expand Down
16 changes: 8 additions & 8 deletions rtl/friscv_memfy.sv
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ module friscv_memfy
opcode_r <= opcode;

// STORE
if (opcode==`STORE && mpu_allow[`PMA_W] && !store_misaligned) begin
if (opcode==`STORE && mpu_allow[`ALW_W] && !store_misaligned) begin

if (waiting_rd_cpl || arvalid) begin
state <= WAIT;
Expand All @@ -460,7 +460,7 @@ module friscv_memfy
arvalid <= 1'b0;

// LOAD
end else if (opcode==`LOAD && mpu_allow[`PMA_R] && !load_misaligned) begin
end else if (opcode==`LOAD && mpu_allow[`ALW_R] && !load_misaligned) begin
if (waiting_wr_cpl || awvalid) begin
state <= WAIT;
arvalid <= 1'b0;
Expand Down Expand Up @@ -637,14 +637,14 @@ module friscv_memfy
end else begin

// Write xfers tracker
if (memfy_valid && memfy_ready && opcode==`STORE && !bvalid && !max_wr_or) begin
if (memfy_valid && memfy_ready && opcode==`STORE && !bvalid && !max_wr_or && mpu_allow[`ALW_W]) begin
wr_or_cnt <= wr_or_cnt + 1'b1;
end else if (!(memfy_valid && memfy_ready && opcode==`STORE) && bvalid && bready && wr_or_cnt!={MAX_OR_W{1'b0}}) begin
wr_or_cnt <= wr_or_cnt - 1'b1;
end

// Read xfers tracker
if (memfy_valid && memfy_ready && opcode==`LOAD && !memfy_rd_wr && !max_rd_or) begin
if (memfy_valid && memfy_ready && opcode==`LOAD && !memfy_rd_wr && !max_rd_or && mpu_allow[`ALW_R]) begin
rd_or_cnt <= rd_or_cnt + 1'b1;
end else if (!(memfy_valid && memfy_ready && opcode==`LOAD) && memfy_rd_wr && rd_or_cnt!={MAX_OR_W{1'b0}}) begin
rd_or_cnt <= rd_or_cnt - 1'b1;
Expand Down Expand Up @@ -769,7 +769,7 @@ module friscv_memfy
------------------------------------------------------------------------------------------------
ACACHE | AWCACHE | ARCACHE
[3] [2] [1] [0] | |
[3] [2] [1] [0] | |
------------------------------------------------------------------------------------------------
0 0 0 0 | Device Non-cacheable Non-bufferable | Device Non-cacheable Non-bufferable
0 0 0 1 | Device Non-cacheable Bufferable | Device Non-cacheable Bufferable
Expand All @@ -781,7 +781,7 @@ module friscv_memfy
| Write-Through Read-Allocate |
------------------------------------------------------------------------------------------------
0 1 1 1 | Write-Back No-Allocate | Write-Back Read-Allocate
| Write-Back Read-Allocate |
| Write-Back Read-Allocate |
------------------------------------------------------------------------------------------------
1 0 1 0 | Write-Through Write-Allocate | Write-Through No-Allocate
| | Write-Through Write-Allocate
Expand Down Expand Up @@ -843,10 +843,10 @@ module friscv_memfy
1'b0 ;

// Load access outside am allowed region
assign load_access_fault = (opcode==`LOAD) & !mpu_allow[`PMA_R] & check_access & active_access;
assign load_access_fault = (opcode==`LOAD) & !mpu_allow[`ALW_R] & check_access & active_access;

// Store access outside am allowed region
assign store_access_fault = (opcode==`STORE) & !mpu_allow[`PMA_W] & check_access & active_access;
assign store_access_fault = (opcode==`STORE) & !mpu_allow[`ALW_W] & check_access & active_access;


// Shared bus routing back to control unit
Expand Down
170 changes: 87 additions & 83 deletions test/priv_sec_testsuite/tests/rv32ui-p-test2.v
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@00010000
6F 00 80 08 73 2F 20 34 93 0E 80 00 63 08 DF 6B
6F 00 80 08 73 2F 20 34 93 0E 80 00 63 02 DF 6D
93 0E 90 00 63 02 DF 1B 93 0E B0 00 63 02 DF 1B
93 0E 20 00 63 00 DF 1B B7 0E 00 80 93 8E BE 00
63 00 DF 6D B7 0E 00 80 93 8E 3E 00 63 0A DF 6B
B7 0E 00 80 93 8E 7E 00 63 04 DF 6B 93 0E 50 00
63 0A DF 6D B7 0E 00 80 93 8E 3E 00 63 04 DF 6D
B7 0E 00 80 93 8E 7E 00 63 0E DF 6B 93 0E 50 00
63 00 DF 3F 93 0E 70 00 63 0C DF 3D 93 0E 10 00
63 08 DF 3D 13 0F 00 00 63 04 0F 00 67 00 0F 00
73 2F 20 34 63 54 0F 00 6F 00 40 00 93 E1 91 53
Expand All @@ -26,109 +26,113 @@ B7 0E 00 80 93 8E 7E 00 63 04 DF 6B 93 0E 50 00
73 00 10 00 93 02 00 00 63 8A 02 00 73 90 52 10
B7 B2 00 00 93 82 92 10 73 90 22 30 73 50 00 30
97 02 00 00 93 82 42 01 73 90 12 34 73 25 40 F1
73 00 20 30 6F 00 40 54 93 8F 1F 00 73 00 10 00
6F 00 00 52 93 8F 1F 00 73 00 10 00 73 10 00 3A
73 00 20 30 6F 00 80 55 93 8F 1F 00 73 00 10 00
6F 00 40 53 93 8F 1F 00 73 00 10 00 73 10 00 3A
73 10 10 3A 73 10 20 3A 73 10 30 3A 73 10 00 3B
73 10 10 3B 73 10 20 3B 73 10 30 3B 73 10 40 3B
73 10 50 3B 73 10 60 3B 73 10 70 3B 73 10 80 3B
73 10 90 3B 73 10 A0 3B 73 10 B0 3B 73 10 C0 3B
73 10 D0 3B 73 10 E0 3B 73 10 F0 3B 6F 00 40 4C
73 10 D0 3B 73 10 E0 3B 73 10 F0 3B 6F 00 80 4D
B7 0E 00 00 93 8E FE FF 73 90 0E 3B 73 2F 00 3B
63 9C EE 59 73 10 00 3B B7 0E 00 00 93 8E FE FF
73 90 1E 3B 73 2F 10 3B 63 90 EE 59 73 10 10 3B
63 98 EE 5F 73 10 00 3B B7 0E 00 00 93 8E FE FF
73 90 1E 3B 73 2F 10 3B 63 9C EE 5D 73 10 10 3B
B7 0E 00 00 93 8E FE FF 73 90 2E 3B 73 2F 20 3B
63 94 EE 57 73 10 20 3B B7 0E 00 00 93 8E FE FF
73 90 3E 3B 73 2F 30 3B 63 98 EE 55 73 10 30 3B
63 90 EE 5D 73 10 20 3B B7 0E 00 00 93 8E FE FF
73 90 3E 3B 73 2F 30 3B 63 94 EE 5B 73 10 30 3B
B7 0E 00 00 93 8E FE FF 73 90 4E 3B 73 2F 40 3B
63 9C EE 53 73 10 40 3B B7 0E 00 00 93 8E FE FF
73 90 5E 3B 73 2F 50 3B 63 90 EE 53 73 10 50 3B
63 98 EE 59 73 10 40 3B B7 0E 00 00 93 8E FE FF
73 90 5E 3B 73 2F 50 3B 63 9C EE 57 73 10 50 3B
B7 0E 00 00 93 8E FE FF 73 90 6E 3B 73 2F 60 3B
63 94 EE 51 73 10 60 3B B7 0E 00 00 93 8E FE FF
73 90 7E 3B 73 2F 70 3B 63 98 EE 4F 73 10 70 3B
63 90 EE 57 73 10 60 3B B7 0E 00 00 93 8E FE FF
73 90 7E 3B 73 2F 70 3B 63 94 EE 55 73 10 70 3B
B7 0E 00 00 93 8E FE FF 73 90 8E 3B 73 2F 80 3B
63 9C EE 4D 73 10 80 3B B7 0E 00 00 93 8E FE FF
73 90 9E 3B 73 2F 90 3B 63 90 EE 4D 73 10 90 3B
63 98 EE 53 73 10 80 3B B7 0E 00 00 93 8E FE FF
73 90 9E 3B 73 2F 90 3B 63 9C EE 51 73 10 90 3B
B7 0E 00 00 93 8E FE FF 73 90 AE 3B 73 2F A0 3B
63 94 EE 4B 73 10 A0 3B B7 0E 00 00 93 8E FE FF
73 90 BE 3B 73 2F B0 3B 63 98 EE 49 73 10 B0 3B
63 90 EE 51 73 10 A0 3B B7 0E 00 00 93 8E FE FF
73 90 BE 3B 73 2F B0 3B 63 94 EE 4F 73 10 B0 3B
B7 0E 00 00 93 8E FE FF 73 90 CE 3B 73 2F C0 3B
63 9C EE 47 73 10 C0 3B B7 0E 00 00 93 8E FE FF
73 90 DE 3B 73 2F D0 3B 63 90 EE 47 73 10 D0 3B
63 98 EE 4D 73 10 C0 3B B7 0E 00 00 93 8E FE FF
73 90 DE 3B 73 2F D0 3B 63 9C EE 4B 73 10 D0 3B
B7 0E 00 00 93 8E FE FF 73 90 EE 3B 73 2F E0 3B
63 94 EE 45 73 10 E0 3B B7 0E 00 00 93 8E FE FF
73 90 FE 3B 73 2F F0 3B 63 98 EE 43 73 10 F0 3B
63 90 EE 4B 73 10 E0 3B B7 0E 00 00 93 8E FE FF
73 90 FE 3B 73 2F F0 3B 63 94 EE 49 73 10 F0 3B
B7 7E 77 77 93 8E 7E 77 73 90 0E 3A 73 2F 00 3A
63 9C EE 41 73 10 00 3A B7 7E 77 77 93 8E 7E 77
73 90 1E 3A 73 2F 10 3A 63 90 EE 41 73 10 10 3A
63 98 EE 47 73 10 00 3A B7 7E 77 77 93 8E 7E 77
73 90 1E 3A 73 2F 10 3A 63 9C EE 45 73 10 10 3A
B7 7E 77 77 93 8E 7E 77 73 90 2E 3A 73 2F 20 3A
63 94 EE 3F 73 10 20 3A B7 7E 77 77 93 8E 7E 77
73 90 3E 3A 73 2F 30 3A 63 98 EE 3D 73 10 30 3A
6F 00 00 2E 37 0F 00 00 13 0F 8F 08 F3 2E 00 30
63 90 EE 45 73 10 20 3A B7 7E 77 77 93 8E 7E 77
73 90 3E 3A 73 2F 30 3A 63 94 EE 43 73 10 30 3A
6F 00 40 2F 37 0F 00 00 13 0F 8F 08 F3 2E 00 30
B3 EE EE 01 73 90 0E 30 37 1F 00 00 13 0F 0F 80
F3 2E 40 30 B3 EE EE 01 73 90 4E 30 6F 00 40 2B
13 04 14 00 73 00 20 30 6F 00 80 2A 93 02 40 00
63 42 55 02 93 02 80 00 63 44 55 0A 93 02 C0 00
63 46 55 12 93 02 00 01 63 48 55 1A 13 05 10 00
6F 00 00 28 93 D5 25 00 73 23 00 3A 93 02 00 00
F3 2E 40 30 B3 EE EE 01 73 90 4E 30 6F 00 80 2C
13 04 14 00 73 00 20 30 6F 00 C0 2B 13 56 16 00
13 06 F6 FF B3 85 C5 00 93 D5 25 00 6F 00 40 00
93 02 40 00 63 42 55 02 93 02 80 00 63 44 55 0A
93 02 C0 00 63 46 55 12 93 02 00 01 63 48 55 1A
13 05 10 00 6F 00 00 28 93 D5 25 00 73 23 00 3A
93 02 00 00 63 8E A2 00 93 02 10 00 63 82 A2 02
93 02 20 00 63 8A A2 02 93 02 30 00 63 82 A2 04
73 90 05 3B 93 02 00 F0 33 73 53 00 6F 00 C0 04
73 90 15 3B B7 02 FF FF 93 82 F2 0F 33 73 53 00
93 96 86 00 6F 00 40 03 73 90 25 3B B7 02 01 FF
93 82 F2 FF 33 73 53 00 93 96 06 01 6F 00 C0 01
73 90 35 3B B7 02 00 01 93 82 F2 FF 33 73 53 00
93 96 86 01 6F 00 40 00 33 63 D3 00 73 10 03 3A
6F 00 40 1F 93 D5 25 00 73 23 10 3A 93 02 00 00
63 8E A2 00 93 02 10 00 63 82 A2 02 93 02 20 00
63 8A A2 02 93 02 30 00 63 82 A2 04 73 90 05 3B
93 02 00 F0 33 73 53 00 6F 00 C0 04 73 90 15 3B
63 8A A2 02 93 02 30 00 63 82 A2 04 73 90 45 3B
93 02 00 F0 33 73 53 00 6F 00 C0 04 73 90 55 3B
B7 02 FF FF 93 82 F2 0F 33 73 53 00 93 96 86 00
6F 00 40 03 73 90 25 3B B7 02 01 FF 93 82 F2 FF
33 73 53 00 93 96 06 01 6F 00 C0 01 73 90 35 3B
6F 00 40 03 73 90 65 3B B7 02 01 FF 93 82 F2 FF
33 73 53 00 93 96 06 01 6F 00 C0 01 73 90 75 3B
B7 02 00 01 93 82 F2 FF 33 73 53 00 93 96 86 01
6F 00 40 00 33 63 D3 00 73 10 03 3A 6F 00 40 1F
6F 00 40 00 33 63 D3 00 73 10 03 3A 6F 00 80 16
93 D5 25 00 73 23 10 3A 93 02 00 00 63 8E A2 00
93 02 10 00 63 82 A2 02 93 02 20 00 63 8A A2 02
93 02 30 00 63 82 A2 04 73 90 45 3B 93 02 00 F0
33 73 53 00 6F 00 C0 04 73 90 55 3B B7 02 FF FF
93 82 F2 0F 33 73 53 00 93 96 86 00 6F 00 40 03
73 90 65 3B B7 02 01 FF 93 82 F2 FF 33 73 53 00
93 96 06 01 6F 00 C0 01 73 90 75 3B B7 02 00 01
93 82 F2 FF 33 73 53 00 93 96 86 01 6F 00 40 00
33 63 D3 00 73 10 03 3A 6F 00 80 16 93 D5 25 00
73 23 10 3A 93 02 00 00 63 8E A2 00 93 02 10 00
93 02 30 00 63 80 A2 04 73 90 85 3B 93 02 00 F0
33 73 53 00 6F 00 80 04 73 90 95 3B B7 02 FF FF
93 82 F2 0F 33 73 53 00 93 96 86 00 6F 00 00 03
B7 02 01 FF 93 82 F2 FF 33 73 53 00 93 96 06 01
6F 00 C0 01 73 90 A5 3B B7 02 00 01 93 82 F2 FF
33 73 53 00 93 96 86 01 6F 00 40 00 73 90 B5 3B
33 63 D3 00 73 10 03 3A 6F 00 C0 0D 93 D5 25 00
73 23 30 3A 93 02 00 00 63 8E A2 00 93 02 10 00
63 82 A2 02 93 02 20 00 63 8A A2 02 93 02 30 00
63 80 A2 04 73 90 85 3B 93 02 00 F0 33 73 53 00
6F 00 80 04 73 90 95 3B B7 02 FF FF 93 82 F2 0F
33 73 53 00 93 96 86 00 6F 00 00 03 B7 02 01 FF
93 82 F2 FF 33 73 53 00 93 96 06 01 6F 00 C0 01
73 90 A5 3B B7 02 00 01 93 82 F2 FF 33 73 53 00
93 96 86 01 6F 00 40 00 73 90 B5 3B 33 63 D3 00
73 10 03 3A 6F 00 C0 0D 93 D5 25 00 73 23 30 3A
93 02 00 00 63 8E A2 00 93 02 10 00 63 82 A2 02
93 02 20 00 63 8A A2 02 93 02 30 00 63 82 A2 04
73 90 C5 3B 93 02 00 F0 33 73 53 00 6F 00 C0 04
73 90 D5 3B B7 02 FF FF 93 82 F2 0F 33 73 53 00
93 96 86 00 6F 00 40 03 73 90 E5 3B B7 02 01 FF
93 82 F2 FF 33 73 53 00 93 96 06 01 6F 00 C0 01
73 90 F5 3B B7 02 00 01 93 82 F2 FF 33 73 53 00
93 96 86 01 6F 00 40 00 33 63 D3 00 73 10 33 3A
6F 00 00 05 93 02 00 00 63 04 57 04 93 02 80 00
E3 0E 57 D8 93 02 00 01 E3 08 57 D8 93 02 80 01
E3 04 57 D8 13 05 10 00 6F 00 80 02 93 0E 00 00
E3 86 D8 B1 93 0E 10 00 E3 8C D8 B5 93 0E 80 00
E3 82 D8 FD 93 0E 90 00 E3 86 D8 D3 6F 00 40 00
F3 2E 10 34 93 8E 4E 00 73 90 1E 34 73 00 20 30
13 0A 1A 00 73 00 20 30 93 08 00 00 73 00 00 00
93 08 10 00 73 00 00 00 13 05 00 00 B7 05 10 00
13 06 00 00 93 06 F0 08 13 07 80 00 93 08 80 00
73 00 00 00 EF 00 00 07 B7 02 10 00 23 A0 02 00
63 82 A2 04 73 90 C5 3B 93 02 00 F0 33 73 53 00
6F 00 C0 04 73 90 D5 3B B7 02 FF FF 93 82 F2 0F
33 73 53 00 93 96 86 00 6F 00 40 03 73 90 E5 3B
B7 02 01 FF 93 82 F2 FF 33 73 53 00 93 96 06 01
6F 00 C0 01 73 90 F5 3B B7 02 00 01 93 82 F2 FF
33 73 53 00 93 96 86 01 6F 00 40 00 33 63 D3 00
73 10 33 3A 6F 00 00 05 93 02 00 00 63 04 57 04
93 02 80 00 E3 0E 57 D8 93 02 00 01 E3 0E 57 D6
93 02 80 01 E3 0C 57 D6 13 05 10 00 6F 00 80 02
93 0E 00 00 E3 8C D8 AF 93 0E 10 00 E3 82 D8 B5
93 0E 80 00 E3 82 D8 FD 93 0E 90 00 E3 8C D8 D1
6F 00 40 00 F3 2E 10 34 93 8E 4E 00 73 90 1E 34
73 00 20 30 13 0A 1A 00 73 00 20 30 93 08 00 00
73 00 00 00 93 08 10 00 73 00 00 00 13 05 00 00
B7 05 10 00 13 06 00 00 93 06 F0 08 13 07 80 00
93 08 80 00 73 00 00 00 EF 00 40 0B B7 02 10 00
23 20 50 00 03 23 00 00 63 9C 62 0C 23 AE 52 FE
03 A3 C2 FF 63 96 62 0C B7 02 10 00 23 A0 02 00
13 00 00 00 13 00 00 00 13 00 00 00 93 02 10 00
63 14 54 08 93 08 00 00 73 00 00 00 13 05 00 00
93 05 00 00 37 06 10 00 93 06 F0 09 93 06 80 01
93 08 80 00 73 00 00 00 EF 00 C0 02 B7 02 10 00
63 18 54 0A 93 08 00 00 73 00 00 00 13 04 00 00
13 05 00 00 93 05 00 00 37 06 10 00 93 06 F0 09
93 06 80 01 93 08 80 00 73 00 00 00 EF 00 00 05
B7 02 10 00 23 20 50 00 03 23 00 00 63 9A 62 06
23 AE 52 FE 03 A3 C2 FF 63 94 62 06 B7 02 10 00
23 A0 02 00 13 00 00 00 13 00 00 00 13 00 00 00
93 02 10 00 63 12 54 04 93 08 00 00 73 00 00 00
6F 00 C0 05 93 02 00 00 13 03 A0 00 93 03 00 00
13 0E 00 00 B3 83 53 00 23 20 7E 00 93 83 13 00
83 23 0E 00 93 82 12 00 13 9E 22 00 E3 94 62 FE
67 80 00 00 63 14 30 02 0F 00 F0 0F 63 80 01 00
93 91 11 00 93 E1 11 00 93 08 D0 05 13 85 01 00
93 8F 1F 00 73 00 10 00 73 00 10 00 0F 00 F0 0F
93 01 10 00 93 08 D0 05 13 05 00 00 73 00 10 00
73 00 10 00 73 10 00 C0 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
93 02 10 00 63 16 54 04 13 04 00 00 93 08 00 00
73 00 00 00 13 04 00 00 6F 00 C0 05 93 02 00 00
13 03 A0 00 93 03 00 00 13 0E 00 00 B3 83 53 00
23 20 7E 00 93 83 13 00 83 23 0E 00 93 82 12 00
13 9E 22 00 E3 94 62 FE 67 80 00 00 63 14 30 02
0F 00 F0 0F 63 80 01 00 93 91 11 00 93 E1 11 00
93 08 D0 05 13 85 01 00 93 8F 1F 00 73 00 10 00
73 00 10 00 0F 00 F0 0F 93 01 10 00 93 08 D0 05
13 05 00 00 73 00 10 00 73 00 10 00 73 10 00 C0
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00
@00011000
Expand Down
Loading

0 comments on commit a12eeeb

Please sign in to comment.