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