source: mainline/kernel/arch/arm32/src/exc_handler.S@ b0c2075

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b0c2075 was 77f91fe, checked in by Jan Vesely <jano.vesely@…>, 13 years ago

arm32: Align stack to 8bytes in exception handlers.

Fixes printf of uint64_t values. (bug #490)

  • Property mode set to 100644
File size: 4.8 KB
Line 
1#
2# Copyright (c) 2009 Vineeth Pillai
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9# - Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# - Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# - The name of the author may not be used to endorse or promote products
15# derived from this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28
29.text
30
31.global irq_exception_entry
32.global fiq_exception_entry
33.global data_abort_exception_entry
34.global prefetch_abort_exception_entry
35.global undef_instr_exception_entry
36.global swi_exception_entry
37.global reset_exception_entry
38
39
40# Switches to kernel stack and saves all registers there.
41#
42# The stack frame created by the function looks like:
43#
44# |_________________|
45# | |
46# | SPSR |
47# | |
48# |_________________|
49# | Stack Pointer |
50# | of |
51# | Previous Mode |
52# |_________________|
53# | Return address |
54# | of |
55# | Previous Mode |
56# |_________________|
57# | R0 - R12 |
58# | of |
59# | Previous Mode |
60# |_________________|
61# | Return address |
62# | from |
63# |Exception Handler|
64# |_________________|
65# | |
66#
67#
68
69.macro SAVE_REGS_TO_STACK
70 stmfd r13!, {r0-r3}
71 mov r3, sp
72 add sp, sp, #16
73 mrs r1, cpsr
74 bic r1, r1, #0x1f
75 mrs r2, spsr
76 and r0, r2, #0x1f
77 cmp r0, #0x10
78 bne 1f
79
80 # prev mode was usermode
81 mov r0, lr
82
83 # Switch to supervisor mode
84 orr r1, r1, #0x13
85 msr cpsr_c, r1
86
87 # Load sp with [supervisor_sp]
88 ldr r13, =supervisor_sp
89 ldr r13, [r13]
90
91 # Populate the stack frame
92 msr spsr, r2
93 mov lr, r0
94 stmfd r13!, {lr}
95 stmfd r13!, {r4-r12}
96 ldmfd r3!, {r4-r7}
97 stmfd r13!, {r4-r7}
98 mov r4, r13
99 stmfd r4, {r13, lr}^
100 nop /* Cannot access r13 immediately after stm(2) */
101 sub r13, r13, #8
102 stmfd r13!, {r2}
103
104 # Stop stack traces here
105 mov fp, #0
106
107 b 2f
108
109 # mode was not usermode
1101:
111 # Switch to previous mode which is undoubtedly the supervisor mode
112 orr r1, r1, r0
113 mov r0, lr
114 msr cpsr_c, r1
115
116 # Populate the stack frame
117 mov r1, sp
118 stmfd r13!, {r0}
119 stmfd r13!, {r4-r12}
120
121 # Store r0-r3 in r4-r7 and then push it on to stack
122 ldmfd r3!, {r4-r7}
123 stmfd r13!, {r4-r7}
124
125 # Push return address and stack pointer on to stack
126 stmfd r13!, {lr}
127 stmfd r13!, {r1}
128 mov lr, r0
129 msr spsr, r2
130 stmfd r13!, {r2}
1312:
132 sub sp, sp, #4
133.endm
134
135.macro LOAD_REGS_FROM_STACK
136 add sp, sp, #4
137 ldmfd r13!, {r0}
138 msr spsr, r0
139 and r0, r0, #0x1f
140 cmp r0, #0x10
141 bne 1f
142
143 # return to user mode
144 mov r0, r13
145 ldmfd r0, {r13, lr}^
146 nop /* Cannot access r13 immediately after ldm(2) */
147 add r13, r13, #8
148 b 2f
149
150 # return to non-user mode
1511:
152 ldmfd r13!, {r1, lr}
153
1542:
155 ldmfd r13!, {r0-r12, pc}^
156.endm
157
158reset_exception_entry:
159 SAVE_REGS_TO_STACK
160 mov r0, #0
161 mov r1, r13
162 bl ras_check
163 LOAD_REGS_FROM_STACK
164
165irq_exception_entry:
166 sub lr, lr, #4
167 SAVE_REGS_TO_STACK
168 mov r0, #5
169 mov r1, r13
170 bl ras_check
171 LOAD_REGS_FROM_STACK
172
173fiq_exception_entry:
174 sub lr, lr, #4
175 SAVE_REGS_TO_STACK
176 mov r0, #6
177 mov r1, r13
178 bl ras_check
179 LOAD_REGS_FROM_STACK
180
181undef_instr_exception_entry:
182 SAVE_REGS_TO_STACK
183 mov r0, #1
184 mov r1, r13
185 bl ras_check
186 LOAD_REGS_FROM_STACK
187
188prefetch_abort_exception_entry:
189 sub lr, lr, #4
190 SAVE_REGS_TO_STACK
191 mov r0, #3
192 mov r1, r13
193 bl ras_check
194 LOAD_REGS_FROM_STACK
195
196data_abort_exception_entry:
197 sub lr, lr, #8
198 SAVE_REGS_TO_STACK
199 mov r0, #4
200 mov r1, r13
201 bl ras_check
202 LOAD_REGS_FROM_STACK
203
204swi_exception_entry:
205 ldr r13, =exc_stack
206 SAVE_REGS_TO_STACK
207 mov r0, #2
208 mov r1, r13
209 bl ras_check
210 LOAD_REGS_FROM_STACK
211
Note: See TracBrowser for help on using the repository browser.