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 //------------------------------------------------------------------------------
19 This is the stack constructed by the exception handler
21 R0 0x00 # stmfd SP!,{R0-R12}
34 SP 0x34 # reserved via adding 0x20 (32) to the SP
43 LR 0x54 # SVC Link register (we need to restore it)
45 LR 0x58 # pushed by srsfd
46 CPSR 0x5c # pushed by srsfd
51 EXPORT ExceptionHandlersStart
52 EXPORT ExceptionHandlersEnd
53 EXPORT CommonExceptionEntry
54 EXPORT AsmCommonExceptionEntry
55 IMPORT CommonCExceptionHandler
58 AREA DxeExceptionHandlers, CODE, READONLY
60 ExceptionHandlersStart
66 b UndefinedInstructionEntry
69 b SoftwareInterruptEntry
78 b ReservedExceptionEntry
87 srsfd #0x13! ; Store return state on SVC stack
88 cpsid if,#0x13 ; Switch to SVC for common stack
89 stmfd SP!,{LR} ; Store the link register for the current mode
90 sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
91 stmfd SP!,{R0-R12} ; Store the register state
94 ldr R1,CommonExceptionEntry
97 UndefinedInstructionEntry
98 srsfd #0x13! ; Store return state on SVC stack
99 cpsid i,#0x13 ; Switch to SVC for common stack
100 stmfd SP!,{LR} ; Store the link register for the current mode
101 sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
102 stmfd SP!,{R0-R12} ; Store the register state
105 ldr R1,CommonExceptionEntry
108 SoftwareInterruptEntry
109 srsfd #0x13! ; Store return state on SVC stack
110 cpsid i,#0x13 ; Switch to SVC for common stack
111 stmfd SP!,{LR} ; Store the link register for the current mode
112 sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
113 stmfd SP!,{R0-R12} ; Store the register state
116 ldr R1,CommonExceptionEntry
121 srsfd #0x13! ; Store return state on SVC stack
122 cpsid i,#0x13 ; Switch to SVC for common stack
123 stmfd SP!,{LR} ; Store the link register for the current mode
124 sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
125 stmfd SP!,{R0-R12} ; Store the register state
128 ldr R1,CommonExceptionEntry
133 srsfd #0x13! ; Store return state on SVC stack
134 cpsid i,#0x13 ; Switch to SVC for common stack
135 stmfd SP!,{LR} ; Store the link register for the current mode
136 sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
137 stmfd SP!,{R0-R12} ; Store the register state
140 ldr R1,CommonExceptionEntry
143 ReservedExceptionEntry
144 srsfd #0x13! ; Store return state on SVC stack
145 cpsid if,#0x13 ; Switch to SVC for common stack
146 stmfd SP!,{LR} ; Store the link register for the current mode
147 sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
148 stmfd SP!,{R0-R12} ; Store the register state
151 ldr R1,CommonExceptionEntry
156 srsfd #0x13! ; Store return state on SVC stack
157 cpsid i,#0x13 ; Switch to SVC for common stack
158 stmfd SP!,{LR} ; Store the link register for the current mode
159 sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
160 stmfd SP!,{R0-R12} ; Store the register state
163 ldr R1,CommonExceptionEntry
168 srsfd #0x13! ; Store return state on SVC stack
169 cpsid if,#0x13 ; Switch to SVC for common stack
170 stmfd SP!,{LR} ; Store the link register for the current mode
171 sub SP,SP,#0x20 ; Save space for SP, LR, PC, IFAR - CPSR
172 stmfd SP!,{R0-R12} ; Store the register state
175 ldr R1,CommonExceptionEntry
183 AsmCommonExceptionEntry
184 mrc p15, 0, R1, c6, c0, 2 ; Read IFAR
185 str R1, [SP, #0x50] ; Store it in EFI_SYSTEM_CONTEXT_ARM.IFAR
187 mrc p15, 0, R1, c5, c0, 1 ; Read IFSR
188 str R1, [SP, #0x4c] ; Store it in EFI_SYSTEM_CONTEXT_ARM.IFSR
190 mrc p15, 0, R1, c6, c0, 0 ; Read DFAR
191 str R1, [SP, #0x48] ; Store it in EFI_SYSTEM_CONTEXT_ARM.DFAR
193 mrc p15, 0, R1, c5, c0, 0 ; Read DFSR
194 str R1, [SP, #0x44] ; Store it in EFI_SYSTEM_CONTEXT_ARM.DFSR
196 ldr R1, [SP, #0x5c] ; srsfd saved pre-exception CPSR on the stack
197 str R1, [SP, #0x40] ; Store it in EFI_SYSTEM_CONTEXT_ARM.CPSR
199 ldr R1, [SP, #0x58] ; PC is the LR pushed by srsfd
200 str R1, [SP, #0x3c] ; Store it in EFI_SYSTEM_CONTEXT_ARM.PC
201 str R1, [SP, #0x38] ; Store it in EFI_SYSTEM_CONTEXT_ARM.LR
203 sub R1, SP, #0x60 ; We pused 0x60 bytes on the stack
204 str R1, [SP, #0x34] ; Store it in EFI_SYSTEM_CONTEXT_ARM.SP
206 ; R0 is exception type
207 mov R1,SP ; Prepare System Context pointer as an argument for the exception handler
208 blx CommonCExceptionHandler ; Call exception handler
210 ldr R2,[SP,#0x40] ; EFI_SYSTEM_CONTEXT_ARM.CPSR
211 str R2,[SP,#0x5c] ; Store it back to srsfd stack slot so it can be restored
213 ldr R2,[SP,#0x3c] ; EFI_SYSTEM_CONTEXT_ARM.PC
214 str R2,[SP,#0x58] ; Store it back to srsfd stack slot so it can be restored
216 ldmfd SP!,{R0-R12} ; Restore general purpose registers
217 ; Exception handler can not change SP or LR as we would blow chunks
219 add SP,SP,#0x20 ; Clear out the remaining stack space
220 ldmfd SP!,{LR} ; restore the link register for this context
221 rfefd SP! ; return from exception via srsfd stack slot