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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1b20da0 was 1b20da0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on non-empty lines, in certain file types.

Command used: tools/srepl '\([^[:space:]]\)\s\+$' '\1' -- *.c *.h *.py *.sh *.s *.S *.ag

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[6ac14a70]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
[73b3ecd]29#include <abi/asmtool.h>
[6ac14a70]30
[1b20da0]31.text
[6ac14a70]32
33# Switches to kernel stack and saves all registers there.
34#
35# The stack frame created by the function looks like:
36#
37# |_________________|
38# | |
39# | SPSR |
40# | |
41# |_________________|
42# | Stack Pointer |
43# | of |
44# | Previous Mode |
45# |_________________|
46# | Return address |
47# | of |
48# | Previous Mode |
49# |_________________|
50# | R0 - R12 |
51# | of |
52# | Previous Mode |
53# |_________________|
54# | Return address |
55# | from |
56# |Exception Handler|
57# |_________________|
58# | |
59#
60#
61
62.macro SAVE_REGS_TO_STACK
63 stmfd r13!, {r0-r3}
64 mov r3, sp
65 add sp, sp, #16
66 mrs r1, cpsr
67 bic r1, r1, #0x1f
68 mrs r2, spsr
69 and r0, r2, #0x1f
70 cmp r0, #0x10
71 bne 1f
72
73 # prev mode was usermode
74 mov r0, lr
75
76 # Switch to supervisor mode
77 orr r1, r1, #0x13
78 msr cpsr_c, r1
79
80 # Load sp with [supervisor_sp]
81 ldr r13, =supervisor_sp
82 ldr r13, [r13]
83
84 # Populate the stack frame
85 msr spsr, r2
86 mov lr, r0
87 stmfd r13!, {lr}
88 stmfd r13!, {r4-r12}
89 ldmfd r3!, {r4-r7}
90 stmfd r13!, {r4-r7}
[dfd735a1]91 mov r4, r13
92 stmfd r4, {r13, lr}^
93 nop /* Cannot access r13 immediately after stm(2) */
[bd11d3e]94 sub r13, r13, #8
[6ac14a70]95 stmfd r13!, {r2}
[8e374ea7]96
97 # Stop stack traces here
98 mov fp, #0
99
[6ac14a70]100 b 2f
101
102 # mode was not usermode
1031:
104 # Switch to previous mode which is undoubtedly the supervisor mode
105 orr r1, r1, r0
106 mov r0, lr
107 msr cpsr_c, r1
108
109 # Populate the stack frame
110 mov r1, sp
111 stmfd r13!, {r0}
112 stmfd r13!, {r4-r12}
113
114 # Store r0-r3 in r4-r7 and then push it on to stack
115 ldmfd r3!, {r4-r7}
116 stmfd r13!, {r4-r7}
117
118 # Push return address and stack pointer on to stack
119 stmfd r13!, {lr}
120 stmfd r13!, {r1}
121 mov lr, r0
122 msr spsr, r2
123 stmfd r13!, {r2}
1242:
[77f91fe]125 sub sp, sp, #4
[6ac14a70]126.endm
127
128.macro LOAD_REGS_FROM_STACK
[77f91fe]129 add sp, sp, #4
[6ac14a70]130 ldmfd r13!, {r0}
131 msr spsr, r0
132 and r0, r0, #0x1f
133 cmp r0, #0x10
134 bne 1f
135
136 # return to user mode
[dfd735a1]137 mov r0, r13
138 ldmfd r0, {r13, lr}^
139 nop /* Cannot access r13 immediately after ldm(2) */
[bd11d3e]140 add r13, r13, #8
[6ac14a70]141 b 2f
142
143 # return to non-user mode
1441:
145 ldmfd r13!, {r1, lr}
146
1472:
148 ldmfd r13!, {r0-r12, pc}^
149.endm
150
[73b3ecd]151SYMBOL(reset_exception_entry)
[6ac14a70]152 SAVE_REGS_TO_STACK
153 mov r0, #0
154 mov r1, r13
[b3b7e14a]155 bl ras_check
[6ac14a70]156 LOAD_REGS_FROM_STACK
157
[73b3ecd]158SYMBOL(irq_exception_entry)
[6ac14a70]159 sub lr, lr, #4
160 SAVE_REGS_TO_STACK
161 mov r0, #5
162 mov r1, r13
[b3b7e14a]163 bl ras_check
[6ac14a70]164 LOAD_REGS_FROM_STACK
165
[73b3ecd]166SYMBOL(fiq_exception_entry)
[6ac14a70]167 sub lr, lr, #4
168 SAVE_REGS_TO_STACK
169 mov r0, #6
170 mov r1, r13
[b3b7e14a]171 bl ras_check
[6ac14a70]172 LOAD_REGS_FROM_STACK
173
[73b3ecd]174SYMBOL(undef_instr_exception_entry)
[6ac14a70]175 SAVE_REGS_TO_STACK
176 mov r0, #1
177 mov r1, r13
[b3b7e14a]178 bl ras_check
[6ac14a70]179 LOAD_REGS_FROM_STACK
180
[73b3ecd]181SYMBOL(prefetch_abort_exception_entry)
[6ac14a70]182 sub lr, lr, #4
183 SAVE_REGS_TO_STACK
184 mov r0, #3
185 mov r1, r13
[b3b7e14a]186 bl ras_check
[6ac14a70]187 LOAD_REGS_FROM_STACK
188
[73b3ecd]189SYMBOL(data_abort_exception_entry)
[6ac14a70]190 sub lr, lr, #8
191 SAVE_REGS_TO_STACK
192 mov r0, #4
193 mov r1, r13
[b3b7e14a]194 bl ras_check
[6ac14a70]195 LOAD_REGS_FROM_STACK
196
[73b3ecd]197SYMBOL(swi_exception_entry)
[6ac14a70]198 ldr r13, =exc_stack
199 SAVE_REGS_TO_STACK
200 mov r0, #2
201 mov r1, r13
[82a04c6]202 bl ras_check
[6ac14a70]203 LOAD_REGS_FROM_STACK
204
Note: See TracBrowser for help on using the repository browser.