From e944876b63fc279a4bb4bb31882564053f006b10 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 21 Nov 2012 16:38:17 -0800 Subject: [PATCH] Add a exception handling helper code This commit add a structure definition that represents the stack frame layout as it is upon entering exception handler. This is useful when one wants to alter the exception return address, or get information about registers state saved by the CPU. --- include/libopencm3/cm3/scb.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/libopencm3/cm3/scb.h b/include/libopencm3/cm3/scb.h index 8e9c757d..a440cb13 100644 --- a/include/libopencm3/cm3/scb.h +++ b/include/libopencm3/cm3/scb.h @@ -365,6 +365,23 @@ BEGIN_DECLS +struct scb_exception_stack_frame { + u32 r0; + u32 r1; + u32 r2; + u32 r3; + u32 r12; + u32 lr; + u32 pc; + u32 xpsr; +} __attribute__((packed)); + +#define SCB_GET_EXCEPTION_STACK_FRAME(f) \ + do { \ + asm volatile ("mov %[frameptr], sp" \ + : [frameptr]"=r" (f)); \ + } while (0) + void scb_reset_core(void); void scb_reset_system(void); void scb_set_priority_grouping(u32 prigroup);