aboutsummaryrefslogtreecommitdiff
path: root/lib/sbi/sbi_hart.c
diff options
context:
space:
mode:
authorgagachang <vivahavey@gmail.com>2022-07-15 01:29:41 +0800
committerAnup Patel <anup@brainfault.org>2022-07-20 10:05:33 +0530
commit0374ccf3f13e11f98da8158d9a5fa2a8607fe50e (patch)
tree67f14c694088575d62b8f6aab2a3cff0f94df8e2 /lib/sbi/sbi_hart.c
parentcaa5eeacacbc935090968e601716f66a6195ceef (diff)
downloadopensbi-0374ccf3f13e11f98da8158d9a5fa2a8607fe50e.zip
opensbi-0374ccf3f13e11f98da8158d9a5fa2a8607fe50e.tar.gz
opensbi-0374ccf3f13e11f98da8158d9a5fa2a8607fe50e.tar.bz2
lib: sbi_hart: Shorten the code to set MPV bit
MPV bit is set when the value of next_virt boolean variable equals true. Since the value of next_virt is either 0 or 1, we can set MPV bit without if-else logic. Signed-off-by: Che-Chia Chang <alvinga@andestech.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'lib/sbi/sbi_hart.c')
-rw-r--r--lib/sbi/sbi_hart.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index de86fee..67b685a 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -769,19 +769,12 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
#if __riscv_xlen == 32
if (misa_extension('H')) {
valH = csr_read(CSR_MSTATUSH);
- if (next_virt)
- valH = INSERT_FIELD(valH, MSTATUSH_MPV, 1);
- else
- valH = INSERT_FIELD(valH, MSTATUSH_MPV, 0);
+ valH = INSERT_FIELD(valH, MSTATUSH_MPV, next_virt);
csr_write(CSR_MSTATUSH, valH);
}
#else
- if (misa_extension('H')) {
- if (next_virt)
- val = INSERT_FIELD(val, MSTATUS_MPV, 1);
- else
- val = INSERT_FIELD(val, MSTATUS_MPV, 0);
- }
+ if (misa_extension('H'))
+ val = INSERT_FIELD(val, MSTATUS_MPV, next_virt);
#endif
csr_write(CSR_MSTATUS, val);
csr_write(CSR_MEPC, next_addr);