From 0e130fc80387fc61941e8cb18914715e434305a1 Mon Sep 17 00:00:00 2001 From: Eyck-Alexander Jentzsch Date: Mon, 2 Feb 2026 12:10:59 +0100 Subject: [PATCH] corrects disass logging of Interrupts and Traps since the spec allows custom interrupts there was the case that the strings were nonsense as no bounds where checked when indexing into the array of strings --- src/iss/arch/riscv_hart_m_p.h | 6 ++++-- src/iss/arch/riscv_hart_msu_vp.h | 6 ++++-- src/iss/arch/riscv_hart_mu_p.h | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/iss/arch/riscv_hart_m_p.h b/src/iss/arch/riscv_hart_m_p.h index 7e40196..6f3834a 100644 --- a/src/iss/arch/riscv_hart_m_p.h +++ b/src/iss/arch/riscv_hart_m_p.h @@ -463,11 +463,13 @@ template uint64_t riscv_hart_m_p::e #endif if((flags & 0xffffffff) != 0xffffffff) { if(trap_id) { + auto irq_str = cause < this->irq_str.size() ? this->irq_str.at(cause) : "Unknown"; ILOG(disasslogger, logging::DEBUG, - fmt::format("Interrupt with cause '{}' ({}) occurred at address {}", this->irq_str[cause], cause, buffer.data())); + fmt::format("Interrupt with cause '{}' ({}) occurred at address {}", irq_str, cause, buffer.data())); } else { + auto irq_str = cause < this->trap_str.size() ? this->trap_str.at(cause) : "Unknown"; ILOG(disasslogger, logging::DEBUG, - fmt::format("Trap with cause '{}' ({}) occurred at address {}", this->trap_str[cause], cause, buffer.data())); + fmt::format("Trap with cause '{}' ({}) occurred at address {}", irq_str, cause, buffer.data())); } } // reset trap state diff --git a/src/iss/arch/riscv_hart_msu_vp.h b/src/iss/arch/riscv_hart_msu_vp.h index 89ca0f4..c520be3 100644 --- a/src/iss/arch/riscv_hart_msu_vp.h +++ b/src/iss/arch/riscv_hart_msu_vp.h @@ -635,11 +635,13 @@ uint64_t riscv_hart_msu_vp::enter_trap(uint64_t flags, uint64_t addr #endif if((flags & 0xffffffff) != 0xffffffff) { if(trap_id) { + auto irq_str = cause < this->irq_str.size() ? this->irq_str.at(cause) : "Unknown"; ILOG(disasslogger, logging::DEBUG, - fmt::format("Interrupt with cause '{}' ({}) occurred at address {}", this->irq_str[cause], cause, buffer.data())); + fmt::format("Interrupt with cause '{}' ({}) occurred at address {}", irq_str, cause, buffer.data())); } else { + auto irq_str = cause < this->trap_str.size() ? this->trap_str.at(cause) : "Unknown"; ILOG(disasslogger, logging::DEBUG, - fmt::format("Trap with cause '{}' ({}) occurred at address {}", this->trap_str[cause], cause, buffer.data())); + fmt::format("Trap with cause '{}' ({}) occurred at address {}", irq_str, cause, buffer.data())); } } // reset trap this->state diff --git a/src/iss/arch/riscv_hart_mu_p.h b/src/iss/arch/riscv_hart_mu_p.h index 032ff17..46a044a 100644 --- a/src/iss/arch/riscv_hart_mu_p.h +++ b/src/iss/arch/riscv_hart_mu_p.h @@ -508,11 +508,13 @@ template uint64_t riscv_hart_mu_p:: #endif if((flags & 0xffffffff) != 0xffffffff) { if(trap_id) { + auto irq_str = cause < this->irq_str.size() ? this->irq_str.at(cause) : "Unknown"; ILOG(disasslogger, logging::DEBUG, - fmt::format("Interrupt with cause '{}' ({}) occurred at address {}", this->irq_str[cause], cause, buffer.data())); + fmt::format("Interrupt with cause '{}' ({}) occurred at address {}", irq_str, cause, buffer.data())); } else { + auto irq_str = cause < this->trap_str.size() ? this->trap_str.at(cause) : "Unknown"; ILOG(disasslogger, logging::DEBUG, - fmt::format("Trap with cause '{}' ({}) occurred at address {}", this->trap_str[cause], cause, buffer.data())); + fmt::format("Trap with cause '{}' ({}) occurred at address {}", irq_str, cause, buffer.data())); } } // reset trap state