source: mainline/kernel/arch/ppc32/src/exception.S@ 3ab2d1e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3ab2d1e was 3ab2d1e, checked in by Jakub Jermar <jakub@…>, 11 years ago

Properly terminate the SP back chain on exception.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1#
2# Copyright (c) 2006 Martin Decky
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#include <arch/asm/regname.h>
30#include <arch/msr.h>
31#include <arch/mm/page.h>
32
33.section K_UNMAPPED_TEXT_START, "ax"
34
35.macro CONTEXT_STORE
36
37 # save r12 in SPRG1, backup CR in r12
38 # save SP in SPRG2
39
40 mtsprg1 r12
41 mfcr r12
42 mtsprg2 sp
43
44 # check whether SP is in kernel
45
46 andis. sp, sp, 0x8000
47 bne 1f
48
49 # stack is in user-space
50
51 mfsprg0 sp
52
53 b 2f
54
55 1:
56
57 # stack is in kernel
58
59 mfsprg2 sp
60 subis sp, sp, 0x8000
61
62 2:
63
64 subi sp, sp, 164
65 stw r0, 8(sp)
66 stw r2, 12(sp)
67 stw r3, 16(sp)
68 stw r4, 20(sp)
69 stw r5, 24(sp)
70 stw r6, 28(sp)
71 stw r7, 32(sp)
72 stw r8, 36(sp)
73 stw r9, 40(sp)
74 stw r10, 44(sp)
75 stw r11, 48(sp)
76 stw r13, 52(sp)
77 stw r14, 56(sp)
78 stw r15, 60(sp)
79 stw r16, 64(sp)
80 stw r17, 68(sp)
81 stw r18, 72(sp)
82 stw r19, 76(sp)
83 stw r20, 80(sp)
84 stw r21, 84(sp)
85 stw r22, 88(sp)
86 stw r23, 92(sp)
87 stw r24, 96(sp)
88 stw r25, 100(sp)
89 stw r26, 104(sp)
90 stw r27, 108(sp)
91 stw r28, 112(sp)
92 stw r29, 116(sp)
93 stw r30, 120(sp)
94 stw r31, 124(sp)
95
96 stw r12, 128(sp)
97
98 mfsrr0 r12
99 stw r12, 132(sp)
100
101 mfsrr1 r12
102 stw r12, 136(sp)
103
104 mflr r12
105 stw r12, 140(sp)
106
107 mfctr r12
108 stw r12, 144(sp)
109
110 mfxer r12
111 stw r12, 148(sp)
112
113 mfdar r12
114 stw r12, 152(sp)
115
116 mfsprg1 r12
117 stw r12, 156(sp)
118
119 mfsprg2 r12
120 stw r12, 160(sp)
121
122 li r12, 0
123 stw r12, 0(sp)
124.endm
125
126.org 0x100
127.global exc_system_reset
128exc_system_reset:
129 CONTEXT_STORE
130
131 li r3, 0
132 b jump_to_kernel
133
134.org 0x200
135.global exc_machine_check
136exc_machine_check:
137 CONTEXT_STORE
138
139 li r3, 1
140 b jump_to_kernel
141
142.org 0x300
143.global exc_data_storage
144exc_data_storage:
145 CONTEXT_STORE
146
147 li r3, 2
148 b jump_to_kernel
149
150.org 0x400
151.global exc_instruction_storage
152exc_instruction_storage:
153 CONTEXT_STORE
154
155 li r3, 3
156 b jump_to_kernel
157
158.org 0x500
159.global exc_external
160exc_external:
161 CONTEXT_STORE
162
163 li r3, 4
164 b jump_to_kernel
165
166.org 0x600
167.global exc_alignment
168exc_alignment:
169 CONTEXT_STORE
170
171 li r3, 5
172 b jump_to_kernel
173
174.org 0x700
175.global exc_program
176exc_program:
177 CONTEXT_STORE
178
179 li r3, 6
180 b jump_to_kernel
181
182.org 0x800
183.global exc_fp_unavailable
184exc_fp_unavailable:
185 CONTEXT_STORE
186
187 li r3, 7
188 b jump_to_kernel
189
190.org 0x900
191.global exc_decrementer
192exc_decrementer:
193 CONTEXT_STORE
194
195 li r3, 8
196 b jump_to_kernel
197
198.org 0xa00
199.global exc_reserved0
200exc_reserved0:
201 CONTEXT_STORE
202
203 li r3, 9
204 b jump_to_kernel
205
206.org 0xb00
207.global exc_reserved1
208exc_reserved1:
209 CONTEXT_STORE
210
211 li r3, 10
212 b jump_to_kernel
213
214.org 0xc00
215.global exc_syscall
216exc_syscall:
217 CONTEXT_STORE
218
219 b jump_to_kernel_syscall
220
221.org 0xd00
222.global exc_trace
223exc_trace:
224 CONTEXT_STORE
225
226 li r3, 12
227 b jump_to_kernel
228
229.org 0x1000
230.global exc_itlb_miss
231exc_itlb_miss:
232 CONTEXT_STORE
233
234 li r3, 13
235 b jump_to_kernel
236
237.org 0x1100
238.global exc_dtlb_miss_load
239exc_dtlb_miss_load:
240 CONTEXT_STORE
241
242 li r3, 14
243 b jump_to_kernel
244
245.org 0x1200
246.global exc_dtlb_miss_store
247exc_dtlb_miss_store:
248 CONTEXT_STORE
249
250 li r3, 15
251 b jump_to_kernel
252
253.org 0x4000
254jump_to_kernel:
255 lis r12, iret@ha
256 addi r12, r12, iret@l
257 mtlr r12
258
259 lis r12, exc_dispatch@ha
260 addi r12, r12, exc_dispatch@l
261 mtsrr0 r12
262
263 mfsrr1 r5
264 andi. r5, r5, MSR_FP
265 mfmsr r12
266 or r12, r12, r5 # Propagate MSR_FP from SRR1 to MSR
267 ori r12, r12, (MSR_IR | MSR_DR)@l
268 mtsrr1 r12
269
270 addis sp, sp, 0x8000
271 mr r4, sp
272 addi r4, r4, 8
273
274 rfi
275
276jump_to_kernel_syscall:
277 lis r12, syscall_handler@ha
278 addi r12, r12, syscall_handler@l
279 mtsrr0 r12
280
281 lis r12, iret_syscall@ha
282 addi r12, r12, iret_syscall@l
283 mtlr r12
284
285 mfsrr1 r0
286 andi. r0, r0, MSR_FP
287 mfmsr r12
288 or r12, r12, r0 # Propagate MSR_FP from SRR1 to MSR
289 ori r12, r12, (MSR_IR | MSR_DR)@l
290 mtsrr1 r12
291
292 addis sp, sp, 0x8000
293 rfi
Note: See TracBrowser for help on using the repository browser.