lib: sbi: abstract out insn decoding to unify mem fault handlers
authorBo Gan <ganboing@gmail.com>
Wed, 6 Mar 2024 02:35:38 +0000 (18:35 -0800)
committerAnup Patel <anup@brainfault.org>
Mon, 11 Mar 2024 05:20:39 +0000 (10:50 +0530)
commit4c112650bbb0611de4939c749e2a34c8168e09f7
tree3d14f806a2cc3993bbdeec3224a87ae5d9a123a5
parent9221fe58d1e65d0a1b6f62098c814994ce04dd5d
lib: sbi: abstract out insn decoding to unify mem fault handlers

This patch abstracts out the instruction decoding part of misaligned ld/st
fault handlers, so it can be reused by ld/st access fault handlers.
Also Added lb/lbu/sb decoding. (previously unreachable by misaligned fault)

sbi_trap_emulate_load/store is now the common handler which takes a `emu`
parameter that is responsible for emulating the misaligned or access fault.
The `emu` callback is expected to fixup the fault, and based on the return
code of `emu`, sbi_trap_emulate_load/store will:

  r/wlen => the fixup is successful and regs/mepc needs to be updated.
  0      => the fixup is successful, but regs/mepc should be left untouched
            (this is usually used if `emu` does `sbi_trap_redirect`)
  -err   => failed, sbi_trap_error will be called

For now, load/store access faults are blindly redirected. It will be
enhanced in the following patches.

Signed-off-by: Bo Gan <ganboing@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
include/sbi/sbi_trap_ldst.h
lib/sbi/sbi_trap.c
lib/sbi/sbi_trap_ldst.c