Subversion Repositories HelenOS

Rev

Rev 1851 | Rev 1855 | 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
 
529 jermar 36
.text
37
 
630 jermar 38
#include <arch/trap/trap_table.h>
39
#include <arch/trap/regwin.h>
663 jermar 40
#include <arch/trap/interrupt.h>
667 jermar 41
#include <arch/trap/exception.h>
863 jermar 42
#include <arch/trap/mmu.h>
667 jermar 43
#include <arch/stack.h>
1851 jermar 44
#include <arch/regdef.h>
529 jermar 45
 
46
#define TABLE_SIZE	TRAP_TABLE_SIZE
47
#define ENTRY_SIZE	TRAP_TABLE_ENTRY_SIZE
48
 
49
/*
634 jermar 50
 * Kernel trap table.
529 jermar 51
 */
52
.align TABLE_SIZE
53
.global trap_table
54
trap_table:
55
 
667 jermar 56
/* TT = 0x08, TL = 0, instruction_access_exception */
57
.org trap_table + TT_INSTRUCTION_ACCESS_EXCEPTION*ENTRY_SIZE
58
.global instruction_access_exception
59
instruction_access_exception:
60
	SIMPLE_HANDLER do_instruction_access_exc
61
 
883 jermar 62
/* TT = 0x10, TL = 0, illegal_instruction */
63
.org trap_table + TT_ILLEGAL_INSTRUCTION*ENTRY_SIZE
64
.global illegal_instruction
65
illegal_instruction:
66
	SIMPLE_HANDLER do_illegal_instruction
67
 
663 jermar 68
/* TT = 0x24, TL = 0, clean_window handler */
634 jermar 69
.org trap_table + TT_CLEAN_WINDOW*ENTRY_SIZE
630 jermar 70
.global clean_window_handler
71
clean_window_handler:
72
	CLEAN_WINDOW_HANDLER
529 jermar 73
 
897 jermar 74
/* TT = 0x32, TL = 0, data_access_error */
75
.org trap_table + TT_DATA_ACCESS_ERROR*ENTRY_SIZE
76
.global data_access_error
77
data_access_error:
78
	SIMPLE_HANDLER do_data_access_error
79
 
667 jermar 80
/* TT = 0x34, TL = 0, mem_address_not_aligned */
81
.org trap_table + TT_MEM_ADDRESS_NOT_ALIGNED*ENTRY_SIZE
82
.global mem_address_not_aligned
83
mem_address_not_aligned:
84
	SIMPLE_HANDLER do_mem_address_not_aligned
85
 
664 jermar 86
/* TT = 0x41, TL = 0, interrupt_level_1 handler */
87
.org trap_table + TT_INTERRUPT_LEVEL_1*ENTRY_SIZE
88
.global interrupt_level_1_handler
89
interrupt_level_1_handler:
90
	INTERRUPT_LEVEL_N_HANDLER 1
91
 
92
/* TT = 0x42, TL = 0, interrupt_level_2 handler */
93
.org trap_table + TT_INTERRUPT_LEVEL_2*ENTRY_SIZE
94
.global interrupt_level_2_handler
95
interrupt_level_2_handler:
96
	INTERRUPT_LEVEL_N_HANDLER 2
97
 
98
/* TT = 0x43, TL = 0, interrupt_level_3 handler */
99
.org trap_table + TT_INTERRUPT_LEVEL_3*ENTRY_SIZE
100
.global interrupt_level_3_handler
101
interrupt_level_3_handler:
102
	INTERRUPT_LEVEL_N_HANDLER 3
103
 
104
/* TT = 0x44, TL = 0, interrupt_level_4 handler */
105
.org trap_table + TT_INTERRUPT_LEVEL_4*ENTRY_SIZE
106
.global interrupt_level_4_handler
107
interrupt_level_4_handler:
108
	INTERRUPT_LEVEL_N_HANDLER 4
109
 
