diff options
author | Vivian Wang <dramforever@live.com> | 2022-08-04 17:32:29 +0300 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2022-08-22 06:19:49 +0300 |
commit | 1c4ce74f5128b7e1094ad253c9bc5fd732e3d82b (patch) | |
tree | 3235779bfcecd71c5921e09d08c9657ef6a71509 | |
parent | 1fbe7778c9843930ce3dadb35804d56e1f782479 (diff) | |
download | opensbi-1c4ce74f5128b7e1094ad253c9bc5fd732e3d82b.tar.xz |
lib: sbi: Set gva when creating sbi_trap_info
In some cases the sbi_trap_info argument passed to sbi_trap_redirect is
created from scratch by filling its fields. Since we previously added a
gva field to struct sbi_trap_info, initialize gva in these cases also.
Suggested-by: Andrew Jones <ajones@ventanamicro.com>
Signed-off-by: Vivian Wang <dramforever@live.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
-rw-r--r-- | lib/sbi/sbi_illegal_insn.c | 1 | ||||
-rw-r--r-- | lib/sbi/sbi_misaligned_ldst.c | 2 | ||||
-rw-r--r-- | lib/sbi/sbi_trap.c | 14 |
3 files changed, 17 insertions, 0 deletions
diff --git a/lib/sbi/sbi_illegal_insn.c b/lib/sbi/sbi_illegal_insn.c index 84c04f8..ecd3508 100644 --- a/lib/sbi/sbi_illegal_insn.c +++ b/lib/sbi/sbi_illegal_insn.c @@ -30,6 +30,7 @@ static int truly_illegal_insn(ulong insn, struct sbi_trap_regs *regs) trap.tval = insn; trap.tval2 = 0; trap.tinst = 0; + trap.gva = 0; return sbi_trap_redirect(regs, &trap); } diff --git a/lib/sbi/sbi_misaligned_ldst.c b/lib/sbi/sbi_misaligned_ldst.c index fd11798..92a2393 100644 --- a/lib/sbi/sbi_misaligned_ldst.c +++ b/lib/sbi/sbi_misaligned_ldst.c @@ -129,6 +129,7 @@ int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst, uptrap.tval = addr; uptrap.tval2 = tval2; uptrap.tinst = tinst; + uptrap.gva = 0; return sbi_trap_redirect(regs, &uptrap); } @@ -244,6 +245,7 @@ int sbi_misaligned_store_handler(ulong addr, ulong tval2, ulong tinst, uptrap.tval = addr; uptrap.tval2 = tval2; uptrap.tinst = tinst; + uptrap.gva = 0; return sbi_trap_redirect(regs, &uptrap); } diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index ee3e4e9..db70c26 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -311,6 +311,20 @@ struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs) trap.tval = mtval; trap.tval2 = mtval2; trap.tinst = mtinst; + + /* + * If the hypervisor extension is not implemented, + * mstatus[h].GVA is a WPRI field, which is guaranteed to read + * as zero. In addition, in this case we don't read mstatush and + * instead pretend it is zero, which handles privileged spec + * version < 1.12. + */ +#if __riscv_xlen == 32 + trap.gva = (regs->mstatusH & MSTATUSH_GVA) ? 1 : 0; +#else + trap.gva = (regs->mstatus & MSTATUS_GVA) ? 1 : 0; +#endif + rc = sbi_trap_redirect(regs, &trap); break; }; |