summaryrefslogtreecommitdiff
path: root/src/luma/application/trap.rs
blob: 7f484ba17e2b8520ec5a26cf89ac422789d331c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2021-2023 Gabriel Jensen.

use crate::luma::application::{Application, TrapKind};
use crate::luma::MEMORY_SIZE;

impl Application {
	pub fn trap(&mut self, kind: TrapKind, address: Option<u32>, opcode: Option<u32>, alignment: Option<u32>) {
		let message = match kind {
			TrapKind::BadAlignment  => format!("bad alignment of address 0x{:08X} (should be {}-byte aligned)", address.unwrap(), alignment.unwrap()),
			TrapKind::InvalidOpcode => format!("invalid opcode 0x{:08X} at 0x{:08X}", opcode.unwrap(), address.unwrap()),
			TrapKind::OutOfBounds   => format!("out-of-bounds address 0x{:08X} (limit is 0x{MEMORY_SIZE:08X})", address.unwrap()),
		};

		eprintln!("trap - {message}");
		eprintln!();
		eprintln!("\tr0:   {:08X}",  self.registers[0x0]);
		eprintln!("\tr1:   {:08X}",  self.registers[0x1]);
		eprintln!("\tr2:   {:08X}",  self.registers[0x2]);
		eprintln!("\tr3:   {:08X}",  self.registers[0x3]);
		eprintln!("\tr4:   {:08X}",  self.registers[0x4]);
		eprintln!("\tr5:   {:08X}",  self.registers[0x5]);
		eprintln!("\tr6:   {:08X}",  self.registers[0x6]);
		eprintln!("\tr7:   {:08X}",  self.registers[0x7]);
		eprintln!("\tr8:   {:08X}",  self.registers[0x8]);
		eprintln!("\tr9:   {:08X}",  self.registers[0x9]);
		eprintln!("\tr10:  {:08X}",  self.registers[0xA]);
		eprintln!("\tr11:  {:08X}",  self.registers[0xB]);
		eprintln!("\tr12:  {:08X}",  self.registers[0xC]);
		eprintln!("\tsp:   {:08X}",  self.registers[0xD]);
		eprintln!("\tlr:   {:08X}",  self.registers[0xE]);
		eprintln!("\tpc:   {:08X}",  self.registers[0xF]);
		eprintln!("\tcpsr: {:032b}", self.psr);

		panic!("{message}");
	}
}