JALR and JAL doesn't check for 4-byte boundaries when C extension is supported.

This commit is contained in:
Màrius Montón 2022-09-19 14:44:44 +02:00
parent 6b21b1bfee
commit 76a9cd2d31
No known key found for this signature in database
GPG Key ID: FA199E7A752699F0
1 changed files with 3 additions and 15 deletions

View File

@ -341,7 +341,7 @@ namespace riscv_tlm {
return true; return true;
} }
bool Exec_JALR() { bool Exec_JALR() const {
signed_T offset; signed_T offset;
unsigned int rd, rs1; unsigned int rd, rs1;
unsigned_T new_pc, old_pc; unsigned_T new_pc, old_pc;
@ -353,22 +353,10 @@ namespace riscv_tlm {
new_pc = static_cast<unsigned_T>((this->regs->getValue(rs1) + offset) & ~1); new_pc = static_cast<unsigned_T>((this->regs->getValue(rs1) + offset) & ~1);
this->regs->setValue(rd, old_pc + 4); this->regs->setValue(rd, old_pc + 4);
if ((new_pc & 0x00000003) != 0) {
// not aligned
this->logger->debug("{} ns. PC: 0x{:x}. JALR: x{:d} <- 0x{:x} PC <- 0x{:x} (0x{:x})",
sc_core::sc_time_stamp().value(),
old_pc,
rd, old_pc + 4, new_pc, offset);
this->logger->debug("{} ns. PC: 0x{:x}. JALR : Exception",
sc_core::sc_time_stamp().value(), old_pc);
this->RaiseException(EXCEPTION_CAUSE_LOAD_ADDR_MISALIGN, this->m_instr);
} else {
this->regs->setPC(new_pc); this->regs->setPC(new_pc);
this->logger->debug("{} ns. PC: 0x{:x}. JALR: x{:d} <- 0x{:x}. PC <- 0x{:x}", this->logger->debug("{} ns. PC: 0x{:x}. JALR: x{:d} <- 0x{:x}. PC <- 0x{:x}",
sc_core::sc_time_stamp().value(), sc_core::sc_time_stamp().value(),
old_pc, rd, old_pc + 4, new_pc); old_pc, rd, old_pc + 4, new_pc);
}
return true; return true;
} }