mirror of
https://github.com/Fishwaldo/opensbi.git
synced 2025-06-23 14:48:26 +00:00
lib: sbi_emulate_csr: Remove scratch and hartid parameter
We remove scratch and hartid parameter from various functions for CSR emulation because we can always get current HART id and current scratch pointer using just one CSR access. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
This commit is contained in:
parent
cb78a48231
commit
d11c79cd97
3 changed files with 15 additions and 14 deletions
|
@ -13,12 +13,11 @@
|
||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
struct sbi_trap_regs;
|
struct sbi_trap_regs;
|
||||||
struct sbi_scratch;
|
|
||||||
|
|
||||||
int sbi_emulate_csr_read(int csr_num, u32 hartid, struct sbi_trap_regs *regs,
|
int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
|
||||||
struct sbi_scratch *scratch, ulong *csr_val);
|
ulong *csr_val);
|
||||||
|
|
||||||
int sbi_emulate_csr_write(int csr_num, u32 hartid, struct sbi_trap_regs *regs,
|
int sbi_emulate_csr_write(int csr_num, struct sbi_trap_regs *regs,
|
||||||
struct sbi_scratch *scratch, ulong csr_val);
|
ulong csr_val);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,14 +13,16 @@
|
||||||
#include <sbi/sbi_console.h>
|
#include <sbi/sbi_console.h>
|
||||||
#include <sbi/sbi_emulate_csr.h>
|
#include <sbi/sbi_emulate_csr.h>
|
||||||
#include <sbi/sbi_error.h>
|
#include <sbi/sbi_error.h>
|
||||||
|
#include <sbi/sbi_scratch.h>
|
||||||
#include <sbi/sbi_timer.h>
|
#include <sbi/sbi_timer.h>
|
||||||
#include <sbi/sbi_trap.h>
|
#include <sbi/sbi_trap.h>
|
||||||
|
|
||||||
int sbi_emulate_csr_read(int csr_num, u32 hartid, struct sbi_trap_regs *regs,
|
int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs,
|
||||||
struct sbi_scratch *scratch, ulong *csr_val)
|
ulong *csr_val)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
ulong cen = -1UL;
|
ulong cen = -1UL;
|
||||||
|
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
||||||
ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT;
|
ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT;
|
||||||
#if __riscv_xlen == 32
|
#if __riscv_xlen == 32
|
||||||
bool virt = (regs->mstatusH & MSTATUSH_MPV) ? TRUE : FALSE;
|
bool virt = (regs->mstatusH & MSTATUSH_MPV) ? TRUE : FALSE;
|
||||||
|
@ -111,15 +113,16 @@ int sbi_emulate_csr_read(int csr_num, u32 hartid, struct sbi_trap_regs *regs,
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
sbi_dprintf(scratch, "%s: hartid%d: invalid csr_num=0x%x\n",
|
sbi_dprintf(scratch, "%s: hartid%d: invalid csr_num=0x%x\n",
|
||||||
__func__, hartid, csr_num);
|
__func__, current_hartid(), csr_num);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sbi_emulate_csr_write(int csr_num, u32 hartid, struct sbi_trap_regs *regs,
|
int sbi_emulate_csr_write(int csr_num, struct sbi_trap_regs *regs,
|
||||||
struct sbi_scratch *scratch, ulong csr_val)
|
ulong csr_val)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
||||||
ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT;
|
ulong prev_mode = (regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT;
|
||||||
#if __riscv_xlen == 32
|
#if __riscv_xlen == 32
|
||||||
bool virt = (regs->mstatusH & MSTATUSH_MPV) ? TRUE : FALSE;
|
bool virt = (regs->mstatusH & MSTATUSH_MPV) ? TRUE : FALSE;
|
||||||
|
@ -179,7 +182,7 @@ int sbi_emulate_csr_write(int csr_num, u32 hartid, struct sbi_trap_regs *regs,
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
sbi_dprintf(scratch, "%s: hartid%d: invalid csr_num=0x%x\n",
|
sbi_dprintf(scratch, "%s: hartid%d: invalid csr_num=0x%x\n",
|
||||||
__func__, hartid, csr_num);
|
__func__, current_hartid(), csr_num);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ static int system_opcode_insn(ulong insn, u32 hartid, ulong mcause,
|
||||||
return truly_illegal_insn(insn, hartid, mcause,
|
return truly_illegal_insn(insn, hartid, mcause,
|
||||||
regs, scratch);
|
regs, scratch);
|
||||||
|
|
||||||
if (sbi_emulate_csr_read(csr_num, hartid, regs, scratch, &csr_val))
|
if (sbi_emulate_csr_read(csr_num, regs, &csr_val))
|
||||||
return truly_illegal_insn(insn, hartid, mcause,
|
return truly_illegal_insn(insn, hartid, mcause,
|
||||||
regs, scratch);
|
regs, scratch);
|
||||||
|
|
||||||
|
@ -87,8 +87,7 @@ static int system_opcode_insn(ulong insn, u32 hartid, ulong mcause,
|
||||||
return truly_illegal_insn(insn, hartid, mcause, regs, scratch);
|
return truly_illegal_insn(insn, hartid, mcause, regs, scratch);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (do_write && sbi_emulate_csr_write(csr_num, hartid, regs,
|
if (do_write && sbi_emulate_csr_write(csr_num, regs, new_csr_val))
|
||||||
scratch, new_csr_val))
|
|
||||||
return truly_illegal_insn(insn, hartid, mcause, regs, scratch);
|
return truly_illegal_insn(insn, hartid, mcause, regs, scratch);
|
||||||
|
|
||||||
SET_RD(insn, regs, csr_val);
|
SET_RD(insn, regs, csr_val);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue