#[allow(missing_docs)]
pub enum Exception {
BranchThroughZero = 0x20000,
UndefinedInstr = 0x20001,
SoftwareInterrupt = 0x20002,
PrefetchAbort = 0x20003,
DataAbort = 0x20004,
AddressException = 0x20005,
IRQ = 0x20006,
FIQ = 0x20007,
BreakPoint = 0x20020,
WatchPoint = 0x20021,
StepComplete = 0x20022,
RunTimeErrorUnknown = 0x20023,
InternalError = 0x20024,
UserInterruption = 0x20025,
ApplicationExit = 0x20026,
StackOverflow = 0x20027,
DivisionByZero = 0x20028,
OSSpecific = 0x20029,
}
pub type ExitStatus = Result<(), ()>;
pub const EXIT_SUCCESS: ExitStatus = Ok(());
pub const EXIT_FAILURE: ExitStatus = Err(());
pub fn exit(status: ExitStatus) {
match status {
EXIT_SUCCESS => report_exception(Exception::ApplicationExit),
EXIT_FAILURE => report_exception(Exception::RunTimeErrorUnknown),
}
}
pub fn report_exception(reason: Exception) {
let code = reason as usize;
unsafe {
#[cfg(target_arch = "riscv64")]
syscall!(REPORT_EXCEPTION, code, 0);
#[cfg(not(target_arch = "riscv64"))]
syscall1!(REPORT_EXCEPTION, code);
}
}