From 2df74cc0557a30be2f8b00c24190dc18509c0879 Mon Sep 17 00:00:00 2001 From: Astro Date: Thu, 30 May 2019 20:30:19 +0200 Subject: [PATCH] add static exception handling --- link.x | 14 +++++++++++++- src/cortex_a9/exceptions.s | 12 ++++++++++++ src/cortex_a9/mod.rs | 2 ++ src/main.rs | 11 +++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/cortex_a9/exceptions.s diff --git a/link.x b/link.x index 4f13df05..985013eb 100644 --- a/link.x +++ b/link.x @@ -1,6 +1,14 @@ ENTRY(_boot_cores); STACK_SIZE = 0x2000 - 0x10; +PROVIDE(Reset = _boot_cores); +PROVIDE(UndefinedInstruction = Reset); +PROVIDE(SoftwareInterrupt = Reset); +PROVIDE(PrefetchAbort = Reset); +PROVIDE(DataAbort = Reset); +PROVIDE(ReservedException = Reset); +PROVIDE(IRQ = Reset); +PROVIDE(FIQ = Reset); MEMORY { @@ -10,9 +18,13 @@ MEMORY SECTIONS { + .exceptions : + { + . = 0x0; + KEEP(*(.text.exceptions)); + } > OCM .text : { - /* Starts at LOADER_ADDR. */ . = 0x8000; KEEP(*(.text.boot)) *(.text .text.*) diff --git a/src/cortex_a9/exceptions.s b/src/cortex_a9/exceptions.s new file mode 100644 index 00000000..f53ece28 --- /dev/null +++ b/src/cortex_a9/exceptions.s @@ -0,0 +1,12 @@ +.section ".text.exceptions" +.global exception_vector + +exception_vector: + b Reset + b UndefinedInstruction + b SoftwareInterrupt + b PrefetchAbort + b DataAbort + b ReservedException + b IRQ + b FIQ diff --git a/src/cortex_a9/mod.rs b/src/cortex_a9/mod.rs index 79d3436d..72f65b0a 100644 --- a/src/cortex_a9/mod.rs +++ b/src/cortex_a9/mod.rs @@ -1,2 +1,4 @@ pub mod asm; pub mod regs; + +global_asm!(include_str!("exceptions.s")); diff --git a/src/main.rs b/src/main.rs index 5feebbcb..6f759153 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #![no_std] #![no_main] #![feature(asm)] +#![feature(global_asm)] #![feature(naked_functions)] use core::fmt::Write; @@ -94,3 +95,13 @@ fn panic(info: &core::panic::PanicInfo) -> ! { slcr::RegisterBlock::unlocked(|slcr| slcr.soft_reset()); unreachable!() } + +#[no_mangle] +pub unsafe extern "C" fn PrefetchAbort() { + panic!("PrefetchAbort"); +} + +#[no_mangle] +pub unsafe extern "C" fn DataAbort() { + panic!("DataAbort"); +}