mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 23:41:23 +01:00
lib: sbi: Fixup tinst for exceptions in sbi_misaligned_*()
If there is an exception while emulating a misaligned load/store, fixup uptrap.tinst before redirecting. Otherwise, HS-mode software may receive an htinst describing the lbu/sb instruction that faulted during emulation[1]. [1]: https://github.com/riscv-software-src/opensbi/issues/258 Signed-off-by: dramforever <dramforever@live.com> Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
@@ -22,6 +22,18 @@ union reg_data {
|
|||||||
u64 data_u64;
|
u64 data_u64;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static ulong sbi_misaligned_tinst_fixup(ulong orig_tinst, ulong new_tinst,
|
||||||
|
ulong addr_offset)
|
||||||
|
{
|
||||||
|
if (new_tinst == INSN_PSEUDO_VS_LOAD ||
|
||||||
|
new_tinst == INSN_PSEUDO_VS_STORE)
|
||||||
|
return new_tinst;
|
||||||
|
else if (orig_tinst == 0)
|
||||||
|
return 0UL;
|
||||||
|
else
|
||||||
|
return orig_tinst | (addr_offset << SH_RS1);
|
||||||
|
}
|
||||||
|
|
||||||
int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst,
|
int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst,
|
||||||
struct sbi_trap_regs *regs)
|
struct sbi_trap_regs *regs)
|
||||||
{
|
{
|
||||||
@@ -126,6 +138,8 @@ int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst,
|
|||||||
&uptrap);
|
&uptrap);
|
||||||
if (uptrap.cause) {
|
if (uptrap.cause) {
|
||||||
uptrap.epc = regs->mepc;
|
uptrap.epc = regs->mepc;
|
||||||
|
uptrap.tinst = sbi_misaligned_tinst_fixup(
|
||||||
|
tinst, uptrap.tinst, i);
|
||||||
return sbi_trap_redirect(regs, &uptrap);
|
return sbi_trap_redirect(regs, &uptrap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,6 +252,8 @@ int sbi_misaligned_store_handler(ulong addr, ulong tval2, ulong tinst,
|
|||||||
&uptrap);
|
&uptrap);
|
||||||
if (uptrap.cause) {
|
if (uptrap.cause) {
|
||||||
uptrap.epc = regs->mepc;
|
uptrap.epc = regs->mepc;
|
||||||
|
uptrap.tinst = sbi_misaligned_tinst_fixup(
|
||||||
|
tinst, uptrap.tinst, i);
|
||||||
return sbi_trap_redirect(regs, &uptrap);
|
return sbi_trap_redirect(regs, &uptrap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user