110
/* TT = 0x45, TL = 0, interrupt_level_5 handler */
111
.org trap_table + TT_INTERRUPT_LEVEL_5*ENTRY_SIZE
112
.global interrupt_level_5_handler
113
interrupt_level_5_handler:
114
	INTERRUPT_LEVEL_N_HANDLER 5
115
 
116
/* TT = 0x46, TL = 0, interrupt_level_6 handler */
117
.org trap_table + TT_INTERRUPT_LEVEL_6*ENTRY_SIZE
118
.global interrupt_level_6_handler
119
interrupt_level_6_handler:
120
	INTERRUPT_LEVEL_N_HANDLER 6
121
 
122
/* TT = 0x47, TL = 0, interrupt_level_7 handler */
123
.org trap_table + TT_INTERRUPT_LEVEL_7*ENTRY_SIZE
124
.global interrupt_level_7_handler
125
interrupt_level_7_handler:
126
	INTERRUPT_LEVEL_N_HANDLER 7
127
 
128
/* TT = 0x48, TL = 0, interrupt_level_8 handler */
129
.org trap_table + TT_INTERRUPT_LEVEL_8*ENTRY_SIZE
130
.global interrupt_level_8_handler
131
interrupt_level_8_handler:
132
	INTERRUPT_LEVEL_N_HANDLER 8
133
 
134
/* TT = 0x49, TL = 0, interrupt_level_9 handler */
135
.org trap_table + TT_INTERRUPT_LEVEL_9*ENTRY_SIZE
136
.global interrupt_level_9_handler
137
interrupt_level_9_handler:
138
	INTERRUPT_LEVEL_N_HANDLER 9
139
 
140
/* TT = 0x4a, TL = 0, interrupt_level_10 handler */
141
.org trap_table + TT_INTERRUPT_LEVEL_10*ENTRY_SIZE
142
.global interrupt_level_10_handler
143
interrupt_level_10_handler:
144
	INTERRUPT_LEVEL_N_HANDLER 10
145
 
146
/* TT = 0x4b, TL = 0, interrupt_level_11 handler */
147
.org trap_table + TT_INTERRUPT_LEVEL_11*ENTRY_SIZE
148
.global interrupt_level_11_handler
149
interrupt_level_11_handler:
150
	INTERRUPT_LEVEL_N_HANDLER 11
151
 
152
/* TT = 0x4c, TL = 0, interrupt_level_12 handler */
153
.org trap_table + TT_INTERRUPT_LEVEL_12*ENTRY_SIZE
154
.global interrupt_level_12_handler
155
interrupt_level_12_handler:
156
	INTERRUPT_LEVEL_N_HANDLER 12
157
 
158
/* TT = 0x4d, TL = 0, interrupt_level_13 handler */
159
.org trap_table + TT_INTERRUPT_LEVEL_13*ENTRY_SIZE
160
.global interrupt_level_13_handler
161
interrupt_level_13_handler:
162
	INTERRUPT_LEVEL_N_HANDLER 13
163
 
164
/* TT = 0x4e, TL = 0, interrupt_level_14 handler */
165
.org trap_table + TT_INTERRUPT_LEVEL_14*ENTRY_SIZE
166
.global interrupt_level_14_handler
167
interrupt_level_14_handler:
168
	INTERRUPT_LEVEL_N_HANDLER 14
169
 
170
/* TT = 0x4f, TL = 0, interrupt_level_15 handler */
171
.org trap_table + TT_INTERRUPT_LEVEL_15*ENTRY_SIZE
172
.global interrupt_level_15_handler
173
interrupt_level_15_handler:
174
	INTERRUPT_LEVEL_N_HANDLER 15
175
 
663 jermar 176
/* TT = 0x60, TL = 0, interrupt_vector_trap handler */
177
.org trap_table + TT_INTERRUPT_VECTOR_TRAP*ENTRY_SIZE
178
.global interrupt_vector_trap_handler
179
interrupt_vector_trap_handler:
180
	INTERRUPT_VECTOR_TRAP_HANDLER
181
 
