mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-06-17 16:41:19 +01:00
lib: sbi: Do not override emulator callback for vector load/store
It's wrong to override the emulator callback in sbi_trap_emulate_load/
store. The function must respect the callback function passed in the
parameter. Hence, let the misaligned emulator callback decide when to
use sbi_misaligned_v_ld/st_emulator. To clean up things, also make the
following changes:
- Add the `insn` parameter to the callback. The trapping insn has been
fetched by the caller already, whether transformed or directly loaded,
thus saving the trouble in the callback. Note that you must not rely
on the length of the `insn`, as it can be a transformed one from tinst
- Also the `tcntx` is added, providing the callback with register values
to handle vector insn or other customized insns.
- Clarify that the read/write length (rlen/wlen) can be 0, in which
case it could be a vector load/store or some customized instruction.
The callback is responsible to handle it accordingly.
Also fixed issues in the sbi_misaligned_v_ld/st_emulator:
a. Redirect the trap when OPENSBI_CC_SUPPORT_VECTOR is not available.
b. Ensure the return code is >0 when no faults are redirected.
Fixes: c2acc5e5b0 ("lib: sbi_misaligned_ldst: Add handling of vector load/store")
Signed-off-by: Bo Gan <ganboing@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Tested-by: Anirudh Srinivasan <asrinivasan@oss.tenstorrent.com>
Link: https://lore.kernel.org/r/20260605113214.242-6-ganboing@gmail.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
@@ -137,13 +137,11 @@ static inline void vsetvl(ulong vl, ulong vtype)
|
||||
:: "r" (vl), "r" (vtype));
|
||||
}
|
||||
|
||||
int sbi_misaligned_v_ld_emulator(int rlen, union sbi_ldst_data *out_val,
|
||||
struct sbi_trap_context *tcntx)
|
||||
int sbi_misaligned_v_ld_emulator(ulong insn, struct sbi_trap_context *tcntx)
|
||||
{
|
||||
const struct sbi_trap_info *orig_trap = &tcntx->trap;
|
||||
struct sbi_trap_regs *regs = &tcntx->regs;
|
||||
struct sbi_trap_info uptrap;
|
||||
ulong insn = sbi_get_insn(regs->mepc, &uptrap);
|
||||
ulong vl = csr_read(CSR_VL);
|
||||
ulong vtype = csr_read(CSR_VTYPE);
|
||||
ulong vlenb = csr_read(CSR_VLENB);
|
||||
@@ -234,16 +232,15 @@ int sbi_misaligned_v_ld_emulator(int rlen, union sbi_ldst_data *out_val,
|
||||
/* restore clobbered vl/vtype */
|
||||
vsetvl(vl, vtype);
|
||||
|
||||
return vl;
|
||||
/* Return a >0 value for the caller to advance mepc */
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sbi_misaligned_v_st_emulator(int wlen, union sbi_ldst_data in_val,
|
||||
struct sbi_trap_context *tcntx)
|
||||
int sbi_misaligned_v_st_emulator(ulong insn, struct sbi_trap_context *tcntx)
|
||||
{
|
||||
const struct sbi_trap_info *orig_trap = &tcntx->trap;
|
||||
struct sbi_trap_regs *regs = &tcntx->regs;
|
||||
struct sbi_trap_info uptrap;
|
||||
ulong insn = sbi_get_insn(regs->mepc, &uptrap);
|
||||
ulong vl = csr_read(CSR_VL);
|
||||
ulong vtype = csr_read(CSR_VTYPE);
|
||||
ulong vlenb = csr_read(CSR_VLENB);
|
||||
@@ -328,17 +325,17 @@ int sbi_misaligned_v_st_emulator(int wlen, union sbi_ldst_data in_val,
|
||||
/* restore clobbered vl/vtype */
|
||||
vsetvl(vl, vtype);
|
||||
|
||||
return vl;
|
||||
/* Return a >0 value for the caller to advance mepc */
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
int sbi_misaligned_v_ld_emulator(int rlen, union sbi_ldst_data *out_val,
|
||||
struct sbi_trap_context *tcntx)
|
||||
int sbi_misaligned_v_ld_emulator(ulong insn, struct sbi_trap_context *tcntx)
|
||||
{
|
||||
/* Unable to emulate, send trap to previous mode. */
|
||||
return sbi_trap_redirect(&tcntx->regs, &tcntx->trap);
|
||||
}
|
||||
int sbi_misaligned_v_st_emulator(int wlen, union sbi_ldst_data in_val,
|
||||
struct sbi_trap_context *tcntx)
|
||||
|
||||
int sbi_misaligned_v_st_emulator(ulong insn, struct sbi_trap_context *tcntx)
|
||||
{
|
||||
/* Unable to emulate, send trap to previous mode. */
|
||||
return sbi_trap_redirect(&tcntx->regs, &tcntx->trap);
|
||||
|
||||
Reference in New Issue
Block a user