From 78c87cd13a75c167a693b173e6e2e0e44ad57328 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Sat, 30 Mar 2019 18:43:49 +0530 Subject: [PATCH] include: Make mstatus parameter optional for get_insn() The mstatus parameter of get_insn() is used to return MSTATUS CSR value which get_insn() saw. Most of the get_insn() callers don't use the value returned in mstatus so this patch makes mstatus parameter optional for get_insn(). Signed-off-by: Anup Patel --- include/sbi/riscv_unpriv.h | 7 ++++--- lib/sbi_illegal_insn.c | 7 ++----- lib/sbi_misaligned_ldst.c | 6 ++---- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/include/sbi/riscv_unpriv.h b/include/sbi/riscv_unpriv.h index c109417..bd134b5 100644 --- a/include/sbi/riscv_unpriv.h +++ b/include/sbi/riscv_unpriv.h @@ -82,7 +82,7 @@ static inline ulong get_insn(ulong mepc, ulong *mstatus) #endif "csrw "STR(CSR_MSTATUS)", %[mstatus]" : [mstatus] "+&r" (__mstatus), [insn] "=&r" (val) - : [mprv] "r" (MSTATUS_MPRV | MSTATUS_MXR), [addr] "r" (__mepc)); + : [mprv] "r" (MSTATUS_MPRV|MSTATUS_MXR), [addr] "r" (__mepc)); #else ulong rvc_mask = 3, tmp; asm ("csrrs %[mstatus], "STR(CSR_MSTATUS)", %[mprv]\n" @@ -107,10 +107,11 @@ static inline ulong get_insn(ulong mepc, ulong *mstatus) "add %[insn], %[insn], %[tmp]\n" "2: csrw "STR(CSR_MSTATUS)", %[mstatus]" : [mstatus] "+&r" (__mstatus), [insn] "=&r" (val), [tmp] "=&r" (tmp) - : [mprv] "r" (MSTATUS_MPRV | MSTATUS_MXR), [addr] "r" (__mepc), + : [mprv] "r" (MSTATUS_MPRV|MSTATUS_MXR), [addr] "r" (__mepc), [rvc_mask] "r" (rvc_mask), [xlen_minus_16] "i" (__riscv_xlen - 16)); #endif - *mstatus = __mstatus; + if (mstatus) + *mstatus = __mstatus; return val; } diff --git a/lib/sbi_illegal_insn.c b/lib/sbi_illegal_insn.c index 820f96c..7184fea 100644 --- a/lib/sbi_illegal_insn.c +++ b/lib/sbi_illegal_insn.c @@ -122,14 +122,11 @@ int sbi_illegal_insn_handler(u32 hartid, ulong mcause, struct sbi_trap_regs *regs, struct sbi_scratch *scratch) { - ulong mstatus; ulong insn = csr_read(mbadaddr); if (unlikely((insn & 3) != 3)) { - if (insn == 0) { - mstatus = csr_read(CSR_MSTATUS); - insn = get_insn(regs->mepc, &mstatus); - } + if (insn == 0) + insn = get_insn(regs->mepc, NULL); if ((insn & 3) != 3) return truly_illegal_insn(insn, hartid, mcause, regs, scratch); diff --git a/lib/sbi_misaligned_ldst.c b/lib/sbi_misaligned_ldst.c index 3fe67ea..5b2df93 100644 --- a/lib/sbi_misaligned_ldst.c +++ b/lib/sbi_misaligned_ldst.c @@ -26,8 +26,7 @@ int sbi_misaligned_load_handler(u32 hartid, ulong mcause, struct sbi_scratch *scratch) { union reg_data val; - ulong mstatus = csr_read(CSR_MSTATUS); - ulong insn = get_insn(regs->mepc, &mstatus); + ulong insn = get_insn(regs->mepc, NULL); ulong addr = csr_read(CSR_MTVAL); int i, fp = 0, shift = 0, len = 0; @@ -112,8 +111,7 @@ int sbi_misaligned_store_handler(u32 hartid, ulong mcause, struct sbi_scratch *scratch) { union reg_data val; - ulong mstatus = csr_read(CSR_MSTATUS); - ulong insn = get_insn(regs->mepc, &mstatus); + ulong insn = get_insn(regs->mepc, NULL); ulong addr = csr_read(CSR_MTVAL); int i, len = 0; -- 2.7.4