863 jermar 182
/* TT = 0x64, TL = 0, fast_instruction_access_MMU_miss */
183
.org trap_table + TT_FAST_INSTRUCTION_ACCESS_MMU_MISS*ENTRY_SIZE
184
.global fast_instruction_access_mmu_miss_handler
185
fast_instruction_access_mmu_miss_handler:
186
	FAST_INSTRUCTION_ACCESS_MMU_MISS_HANDLER
187
 
188
/* TT = 0x68, TL = 0, fast_data_access_MMU_miss */
189
.org trap_table + TT_FAST_DATA_ACCESS_MMU_MISS*ENTRY_SIZE
190
.global fast_data_access_mmu_miss_handler
191
fast_data_access_mmu_miss_handler:
192
	FAST_DATA_ACCESS_MMU_MISS_HANDLER
193
 
194
/* TT = 0x6c, TL = 0, fast_data_access_protection */
195
.org trap_table + TT_FAST_DATA_ACCESS_PROTECTION*ENTRY_SIZE
196
.global fast_data_access_protection_handler
197
fast_data_access_protection_handler:
198
	FAST_DATA_ACCESS_PROTECTION_HANDLER
199
 
663 jermar 200
/* TT = 0x80, TL = 0, spill_0_normal handler */
634 jermar 201
.org trap_table + TT_SPILL_0_NORMAL*ENTRY_SIZE
630 jermar 202
.global spill_0_normal
203
spill_0_normal:
1852 jermar 204
	SPILL_NORMAL_HANDLER_KERNEL
529 jermar 205
 
663 jermar 206
/* TT = 0xc0, TL = 0, fill_0_normal handler */
634 jermar 207
.org trap_table + TT_FILL_0_NORMAL*ENTRY_SIZE
663 jermar 208
.global fill_0_normal
630 jermar 209
fill_0_normal:
1852 jermar 210
	FILL_NORMAL_HANDLER_KERNEL
630 jermar 211
 
529 jermar 212
/*
663 jermar 213
 * Handlers for TL>0.
529 jermar 214
 */
215
 
667 jermar 216
/* TT = 0x08, TL > 0, instruction_access_exception */
217
.org trap_table + (TT_INSTRUCTION_ACCESS_EXCEPTION+512)*ENTRY_SIZE
218
.global instruction_access_exception_high
219
instruction_access_exception_high:
220
	SIMPLE_HANDLER do_instruction_access_exc
221
 
883 jermar 222
/* TT = 0x10, TL > 0, illegal_instruction */
223
.org trap_table + (TT_ILLEGAL_INSTRUCTION+512)*ENTRY_SIZE
224
.global illegal_instruction_high
225
illegal_instruction_high:
226
	SIMPLE_HANDLER do_illegal_instruction
227
 
663 jermar 228
/* TT = 0x24, TL > 0, clean_window handler */
229
.org trap_table + (TT_CLEAN_WINDOW+512)*ENTRY_SIZE
230
.global clean_window_handler_high
231
clean_window_handler_high:
232
	CLEAN_WINDOW_HANDLER
529 jermar 233
 
897 jermar 234
/* TT = 0x32, TL > 0, data_access_error */
235
.org trap_table + (TT_DATA_ACCESS_ERROR+512)*ENTRY_SIZE
236
.global data_access_error_high
237
data_access_error_high:
238
	SIMPLE_HANDLER do_data_access_error
239
 
667 jermar 240
/* TT = 0x34, TL > 0, mem_address_not_aligned */
241
.org trap_table + (TT_MEM_ADDRESS_NOT_ALIGNED+512)*ENTRY_SIZE
242
.global mem_address_not_aligned_high
243
mem_address_not_aligned_high:
244
	SIMPLE_HANDLER do_mem_address_not_aligned
529 jermar 245
 
