aboutsummaryrefslogtreecommitdiff
path: root/machine
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2019-07-17 16:36:51 -0700
committerAndrew Waterman <andrew@sifive.com>2019-07-17 16:36:51 -0700
commit31878c5e2f7a989977ef3f64da48e14387bbe0a2 (patch)
tree337da391ee1cfce345a34f7df0d16decb521bad6 /machine
parent3d681ed0d01df2fa65f15df86e06b63a7a696d1f (diff)
downloadriscv-pk-31878c5e2f7a989977ef3f64da48e14387bbe0a2.zip
riscv-pk-31878c5e2f7a989977ef3f64da48e14387bbe0a2.tar.gz
riscv-pk-31878c5e2f7a989977ef3f64da48e14387bbe0a2.tar.bz2
Make illegal-instruction jump table entries relative to their base
This supports bbl living above 4 GiB.
Diffstat (limited to 'machine')
-rw-r--r--machine/emulation.c86
-rw-r--r--machine/fp_emulation.c68
2 files changed, 77 insertions, 77 deletions
diff --git a/machine/emulation.c b/machine/emulation.c
index 132e977..c077a53 100644
--- a/machine/emulation.c
+++ b/machine/emulation.c
@@ -72,62 +72,62 @@ void illegal_insn_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc)
{
asm (".pushsection .rodata\n"
"illegal_insn_trap_table:\n"
- " .word truly_illegal_insn\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
#if !defined(__riscv_flen) && defined(PK_ENABLE_FP_EMULATION)
- " .word emulate_float_load\n"
+ " .word emulate_float_load - illegal_insn_trap_table\n"
#else
- " .word truly_illegal_insn\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
#endif
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
#if !defined(__riscv_flen) && defined(PK_ENABLE_FP_EMULATION)
- " .word emulate_float_store\n"
+ " .word emulate_float_store - illegal_insn_trap_table\n"
#else
- " .word truly_illegal_insn\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
#endif
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
#if !defined(__riscv_muldiv)
- " .word emulate_mul_div\n"
+ " .word emulate_mul_div - illegal_insn_trap_table\n"
#else
- " .word truly_illegal_insn\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
#endif
- " .word truly_illegal_insn\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
#if !defined(__riscv_muldiv) && __riscv_xlen >= 64
- " .word emulate_mul_div32\n"
+ " .word emulate_mul_div32 - illegal_insn_trap_table\n"
#else
- " .word truly_illegal_insn\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
#endif
- " .word truly_illegal_insn\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
#ifdef PK_ENABLE_FP_EMULATION
- " .word emulate_fmadd\n"
- " .word emulate_fmadd\n"
- " .word emulate_fmadd\n"
- " .word emulate_fmadd\n"
- " .word emulate_fp\n"
+ " .word emulate_fmadd - illegal_insn_trap_table\n"
+ " .word emulate_fmadd - illegal_insn_trap_table\n"
+ " .word emulate_fmadd - illegal_insn_trap_table\n"
+ " .word emulate_fmadd - illegal_insn_trap_table\n"
+ " .word emulate_fp - illegal_insn_trap_table\n"
#else
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
#endif
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word emulate_system_opcode\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word emulate_system_opcode - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
+ " .word truly_illegal_insn - illegal_insn_trap_table\n"
" .popsection");
uintptr_t mstatus = read_csr(mstatus);
@@ -143,8 +143,8 @@ void illegal_insn_trap(uintptr_t* regs, uintptr_t mcause, uintptr_t mepc)
write_csr(mepc, mepc + 4);
extern uint32_t illegal_insn_trap_table[];
- uint32_t* pf = (void*)illegal_insn_trap_table + (insn & 0x7c);
- emulation_func f = (emulation_func)(uintptr_t)*pf;
+ int32_t* pf = (void*)illegal_insn_trap_table + (insn & 0x7c);
+ emulation_func f = (emulation_func)((void*)illegal_insn_trap_table + *pf);
f(regs, mcause, mepc, mstatus, insn);
}
diff --git a/machine/fp_emulation.c b/machine/fp_emulation.c
index 8c40f61..c16aff9 100644
--- a/machine/fp_emulation.c
+++ b/machine/fp_emulation.c
@@ -10,38 +10,38 @@ DECLARE_EMULATION_FUNC(emulate_fp)
{
asm (".pushsection .rodata\n"
"fp_emulation_table:\n"
- " .word emulate_fadd\n"
- " .word emulate_fsub\n"
- " .word emulate_fmul\n"
- " .word emulate_fdiv\n"
- " .word emulate_fsgnj\n"
- " .word emulate_fmin\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word emulate_fcvt_ff\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word emulate_fsqrt\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word emulate_fcmp\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word truly_illegal_insn\n"
- " .word emulate_fcvt_if\n"
- " .word truly_illegal_insn\n"
- " .word emulate_fcvt_fi\n"
- " .word truly_illegal_insn\n"
- " .word emulate_fmv_if\n"
- " .word truly_illegal_insn\n"
- " .word emulate_fmv_fi\n"
- " .word truly_illegal_insn\n"
+ " .word emulate_fadd - fp_emulation_table\n"
+ " .word emulate_fsub - fp_emulation_table\n"
+ " .word emulate_fmul - fp_emulation_table\n"
+ " .word emulate_fdiv - fp_emulation_table\n"
+ " .word emulate_fsgnj - fp_emulation_table\n"
+ " .word emulate_fmin - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word emulate_fcvt_ff - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word emulate_fsqrt - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word emulate_fcmp - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word emulate_fcvt_if - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word emulate_fcvt_fi - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word emulate_fmv_if - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
+ " .word emulate_fmv_fi - fp_emulation_table\n"
+ " .word truly_illegal_insn - fp_emulation_table\n"
" .popsection");
// if FPU is disabled, punt back to the OS
@@ -49,8 +49,8 @@ DECLARE_EMULATION_FUNC(emulate_fp)
return truly_illegal_insn(regs, mcause, mepc, mstatus, insn);
extern uint32_t fp_emulation_table[];
- uint32_t* pf = (void*)fp_emulation_table + ((insn >> 25) & 0x7c);
- emulation_func f = (emulation_func)(uintptr_t)*pf;
+ int32_t* pf = (void*)fp_emulation_table + ((insn >> 25) & 0x7c);
+ emulation_func f = (emulation_func)((void*)fp_emulation_table + *pf);
SETUP_STATIC_ROUNDING(insn);
return f(regs, mcause, mepc, mstatus, insn);