1 #------------------------------------------------------------------------------
3 # Copyright (c) 2008-2009 Apple Inc. All rights reserved.
5 # All rights reserved. This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #------------------------------------------------------------------------------
18 .globl _ExceptionHandlersStart
19 .globl _ExceptionHandlersEnd
20 .globl _CommonExceptionEntry
21 .globl _AsmCommonExceptionEntry
22 .globl _gExceptionHandlers
24 _ExceptionHandlersStart:
29 _UndefinedInstruction:
30 b _UndefinedInstructionEntry
33 b _SoftwareInterruptEntry
42 b _ReservedExceptionEntry
53 ldr r1,_CommonExceptionEntry
56 _UndefinedInstructionEntry:
59 ldr r1,_CommonExceptionEntry
62 _SoftwareInterruptEntry:
65 ldr r1,_CommonExceptionEntry
72 ldr r1,_CommonExceptionEntry
79 ldr r1,_CommonExceptionEntry
82 _ReservedExceptionEntry:
85 ldr r1,_CommonExceptionEntry
92 ldr r1,_CommonExceptionEntry
99 ldr r1,_CommonExceptionEntry
102 _CommonExceptionEntry:
108 _ExceptionHandlersEnd:
110 LIndirectgExceptionHandlers:
111 .long _gExceptionHandlers
113 _AsmCommonExceptionEntry:
114 mrc p15, 0, r1, c6, c0, 2 @ Read IFAR
115 stmfd sp!,{r1} @ Store the IFAR
117 mrc p15, 0, r1, c5, c0, 1 @ Read IFSR
118 stmfd sp!,{r1} @ Store the IFSR
120 mrc p15, 0, r1, c6, c0, 0 @ Read DFAR
121 stmfd sp!,{r1} @ Store the DFAR
123 mrc p15, 0, r1, c5, c0, 0 @ Read DFSR
124 stmfd sp!,{r1} @ Store the DFSR
126 mrs r1,spsr @ Read SPSR (which is the pre-exception CPSR)
127 stmfd sp!,{r1} @ Store the SPSR
129 stmfd sp!,{lr} @ Store the link register (which is the pre-exception PC)
130 stmfd sp,{sp,lr}^ @ Store user/system mode stack pointer and link register
131 nop @ Required by ARM architecture
132 sub sp,sp,#0x08 @ Adjust stack pointer
133 stmfd sp!,{r2-r12} @ Store general purpose registers
135 ldr r3,[sp,#0x40] @ Read saved R1 from the stack (it was saved by the exception entry routine)
136 ldr r2,[sp,#0x3C] @ Read saved R0 from the stack (it was saved by the exception entry routine)
137 stmfd sp!,{r2-r3} @ Store general purpose registers R0 and R1
139 mov r1,sp @ Prepare System Context pointer as an argument for the exception handler
141 ldr r2,LIndirectgExceptionHandlers @ Offset to 32-bit address of exception handler
142 ldr r2,[r2] @ Load exception handler table
143 ldr r3,[r2,r0,lsl #2] @ Index to find the handler for this exception
145 // blx r3 @ Call exception handler
146 bx r3 @ Call exception handler
148 ldr r2,[sp,#0x40] @ Load CPSR from context, in case it has changed
149 msr SPSR_cxsf,r2 @ Store it back to the SPSR to be restored when exiting this handler
151 ldmfd sp!,{r0-r12} @ Restore general purpose registers
152 ldmia sp,{sp,lr}^ @ Restore user/system mode stack pointer and link register
153 nop @ Required by ARM architecture
154 add sp,sp,#0x08 @ Adjust stack pointer
155 ldmfd sp!,{lr} @ Restore the link register (which is the pre-exception PC)
156 add sp,sp,#0x1C @ Clear out the remaining stack space
157 movs pc,lr @ Return from exception