Skip to content

Commit

Permalink
Merge pull request chipsalliance#903 from marnovandermaas/pmp_mml_tra…
Browse files Browse the repository at this point in the history
…p_fixes

[pmp] Fix ePMP related trap handling
  • Loading branch information
weicaiyang authored Oct 24, 2022
2 parents e0eae9e + c2eb8fa commit ada58fc
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 121 deletions.
11 changes: 7 additions & 4 deletions src/riscv_asm_program_gen.sv
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ class riscv_asm_program_gen extends uvm_object;
virtual function void gen_pmp_csr_write(int hart);
string instr[$];
if (riscv_instr_pkg::support_pmp && cfg.pmp_cfg.enable_write_pmp_csr) begin
cfg.pmp_cfg.gen_pmp_write_test({cfg.scratch_reg, cfg.pmp_reg}, instr);
cfg.pmp_cfg.gen_pmp_write_test({cfg.scratch_reg, cfg.pmp_reg[0]}, instr);
gen_section(get_label("pmp_csr_write_test", hart), instr);
end
endfunction
Expand Down Expand Up @@ -1216,7 +1216,8 @@ class riscv_asm_program_gen extends uvm_object;
gen_signature_handshake(instr, CORE_STATUS, INSTR_FAULT_EXCEPTION);
gen_signature_handshake(.instr(instr), .signature_type(WRITE_CSR), .csr(MCAUSE));
if (cfg.pmp_cfg.enable_pmp_exception_handler) begin
cfg.pmp_cfg.gen_pmp_exception_routine({cfg.gpr, cfg.scratch_reg, cfg.pmp_reg},
cfg.pmp_cfg.gen_pmp_exception_routine({cfg.gpr, cfg.scratch_reg, cfg.pmp_reg[0],
cfg.pmp_reg[1]},
INSTRUCTION_ACCESS_FAULT,
instr);
end
Expand All @@ -1231,7 +1232,8 @@ class riscv_asm_program_gen extends uvm_object;
gen_signature_handshake(instr, CORE_STATUS, LOAD_FAULT_EXCEPTION);
gen_signature_handshake(.instr(instr), .signature_type(WRITE_CSR), .csr(MCAUSE));
if (cfg.pmp_cfg.enable_pmp_exception_handler) begin
cfg.pmp_cfg.gen_pmp_exception_routine({cfg.gpr, cfg.scratch_reg, cfg.pmp_reg},
cfg.pmp_cfg.gen_pmp_exception_routine({cfg.gpr, cfg.scratch_reg, cfg.pmp_reg[0],
cfg.pmp_reg[1]},
LOAD_ACCESS_FAULT,
instr);
end
Expand All @@ -1246,7 +1248,8 @@ class riscv_asm_program_gen extends uvm_object;
gen_signature_handshake(instr, CORE_STATUS, STORE_FAULT_EXCEPTION);
gen_signature_handshake(.instr(instr), .signature_type(WRITE_CSR), .csr(MCAUSE));
if (cfg.pmp_cfg.enable_pmp_exception_handler) begin
cfg.pmp_cfg.gen_pmp_exception_routine({cfg.gpr, cfg.scratch_reg, cfg.pmp_reg},
cfg.pmp_cfg.gen_pmp_exception_routine({cfg.gpr, cfg.scratch_reg, cfg.pmp_reg[0],
cfg.pmp_reg[1]},
STORE_AMO_ACCESS_FAULT,
instr);
end
Expand Down
9 changes: 6 additions & 3 deletions src/riscv_instr_gen_config.sv
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class riscv_instr_gen_config extends uvm_object;
// Can overlap with the other GPRs used in the random generation,
// as PMP exception handler is hardcoded and does not include any
// random instructions.
rand riscv_reg_t pmp_reg;
rand riscv_reg_t pmp_reg[2];
// Use a random register for stack pointer/thread pointer
rand riscv_reg_t sp;
rand riscv_reg_t tp;
Expand Down Expand Up @@ -430,10 +430,13 @@ class riscv_instr_gen_config extends uvm_object;
!(scratch_reg inside {ZERO, sp, tp, ra, GP});
}

// This reg is only used inside PMP exception routine,
// These registers is only used inside PMP exception routine,
// so we can be a bit looser with constraints.
constraint reserve_pmp_reg_c {
!(pmp_reg inside {ZERO, sp, tp});
foreach (pmp_reg[i]) {
!(pmp_reg[i] inside {ZERO, sp, tp, scratch_reg});
}
unique {pmp_reg};
}

constraint gpr_c {
Expand Down
4 changes: 4 additions & 0 deletions src/riscv_instr_pkg.sv
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,8 @@ package riscv_instr_pkg;
// The offset from the address of <main> - automatically populated by the
// PMP generation routine.
bit [XLEN - 1 : 0] offset;
// The size of the region in case of NAPOT and overlap in case of TOR.
integer addr_mode;
`else
typedef struct{
rand bit l;
Expand All @@ -1258,6 +1260,8 @@ package riscv_instr_pkg;
// The offset from the address of <main> - automatically populated by the
// PMP generation routine.
rand bit [XLEN - 1 : 0] offset;
// The size of the region in case of NAPOT and allows for top less than bottom in TOR when 0.
rand integer addr_mode;
`endif
} pmp_cfg_reg_t;

Expand Down
Loading

0 comments on commit ada58fc

Please sign in to comment.