source: mainline/kernel/arch/sparc32/src/trap_table.S@ e76fed9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e76fed9 was 1f12fab, checked in by Jakub Klama <jakub.klama@…>, 12 years ago

First attempt to implement preemptive trap handlers
and switch to userspace. Preemptive traps are needed
for at least page faults, as page fault handling code
can trigger window underflow/overflow exceptions.

This commit also introduces userspace window buffer
for saving userspace register windows (just as in
sparc64).

These changes are unfinished and far from working
correctly.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1#
2# Copyright (c) 2013 Jakub Klama
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/trap.h>
30
31.text
32
33.global trap_table
34.global reset_trap
35.global preemptible_trap
36.global window_overflow_trap
37.global window_underflow_trap
38
39reset_trap:
40 set 0x80000100, %l0
41 set 'r', %l1
42 sta %l1, [%l0] 0x1c
43 rett
44
45window_overflow_trap:
46 /* rotate WIM on bit right, we have 8 windows */
47 mov %wim,%l3
48 sll %l3,7,%l4
49 srl %l3,1,%l3
50 or %l3,%l4,%l3
51 and %l3,0xff,%l3
52
53 /* disable WIM traps */
54 mov %g0,%wim
55 nop; nop; nop
56
57 /* point to correct window */
58 save
59
60 /* dump registers to stack */
61 std %l0, [%sp + 0]
62 std %l2, [%sp + 8]
63 std %l4, [%sp + 16]
64 std %l6, [%sp + 24]
65 std %i0, [%sp + 32]
66 std %i2, [%sp + 40]
67 std %i4, [%sp + 48]
68 std %i6, [%sp + 56]
69
70 /* back to where we should be */
71 restore
72
73 /* set new value of window */
74 mov %l3,%wim
75 nop; nop; nop
76
77 /* go home */
78 jmp %l1
79 rett %l2
80
81window_underflow_trap:
82 /* rotate WIM on bit LEFT, we have 8 windows */
83 mov %wim,%l3
84 srl %l3,7,%l4
85 sll %l3,1,%l3
86 or %l3,%l4,%l3
87 and %l3, 0xff,%l3
88
89 /* disable WIM traps */
90 mov %g0,%wim
91 nop; nop; nop
92
93 /* point to correct window */
94 restore
95 restore
96
97 /* dump registers to stack */
98 ldd [%sp + 0], %l0
99 ldd [%sp + 8], %l2
100 ldd [%sp + 16], %l4
101 ldd [%sp + 24], %l6
102 ldd [%sp + 32], %i0
103 ldd [%sp + 40], %i2
104 ldd [%sp + 48], %i4
105 ldd [%sp + 56], %i6
106
107 /* back to where we should be */
108 save
109 save
110
111 /* set new value of window */
112 mov %l3,%wim
113 nop; nop; nop
114
115 /* go home */
116 jmp %l1
117 rett %l2
118
119preemptible_trap:
120 /* Enable traps */
121 mov %psr, %l0
122 or %l0, (1 << 5), %l0
123 mov %l0, %psr
124
125 /* Check whether previous mode was usermode */
126 and %l0, (1 << 6), %l0
127 cmp %l0, 0
128 bne 1f
129 nop
130
131 /* Set up stack */
132 set kernel_sp, %l4
133 ld [%l4], %sp
134 mov %sp, %fp
1351: sub %sp, 112, %sp
136
137 /* Save trap data on stack */
138 st %l1, [%fp - 4]
139 st %l2, [%fp - 8]
140 st %l0, [%fp - 12]
141
142 /* Jump to actual subroutine */
143 mov 1, %o0
144 jmp %g1
145 sub %fp, 12, %o1
146
147 /* Return from handler */
148 ld [%fp - 4], %l1
149 ld [%fp - 8], %l2
150 jmp %l1
151 rett %l2
152
153#define STRAP(_vector, _handler) \
154 .org trap_table + _vector * TRAP_ENTRY_SIZE; \
155 mov %psr, %l0 ; \
156 sethi %hi(_handler), %l4 ; \
157 jmp %lo(_handler) + %l4 ; \
158 nop
159
160#define TRAP(_vector, _handler) \
161 .org trap_table + _vector * TRAP_ENTRY_SIZE; \
162 sethi %hi(_handler), %g1 ; \
163 b preemptible_trap ; \
164 or %g1, %lo(_handler), %g1 ;
165
166#define INTERRUPT(_vector, _priority) \
167 .org trap_table + _vector * TRAP_ENTRY_SIZE; \
168 mov %psr, %l0 ; \
169 mov _priority, %g2 ; \
170 call exc_dispatch ; \
171 nop ;
172
173#define BADTRAP(_vector) \
174 .org trap_table + _vector * TRAP_ENTRY_SIZE ; \
175 ta 0 ;
176
177.align TRAP_TABLE_SIZE
178trap_table:
179 TRAP(0x0, reset_trap)
180 TRAP(0x1, instruction_access_exception)
181 TRAP(0x2, illegal_instruction)
182 TRAP(0x3, privileged_instruction)
183 TRAP(0x4, fp_disabled)
184 STRAP(0x5, window_overflow_trap)
185 STRAP(0x6, window_underflow_trap)
186 TRAP(0x7, mem_address_not_aligned)
187 TRAP(0x8, fp_exception)
188 TRAP(0x9, data_access_exception)
189 TRAP(0xa, tag_overflow)
190 BADTRAP(0xb)
191 BADTRAP(0xc)
192 BADTRAP(0xd)
193 BADTRAP(0xe)
194 BADTRAP(0xf)
195 BADTRAP(0x10)
196 INTERRUPT(0x11, 1)
197 INTERRUPT(0x12, 2)
198 INTERRUPT(0x13, 3)
199 INTERRUPT(0x14, 4)
200 INTERRUPT(0x15, 5)
201 INTERRUPT(0x16, 6)
202 INTERRUPT(0x17, 7)
203 INTERRUPT(0x18, 8)
204 INTERRUPT(0x19, 9)
205 INTERRUPT(0x1a, 10)
206 INTERRUPT(0x1b, 11)
207 INTERRUPT(0x1c, 12)
208 INTERRUPT(0x1d, 13)
209 INTERRUPT(0x1e, 14)
210 INTERRUPT(0x1f, 15)
211 TRAP(0x21, instruction_access_error)
212 BADTRAP(0x22)
213 BADTRAP(0x23)
214 BADTRAP(0x24)
215 BADTRAP(0x25)
216 BADTRAP(0x26)
217 BADTRAP(0x27)
218 BADTRAP(0x28)
219 TRAP(0x29, data_access_error)
220 TRAP(0x2a, division_by_zero)
221 TRAP(0x2b, data_store_error)
222 TRAP(0x2c, data_access_mmu_miss)
223 BADTRAP(0x2d)
224 BADTRAP(0x2e)
225 BADTRAP(0x2f)
226 BADTRAP(0x30)
227 BADTRAP(0x31)
228 BADTRAP(0x32)
229 BADTRAP(0x33)
230 BADTRAP(0x34)
231 BADTRAP(0x35)
232 BADTRAP(0x36)
233 BADTRAP(0x37)
234 BADTRAP(0x38)
235 BADTRAP(0x39)
236 BADTRAP(0x3a)
237 BADTRAP(0x3b)
238 BADTRAP(0x3c)
239 BADTRAP(0x3d)
240 BADTRAP(0x3e)
241 BADTRAP(0x3f)
242 BADTRAP(0x40)
243 BADTRAP(0x41)
244 BADTRAP(0x42)
245 BADTRAP(0x43)
246 BADTRAP(0x44)
247 BADTRAP(0x45)
248 BADTRAP(0x46)
249 BADTRAP(0x47)
250 BADTRAP(0x48)
251 BADTRAP(0x49)
252 BADTRAP(0x4a)
253 BADTRAP(0x4b)
254 BADTRAP(0x4c)
255 BADTRAP(0x4d)
256 BADTRAP(0x4e)
257 BADTRAP(0x4f)
258 BADTRAP(0x50)
259 BADTRAP(0x51)
260 BADTRAP(0x52)
261 BADTRAP(0x53)
262 BADTRAP(0x54)
263 BADTRAP(0x55)
264 BADTRAP(0x56)
265 BADTRAP(0x57)
266 BADTRAP(0x58)
267 BADTRAP(0x59)
268 BADTRAP(0x5a)
269 BADTRAP(0x5b)
270 BADTRAP(0x5c)
271 BADTRAP(0x5d)
272 BADTRAP(0x5e)
273 BADTRAP(0x5f)
274 BADTRAP(0x60)
275 BADTRAP(0x61)
276 BADTRAP(0x62)
277 BADTRAP(0x63)
278 BADTRAP(0x64)
279 BADTRAP(0x65)
280 BADTRAP(0x66)
281 BADTRAP(0x67)
282 BADTRAP(0x68)
283 BADTRAP(0x69)
284 BADTRAP(0x6a)
285 BADTRAP(0x6b)
286 BADTRAP(0x6c)
287 BADTRAP(0x6d)
288 BADTRAP(0x6e)
289 BADTRAP(0x6f)
290 BADTRAP(0x70)
291 BADTRAP(0x71)
292 BADTRAP(0x72)
293 BADTRAP(0x73)
294 BADTRAP(0x74)
295 BADTRAP(0x75)
296 BADTRAP(0x76)
297 BADTRAP(0x77)
298 BADTRAP(0x78)
299 BADTRAP(0x79)
300 BADTRAP(0x7a)
301 BADTRAP(0x7b)
302 BADTRAP(0x7c)
303 BADTRAP(0x7d)
304 BADTRAP(0x7e)
305 BADTRAP(0x7f)
306
Note: See TracBrowser for help on using the repository browser.