Skip to content

Commit

Permalink
SQUASH: move everything inside #ifdef DEVELHELP
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-k committed Aug 4, 2015
1 parent 842832e commit caeb7aa
Showing 1 changed file with 41 additions and 33 deletions.
74 changes: 41 additions & 33 deletions cpu/cortexm_common/vectors_cortexm.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,44 @@ void nmi_default(void)
core_panic(PANIC_NMI_HANDLER, "NMI HANDLER");
}

#ifdef DEVELHELP

/* Trampoline function to save stackpointer before calling hardfault handler */
void hard_fault_default(void)
{
/* Get stackpointer where exception stackframe lies */
__ASM volatile
(
"movs r0, #4 \n" /* r0 = 0x4 */
"mov r1, lr \n" /* r1 = lr */
"tst r1, r0 \n" /* if(lr & 0x4) */
"bne use_psp \n" /* { */
"mrs r0, msp \n" /* r0 = msp */
"b out \n" /* } */
" use_psp: \n" /* else { */
"mrs r0, psp \n" /* r0 = psp */
" out: \n" /* } */
"mov r1, #0 \n" /* corrupted = false */
"cmp r0, sp \n" /* If msp is active stack- */
"bne hardfault \n" /* pointer, check if valid so */
"cmp r0, %[eram] \n" /* so calling c-func works . */
"bge fix_msp \n" /* if(r0 == msp) { */
"cmn r0, %[sram] \n" /* if( (r0 >= estack) || */
"bl hardfault \n" /* (r0 < sstack) ) { */
" fix_msp: \n" /* corrupted = true */
"mov r0, %[estack] \n" /* r0 = _estack */
"mov sp, r0 \n" /* sp = _estack */
"mov r1, #1 \n" /* } */
" hardfault: \n" /* } */
"b hard_fault_handler \n" /* hard_fault_handler(r0) */
:
: [sram] "r" (&_sram),
[eram] "r" (&_eram),
[estack] "r" (&_estack)
: "r0","r1"
);
}

void hard_fault_handler(uint32_t* sp, uint32_t corrupted)
{
/* Make them volatile so that they won't get optimized out */
Expand Down Expand Up @@ -157,42 +195,12 @@ void hard_fault_handler(uint32_t* sp, uint32_t corrupted)

core_panic(PANIC_HARD_FAULT, "HARD FAULT HANDLER");
}

/* Trampoline function to save stackpointer before calling hardfault handler */
#else
void hard_fault_default(void)
{
/* Get stackpointer where exception stackframe lies */
__ASM volatile
(
"movs r0, #4 \n" /* r0 = 0x4 */
"mov r1, lr \n" /* r1 = lr */
"tst r1, r0 \n" /* if(lr & 0x4) */
"bne use_psp \n" /* { */
"mrs r0, msp \n" /* r0 = msp */
"b out \n" /* } */
" use_psp: \n" /* else { */
"mrs r0, psp \n" /* r0 = psp */
" out: \n" /* } */
"mov r1, #0 \n" /* corrupted = false */
"cmp r0, sp \n" /* If msp is active stack- */
"bne hardfault \n" /* pointer, check if valid so */
"cmp r0, %[eram] \n" /* so calling c-func works . */
"bge fix_msp \n" /* if(r0 == msp) { */
"cmn r0, %[sram] \n" /* if( (r0 >= estack) || */
"bl hardfault \n" /* (r0 < sstack) ) { */
" fix_msp: \n" /* corrupted = true */
"mov r0, %[estack] \n" /* r0 = _estack */
"mov sp, r0 \n" /* sp = _estack */
"mov r1, #1 \n" /* } */
" hardfault: \n" /* } */
"b hard_fault_handler \n" /* hard_fault_handler(r0) */
:
: [sram] "r" (&_sram),
[eram] "r" (&_eram),
[estack] "r" (&_estack)
: "r0","r1"
);
core_panic(PANIC_HARD_FAULT, "HARD FAULT HANDLER");
}
#endif /* DEVELHELP */

#if defined(CPU_ARCH_CORTEX_M3) || defined(CPU_ARCH_CORTEX_M4) || \
defined(CPU_ARCH_CORTEX_M4F)
Expand Down

0 comments on commit caeb7aa

Please sign in to comment.