Rev 667 | Rev 883 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
529 | jermar | 1 | # |
2 | # Copyright (C) 2005 Jakub Jermar |
||
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 | /** |
||
634 | jermar | 30 | * This file contains two trap tables. |
31 | * First, trap_table, is the one wich contains handlers implemented by |
||
32 | * kernel. During initialization, these handlers are copied out to |
||
33 | * the second trap table, trap_table_save, and the first table is |
||
34 | * overwritten with copy of OFW's own trap table. The copy is then patched |
||
35 | * from the trap_table_save. |
||
36 | * |
||
37 | * This arrangement is beneficial because kernel handlers stay on their |
||
38 | * link-time addresses which is good for debugging. |
||
529 | jermar | 39 | */ |
666 | jermar | 40 | |
41 | .register %g2, #scratch |
||
42 | .register %g3, #scratch |
||
43 | .register %g6, #scratch |
||
44 | .register %g7, #scratch |
||
45 | |||
529 | jermar | 46 | .text |
47 | |||
630 | jermar | 48 | #include <arch/trap/trap_table.h> |
49 | #include <arch/trap/regwin.h> |
||
663 | jermar | 50 | #include <arch/trap/interrupt.h> |
667 | jermar | 51 | #include <arch/trap/exception.h> |
863 | jermar | 52 | #include <arch/trap/mmu.h> |
667 | jermar | 53 | #include <arch/stack.h> |
529 | jermar | 54 | |
55 | #define TABLE_SIZE TRAP_TABLE_SIZE |
||
56 | #define ENTRY_SIZE TRAP_TABLE_ENTRY_SIZE |
||
57 | |||
58 | /* |
||
634 | jermar | 59 | * Kernel trap table. |
529 | jermar | 60 | */ |
61 | .align TABLE_SIZE |
||
62 | .global trap_table |
||
63 | trap_table: |
||
64 | |||
667 | jermar | 65 | /* TT = 0x08, TL = 0, instruction_access_exception */ |
66 | .org trap_table + TT_INSTRUCTION_ACCESS_EXCEPTION*ENTRY_SIZE |
||
67 | .global instruction_access_exception |
||
68 | instruction_access_exception: |
||
69 | SIMPLE_HANDLER do_instruction_access_exc |
||
70 | |||
663 | jermar | 71 | /* TT = 0x24, TL = 0, clean_window handler */ |
634 | jermar | 72 | .org trap_table + TT_CLEAN_WINDOW*ENTRY_SIZE |
630 | jermar | 73 | .global clean_window_handler |
74 | clean_window_handler: |
||
75 | CLEAN_WINDOW_HANDLER |
||
529 | jermar | 76 | |
667 | jermar | 77 | /* TT = 0x34, TL = 0, mem_address_not_aligned */ |
78 | .org trap_table + TT_MEM_ADDRESS_NOT_ALIGNED*ENTRY_SIZE |
||
79 | .global mem_address_not_aligned |
||
80 | mem_address_not_aligned: |
||
81 | SIMPLE_HANDLER do_mem_address_not_aligned |
||
82 | |||
664 | jermar | 83 | /* TT = 0x41, TL = 0, interrupt_level_1 handler */ |
84 | .org trap_table + TT_INTERRUPT_LEVEL_1*ENTRY_SIZE |
||
85 | .global interrupt_level_1_handler |
||
86 | interrupt_level_1_handler: |
||
87 | INTERRUPT_LEVEL_N_HANDLER 1 |
||
88 | |||
89 | /* TT = 0x42, TL = 0, interrupt_level_2 handler */ |
||
90 | .org trap_table + TT_INTERRUPT_LEVEL_2*ENTRY_SIZE |
||
91 | .global interrupt_level_2_handler |
||
92 | interrupt_level_2_handler: |
||
93 | INTERRUPT_LEVEL_N_HANDLER 2 |
||
94 | |||
95 | /* TT = 0x43, TL = 0, interrupt_level_3 handler */ |
||
96 | .org trap_table + TT_INTERRUPT_LEVEL_3*ENTRY_SIZE |
||
97 | .global interrupt_level_3_handler |
||
98 | interrupt_level_3_handler: |
||
99 | INTERRUPT_LEVEL_N_HANDLER 3 |
||
100 | |||
101 | /* TT = 0x44, TL = 0, interrupt_level_4 handler */ |
||
102 | .org trap_table + TT_INTERRUPT_LEVEL_4*ENTRY_SIZE |
||
103 | .global interrupt_level_4_handler |
||
104 | interrupt_level_4_handler: |
||
105 | INTERRUPT_LEVEL_N_HANDLER 4 |
||
106 | |||
107 | /* TT = 0x45, TL = 0, interrupt_level_5 handler */ |
||
108 | .org trap_table + TT_INTERRUPT_LEVEL_5*ENTRY_SIZE |
||
109 | .global interrupt_level_5_handler |
||
110 | interrupt_level_5_handler: |
||
111 | INTERRUPT_LEVEL_N_HANDLER 5 |
||
112 | |||
113 | /* TT = 0x46, TL = 0, interrupt_level_6 handler */ |
||
114 | .org trap_table + TT_INTERRUPT_LEVEL_6*ENTRY_SIZE |
||
115 | .global interrupt_level_6_handler |
||
116 | interrupt_level_6_handler: |
||
117 | INTERRUPT_LEVEL_N_HANDLER 6 |
||
118 | |||
119 | /* TT = 0x47, TL = 0, interrupt_level_7 handler */ |
||
120 | .org trap_table + TT_INTERRUPT_LEVEL_7*ENTRY_SIZE |
||
121 | .global interrupt_level_7_handler |
||
122 | interrupt_level_7_handler: |
||
123 | INTERRUPT_LEVEL_N_HANDLER 7 |
||
124 | |||
125 | /* TT = 0x48, TL = 0, interrupt_level_8 handler */ |
||
126 | .org trap_table + TT_INTERRUPT_LEVEL_8*ENTRY_SIZE |
||
127 | .global interrupt_level_8_handler |
||
128 | interrupt_level_8_handler: |
||
129 | INTERRUPT_LEVEL_N_HANDLER 8 |
||
130 | |||
131 | /* TT = 0x49, TL = 0, interrupt_level_9 handler */ |
||
132 | .org trap_table + TT_INTERRUPT_LEVEL_9*ENTRY_SIZE |
||
133 | .global interrupt_level_9_handler |
||
134 | interrupt_level_9_handler: |
||
135 | INTERRUPT_LEVEL_N_HANDLER 9 |
||
136 | |||
137 | /* TT = 0x4a, TL = 0, interrupt_level_10 handler */ |
||
138 | .org trap_table + TT_INTERRUPT_LEVEL_10*ENTRY_SIZE |
||
139 | .global interrupt_level_10_handler |
||
140 | interrupt_level_10_handler: |
||
141 | INTERRUPT_LEVEL_N_HANDLER 10 |
||
142 | |||
143 | /* TT = 0x4b, TL = 0, interrupt_level_11 handler */ |
||
144 | .org trap_table + TT_INTERRUPT_LEVEL_11*ENTRY_SIZE |
||
145 | .global interrupt_level_11_handler |
||
146 | interrupt_level_11_handler: |
||
147 | INTERRUPT_LEVEL_N_HANDLER 11 |
||
148 | |||
149 | /* TT = 0x4c, TL = 0, interrupt_level_12 handler */ |
||
150 | .org trap_table + TT_INTERRUPT_LEVEL_12*ENTRY_SIZE |
||
151 | .global interrupt_level_12_handler |
||
152 | interrupt_level_12_handler: |
||
153 | INTERRUPT_LEVEL_N_HANDLER 12 |
||
154 | |||
155 | /* TT = 0x4d, TL = 0, interrupt_level_13 handler */ |
||
156 | .org trap_table + TT_INTERRUPT_LEVEL_13*ENTRY_SIZE |
||
157 | .global interrupt_level_13_handler |
||
158 | interrupt_level_13_handler: |
||
159 | INTERRUPT_LEVEL_N_HANDLER 13 |
||
160 | |||
161 | /* TT = 0x4e, TL = 0, interrupt_level_14 handler */ |
||
162 | .org trap_table + TT_INTERRUPT_LEVEL_14*ENTRY_SIZE |
||
163 | .global interrupt_level_14_handler |
||
164 | interrupt_level_14_handler: |
||
165 | INTERRUPT_LEVEL_N_HANDLER 14 |
||
166 | |||
167 | /* TT = 0x4f, TL = 0, interrupt_level_15 handler */ |
||
168 | .org trap_table + TT_INTERRUPT_LEVEL_15*ENTRY_SIZE |
||
169 | .global interrupt_level_15_handler |
||
170 | interrupt_level_15_handler: |
||
171 | INTERRUPT_LEVEL_N_HANDLER 15 |
||
172 | |||
663 | jermar | 173 | /* TT = 0x60, TL = 0, interrupt_vector_trap handler */ |
174 | .org trap_table + TT_INTERRUPT_VECTOR_TRAP*ENTRY_SIZE |
||
175 | .global interrupt_vector_trap_handler |
||
176 | interrupt_vector_trap_handler: |
||
177 | INTERRUPT_VECTOR_TRAP_HANDLER |
||
178 | |||
863 | jermar | 179 | /* TT = 0x64, TL = 0, fast_instruction_access_MMU_miss */ |
180 | .org trap_table + TT_FAST_INSTRUCTION_ACCESS_MMU_MISS*ENTRY_SIZE |
||
181 | .global fast_instruction_access_mmu_miss_handler |
||
182 | fast_instruction_access_mmu_miss_handler: |
||
183 | FAST_INSTRUCTION_ACCESS_MMU_MISS_HANDLER |
||
184 | |||
185 | /* TT = 0x68, TL = 0, fast_data_access_MMU_miss */ |
||
186 | .org trap_table + TT_FAST_DATA_ACCESS_MMU_MISS*ENTRY_SIZE |
||
187 | .global fast_data_access_mmu_miss_handler |
||
188 | fast_data_access_mmu_miss_handler: |
||
189 | FAST_DATA_ACCESS_MMU_MISS_HANDLER |
||
190 | |||
191 | /* TT = 0x6c, TL = 0, fast_data_access_protection */ |
||
192 | .org trap_table + TT_FAST_DATA_ACCESS_PROTECTION*ENTRY_SIZE |
||
193 | .global fast_data_access_protection_handler |
||
194 | fast_data_access_protection_handler: |
||
195 | FAST_DATA_ACCESS_PROTECTION_HANDLER |
||
196 | |||
663 | jermar | 197 | /* TT = 0x80, TL = 0, spill_0_normal handler */ |
634 | jermar | 198 | .org trap_table + TT_SPILL_0_NORMAL*ENTRY_SIZE |
630 | jermar | 199 | .global spill_0_normal |
200 | spill_0_normal: |
||
201 | SPILL_NORMAL_HANDLER |
||
529 | jermar | 202 | |
663 | jermar | 203 | /* TT = 0xc0, TL = 0, fill_0_normal handler */ |
634 | jermar | 204 | .org trap_table + TT_FILL_0_NORMAL*ENTRY_SIZE |
663 | jermar | 205 | .global fill_0_normal |
630 | jermar | 206 | fill_0_normal: |
207 | FILL_NORMAL_HANDLER |
||
208 | |||
529 | jermar | 209 | /* |
663 | jermar | 210 | * Handlers for TL>0. |
529 | jermar | 211 | */ |
212 | |||
667 | jermar | 213 | /* TT = 0x08, TL > 0, instruction_access_exception */ |
214 | .org trap_table + (TT_INSTRUCTION_ACCESS_EXCEPTION+512)*ENTRY_SIZE |
||
215 | .global instruction_access_exception_high |
||
216 | instruction_access_exception_high: |
||
217 | SIMPLE_HANDLER do_instruction_access_exc |
||
218 | |||
663 | jermar | 219 | /* TT = 0x24, TL > 0, clean_window handler */ |
220 | .org trap_table + (TT_CLEAN_WINDOW+512)*ENTRY_SIZE |
||
221 | .global clean_window_handler_high |
||
222 | clean_window_handler_high: |
||
223 | CLEAN_WINDOW_HANDLER |
||
529 | jermar | 224 | |
667 | jermar | 225 | /* TT = 0x34, TL > 0, mem_address_not_aligned */ |
226 | .org trap_table + (TT_MEM_ADDRESS_NOT_ALIGNED+512)*ENTRY_SIZE |
||
227 | .global mem_address_not_aligned_high |
||
228 | mem_address_not_aligned_high: |
||
229 | SIMPLE_HANDLER do_mem_address_not_aligned |
||
529 | jermar | 230 | |
863 | jermar | 231 | /* TT = 0x64, TL > 0, fast_instruction_access_MMU_miss */ |
232 | .org trap_table + (TT_FAST_INSTRUCTION_ACCESS_MMU_MISS+512)*ENTRY_SIZE |
||
233 | .global fast_instruction_access_mmu_miss_handler_high |
||
234 | fast_instruction_access_mmu_miss_handler_high: |
||
235 | FAST_INSTRUCTION_ACCESS_MMU_MISS_HANDLER |
||
236 | |||
237 | /* TT = 0x68, TL > 0, fast_data_access_MMU_miss */ |
||
238 | .org trap_table + (TT_FAST_DATA_ACCESS_MMU_MISS+512)*ENTRY_SIZE |
||
239 | .global fast_data_access_mmu_miss_handler_high |
||
240 | fast_data_access_mmu_miss_handler_high: |
||
241 | FAST_DATA_ACCESS_MMU_MISS_HANDLER |
||
242 | |||
243 | /* TT = 0x6c, TL > 0, fast_data_access_protection */ |
||
244 | .org trap_table + (TT_FAST_DATA_ACCESS_PROTECTION+512)*ENTRY_SIZE |
||
245 | .global fast_data_access_protection_handler_high |
||
246 | fast_data_access_protection_handler_high: |
||
247 | FAST_DATA_ACCESS_PROTECTION_HANDLER |
||
248 | |||
663 | jermar | 249 | /* TT = 0x80, TL > 0, spill_0_normal handler */ |
250 | .org trap_table + (TT_SPILL_0_NORMAL+512)*ENTRY_SIZE |
||
251 | .global spill_0_normal_high |
||
252 | spill_0_normal_high: |
||
253 | SPILL_NORMAL_HANDLER |
||
529 | jermar | 254 | |
663 | jermar | 255 | /* TT = 0xc0, TL > 0, fill_0_normal handler */ |
256 | .org trap_table + (TT_FILL_0_NORMAL+512)*ENTRY_SIZE |
||
257 | .global fill_0_normal_high |
||
258 | fill_0_normal_high: |
||
259 | FILL_NORMAL_HANDLER |
||
634 | jermar | 260 | |
663 | jermar | 261 | |
262 | |||
634 | jermar | 263 | /* |
264 | * Save trap table. |
||
265 | */ |
||
663 | jermar | 266 | .align TABLE_SIZE |
634 | jermar | 267 | .global trap_table_save |
268 | trap_table_save: |
||
269 | .space TABLE_SIZE, 0 |
||
666 | jermar | 270 | |
271 | |||
667 | jermar | 272 | /* Preemptible trap handler. |
666 | jermar | 273 | * |
667 | jermar | 274 | * This trap handler makes arrangements to |
275 | * make calling scheduler() possible. |
||
276 | * |
||
277 | * The caller is responsible for doing save |
||
278 | * and allocating PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE |
||
279 | * bytes on stack. |
||
280 | * |
||
666 | jermar | 281 | * Input registers: |
282 | * %l0 Address of function to call. |
||
283 | * Output registers: |
||
284 | * %l1 - %l7 Copy of %g1 - %g7 |
||
285 | */ |
||
667 | jermar | 286 | .global preemptible_handler |
287 | preemptible_handler: |
||
288 | /* |
||
289 | * Save TSTATE, TPC, TNPC and PSTATE aside. |
||
290 | */ |
||
291 | rdpr %tstate, %g1 |
||
292 | rdpr %tpc, %g2 |
||
293 | rdpr %tnpc, %g3 |
||
294 | rdpr %pstate, %g4 |
||
295 | |||
296 | stx %g1, [%fp + STACK_BIAS + SAVED_TSTATE] |
||
297 | stx %g2, [%fp + STACK_BIAS + SAVED_TPC] |
||
298 | stx %g3, [%fp + STACK_BIAS + SAVED_TNPC] |
||
299 | stx %g4, [%fp + STACK_BIAS + SAVED_PSTATE] |
||
300 | |||
301 | /* |
||
302 | * Write 0 to TL. |
||
303 | */ |
||
304 | wrpr %g0, 0, %tl |
||
305 | |||
306 | /* |
||
307 | * Alter PSTATE. |
||
308 | * - switch to normal globals. |
||
309 | */ |
||
310 | and %g4, ~1, %g4 ! mask alternate globals |
||
311 | wrpr %g4, 0, %pstate |
||
312 | |||
313 | /* |
||
314 | * Save the normal globals. |
||
315 | */ |
||
666 | jermar | 316 | SAVE_GLOBALS |
667 | jermar | 317 | |
318 | /* |
||
319 | * Call the higher-level handler. |
||
320 | */ |
||
666 | jermar | 321 | call %l0 |
322 | nop |
||
667 | jermar | 323 | |
324 | /* |
||
325 | * Restore the normal global register set. |
||
326 | */ |
||
666 | jermar | 327 | RESTORE_GLOBALS |
667 | jermar | 328 | |
329 | /* |
||
330 | * Restore PSTATE from saved copy. |
||
331 | * Alternate globals become active. |
||
332 | */ |
||
333 | ldx [%fp + STACK_BIAS + SAVED_PSTATE], %l4 |
||
334 | wrpr %l4, 0, %pstate |
||
335 | |||
336 | /* |
||
337 | * Write 1 to TL. |
||
338 | */ |
||
339 | wrpr %g0, 1, %tl |
||
340 | |||
341 | /* |
||
342 | * Read TSTATE, TPC and TNPC from saved copy. |
||
343 | */ |
||
344 | ldx [%fp + STACK_BIAS + SAVED_TSTATE], %g1 |
||
345 | ldx [%fp + STACK_BIAS + SAVED_TPC], %g2 |
||
346 | ldx [%fp + STACK_BIAS + SAVED_TNPC], %g3 |
||
347 | |||
348 | /* |
||
349 | * Do restore to match the save instruction from the top-level handler. |
||
350 | */ |
||
351 | restore |
||
352 | |||
353 | /* |
||
354 | * On execution of retry instruction, CWP will be restored from TSTATE register. |
||
355 | * However, because of scheduling, it is possible that CWP in saved TSTATE |
||
356 | * is different from current CWP. The following chunk of code fixes CWP |
||
357 | * in the saved copy of TSTATE. |
||
358 | */ |
||
359 | rdpr %cwp, %g4 ! read current CWP |
||
360 | and %g1, ~0x1f, %g1 ! clear CWP field in saved TSTATE |
||
361 | or %g1, %g4, %g1 ! write current CWP to TSTATE |
||
362 | |||
363 | /* |
||
364 | * Restore TSTATE, TPC and TNPC from saved copies. |
||
365 | */ |
||
366 | wrpr %g1, 0, %tstate |
||
367 | wrpr %g2, 0, %tpc |
||
368 | wrpr %g3, 0, %tnpc |
||
369 | |||
370 | /* |
||
371 | * Return from interrupt. |
||
372 | */ |
||
666 | jermar | 373 | retry |