863 jermar 246
/* TT = 0x64, TL > 0, fast_instruction_access_MMU_miss */
247
.org trap_table + (TT_FAST_INSTRUCTION_ACCESS_MMU_MISS+512)*ENTRY_SIZE
248
.global fast_instruction_access_mmu_miss_handler_high
249
fast_instruction_access_mmu_miss_handler_high:
250
	FAST_INSTRUCTION_ACCESS_MMU_MISS_HANDLER
251
 
252
/* TT = 0x68, TL > 0, fast_data_access_MMU_miss */
253
.org trap_table + (TT_FAST_DATA_ACCESS_MMU_MISS+512)*ENTRY_SIZE
254
.global fast_data_access_mmu_miss_handler_high
255
fast_data_access_mmu_miss_handler_high:
256
	FAST_DATA_ACCESS_MMU_MISS_HANDLER
257
 
258
/* TT = 0x6c, TL > 0, fast_data_access_protection */
259
.org trap_table + (TT_FAST_DATA_ACCESS_PROTECTION+512)*ENTRY_SIZE
260
.global fast_data_access_protection_handler_high
261
fast_data_access_protection_handler_high:
262
	FAST_DATA_ACCESS_PROTECTION_HANDLER
263
 
663 jermar 264
/* TT = 0x80, TL > 0, spill_0_normal handler */
265
.org trap_table + (TT_SPILL_0_NORMAL+512)*ENTRY_SIZE
266
.global spill_0_normal_high
267
spill_0_normal_high:
1852 jermar 268
	SPILL_NORMAL_HANDLER_KERNEL
529 jermar 269
 
663 jermar 270
/* TT = 0xc0, TL > 0, fill_0_normal handler */
271
.org trap_table + (TT_FILL_0_NORMAL+512)*ENTRY_SIZE
272
.global fill_0_normal_high
273
fill_0_normal_high:
1852 jermar 274
	FILL_NORMAL_HANDLER_KERNEL
634 jermar 275
 
663 jermar 276
 
1851 jermar 277
/* Preemptible trap handler for TL=1.
666 jermar 278
 *
1851 jermar 279
 * This trap handler makes arrangements to make calling of scheduler() from
1852 jermar 280
 * within a trap context possible. It is called from several other trap
281
 * handlers.
667 jermar 282
 *
1852 jermar 283
 * This function can be entered either with interrupt globals or alternate globals.
284
 * Memory management trap handlers are obliged to switch to one of those global sets
285
 * prior to calling this function. Register window management functions are not
286
 * allowed to modify the alternate global registers.
667 jermar 287
 *
666 jermar 288
 * Input registers:
1852 jermar 289
 *	%g1		Address of function to call.
290
 * 	%g2	 	Argument for the function.
291
 *	%g6		Pre-set as kernel stack base if trap from userspace.
292
 *	%g7		Reserved.
666 jermar 293
 */
667 jermar 294
.global preemptible_handler
295
preemptible_handler:
1852 jermar 296
	rdpr %tstate, %g3
297
	andcc %g3, TSTATE_PRIV_BIT, %g0		! if this trap came from the privileged mode...
298
	bnz 0f					! ...skip setting of kernel stack and primary context
299
	nop
300
 
667 jermar 301
	/*
1852 jermar 302
	 * Switch to kernel stack. The old stack is
303
	 * automatically saved in the old window's %sp
304
	 * and the new window's %fp.
667 jermar 305
	 */
1852 jermar 306
	save %g6, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
307
 
308
	/*
309
	 * Mark the CANSAVE windows as OTHER windows.
310
	 * Set CLEANWIN to NWINDOW-1 so that clean_window traps do not occur.
311
	 */
312
	rdpr %cansave, %l0
313
	wrpr %l0, %otherwin
314
	wrpr %g0, %cansave
315
	wrpr %g0, NWINDOW-1, %cleanwin
316
 
317
	/*
318
	 * Switch to primary context 0.
319
	 */
320
	mov VA_PRIMARY_CONTEXT_REG, %l0
321
        stxa %g0, [%l0] ASI_DMMU
322
	set kernel_image_start, %l0
323
        flush %l0
324
 
