Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid exception handling loops if no handler is defined #770

Merged
merged 2 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion emulator/src/runtime/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use thiserror::Error;
use super::memory::MemoryError;
use crate::constants::Word;

#[derive(Error, Debug)]
#[derive(Error, Debug, Clone)]
pub enum Exception {
#[error("hardware interrupt")]
HardwareInterrupt,
Expand Down
2 changes: 1 addition & 1 deletion emulator/src/runtime/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl TryFrom<&Cell> for Address {
}

/// Represents errors related to memory manipulations
#[derive(Debug, Error)]
#[derive(Debug, Error, Clone, Copy)]
pub enum MemoryError {
/// The given address was invalid
#[error("invalid address {0}")]
Expand Down
10 changes: 10 additions & 0 deletions emulator/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ impl Computer {
&mut self,
exception: &Exception,
) -> std::result::Result<(), Exception> {
// We don't want to recover from the exception if there is no handler setup
let handler = self.memory.get(C::INTERRUPT_HANDLER)?;
if handler.extract_instruction().is_err() {
tracing::warn!(
"No exception handler at address 200 for exception {:?}",
exception
);
return Err(exception.clone());
}

debug!(exception = %exception, "Recovering from exception");
*(self.memory.get_mut(C::INTERRUPT_PC_SAVE)?) = self.registers.get(&Reg::PC);
*(self.memory.get_mut(C::INTERRUPT_SR_SAVE)?) = self.registers.get(&Reg::SR);
Expand Down