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 //------------------------------------------------------------------------------
15 EXPORT ExceptionHandlersStart
16 EXPORT ExceptionHandlersEnd
17 EXPORT CommonExceptionEntry
18 EXPORT AsmCommonExceptionEntry
19 IMPORT gExceptionHandlers
21 AREA DxeExceptionHandlers, CODE, READONLY
23 ExceptionHandlersStart
29 B UndefinedInstructionEntry
32 B SoftwareInterruptEntry
41 B ReservedExceptionEntry
52 LDR R1,CommonExceptionEntry
55 UndefinedInstructionEntry
58 LDR R1,CommonExceptionEntry
61 SoftwareInterruptEntry
64 LDR R1,CommonExceptionEntry
71 LDR R1,CommonExceptionEntry
78 LDR R1,CommonExceptionEntry
81 ReservedExceptionEntry
84 LDR R1,CommonExceptionEntry
91 LDR R1,CommonExceptionEntry
98 LDR R1,CommonExceptionEntry
106 AsmCommonExceptionEntry
107 MRC p15, 0, r1, c6, c0, 2 ; Read IFAR
108 STMFD SP!,{R1} ; Store the IFAR
110 MRC p15, 0, r1, c5, c0, 1 ; Read IFSR
111 STMFD SP!,{R1} ; Store the IFSR
113 MRC p15, 0, r1, c6, c0, 0 ; Read DFAR
114 STMFD SP!,{R1} ; Store the DFAR
116 MRC p15, 0, r1, c5, c0, 0 ; Read DFSR
117 STMFD SP!,{R1} ; Store the DFSR
119 MRS R1,SPSR ; Read SPSR (which is the pre-exception CPSR)
120 STMFD SP!,{R1} ; Store the SPSR
122 STMFD SP!,{LR} ; Store the link register (which is the pre-exception PC)
123 STMFD SP,{SP,LR}^ ; Store user/system mode stack pointer and link register
124 NOP ; Required by ARM architecture
125 SUB SP,SP,#0x08 ; Adjust stack pointer
126 STMFD SP!,{R2-R12} ; Store general purpose registers
128 LDR R3,[SP,#0x40] ; Read saved R1 from the stack (it was saved by the exception entry routine)
129 LDR R2,[SP,#0x3C] ; Read saved R0 from the stack (it was saved by the exception entry routine)
130 STMFD SP!,{R2-R3} ; Store general purpose registers R0 and R1
132 MOV R1,SP ; Prepare System Context pointer as an argument for the exception handler
134 LDR R2,=gExceptionHandlers ; Load exception handler table
135 LDR R3,[R2,R0,LSL #2] ; Index to find the handler for this exception
137 BLX R3 ; Call exception handler
139 LDR R2,[SP,#0x40] ; Load CPSR from context, in case it has changed
140 MSR SPSR_cxsf,R2 ; Store it back to the SPSR to be restored when exiting this handler
142 LDMFD SP!,{R0-R12} ; Restore general purpose registers
143 LDM SP,{SP,LR}^ ; Restore user/system mode stack pointer and link register
144 NOP ; Required by ARM architecture
145 ADD SP,SP,#0x08 ; Adjust stack pointer
146 LDMFD SP!,{LR} ; Restore the link register (which is the pre-exception PC)
147 ADD SP,SP,#0x1C ; Clear out the remaining stack space
148 MOVS PC,LR ; Return from exception