1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
#------------------------------------------------------------------------------
#
# Copyright (c) 2008-2009 Apple Inc. All rights reserved.
#
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#------------------------------------------------------------------------------
.text
.align 2
.globl _ExceptionHandlersStart
.globl _ExceptionHandlersEnd
.globl _CommonExceptionEntry
.globl _AsmCommonExceptionEntry
.globl _gExceptionHandlers
_ExceptionHandlersStart:
_Reset:
b _ResetEntry
_UndefinedInstruction:
b _UndefinedInstructionEntry
_SoftwareInterrupt:
b _SoftwareInterruptEntry
_PrefetchAbort:
b _PrefetchAbortEntry
_DataAbort:
b _DataAbortEntry
_ReservedException:
b _ReservedExceptionEntry
_Irq:
b _IrqEntry
_Fiq:
b _FiqEntry
_ResetEntry:
stmfd sp!,{r0-r1}
mov r0,#0
ldr r1,_CommonExceptionEntry
bx r1
_UndefinedInstructionEntry:
stmfd sp!,{r0-r1}
mov r0,#1
ldr r1,_CommonExceptionEntry
bx r1
_SoftwareInterruptEntry:
stmfd sp!,{r0-r1}
mov r0,#2
ldr r1,_CommonExceptionEntry
bx r1
_PrefetchAbortEntry:
stmfd sp!,{r0-r1}
mov r0,#3
sub lr,lr,#4
ldr r1,_CommonExceptionEntry
bx r1
_DataAbortEntry:
stmfd sp!,{r0-r1}
mov r0,#4
sub lr,lr,#8
ldr r1,_CommonExceptionEntry
bx r1
_ReservedExceptionEntry:
stmfd sp!,{r0-r1}
mov r0,#5
ldr r1,_CommonExceptionEntry
bx r1
_IrqEntry:
stmfd sp!,{r0-r1}
mov r0,#6
sub lr,lr,#4
ldr r1,_CommonExceptionEntry
bx r1
_FiqEntry:
stmfd sp!,{r0-r1}
mov r0,#7
sub lr,lr,#4
ldr r1,_CommonExceptionEntry
bx r1
_CommonExceptionEntry:
.byte 0x12
.byte 0x34
.byte 0x56
.byte 0x78
_ExceptionHandlersEnd:
LIndirectgExceptionHandlers:
.long _gExceptionHandlers
_AsmCommonExceptionEntry:
mrc p15, 0, r1, c6, c0, 2 @ Read IFAR
stmfd sp!,{r1} @ Store the IFAR
mrc p15, 0, r1, c5, c0, 1 @ Read IFSR
stmfd sp!,{r1} @ Store the IFSR
mrc p15, 0, r1, c6, c0, 0 @ Read DFAR
stmfd sp!,{r1} @ Store the DFAR
mrc p15, 0, r1, c5, c0, 0 @ Read DFSR
stmfd sp!,{r1} @ Store the DFSR
mrs r1,spsr @ Read SPSR (which is the pre-exception CPSR)
stmfd sp!,{r1} @ Store the SPSR
stmfd sp!,{lr} @ Store the link register (which is the pre-exception PC)
stmfd sp,{sp,lr}^ @ Store user/system mode stack pointer and link register
nop @ Required by ARM architecture
sub sp,sp,#0x08 @ Adjust stack pointer
stmfd sp!,{r2-r12} @ Store general purpose registers
ldr r3,[sp,#0x40] @ Read saved R1 from the stack (it was saved by the exception entry routine)
ldr r2,[sp,#0x3C] @ Read saved R0 from the stack (it was saved by the exception entry routine)
stmfd sp!,{r2-r3} @ Store general purpose registers R0 and R1
mov r1,sp @ Prepare System Context pointer as an argument for the exception handler
ldr r2,LIndirectgExceptionHandlers @ Offset to 32-bit address of exception handler
ldr r2,[r2] @ Load exception handler table
ldr r3,[r2,r0,lsl #2] @ Index to find the handler for this exception
// blx r3 @ Call exception handler
bx r3 @ Call exception handler
ldr r2,[sp,#0x40] @ Load CPSR from context, in case it has changed
msr SPSR_cxsf,r2 @ Store it back to the SPSR to be restored when exiting this handler
ldmfd sp!,{r0-r12} @ Restore general purpose registers
ldmia sp,{sp,lr}^ @ Restore user/system mode stack pointer and link register
nop @ Required by ARM architecture
add sp,sp,#0x08 @ Adjust stack pointer
ldmfd sp!,{lr} @ Restore the link register (which is the pre-exception PC)
add sp,sp,#0x1C @ Clear out the remaining stack space
movs pc,lr @ Return from exception
|