ax_cpu/trap/boot.rs
1//! Early exception handoff without runtime task or CPU-local dependencies.
2
3#[cfg(target_arch = "aarch64")]
4pub use crate::arch::current::trap::{TrapKind, TrapSource};
5
6/// Copied machine state at an early exception boundary.
7#[derive(Clone, Copy, Debug)]
8pub struct BootException {
9 /// Architecture-native saved integer registers.
10 pub registers: crate::registers::GeneralRegisters,
11 /// Saved exception return address.
12 pub pc: usize,
13 /// Interrupted stack pointer.
14 pub sp: usize,
15 /// Saved PSTATE, SSTATUS, PRMD or RFLAGS.
16 pub status: u64,
17 /// ESR, SCAUSE, ESTAT or x86 error code captured by the owning vector.
18 pub syndrome: u64,
19 /// FAR, STVAL, BADV or CR2 captured by the owning vector.
20 pub fault_address: crate::VirtAddr,
21 /// x86 exception vector; `syndrome` contains its hardware error code.
22 #[cfg(target_arch = "x86_64")]
23 pub vector: u8,
24 /// Architectural exception level (1 or 2).
25 #[cfg(target_arch = "aarch64")]
26 pub level: u8,
27 /// Synchronous, IRQ, FIQ or SError vector kind.
28 #[cfg(target_arch = "aarch64")]
29 pub kind: TrapKind,
30 /// Vector source domain.
31 #[cfg(target_arch = "aarch64")]
32 pub source: TrapSource,
33}
34
35/// Early exception policy supplied by the boot owner.
36/// The callback may run before runtime CPU-local, TLS or scheduling exists.
37#[trait_ffi::def_extern_trait(mod_path = "trap::boot")]
38pub trait BootTrapHandler {
39 /// Reports or handles the copied exception without retaining stack references.
40 /// Returning resumes the unchanged saved machine context. A fatal handler
41 /// must use the boot owner's diagnostics without depending on runtime state.
42 fn handle(exception: &BootException);
43}