mirror of
https://github.com/Fishwaldo/opensbi.git
synced 2025-07-11 07:28:20 +00:00
lib: sbi_trap: Add helper to get GVA in sbi_trap_regs
The GVA bit is in mstatus on RV64, and in mstatush in RV32. Refactor code handling this in sbi_trap_handler into a helper function to extract GVA from sbi_trap_regs, so that future code accessing GVA can be XLEN-agnostic. Signed-off-by: Vivian Wang <dramforever@live.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
parent
19664f6757
commit
37a0d83b6d
2 changed files with 19 additions and 13 deletions
|
@ -10,6 +10,8 @@
|
||||||
#ifndef __SBI_TRAP_H__
|
#ifndef __SBI_TRAP_H__
|
||||||
#define __SBI_TRAP_H__
|
#define __SBI_TRAP_H__
|
||||||
|
|
||||||
|
#include <sbi/riscv_encoding.h>
|
||||||
|
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
|
|
||||||
/** Index of zero member in sbi_trap_regs */
|
/** Index of zero member in sbi_trap_regs */
|
||||||
|
@ -206,6 +208,22 @@ struct sbi_trap_info {
|
||||||
unsigned long gva;
|
unsigned long gva;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline unsigned long sbi_regs_gva(const struct sbi_trap_regs *regs)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
return (regs->mstatusH & MSTATUSH_GVA) ? 1 : 0;
|
||||||
|
#else
|
||||||
|
return (regs->mstatus & MSTATUS_GVA) ? 1 : 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int sbi_trap_redirect(struct sbi_trap_regs *regs,
|
int sbi_trap_redirect(struct sbi_trap_regs *regs,
|
||||||
struct sbi_trap_info *trap);
|
struct sbi_trap_info *trap);
|
||||||
|
|
||||||
|
|
|
@ -316,19 +316,7 @@ struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs)
|
||||||
trap.tval = mtval;
|
trap.tval = mtval;
|
||||||
trap.tval2 = mtval2;
|
trap.tval2 = mtval2;
|
||||||
trap.tinst = mtinst;
|
trap.tinst = mtinst;
|
||||||
|
trap.gva = sbi_regs_gva(regs);
|
||||||
/*
|
|
||||||
* 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);
|
rc = sbi_trap_redirect(regs, &trap);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue