Skip to content

Commit

Permalink
Merge pull request #1783 from riscv-software-src/fix-1782
Browse files Browse the repository at this point in the history
Fix exception priority for RV32E JAL[R], loads, AMOs
  • Loading branch information
aswaterman committed Aug 23, 2024
2 parents a8c9d9c + 73bc678 commit 1b80449
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
3 changes: 2 additions & 1 deletion riscv/decode_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define RS2 READ_REG(insn.rs2())
#define RS3 READ_REG(insn.rs3())
#define WRITE_RD(value) WRITE_REG(insn.rd(), value)
#define CHECK_RD() CHECK_REG(insn.rd())

/* 0 : int
* 1 : floating
Expand All @@ -30,9 +31,9 @@
* 4 : csr
*/
#define WRITE_REG(reg, value) ({ \
CHECK_REG(reg); \
reg_t wdata = (value); /* value may have side effects */ \
if (DECODE_MACRO_USAGE_LOGGED) STATE.log_reg_write[(reg) << 4] = {wdata, 0}; \
CHECK_REG(reg); \
STATE.XPR.write(reg, wdata); \
})
#define WRITE_FREG(reg, value) ({ \
Expand Down
47 changes: 23 additions & 24 deletions riscv/insn_template.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@

#define DECODE_MACRO_USAGE_LOGGED 0

#define PROLOGUE \
reg_t npc = sext_xlen(pc + insn_length(OPCODE))

#define EPILOGUE \
trace_opcode(p, OPCODE, insn); \
return npc

reg_t fast_rv32i_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 32
reg_t npc = sext_xlen(pc + insn_length(OPCODE));
PROLOGUE;
#include "insns/NAME.h"
trace_opcode(p, OPCODE, insn);
EPILOGUE;
#undef xlen
return npc;
}

reg_t fast_rv64i_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 64
reg_t npc = sext_xlen(pc + insn_length(OPCODE));
PROLOGUE;
#include "insns/NAME.h"
trace_opcode(p, OPCODE, insn);
EPILOGUE;
#undef xlen
return npc;
}

#undef DECODE_MACRO_USAGE_LOGGED
Expand All @@ -31,21 +36,19 @@ reg_t fast_rv64i_NAME(processor_t* p, insn_t insn, reg_t pc)
reg_t logged_rv32i_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 32
reg_t npc = sext_xlen(pc + insn_length(OPCODE));
PROLOGUE;
#include "insns/NAME.h"
trace_opcode(p, OPCODE, insn);
EPILOGUE;
#undef xlen
return npc;
}

reg_t logged_rv64i_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 64
reg_t npc = sext_xlen(pc + insn_length(OPCODE));
PROLOGUE;
#include "insns/NAME.h"
trace_opcode(p, OPCODE, insn);
EPILOGUE;
#undef xlen
return npc;
}

#undef CHECK_REG
Expand All @@ -57,21 +60,19 @@ reg_t logged_rv64i_NAME(processor_t* p, insn_t insn, reg_t pc)
reg_t fast_rv32e_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 32
reg_t npc = sext_xlen(pc + insn_length(OPCODE));
PROLOGUE;
#include "insns/NAME.h"
trace_opcode(p, OPCODE, insn);
EPILOGUE;
#undef xlen
return npc;
}

reg_t fast_rv64e_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 64
reg_t npc = sext_xlen(pc + insn_length(OPCODE));
PROLOGUE;
#include "insns/NAME.h"
trace_opcode(p, OPCODE, insn);
EPILOGUE;
#undef xlen
return npc;
}

#undef DECODE_MACRO_USAGE_LOGGED
Expand All @@ -80,19 +81,17 @@ reg_t fast_rv64e_NAME(processor_t* p, insn_t insn, reg_t pc)
reg_t logged_rv32e_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 32
reg_t npc = sext_xlen(pc + insn_length(OPCODE));
PROLOGUE;
#include "insns/NAME.h"
trace_opcode(p, OPCODE, insn);
EPILOGUE;
#undef xlen
return npc;
}

reg_t logged_rv64e_NAME(processor_t* p, insn_t insn, reg_t pc)
{
#define xlen 64
reg_t npc = sext_xlen(pc + insn_length(OPCODE));
PROLOGUE;
#include "insns/NAME.h"
trace_opcode(p, OPCODE, insn);
EPILOGUE;
#undef xlen
return npc;
}
1 change: 1 addition & 0 deletions riscv/insns/jal.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CHECK_RD();
reg_t tmp = npc;
set_pc(JUMP_TARGET);
WRITE_RD(tmp);
1 change: 1 addition & 0 deletions riscv/insns/jalr.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CHECK_RD();
reg_t tmp = npc;
set_pc((RS1 + insn.i_imm()) & ~reg_t(1));
WRITE_RD(tmp);
Expand Down

0 comments on commit 1b80449

Please sign in to comment.