325
	ba 1f
326
	nop
327
 
328
0:
329
	save %sp, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
330
 
331
	/*
332
	 * At this moment, we are using the kernel stack 
333
	 * and have successfully allocated a register window.
334
	 */
335
1:
336
 
337
	/*
338
	 * Copy arguments.
339
	 */
340
	mov %g1, %l0
341
	mov %g2, %o0
342
 
343
	/*
344
	 * Save TSTATE, TPC and TNPC aside.
345
	 */
667 jermar 346
	rdpr %tstate, %g1
347
	rdpr %tpc, %g2
348
	rdpr %tnpc, %g3
349
 
1851 jermar 350
	/*
351
	 * The following memory accesses will not fault
352
	 * because special provisions are made to have
353
	 * the kernel stack of THREAD locked in DTLB.
354
	 */
1852 jermar 355
	stx %g1, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TSTATE]
356
	stx %g2, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TPC]
357
	stx %g3, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC]
667 jermar 358
 
359
	wrpr %g0, 0, %tl
1852 jermar 360
	wrpr %g0, PSTATE_PRIV_BIT, %pstate
666 jermar 361
	SAVE_GLOBALS
667 jermar 362
 
363
	/*
1852 jermar 364
	 * Call the higher-level handler and pass istate as second parameter.
667 jermar 365
	 */
666 jermar 366
	call %l0
1852 jermar 367
	add %sp, PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC, %o1
368
 
369
	RESTORE_GLOBALS
370
	wrpr %g0, PSTATE_AG_BIT | PSTATE_PRIV_BIT, %pstate
371
	wrpr %g0, 1, %tl
667 jermar 372
 
373
	/*
1852 jermar 374
	 * Read TSTATE, TPC and TNPC from saved copy.
667 jermar 375
	 */
1852 jermar 376
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TSTATE], %g1
377
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TPC], %g2
378
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC], %g3
379
 
667 jermar 380
	/*
1852 jermar 381
	 * Restore TSTATE, TPC and TNPC from saved copies.
667 jermar 382
	 */
1852 jermar 383
	wrpr %g1, 0, %tstate
384
	wrpr %g2, 0, %tpc
385
	wrpr %g3, 0, %tnpc
386
 
667 jermar 387
	/*
1852 jermar 388
	 * If OTHERWIN is zero, then all the userspace windows have been
389
	 * spilled to kernel memory (i.e. register window buffer). If
390
	 * OTHERWIN is non-zero, then some userspace windows are still
391
	 * valid. Others might have been spilled. However, the CWP pointer
392
	 * needs no fixing because the scheduler had not been called.
667 jermar 393
	 */
1852 jermar 394
	rdpr %otherwin, %l0
395
	brnz %l0, 0f
396
	nop
397
 
667 jermar 398
	/*
1852 jermar 399
	 * OTHERWIN == 0
667 jermar 400
	 */
401
 
402
	/*
1852 jermar 403
	 * If TSTATE.CWP + 1 == CWP, then we still do not have to fix CWP.
667 jermar 404
	 */
1852 jermar 405
	and %g1, TSTATE_CWP_MASK, %l0
406
	inc %l0
407
	and %l0, TSTATE_CWP_MASK, %l0	! %l0 mod NWINDOW
408
	rdpr %cwp, %l1
409
	cmp %l0, %l1
410
	bz 0f				! CWP is ok
411
	nop
667 jermar 412
 
413
	/*
1852 jermar 414
	 * Fix CWP.
667 jermar 415
	 */
1852 jermar 416
	mov %fp, %g1
417
	flushw
418
	wrpr %l0, 0, %cwp
419
	mov %g1, %fp
667 jermar 420
 
421
	/*
1852 jermar 422
	 * OTHERWIN != 0 or fall-through from the OTHERWIN == 0 case.
667 jermar 423
	 */
1852 jermar 424
0:
425
	! TODO: restore register windows from register window memory buffer
426
 
427
	restore
666 jermar 428
	retry