Subversion Repositories HelenOS

Rev

Rev 1861 | Rev 1863 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1861 Rev 1862
Line 37... Line 37...
37
 
37
 
38
#include <arch/trap/trap_table.h>
38
#include <arch/trap/trap_table.h>
39
#include <arch/trap/regwin.h>
39
#include <arch/trap/regwin.h>
40
#include <arch/trap/interrupt.h>
40
#include <arch/trap/interrupt.h>
41
#include <arch/trap/exception.h>
41
#include <arch/trap/exception.h>
-
 
42
#include <arch/trap/syscall.h>
42
#include <arch/trap/mmu.h>
43
#include <arch/trap/mmu.h>
43
#include <arch/mm/mmu.h>
44
#include <arch/mm/mmu.h>
44
#include <arch/mm/page.h>
45
#include <arch/mm/page.h>
45
#include <arch/stack.h>
46
#include <arch/stack.h>
46
#include <arch/regdef.h>
47
#include <arch/regdef.h>
Line 227... Line 228...
227
.org trap_table + TT_FILL_1_NORMAL*ENTRY_SIZE
228
.org trap_table + TT_FILL_1_NORMAL*ENTRY_SIZE
228
.global fill_1_normal
229
.global fill_1_normal
229
fill_1_normal:
230
fill_1_normal:
230
	FILL_NORMAL_HANDLER_USERSPACE
231
	FILL_NORMAL_HANDLER_USERSPACE
231
 
232
 
-
 
233
/* TT = 0x100, TL = 0, trap_instruction_0 */
-
 
234
.org trap_table + TT_TRAP_INSTRUCTION(0)*ENTRY_SIZE
-
 
235
.global trap_instruction_0
-
 
236
trap_instruction_0:
-
 
237
	TRAP_INSTRUCTION 0
-
 
238
 
-
 
239
/* TT = 0x101, TL = 0, trap_instruction_1 */
-
 
240
.org trap_table + TT_TRAP_INSTRUCTION(1)*ENTRY_SIZE
-
 
241
.global trap_instruction_1
-
 
242
trap_instruction_1:
-
 
243
	TRAP_INSTRUCTION 1
-
 
244
 
-
 
245
/* TT = 0x102, TL = 0, trap_instruction_2 */
-
 
246
.org trap_table + TT_TRAP_INSTRUCTION(2)*ENTRY_SIZE
-
 
247
.global trap_instruction_2
-
 
248
trap_instruction_2:
-
 
249
	TRAP_INSTRUCTION 2
-
 
250
 
-
 
251
/* TT = 0x103, TL = 0, trap_instruction_3 */
-
 
252
.org trap_table + TT_TRAP_INSTRUCTION(3)*ENTRY_SIZE
-
 
253
.global trap_instruction_3
-
 
254
trap_instruction_3:
-
 
255
	TRAP_INSTRUCTION 3
-
 
256
 
-
 
257
/* TT = 0x104, TL = 0, trap_instruction_4 */
-
 
258
.org trap_table + TT_TRAP_INSTRUCTION(4)*ENTRY_SIZE
-
 
259
.global trap_instruction_4
-
 
260
trap_instruction_4:
-
 
261
	TRAP_INSTRUCTION 4
-
 
262
 
-
 
263
/* TT = 0x105, TL = 0, trap_instruction_5 */
-
 
264
.org trap_table + TT_TRAP_INSTRUCTION(5)*ENTRY_SIZE
-
 
265
.global trap_instruction_5
-
 
266
trap_instruction_5:
-
 
267
	TRAP_INSTRUCTION 5
-
 
268
 
-
 
269
/* TT = 0x106, TL = 0, trap_instruction_6 */
-
 
270
.org trap_table + TT_TRAP_INSTRUCTION(6)*ENTRY_SIZE
-
 
271
.global trap_instruction_6
-
 
272
trap_instruction_6:
-
 
273
	TRAP_INSTRUCTION 6
-
 
274
 
-
 
275
/* TT = 0x107, TL = 0, trap_instruction_7 */
-
 
276
.org trap_table + TT_TRAP_INSTRUCTION(7)*ENTRY_SIZE
-
 
277
.global trap_instruction_7
-
 
278
trap_instruction_7:
-
 
279
	TRAP_INSTRUCTION 7
-
 
280
 
-
 
281
/* TT = 0x108, TL = 0, trap_instruction_8 */
-
 
