mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-25 07:41:42 +01:00
lib: sbi: Simplify parameters of misaligned and access fault handlers
The struct sbi_trap_context already has the information needed by misaligned load/store and access fault load/store handlers so directly pass struct sbi_trap_context pointer to these functions. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Clément Léger <cleger@rivosinc.com>
This commit is contained in:
@@ -20,16 +20,12 @@ union sbi_ldst_data {
|
|||||||
ulong data_ulong;
|
ulong data_ulong;
|
||||||
};
|
};
|
||||||
|
|
||||||
int sbi_misaligned_load_handler(struct sbi_trap_regs *regs,
|
int sbi_misaligned_load_handler(struct sbi_trap_context *tcntx);
|
||||||
const struct sbi_trap_info *orig_trap);
|
|
||||||
|
|
||||||
int sbi_misaligned_store_handler(struct sbi_trap_regs *regs,
|
int sbi_misaligned_store_handler(struct sbi_trap_context *tcntx);
|
||||||
const struct sbi_trap_info *orig_trap);
|
|
||||||
|
|
||||||
int sbi_load_access_handler(struct sbi_trap_regs *regs,
|
int sbi_load_access_handler(struct sbi_trap_context *tcntx);
|
||||||
const struct sbi_trap_info *orig_trap);
|
|
||||||
|
|
||||||
int sbi_store_access_handler(struct sbi_trap_regs *regs,
|
int sbi_store_access_handler(struct sbi_trap_context *tcntx);
|
||||||
const struct sbi_trap_info *orig_trap);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -290,12 +290,12 @@ struct sbi_trap_context *sbi_trap_handler(struct sbi_trap_context *tcntx)
|
|||||||
break;
|
break;
|
||||||
case CAUSE_MISALIGNED_LOAD:
|
case CAUSE_MISALIGNED_LOAD:
|
||||||
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_LOAD);
|
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_LOAD);
|
||||||
rc = sbi_misaligned_load_handler(regs, trap);
|
rc = sbi_misaligned_load_handler(tcntx);
|
||||||
msg = "misaligned load handler failed";
|
msg = "misaligned load handler failed";
|
||||||
break;
|
break;
|
||||||
case CAUSE_MISALIGNED_STORE:
|
case CAUSE_MISALIGNED_STORE:
|
||||||
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_STORE);
|
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_STORE);
|
||||||
rc = sbi_misaligned_store_handler(regs, trap);
|
rc = sbi_misaligned_store_handler(tcntx);
|
||||||
msg = "misaligned store handler failed";
|
msg = "misaligned store handler failed";
|
||||||
break;
|
break;
|
||||||
case CAUSE_SUPERVISOR_ECALL:
|
case CAUSE_SUPERVISOR_ECALL:
|
||||||
@@ -305,12 +305,12 @@ struct sbi_trap_context *sbi_trap_handler(struct sbi_trap_context *tcntx)
|
|||||||
break;
|
break;
|
||||||
case CAUSE_LOAD_ACCESS:
|
case CAUSE_LOAD_ACCESS:
|
||||||
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ACCESS_LOAD);
|
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ACCESS_LOAD);
|
||||||
rc = sbi_load_access_handler(regs, trap);
|
rc = sbi_load_access_handler(tcntx);
|
||||||
msg = "load fault handler failed";
|
msg = "load fault handler failed";
|
||||||
break;
|
break;
|
||||||
case CAUSE_STORE_ACCESS:
|
case CAUSE_STORE_ACCESS:
|
||||||
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ACCESS_STORE);
|
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ACCESS_STORE);
|
||||||
rc = sbi_store_access_handler(regs, trap);
|
rc = sbi_store_access_handler(tcntx);
|
||||||
msg = "store fault handler failed";
|
msg = "store fault handler failed";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@@ -12,7 +12,6 @@
|
|||||||
#include <sbi/riscv_fp.h>
|
#include <sbi/riscv_fp.h>
|
||||||
#include <sbi/sbi_error.h>
|
#include <sbi/sbi_error.h>
|
||||||
#include <sbi/sbi_trap_ldst.h>
|
#include <sbi/sbi_trap_ldst.h>
|
||||||
#include <sbi/sbi_pmu.h>
|
|
||||||
#include <sbi/sbi_trap.h>
|
#include <sbi/sbi_trap.h>
|
||||||
#include <sbi/sbi_unpriv.h>
|
#include <sbi/sbi_unpriv.h>
|
||||||
#include <sbi/sbi_platform.h>
|
#include <sbi/sbi_platform.h>
|
||||||
@@ -23,8 +22,7 @@
|
|||||||
* @return rlen=success, 0=success w/o regs modification, or negative error
|
* @return rlen=success, 0=success w/o regs modification, or negative error
|
||||||
*/
|
*/
|
||||||
typedef int (*sbi_trap_ld_emulator)(int rlen, union sbi_ldst_data *out_val,
|
typedef int (*sbi_trap_ld_emulator)(int rlen, union sbi_ldst_data *out_val,
|
||||||
struct sbi_trap_regs *regs,
|
struct sbi_trap_context *tcntx);
|
||||||
const struct sbi_trap_info *orig_trap);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store emulator callback:
|
* Store emulator callback:
|
||||||
@@ -32,8 +30,7 @@ typedef int (*sbi_trap_ld_emulator)(int rlen, union sbi_ldst_data *out_val,
|
|||||||
* @return wlen=success, 0=success w/o regs modification, or negative error
|
* @return wlen=success, 0=success w/o regs modification, or negative error
|
||||||
*/
|
*/
|
||||||
typedef int (*sbi_trap_st_emulator)(int wlen, union sbi_ldst_data in_val,
|
typedef int (*sbi_trap_st_emulator)(int wlen, union sbi_ldst_data in_val,
|
||||||
struct sbi_trap_regs *regs,
|
struct sbi_trap_context *tcntx);
|
||||||
const struct sbi_trap_info *orig_trap);
|
|
||||||
|
|
||||||
static ulong sbi_misaligned_tinst_fixup(ulong orig_tinst, ulong new_tinst,
|
static ulong sbi_misaligned_tinst_fixup(ulong orig_tinst, ulong new_tinst,
|
||||||
ulong addr_offset)
|
ulong addr_offset)
|
||||||
@@ -47,10 +44,11 @@ static ulong sbi_misaligned_tinst_fixup(ulong orig_tinst, ulong new_tinst,
|
|||||||
return orig_tinst | (addr_offset << SH_RS1);
|
return orig_tinst | (addr_offset << SH_RS1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sbi_trap_emulate_load(struct sbi_trap_regs *regs,
|
static int sbi_trap_emulate_load(struct sbi_trap_context *tcntx,
|
||||||
const struct sbi_trap_info *orig_trap,
|
|
||||||
sbi_trap_ld_emulator emu)
|
sbi_trap_ld_emulator emu)
|
||||||
{
|
{
|
||||||
|
const struct sbi_trap_info *orig_trap = &tcntx->trap;
|
||||||
|
struct sbi_trap_regs *regs = &tcntx->regs;
|
||||||
ulong insn, insn_len;
|
ulong insn, insn_len;
|
||||||
union sbi_ldst_data val = { 0 };
|
union sbi_ldst_data val = { 0 };
|
||||||
struct sbi_trap_info uptrap;
|
struct sbi_trap_info uptrap;
|
||||||
@@ -150,8 +148,7 @@ static int sbi_trap_emulate_load(struct sbi_trap_regs *regs,
|
|||||||
return sbi_trap_redirect(regs, orig_trap);
|
return sbi_trap_redirect(regs, orig_trap);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = emu(len, &val, regs, orig_trap);
|
rc = emu(len, &val, tcntx);
|
||||||
|
|
||||||
if (rc <= 0)
|
if (rc <= 0)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
@@ -169,10 +166,11 @@ static int sbi_trap_emulate_load(struct sbi_trap_regs *regs,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sbi_trap_emulate_store(struct sbi_trap_regs *regs,
|
static int sbi_trap_emulate_store(struct sbi_trap_context *tcntx,
|
||||||
const struct sbi_trap_info *orig_trap,
|
|
||||||
sbi_trap_st_emulator emu)
|
sbi_trap_st_emulator emu)
|
||||||
{
|
{
|
||||||
|
const struct sbi_trap_info *orig_trap = &tcntx->trap;
|
||||||
|
struct sbi_trap_regs *regs = &tcntx->regs;
|
||||||
ulong insn, insn_len;
|
ulong insn, insn_len;
|
||||||
union sbi_ldst_data val;
|
union sbi_ldst_data val;
|
||||||
struct sbi_trap_info uptrap;
|
struct sbi_trap_info uptrap;
|
||||||
@@ -254,8 +252,7 @@ static int sbi_trap_emulate_store(struct sbi_trap_regs *regs,
|
|||||||
return sbi_trap_redirect(regs, orig_trap);
|
return sbi_trap_redirect(regs, orig_trap);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = emu(len, val, regs, orig_trap);
|
rc = emu(len, val, tcntx);
|
||||||
|
|
||||||
if (rc <= 0)
|
if (rc <= 0)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
@@ -265,9 +262,10 @@ static int sbi_trap_emulate_store(struct sbi_trap_regs *regs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int sbi_misaligned_ld_emulator(int rlen, union sbi_ldst_data *out_val,
|
static int sbi_misaligned_ld_emulator(int rlen, union sbi_ldst_data *out_val,
|
||||||
struct sbi_trap_regs *regs,
|
struct sbi_trap_context *tcntx)
|
||||||
const struct sbi_trap_info *orig_trap)
|
|
||||||
{
|
{
|
||||||
|
const struct sbi_trap_info *orig_trap = &tcntx->trap;
|
||||||
|
struct sbi_trap_regs *regs = &tcntx->regs;
|
||||||
struct sbi_trap_info uptrap;
|
struct sbi_trap_info uptrap;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -283,17 +281,16 @@ static int sbi_misaligned_ld_emulator(int rlen, union sbi_ldst_data *out_val,
|
|||||||
return rlen;
|
return rlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sbi_misaligned_load_handler(struct sbi_trap_regs *regs,
|
int sbi_misaligned_load_handler(struct sbi_trap_context *tcntx)
|
||||||
const struct sbi_trap_info *orig_trap)
|
|
||||||
{
|
{
|
||||||
return sbi_trap_emulate_load(regs, orig_trap,
|
return sbi_trap_emulate_load(tcntx, sbi_misaligned_ld_emulator);
|
||||||
sbi_misaligned_ld_emulator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sbi_misaligned_st_emulator(int wlen, union sbi_ldst_data in_val,
|
static int sbi_misaligned_st_emulator(int wlen, union sbi_ldst_data in_val,
|
||||||
struct sbi_trap_regs *regs,
|
struct sbi_trap_context *tcntx)
|
||||||
const struct sbi_trap_info *orig_trap)
|
|
||||||
{
|
{
|
||||||
|
const struct sbi_trap_info *orig_trap = &tcntx->trap;
|
||||||
|
struct sbi_trap_regs *regs = &tcntx->regs;
|
||||||
struct sbi_trap_info uptrap;
|
struct sbi_trap_info uptrap;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -309,17 +306,17 @@ static int sbi_misaligned_st_emulator(int wlen, union sbi_ldst_data in_val,
|
|||||||
return wlen;
|
return wlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sbi_misaligned_store_handler(struct sbi_trap_regs *regs,
|
int sbi_misaligned_store_handler(struct sbi_trap_context *tcntx)
|
||||||
const struct sbi_trap_info *orig_trap)
|
|
||||||
{
|
{
|
||||||
return sbi_trap_emulate_store(regs, orig_trap,
|
return sbi_trap_emulate_store(tcntx, sbi_misaligned_st_emulator);
|
||||||
sbi_misaligned_st_emulator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sbi_ld_access_emulator(int rlen, union sbi_ldst_data *out_val,
|
static int sbi_ld_access_emulator(int rlen, union sbi_ldst_data *out_val,
|
||||||
struct sbi_trap_regs *regs,
|
struct sbi_trap_context *tcntx)
|
||||||
const struct sbi_trap_info *orig_trap)
|
|
||||||
{
|
{
|
||||||
|
const struct sbi_trap_info *orig_trap = &tcntx->trap;
|
||||||
|
struct sbi_trap_regs *regs = &tcntx->regs;
|
||||||
|
|
||||||
/* If fault came from M mode, just fail */
|
/* If fault came from M mode, just fail */
|
||||||
if (((regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT) == PRV_M)
|
if (((regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT) == PRV_M)
|
||||||
return SBI_EINVAL;
|
return SBI_EINVAL;
|
||||||
@@ -332,16 +329,17 @@ static int sbi_ld_access_emulator(int rlen, union sbi_ldst_data *out_val,
|
|||||||
return rlen;
|
return rlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sbi_load_access_handler(struct sbi_trap_regs *regs,
|
int sbi_load_access_handler(struct sbi_trap_context *tcntx)
|
||||||
const struct sbi_trap_info *orig_trap)
|
|
||||||
{
|
{
|
||||||
return sbi_trap_emulate_load(regs, orig_trap, sbi_ld_access_emulator);
|
return sbi_trap_emulate_load(tcntx, sbi_ld_access_emulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sbi_st_access_emulator(int wlen, union sbi_ldst_data in_val,
|
static int sbi_st_access_emulator(int wlen, union sbi_ldst_data in_val,
|
||||||
struct sbi_trap_regs *regs,
|
struct sbi_trap_context *tcntx)
|
||||||
const struct sbi_trap_info *orig_trap)
|
|
||||||
{
|
{
|
||||||
|
const struct sbi_trap_info *orig_trap = &tcntx->trap;
|
||||||
|
struct sbi_trap_regs *regs = &tcntx->regs;
|
||||||
|
|
||||||
/* If fault came from M mode, just fail */
|
/* If fault came from M mode, just fail */
|
||||||
if (((regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT) == PRV_M)
|
if (((regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT) == PRV_M)
|
||||||
return SBI_EINVAL;
|
return SBI_EINVAL;
|
||||||
@@ -354,8 +352,7 @@ static int sbi_st_access_emulator(int wlen, union sbi_ldst_data in_val,
|
|||||||
return wlen;
|
return wlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sbi_store_access_handler(struct sbi_trap_regs *regs,
|
int sbi_store_access_handler(struct sbi_trap_context *tcntx)
|
||||||
const struct sbi_trap_info *orig_trap)
|
|
||||||
{
|
{
|
||||||
return sbi_trap_emulate_store(regs, orig_trap, sbi_st_access_emulator);
|
return sbi_trap_emulate_store(tcntx, sbi_st_access_emulator);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user