Reformat except.S

Tidy up formatting, and make all 3 toolchain versions more consistent,
for ease of diffing and transferring changes between them.
pull/12824/head
Kevin Bracey 2020-04-17 12:04:07 +03:00
parent 5e765487c4
commit c1641e79c5
3 changed files with 350 additions and 352 deletions

View File

@ -22,141 +22,141 @@
; * ----------------------------------------------------------------------------- ; * -----------------------------------------------------------------------------
; */ ; */
#ifndef MBED_FAULT_HANDLER_DISABLED #ifndef MBED_FAULT_HANDLER_DISABLED
#ifndef DOMAIN_NS #ifndef DOMAIN_NS
#define DOMAIN_NS 1 #define DOMAIN_NS 1
#endif #endif
FAULT_TYPE_HARD_FAULT EQU 0x10
FAULT_TYPE_MEMMANAGE_FAULT EQU 0x20
FAULT_TYPE_BUS_FAULT EQU 0x30
FAULT_TYPE_USAGE_FAULT EQU 0x40
PRESERVE8 FAULT_TYPE_HARD_FAULT EQU 0x10
THUMB FAULT_TYPE_MEMMANAGE_FAULT EQU 0x20
FAULT_TYPE_BUS_FAULT EQU 0x30
FAULT_TYPE_USAGE_FAULT EQU 0x40
AREA |.text|, CODE, READONLY PRESERVE8
THUMB
AREA |.text|, CODE, READONLY
HardFault_Handler\ HardFault_Handler\
PROC PROC
EXPORT HardFault_Handler EXPORT HardFault_Handler
LDR R3,=FAULT_TYPE_HARD_FAULT LDR R3,=FAULT_TYPE_HARD_FAULT
B Fault_Handler B Fault_Handler
ENDP ENDP
MemManage_Handler\ MemManage_Handler\
PROC PROC
EXPORT MemManage_Handler EXPORT MemManage_Handler
LDR R3,=FAULT_TYPE_MEMMANAGE_FAULT LDR R3,=FAULT_TYPE_MEMMANAGE_FAULT
B Fault_Handler B Fault_Handler
ENDP ENDP
BusFault_Handler\ BusFault_Handler\
PROC PROC
EXPORT BusFault_Handler EXPORT BusFault_Handler
LDR R3,=FAULT_TYPE_BUS_FAULT LDR R3,=FAULT_TYPE_BUS_FAULT
B Fault_Handler B Fault_Handler
ENDP ENDP
UsageFault_Handler\ UsageFault_Handler\
PROC PROC
EXPORT UsageFault_Handler EXPORT UsageFault_Handler
LDR R3,=FAULT_TYPE_USAGE_FAULT LDR R3,=FAULT_TYPE_USAGE_FAULT
B Fault_Handler B Fault_Handler
ENDP ENDP
Fault_Handler PROC Fault_Handler\
EXPORT Fault_Handler PROC
EXPORT Fault_Handler
#if (DOMAIN_NS == 1) #if (DOMAIN_NS == 1)
IMPORT mbed_fault_handler IMPORT mbed_fault_context
IMPORT mbed_fault_context IMPORT mbed_fault_handler
MRS R0,MSP MRS R0,MSP
LDR R1,=0x4 LDR R1,=0x4
MOV R2,LR MOV R2,LR
TST R2,R1 ; Check EXC_RETURN for bit 2 TST R2,R1 ; Check EXC_RETURN for bit 2
BEQ Fault_Handler_Continue BEQ Fault_Handler_Continue
MRS R0,PSP MRS R0,PSP
Fault_Handler_Continue Fault_Handler_Continue
MOV R12,R3 MOV R12,R3
LDR R3,=mbed_fault_context LDR R3,=mbed_fault_context
LDR R1,[R3] LDR R1,[R3]
LDR R2,[R0] ; Capture R0 LDR R2,[R0] ; Capture R0
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#4] ; Capture R1 LDR R2,[R0,#4] ; Capture R1
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#8] ; Capture R2 LDR R2,[R0,#8] ; Capture R2
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#12] ; Capture R3 LDR R2,[R0,#12] ; Capture R3
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
STMIA R1!,{R4-R7} ; Capture R4..R7 STMIA R1!,{R4-R7} ; Capture R4..R7
MOV R7,R8 ; Capture R8 MOV R7,R8 ; Capture R8
STR R7,[R1] STR R7,[R1]
ADDS R1,#4 ADDS R1,#4
MOV R7,R9 ; Capture R9 MOV R7,R9 ; Capture R9
STR R7,[R1] STR R7,[R1]
ADDS R1,#4 ADDS R1,#4
MOV R7,R10 ; Capture R10 MOV R7,R10 ; Capture R10
STR R7,[R1] STR R7,[R1]
ADDS R1,#4 ADDS R1,#4
MOV R7,R11 ; Capture R11 MOV R7,R11 ; Capture R11
STR R7,[R1] STR R7,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#16] ; Capture R12 LDR R2,[R0,#16] ; Capture R12
STR R2,[R1] STR R2,[R1]
ADDS R1,#8 ; Add 8 here to capture LR next, we will capture SP later ADDS R1,#8 ; Add 8 here to capture LR next, we will capture SP later
LDR R2,[R0,#20] ; Capture LR LDR R2,[R0,#20] ; Capture LR
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#24] ; Capture PC LDR R2,[R0,#24] ; Capture PC
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#28] ; Capture xPSR LDR R2,[R0,#28] ; Capture xPSR
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
; Adjust stack pointer to its original value and capture it ; Adjust stack pointer to its original value and capture it
MOV R3,R0 MOV R3,R0
ADDS R3,#0x20 ; Add 0x20 to get the SP value prior to exception ADDS R3,#0x20 ; Add 0x20 to get the SP value prior to exception
LDR R6,=0x200 LDR R6,=0x200
TST R2,R6 ; Check for if STK was aligned by checking bit-9 in xPSR value TST R2,R6 ; Check for if STK was aligned by checking bit-9 in xPSR value
BEQ Fault_Handler_Continue1 BEQ Fault_Handler_Continue1
ADDS R3,#0x4 ADDS R3,#0x4
Fault_Handler_Continue1 Fault_Handler_Continue1
MOV R5,LR MOV R5,LR
LDR R6,=0x10 ; Check for bit-4 to see if FP context was saved LDR R6,=0x10 ; Check for bit-4 to see if FP context was saved
TST R5,R6 TST R5,R6
BNE Fault_Handler_Continue2 BNE Fault_Handler_Continue2
ADDS R3,#0x48 ; 16 FP regs + FPCSR + 1 Reserved ADDS R3,#0x48 ; 16 FP regs + FPCSR + 1 Reserved
Fault_Handler_Continue2 Fault_Handler_Continue2
MOV R4,R1 MOV R4,R1
SUBS R4,#0x10 ; Set the location of SP in ctx SUBS R4,#0x10 ; Set the location of SP in ctx
STR R3,[R4] ; Capture the adjusted SP STR R3,[R4] ; Capture the adjusted SP
MRS R2,PSP ; Get PSP MRS R2,PSP ; Get PSP
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
MRS R2,MSP ; Get MSP MRS R2,MSP ; Get MSP
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
MOV R2,LR ; Get current LR(EXC_RETURN) MOV R2,LR ; Get current LR(EXC_RETURN)
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
MRS R2,CONTROL ; Get CONTROL Reg MRS R2,CONTROL ; Get CONTROL Reg
STR R2,[R1] STR R2,[R1]
MOV R0,R12 MOV R0,R12
LDR R3,=mbed_fault_context LDR R3,=mbed_fault_context
LDR R1,[R3] LDR R1,[R3]
BL mbed_fault_handler BL mbed_fault_handler
#endif
B . ; Just in case we come back here
ENDP
#endif #endif
B . ; Just in case we come back here
END ENDP
#endif
END

View File

@ -23,17 +23,17 @@
*/ */
#ifndef MBED_FAULT_HANDLER_DISABLED #ifndef MBED_FAULT_HANDLER_DISABLED
.file "except.S" .file "except.S"
.syntax unified .syntax unified
#ifndef DOMAIN_NS #ifndef DOMAIN_NS
#define DOMAIN_NS 1 #define DOMAIN_NS 1
#endif #endif
.equ FAULT_TYPE_HARD_FAULT, 0x10 .equ FAULT_TYPE_HARD_FAULT, 0x10
.equ FAULT_TYPE_MEMMANAGE_FAULT, 0x20 .equ FAULT_TYPE_MEMMANAGE_FAULT, 0x20
.equ FAULT_TYPE_BUS_FAULT, 0x30 .equ FAULT_TYPE_BUS_FAULT, 0x30
.equ FAULT_TYPE_USAGE_FAULT, 0x40 .equ FAULT_TYPE_USAGE_FAULT, 0x40
.thumb .thumb
.section ".text" .section ".text"
@ -41,159 +41,157 @@
//HardFault_Handler //HardFault_Handler
.thumb_func .thumb_func
.type HardFault_Handler, %function .type HardFault_Handler, %function
.global HardFault_Handler .global HardFault_Handler
.fnstart .fnstart
.cantunwind .cantunwind
HardFault_Handler: HardFault_Handler:
LDR R3,=FAULT_TYPE_HARD_FAULT LDR R3,=FAULT_TYPE_HARD_FAULT
B Fault_Handler B Fault_Handler
.fnend .fnend
.size HardFault_Handler, .-HardFault_Handler .size HardFault_Handler, .-HardFault_Handler
//MemManage_Handler //MemManage_Handler
.thumb_func .thumb_func
.type MemManage_Handler, %function .type MemManage_Handler, %function
.global MemManage_Handler .global MemManage_Handler
.fnstart .fnstart
.cantunwind .cantunwind
MemManage_Handler: MemManage_Handler:
LDR R3,=FAULT_TYPE_MEMMANAGE_FAULT LDR R3,=FAULT_TYPE_MEMMANAGE_FAULT
B Fault_Handler B Fault_Handler
.fnend .fnend
.size MemManage_Handler, .-MemManage_Handler .size MemManage_Handler, .-MemManage_Handler
//BusFault_Handler //BusFault_Handler
.thumb_func .thumb_func
.type BusFault_Handler, %function .type BusFault_Handler, %function
.global BusFault_Handler .global BusFault_Handler
.fnstart .fnstart
.cantunwind .cantunwind
BusFault_Handler: BusFault_Handler:
LDR R3,=FAULT_TYPE_BUS_FAULT LDR R3,=FAULT_TYPE_BUS_FAULT
B Fault_Handler B Fault_Handler
.fnend .fnend
.size BusFault_Handler, .-BusFault_Handler .size BusFault_Handler, .-BusFault_Handler
//UsageFault_Handler //UsageFault_Handler
.thumb_func .thumb_func
.type UsageFault_Handler, %function .type UsageFault_Handler, %function
.global UsageFault_Handler .global UsageFault_Handler
.fnstart .fnstart
.cantunwind .cantunwind
UsageFault_Handler: UsageFault_Handler:
LDR R3,=FAULT_TYPE_USAGE_FAULT LDR R3,=FAULT_TYPE_USAGE_FAULT
B Fault_Handler B Fault_Handler
.fnend .fnend
.size UsageFault_Handler, .-UsageFault_Handler .size UsageFault_Handler, .-UsageFault_Handler
//Common Fault_Handler to capture the context //Common Fault_Handler to capture the context
.thumb_func .thumb_func
.type Fault_Handler, %function .type Fault_Handler, %function
.global Fault_Handler .global Fault_Handler
.fnstart .fnstart
.cantunwind .cantunwind
Fault_Handler: Fault_Handler:
#if (DOMAIN_NS == 1) #if (DOMAIN_NS == 1)
MRS R0,MSP MRS R0,MSP
LDR R1,=0x4 LDR R1,=0x4
MOV R2,LR MOV R2,LR
TST R2,R1 // Check EXC_RETURN for bit 2 TST R2,R1 // Check EXC_RETURN for bit 2
BEQ Fault_Handler_Continue BEQ Fault_Handler_Continue
MRS R0,PSP MRS R0,PSP
Fault_Handler_Continue: Fault_Handler_Continue:
MOV R12,R3 MOV R12,R3
LDR R3,=mbed_fault_context LDR R3,=mbed_fault_context
LDR R1,[R3] LDR R1,[R3]
LDR R2,[R0] // Capture R0 LDR R2,[R0] // Capture R0
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#4] // Capture R1 LDR R2,[R0,#4] // Capture R1
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#8] // Capture R2 LDR R2,[R0,#8] // Capture R2
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#12] // Capture R3 LDR R2,[R0,#12] // Capture R3
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
STMIA R1!,{R4-R7} // Capture R4..R7 STMIA R1!,{R4-R7} // Capture R4..R7
MOV R7,R8 // Capture R8 MOV R7,R8 // Capture R8
STR R7,[R1] STR R7,[R1]
ADDS R1,#4 ADDS R1,#4
MOV R7,R9 // Capture R9 MOV R7,R9 // Capture R9
STR R7,[R1] STR R7,[R1]
ADDS R1,#4 ADDS R1,#4
MOV R7,R10 // Capture R10 MOV R7,R10 // Capture R10
STR R7,[R1] STR R7,[R1]
ADDS R1,#4 ADDS R1,#4
MOV R7,R11 // Capture R11 MOV R7,R11 // Capture R11
STR R7,[R1] STR R7,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#16] // Capture R12 LDR R2,[R0,#16] // Capture R12
STR R2,[R1] STR R2,[R1]
ADDS R1,#8 // Add 8 here to capture LR next, we will capture SP later ADDS R1,#8 // Add 8 here to capture LR next, we will capture SP later
LDR R2,[R0,#20] // Capture LR LDR R2,[R0,#20] // Capture LR
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#24] // Capture PC LDR R2,[R0,#24] // Capture PC
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#28] // Capture xPSR LDR R2,[R0,#28] // Capture xPSR
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
// Adjust stack pointer to its original value and capture it // Adjust stack pointer to its original value and capture it
MOV R3,R0 MOV R3,R0
ADDS R3,#0x20 // Add 0x20 to get the SP value prior to exception ADDS R3,#0x20 // Add 0x20 to get the SP value prior to exception
LDR R6,=0x200 LDR R6,=0x200
TST R2,R6 // Check for if STK was aligned by checking bit-9 in xPSR value TST R2,R6 // Check for if STK was aligned by checking bit-9 in xPSR value
BEQ Fault_Handler_Continue1 BEQ Fault_Handler_Continue1
ADDS R3,#0x4 ADDS R3,#0x4
Fault_Handler_Continue1: Fault_Handler_Continue1:
MOV R5,LR MOV R5,LR
LDR R6,=0x10 // Check for bit-4 to see if FP context was saved LDR R6,=0x10 // Check for bit-4 to see if FP context was saved
TST R5,R6 TST R5,R6
BNE Fault_Handler_Continue2 BNE Fault_Handler_Continue2
ADDS R3,#0x48 // 16 FP regs + FPCSR + 1 Reserved ADDS R3,#0x48 // 16 FP regs + FPCSR + 1 Reserved
Fault_Handler_Continue2: Fault_Handler_Continue2:
MOV R4,R1 MOV R4,R1
SUBS R4,#0x10 // Set the location of SP in ctx SUBS R4,#0x10 // Set the location of SP in ctx
STR R3,[R4] // Capture the adjusted SP STR R3,[R4] // Capture the adjusted SP
MRS R2,PSP // Get PSP MRS R2,PSP // Get PSP
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
MRS R2,MSP // Get MSP MRS R2,MSP // Get MSP
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
MOV R2,LR // Get current LR(EXC_RETURN) MOV R2,LR // Get current LR(EXC_RETURN)
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
MRS R2,CONTROL // Get CONTROL Reg MRS R2,CONTROL // Get CONTROL Reg
STR R2,[R1] STR R2,[R1]
MOV R0,R12 MOV R0,R12
LDR R3,=mbed_fault_context LDR R3,=mbed_fault_context
LDR R1,[R3] LDR R1,[R3]
BL mbed_fault_handler BL mbed_fault_handler
#endif #endif
B . // Just in case we come back here B . // Just in case we come back here
.fnend .fnend
.size Fault_Handler, .-Fault_Handler .size Fault_Handler, .-Fault_Handler
#endif #endif
.end .end

View File

@ -17,139 +17,139 @@
; * ; *
; * ----------------------------------------------------------------------------- ; * -----------------------------------------------------------------------------
; * ; *
; * Title: Cortex-M Fault Exception handlers ( Common for both ARMv7M and ARMV6M ); ; * Title: Cortex-M Fault Exception handlers ( Common for both ARMv7M and ARMV6M )
; * ; *
; * ----------------------------------------------------------------------------- ; * -----------------------------------------------------------------------------
; */ ; */
NAME except.S NAME except.S
FAULT_TYPE_HARD_FAULT EQU 0x10
FAULT_TYPE_MEMMANAGE_FAULT EQU 0x20
FAULT_TYPE_BUS_FAULT EQU 0x30
FAULT_TYPE_USAGE_FAULT EQU 0x40
#ifndef MBED_FAULT_HANDLER_DISABLED #ifndef MBED_FAULT_HANDLER_DISABLED
#ifndef DOMAIN_NS #ifndef DOMAIN_NS
#define DOMAIN_NS 1 #define DOMAIN_NS 1
#endif #endif
PRESERVE8
SECTION .rodata:DATA:NOROOT(2) FAULT_TYPE_HARD_FAULT EQU 0x10
FAULT_TYPE_MEMMANAGE_FAULT EQU 0x20
THUMB FAULT_TYPE_BUS_FAULT EQU 0x30
SECTION .text:CODE:NOROOT(2) FAULT_TYPE_USAGE_FAULT EQU 0x40
PRESERVE8
THUMB
SECTION .text:CODE:NOROOT(2)
HardFault_Handler HardFault_Handler
EXPORT HardFault_Handler EXPORT HardFault_Handler
LDR R3,=FAULT_TYPE_HARD_FAULT LDR R3,=FAULT_TYPE_HARD_FAULT
B Fault_Handler B Fault_Handler
MemManage_Handler MemManage_Handler
EXPORT MemManage_Handler EXPORT MemManage_Handler
LDR R3,=FAULT_TYPE_MEMMANAGE_FAULT LDR R3,=FAULT_TYPE_MEMMANAGE_FAULT
B Fault_Handler B Fault_Handler
BusFault_Handler BusFault_Handler
EXPORT BusFault_Handler EXPORT BusFault_Handler
LDR R3,=FAULT_TYPE_BUS_FAULT LDR R3,=FAULT_TYPE_BUS_FAULT
B Fault_Handler B Fault_Handler
UsageFault_Handler UsageFault_Handler
EXPORT UsageFault_Handler EXPORT UsageFault_Handler
LDR R3,=FAULT_TYPE_USAGE_FAULT LDR R3,=FAULT_TYPE_USAGE_FAULT
B Fault_Handler B Fault_Handler
Fault_Handler Fault_Handler
EXPORT Fault_Handler EXPORT Fault_Handler
#if (DOMAIN_NS == 1) #if (DOMAIN_NS == 1)
IMPORT mbed_fault_context IMPORT mbed_fault_context
IMPORT mbed_fault_handler IMPORT mbed_fault_handler
MRS R0,MSP MRS R0,MSP
LDR R1,=0x4 LDR R1,=0x4
MOV R2,LR MOV R2,LR
TST R2,R1 ; Check EXC_RETURN for bit 2 TST R2,R1 ; Check EXC_RETURN for bit 2
BEQ Fault_Handler_Continue BEQ Fault_Handler_Continue
MRS R0,PSP MRS R0,PSP
Fault_Handler_Continue Fault_Handler_Continue
MOV R12,R3 MOV R12,R3
LDR R3,=mbed_fault_context LDR R3,=mbed_fault_context
LDR R1,[R3] LDR R1,[R3]
LDR R2,[R0] ; Capture R0 LDR R2,[R0] ; Capture R0
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#4] ; Capture R1 LDR R2,[R0,#4] ; Capture R1
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#8] ; Capture R2 LDR R2,[R0,#8] ; Capture R2
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#12] ; Capture R3 LDR R2,[R0,#12] ; Capture R3
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
STMIA R1!,{R4-R7} ; Capture R4..R7 STMIA R1!,{R4-R7} ; Capture R4..R7
MOV R7,R8 ; Capture R8 MOV R7,R8 ; Capture R8
STR R7,[R1] STR R7,[R1]
ADDS R1,#4 ADDS R1,#4
MOV R7,R9 ; Capture R9 MOV R7,R9 ; Capture R9
STR R7,[R1] STR R7,[R1]
ADDS R1,#4 ADDS R1,#4
MOV R7,R10 ; Capture R10 MOV R7,R10 ; Capture R10
STR R7,[R1] STR R7,[R1]
ADDS R1,#4 ADDS R1,#4
MOV R7,R11 ; Capture R11 MOV R7,R11 ; Capture R11
STR R7,[R1] STR R7,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#16] ; Capture R12 LDR R2,[R0,#16] ; Capture R12
STR R2,[R1] STR R2,[R1]
ADDS R1,#8 ; Add 8 here to capture LR next, we will capture SP later ADDS R1,#8 ; Add 8 here to capture LR next, we will capture SP later
LDR R2,[R0,#20] ; Capture LR LDR R2,[R0,#20] ; Capture LR
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#24] ; Capture PC LDR R2,[R0,#24] ; Capture PC
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
LDR R2,[R0,#28] ; Capture xPSR LDR R2,[R0,#28] ; Capture xPSR
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
; Adjust stack pointer to its original value and capture it ; Adjust stack pointer to its original value and capture it
MOV R3,R0 MOV R3,R0
ADDS R3,#0x20 ; Add 0x20 to get the SP value prior to exception ADDS R3,#0x20 ; Add 0x20 to get the SP value prior to exception
LDR R6,=0x200 LDR R6,=0x200
TST R2,R6 ; Check for if STK was aligned by checking bit-9 in xPSR value TST R2,R6 ; Check for if STK was aligned by checking bit-9 in xPSR value
BEQ Fault_Handler_Continue1 BEQ Fault_Handler_Continue1
ADDS R3,#0x4 ADDS R3,#0x4
Fault_Handler_Continue1 Fault_Handler_Continue1
MOV R5,LR MOV R5,LR
LDR R6,=0x10 ; Check for bit-4 to see if FP context was saved LDR R6,=0x10 ; Check for bit-4 to see if FP context was saved
TST R5,R6 TST R5,R6
BNE Fault_Handler_Continue2 BNE Fault_Handler_Continue2
ADDS R3,#0x48 ; 16 FP regs + FPCSR + 1 Reserved ADDS R3,#0x48 ; 16 FP regs + FPCSR + 1 Reserved
Fault_Handler_Continue2 Fault_Handler_Continue2
MOV R4,R1 MOV R4,R1
SUBS R4,#0x10 ; Set the location of SP in ctx SUBS R4,#0x10 ; Set the location of SP in ctx
STR R3,[R4] ; Capture the adjusted SP STR R3,[R4] ; Capture the adjusted SP
MRS R2,PSP ; Get PSP MRS R2,PSP ; Get PSP
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
MRS R2,MSP ; Get MSP MRS R2,MSP ; Get MSP
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
MOV R2,LR ; Get current LR(EXC_RETURN) MOV R2,LR ; Get current LR(EXC_RETURN)
STR R2,[R1] STR R2,[R1]
ADDS R1,#4 ADDS R1,#4
MRS R2,CONTROL ; Get CONTROL Reg MRS R2,CONTROL ; Get CONTROL Reg
STR R2,[R1] STR R2,[R1]
MOV R0,R12 MOV R0,R12
LDR R3,=mbed_fault_context LDR R3,=mbed_fault_context
LDR R1,[R3] LDR R1,[R3]
BL mbed_fault_handler BL mbed_fault_handler
#endif #endif
B . ; Just in case we come back here B . ; Just in case we come back here
#endif ; #if (MBED_FAULT_HANDLER_SUPPORT == 1) #endif
END END