282
.org trap_table + TT_TRAP_INSTRUCTION(8)*ENTRY_SIZE
-
 
283
.global trap_instruction_8
-
 
284
trap_instruction_8:
-
 
285
	TRAP_INSTRUCTION 8
-
 
286
 
-
 
287
/* TT = 0x109, TL = 0, trap_instruction_9 */
-
 
288
.org trap_table + TT_TRAP_INSTRUCTION(9)*ENTRY_SIZE
-
 
289
.global trap_instruction_9
-
 
290
trap_instruction_9:
-
 
291
	TRAP_INSTRUCTION 9
-
 
292
 
-
 
293
/* TT = 0x10a, TL = 0, trap_instruction_10 */
-
 
294
.org trap_table + TT_TRAP_INSTRUCTION(10)*ENTRY_SIZE
-
 
295
.global trap_instruction_10
-
 
296
trap_instruction_10:
-
 
297
	TRAP_INSTRUCTION 10
-
 
298
 
-
 
299
/* TT = 0x10b, TL = 0, trap_instruction_11 */
-
 
300
.org trap_table + TT_TRAP_INSTRUCTION(11)*ENTRY_SIZE
-
 
301
.global trap_instruction_11
-
 
302
trap_instruction_11:
-
 
303
	TRAP_INSTRUCTION 11
-
 
304
 
-
 
305
/* TT = 0x10c, TL = 0, trap_instruction_12 */
-
 
306
.org trap_table + TT_TRAP_INSTRUCTION(12)*ENTRY_SIZE
-
 
307
.global trap_instruction_12
-
 
308
trap_instruction_12:
-
 
309
	TRAP_INSTRUCTION 12
-
 
310
 
-
 
311
/* TT = 0x10d, TL = 0, trap_instruction_13 */
-
 
312
.org trap_table + TT_TRAP_INSTRUCTION(13)*ENTRY_SIZE
-
 
313
.global trap_instruction_13
-
 
314
trap_instruction_13:
-
 
315
	TRAP_INSTRUCTION 13
-
 
316
 
-
 
317
/* TT = 0x10e, TL = 0, trap_instruction_14 */
-
 
318
.org trap_table + TT_TRAP_INSTRUCTION(14)*ENTRY_SIZE
-
 
319
.global trap_instruction_14
-
 
320
trap_instruction_14:
-
 
321
	TRAP_INSTRUCTION 14
-
 
322
 
-
 
323
/* TT = 0x10f, TL = 0, trap_instruction_15 */
-
 
324
.org trap_table + TT_TRAP_INSTRUCTION(15)*ENTRY_SIZE
-
 
325
.global trap_instruction_15
-
 
326
trap_instruction_15:
-
 
327
	TRAP_INSTRUCTION 15
-
 
328
 
-
 
329
/* TT = 0x110, TL = 0, trap_instruction_16 */
-
 
330
.org trap_table + TT_TRAP_INSTRUCTION(16)*ENTRY_SIZE
-
 
331
.global trap_instruction_16
-
 
332
trap_instruction_16:
-
 
333
	TRAP_INSTRUCTION 16
-
 
334
 
-
 
335
/* TT = 0x111, TL = 0, trap_instruction_17 */
-
 
336
.org trap_table + TT_TRAP_INSTRUCTION(17)*ENTRY_SIZE
-
 
337
.global trap_instruction_17
-
 
338
trap_instruction_17:
-
 
339
	TRAP_INSTRUCTION 17
-
 
340
 
-
 
341
/* TT = 0x112, TL = 0, trap_instruction_18 */
-
 
342
.org trap_table + TT_TRAP_INSTRUCTION(18)*ENTRY_SIZE
-
 
343
.global trap_instruction_18
-
 
344
trap_instruction_18:
-
 
345
	TRAP_INSTRUCTION 18
-
 
346
 
-
 
347
/* TT = 0x113, TL = 0, trap_instruction_19 */
-
 
348
.org trap_table + TT_TRAP_INSTRUCTION(19)*ENTRY_SIZE
-
 
349
.global trap_instruction_19
-
 
350
trap_instruction_19:
-
 
351
	TRAP_INSTRUCTION 19
-
 
352
 
-
 
353
/* TT = 0x114, TL = 0, trap_instruction_20 */
-
 
354
.org trap_table + TT_TRAP_INSTRUCTION(20)*ENTRY_SIZE
-
 
355
.global trap_instruction_20
-
 
356
trap_instruction_20:
-
 
