diff options
| author | Xiang W <[email protected]> | 2022-05-26 22:14:44 +0800 |
|---|---|---|
| committer | Anup Patel <[email protected]> | 2022-05-30 10:22:13 +0530 |
| commit | f067bb84cf2dd6493ff3fa49294d3ec80481ad75 (patch) | |
| tree | 2fb2a81c33b807e24fac4d789ca33f86e074c353 | |
| parent | 1bc67db80cb0a10d8ebbaaf550a79eee2a07158e (diff) | |
lib: sbi: fix system_opcode_insn
If the csr's operation comes from M mode, it should not be forwarded
to low-privilege processing, this patch fixes this problem.
Signed-off-by: Xiang W <[email protected]>
Reviewed-by: Anup Patel <[email protected]>
| -rw-r--r-- | lib/sbi/sbi_illegal_insn.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/sbi/sbi_illegal_insn.c b/lib/sbi/sbi_illegal_insn.c index bfe7d619..388ad55d 100644 --- a/lib/sbi/sbi_illegal_insn.c +++ b/lib/sbi/sbi_illegal_insn.c @@ -16,6 +16,7 @@ #include <sbi/sbi_pmu.h> #include <sbi/sbi_trap.h> #include <sbi/sbi_unpriv.h> +#include <sbi/sbi_console.h> typedef int (*illegal_insn_func)(ulong insn, struct sbi_trap_regs *regs); @@ -37,8 +38,15 @@ static int system_opcode_insn(ulong insn, struct sbi_trap_regs *regs) int do_write, rs1_num = (insn >> 15) & 0x1f; ulong rs1_val = GET_RS1(insn, regs); int csr_num = (u32)insn >> 20; + ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT; ulong csr_val, new_csr_val; + if (prev_mode == PRV_M) { + sbi_printf("%s: Failed to access CSR %#x from M-mode", + __func__, csr_num); + return SBI_EFAIL; + } + /* TODO: Ensure that we got CSR read/write instruction */ if (sbi_emulate_csr_read(csr_num, regs, &csr_val)) |