357
	TRAP_INSTRUCTION 20
-
 
358
 
-
 
359
/* TT = 0x115, TL = 0, trap_instruction_21 */
-
 
360
.org trap_table + TT_TRAP_INSTRUCTION(21)*ENTRY_SIZE
-
 
361
.global trap_instruction_21
-
 
362
trap_instruction_21:
-
 
363
	TRAP_INSTRUCTION 21
-
 
364
 
-
 
365
/* TT = 0x116, TL = 0, trap_instruction_22 */
-
 
366
.org trap_table + TT_TRAP_INSTRUCTION(22)*ENTRY_SIZE
-
 
367
.global trap_instruction_22
-
 
368
trap_instruction_22:
-
 
369
	TRAP_INSTRUCTION 22
-
 
370
 
-
 
371
/* TT = 0x117, TL = 0, trap_instruction_23 */
-
 
372
.org trap_table + TT_TRAP_INSTRUCTION(23)*ENTRY_SIZE
-
 
373
.global trap_instruction_23
-
 
374
trap_instruction_23:
-
 
375
	TRAP_INSTRUCTION 23
-
 
376
 
-
 
377
/* TT = 0x118, TL = 0, trap_instruction_24 */
-
 
378
.org trap_table + TT_TRAP_INSTRUCTION(24)*ENTRY_SIZE
-
 
379
.global trap_instruction_24
-
 
380
trap_instruction_24:
-
 
381
	TRAP_INSTRUCTION 24
-
 
382
 
-
 
383
/* TT = 0x119, TL = 0, trap_instruction_25 */
-
 
384
.org trap_table + TT_TRAP_INSTRUCTION(25)*ENTRY_SIZE
-
 
385
.global trap_instruction_25
-
 
386
trap_instruction_25:
-
 
387
	TRAP_INSTRUCTION 25
-
 
388
 
-
 
389
/* TT = 0x11a, TL = 0, trap_instruction_26 */
-
 
390
.org trap_table + TT_TRAP_INSTRUCTION(26)*ENTRY_SIZE
-
 
391
.global trap_instruction_26
-
 
392
trap_instruction_26:
-
 
393
	TRAP_INSTRUCTION 26
-
 
394
 
-
 
395
/* TT = 0x11b, TL = 0, trap_instruction_27 */
-
 
396
.org trap_table + TT_TRAP_INSTRUCTION(27)*ENTRY_SIZE
-
 
397
.global trap_instruction_27
-
 
398
trap_instruction_27:
-
 
399
	TRAP_INSTRUCTION 27
-
 
400
 
-
 
401
/* TT = 0x11c, TL = 0, trap_instruction_28 */
-
 
402
.org trap_table + TT_TRAP_INSTRUCTION(28)*ENTRY_SIZE
-
 
403
.global trap_instruction_28
-
 
404
trap_instruction_28:
-
 
405
	TRAP_INSTRUCTION 28
-
 
406
 
-
 
407
/* TT = 0x11d, TL = 0, trap_instruction_29 */
-
 
408
.org trap_table + TT_TRAP_INSTRUCTION(29)*ENTRY_SIZE
-
 
409
.global trap_instruction_29
-
 
410
trap_instruction_29:
-
 
411
	TRAP_INSTRUCTION 29
-
 
412
 
-
 
413
/* TT = 0x11e, TL = 0, trap_instruction_30 */
-
 
414
.org trap_table + TT_TRAP_INSTRUCTION(30)*ENTRY_SIZE
-
 
415
.global trap_instruction_30
-
 
416
trap_instruction_30:
-
 
417
	TRAP_INSTRUCTION 30
-
 
418
 
-
 
419
/* TT = 0x11f, TL = 0, trap_instruction_31 */
-
 
420
.org trap_table + TT_TRAP_INSTRUCTION(31)*ENTRY_SIZE
-
 
421
.global trap_instruction_31
-
 
422
trap_instruction_31:
-
 
423
	TRAP_INSTRUCTION 31
-
 
424
 
232
/*
425
/*
233
 * Handlers for TL>0.
426
 * Handlers for TL>0.
234
 */
427
 */
235
 
428
 
236
/* TT = 0x08, TL > 0, instruction_access_exception */
429
/* TT = 0x08, TL > 0, instruction_access_exception */
Line 303... Line 496...
303
.org trap_table + (TT_FILL_0_NORMAL+512)*ENTRY_SIZE
496
.org trap_table + (TT_FILL_0_NORMAL+512)*ENTRY_SIZE
304
.global fill_0_normal_high
497
.global fill_0_normal_high
305
fill_0_normal_high:
498
fill_0_normal_high:
306
	FILL_NORMAL_HANDLER_KERNEL
499
	FILL_NORMAL_HANDLER_KERNEL
307
 
500
 
-
 
501
#define NOT(x)	((x) == 0)
308
 
502
 
309
/* Preemptible trap handler for TL=1.
503
/* Preemptible trap handler for TL=1.
310
 *
504
 *
311
 * This trap handler makes arrangements to make calling of scheduler() from
505
 * This trap handler makes arrangements to make calling of scheduler() from
312
 * within a trap context possible. It is called from several other trap
506
 * within a trap context possible. It is called from several other trap
Line 321... Line 515...
321
 *	%g1		Address of function to call.
515
 *	%g1		Address of function to call.
322
 * 	%g2	 	Argument for the function.
516
 * 	%g2	 	Argument for the function.
323
 *	%g6		Pre-set as kernel stack base if trap from userspace.
517
 *	%g6		Pre-set as kernel stack base if trap from userspace.
324
 *	%g7		Pre-set as address of the userspace window buffer.
518
 *	%g7		Pre-set as address of the userspace window buffer.
325
 */
519
 */
326
.global preemptible_handler
520
.macro PREEMPTIBLE_HANDLER_TEMPLATE is_syscall
327
preemptible_handler:
521
.if NOT(\is_syscall)
328
	rdpr %tstate, %g3
522
	rdpr %tstate, %g3
329
	andcc %g3, TSTATE_PRIV_BIT, %g0		! if this trap came from the privileged mode...
523
	andcc %g3, TSTATE_PRIV_BIT, %g0		! if this trap came from the privileged mode...
330
	bnz 0f					! ...skip setting of kernel stack and primary context
524
	bnz 0f					! ...skip setting of kernel stack and primary context
331
	nop
525
	nop
332
 
526
.endif
333
	/*
527
	/*
334
	 * Normal window spills will go to the userspace window buffer.
528
	 * Normal window spills will go to the userspace window buffer.
335
	 */
529
	 */
336
	wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(2), %wstate
530
	wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(2), %wstate
337
 
531
 
Line 340... Line 534...
340
	 * automatically saved in the old window's %sp
534
	 * automatically saved in the old window's %sp
341
	 * and the new window's %fp.
535
	 * and the new window's %fp.
342
	 */
536
	 */
343
	save %g6, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
537
	save %g6, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
344
 
538
 
-
 
539
.if \is_syscall
-
 
540
	/*
-
 
541
	 * Copy arguments for the syscall to the new window.
-
 
542
	 */
-
 
543
	mov %i0, %o2
-
 
544
	mov %i1, %o3
-
 
545
	mov %i2, %o4
-
 
546
	mov %i3, %o5
-
 
547
.endif
-
 
548
 
345
	/*
549
	/*
346
	 * Mark the CANSAVE windows as OTHER windows.
550
	 * Mark the CANSAVE windows as OTHER windows.
347
	 * Set CLEANWIN to NWINDOW-1 so that clean_window traps do not occur.
551
	 * Set CLEANWIN to NWINDOW-1 so that clean_window traps do not occur.
348
	 */
552
	 */
349
	rdpr %cansave, %l0
553
	rdpr %cansave, %l0
Line 357... Line 561...
357
	mov VA_PRIMARY_CONTEXT_REG, %l0
561
	mov VA_PRIMARY_CONTEXT_REG, %l0
358
	stxa %g0, [%l0] ASI_DMMU
562
	stxa %g0, [%l0] ASI_DMMU
359
	rd %pc, %l0
563
	rd %pc, %l0
360
	flush %l0
564
	flush %l0
361
 
565
 
-
 
566
.if NOT(\is_syscall)
362
	ba 1f
567
	ba 1f
363
	nop
568
	nop
364
 
569
 
365
0:
570
0:
366
	save %sp, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
571
	save %sp, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
Line 368... Line 573...
368
	/*
573
	/*
369
	 * At this moment, we are using the kernel stack 
574
	 * At this moment, we are using the kernel stack 
370
	 * and have successfully allocated a register window.
575
	 * and have successfully allocated a register window.
371
	 */
576
	 */
372
1:
577
1:
373
	
578
.endif
374
	/*
579
	/*
375
	 * Other window spills will go to the userspace window buffer
580
	 * Other window spills will go to the userspace window buffer
376
	 * and normal spills will go to the kernel stack.
581
	 * and normal spills will go to the kernel stack.
377
	 */
582
	 */
378
	wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(0), %wstate
583
	wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(0), %wstate
Line 407... Line 612...
407
	 * Call the higher-level handler and pass istate as second parameter.
612
	 * Call the higher-level handler and pass istate as second parameter.
408
	 */
613
	 */
409
	call %l0
614
	call %l0
410
	add %sp, PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC, %o1
615
	add %sp, PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_TNPC, %o1
411
 
616
 
-
 
617
.if \is_syscall
-
 
618
	/*
-
 
619
	 * Copy the value returned by the syscall.
-
 
620
	 */
-
 
621
	mov %o0, %i0
-
 
622
.endif
-
 
623
 
412
	RESTORE_GLOBALS
624
	RESTORE_GLOBALS
413
	wrpr %g0, PSTATE_AG_BIT | PSTATE_PRIV_BIT, %pstate
625
	wrpr %g0, PSTATE_AG_BIT | PSTATE_PRIV_BIT, %pstate
414
	wrpr %g0, 1, %tl
626
	wrpr %g0, 1, %tl
415
	
627
	
416
	/*
628
	/*
Line 486... Line 698...
486
	 * OTHERWIN != 0 or fall-through from the OTHERWIN == 0 case.
698
	 * OTHERWIN != 0 or fall-through from the OTHERWIN == 0 case.
487
	 * The CWP has already been restored to the value it had prior to the SAVE
699
	 * The CWP has already been restored to the value it had prior to the SAVE
488
	 * at the beginning of this function.
700
	 * at the beginning of this function.
489
	 */
701
	 */
490
0:
702
0:
-
 
703
.if NOT(\is_syscall)
491
	rdpr %tstate, %g1
704
	rdpr %tstate, %g1
492
	andcc %g1, TSTATE_PRIV_BIT, %g0		! if we are not returning to userspace...,
705
	andcc %g1, TSTATE_PRIV_BIT, %g0		! if we are not returning to userspace...,
493
	bnz 1f					! ...skip restoring userspace windows
706
	bnz 1f					! ...skip restoring userspace windows
494
	nop
707
	nop
-
 
708
.endif
495
 
709
 
496
	/*
710
	/*
497
	 * Spills and fills will be processed by the {spill,fill}_1_normal
711
	 * Spills and fills will be processed by the {spill,fill}_1_normal
498
	 * handlers.
712
	 * handlers.
499
	 */
713
	 */
Line 570... Line 784...
570
	wrpr %g2, 0, %canrestore		! OTHERWIN + windows in the buffer
784
	wrpr %g2, 0, %canrestore		! OTHERWIN + windows in the buffer
571
	wrpr %g2, 0, %cleanwin			! avoid information leak
785
	wrpr %g2, 0, %cleanwin			! avoid information leak
572
 
786
 
573
1:
787
1:
574
	restore
788
	restore
-
 
789
 
-
 
790
.if \is_syscall
-
 
791
	done
-
 
792
.else
575
	retry
793
	retry
-
 
794
.endif
576
 
795
 
577
	/*
796
	/*
578
	 * We got here in order to avoid inconsistency of the window state registers.
797
	 * We got here in order to avoid inconsistency of the window state registers.
579
	 * If the:
798
	 * If the:
580
	 *
799
	 *
Line 603... Line 822...
603
	rdpr %cwp, %g1
822
	rdpr %cwp, %g1
604
	dec %g1
823
	dec %g1
605
	and %g1, NWINDOW - 1, %g1
824
	and %g1, NWINDOW - 1, %g1
606
	wrpr %g1, 0, %cwp			! CWP--
825
	wrpr %g1, 0, %cwp			! CWP--
607
	
826
	
-
 
827
.if \is_syscall
-
 
828
	done
-
 
829
.else
608
	retry
830
	retry
-
 
831
.endif
-
 
832
 
-
 
833
.endm
-
 
834
 
-
 
835
.global preemptible_handler
-
 
836
preemptible_handler:
-
 
837
	PREEMPTIBLE_HANDLER_TEMPLATE 0
-
 
838
 
-
 
839
.global trap_instruction_handler
-
 
840
trap_instruction_handler:
-
 
841
	PREEMPTIBLE_HANDLER_TEMPLATE 1