Subversion Repositories HelenOS

Rev

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

Rev 1856 Rev 1857
Line 38... Line 38...
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/mmu.h>
42
#include <arch/trap/mmu.h>
-
 
43
#include <arch/mm/page.h>
43
#include <arch/stack.h>
44
#include <arch/stack.h>
44
#include <arch/regdef.h>
45
#include <arch/regdef.h>
45
 
46
 
46
#define TABLE_SIZE	TRAP_TABLE_SIZE
47
#define TABLE_SIZE	TRAP_TABLE_SIZE
47
#define ENTRY_SIZE	TRAP_TABLE_ENTRY_SIZE
48
#define ENTRY_SIZE	TRAP_TABLE_ENTRY_SIZE
Line 327... Line 328...
327
	andcc %g3, TSTATE_PRIV_BIT, %g0		! if this trap came from the privileged mode...
328
	andcc %g3, TSTATE_PRIV_BIT, %g0		! if this trap came from the privileged mode...
328
	bnz 0f					! ...skip setting of kernel stack and primary context
329
	bnz 0f					! ...skip setting of kernel stack and primary context
329
	nop
330
	nop
330
 
331
 
331
	/*
332
	/*
-
 
333
	 * Normal window spills will go to the userspace window buffer.
-
 
334
	 */
-
 
335
	wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(2), %wstate
-
 
336
 
-
 
337
	/*
332
	 * Switch to kernel stack. The old stack is
338
	 * Switch to kernel stack. The old stack is
333
	 * automatically saved in the old window's %sp
339
	 * automatically saved in the old window's %sp
334
	 * and the new window's %fp.
340
	 * and the new window's %fp.
335
	 */
341
	 */
336
	save %g6, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
342
	save %g6, -PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE, %sp
Line 361... Line 367...
361
	/*
367
	/*
362
	 * At this moment, we are using the kernel stack 
368
	 * At this moment, we are using the kernel stack 
363
	 * and have successfully allocated a register window.
369
	 * and have successfully allocated a register window.
364
	 */
370
	 */
365
1:
371
1:
366
 
372
	
-
 
373
	/*
-
 
374
	 * Other window spills will go to the userspace window buffer
-
 
375
	 * and normal spills will go to the kernel stack.
-
 
376
	 */
-
 
377
	wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(0), %wstate
-
 
378
	
367
	/*
379
	/*
368
	 * Copy arguments.
380
	 * Copy arguments.
369
	 */
381
	 */
370
	mov %g1, %l0
382
	mov %g1, %l0
371
	mov %g2, %o0
383
	mov %g2, %o0
Line 447... Line 459...
447
	 * restore. Because the fill trap fills only input and local
459
	 * restore. Because the fill trap fills only input and local
448
	 * registers of a window, we need to preserve those output
460
	 * registers of a window, we need to preserve those output
449
	 * registers manually.
461
	 * registers manually.
450
	 */
462
	 */
451
	flushw
463
	flushw
452
	mov %sp, %g1
464
	mov %sp, %g2
453
	stx %i0, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I0]
465
	stx %i0, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I0]
454
	stx %i1, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I1]
466
	stx %i1, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I1]
455
	stx %i2, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I2]
467
	stx %i2, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I2]
456
	stx %i3, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I3]
468
	stx %i3, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I3]
457
	stx %i4, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I4]
469
	stx %i4, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I4]
458
	stx %i5, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I5]
470
	stx %i5, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I5]
459
	stx %i6, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I6]
471
	stx %i6, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I6]
460
	stx %i7, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I7]
472
	stx %i7, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I7]
461
	wrpr %l0, 0, %cwp
473
	wrpr %l0, 0, %cwp
462
	mov %g1, %sp
474
	mov %g2, %sp
463
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I0], %i0
475
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I0], %i0
464
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I1], %i1
476
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I1], %i1
465
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I2], %i2
477
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I2], %i2
466
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I3], %i3
478
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I3], %i3
467
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I4], %i4
479
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I4], %i4
Line 469... Line 481...
469
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I6], %i6
481
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I6], %i6
470
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I7], %i7
482
	ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I7], %i7
471
 
483
 
472
	/*
484
	/*
473
	 * OTHERWIN != 0 or fall-through from the OTHERWIN == 0 case.
485
	 * OTHERWIN != 0 or fall-through from the OTHERWIN == 0 case.
-
 
486
	 * The CWP has already been restored to the value it had prior to the SAVE
-
 
487
	 * at the beginning of this function.
474
	 */
488
	 */
475
0:
489
0:
-
 
490
	rdpr %tstate, %g1
-
 
491
	andcc %g1, TSTATE_PRIV_BIT, %g0		! if we are not returning to userspace...,
476
	! TODO: restore register windows from register window memory buffer
492
	bnz 1f					! ...skip restoring userspace windows
-
 
493
	nop
-
 
494
	
-
 
495
	rdpr %cwp, %g1
-
 
496
	rdpr %otherwin, %g2
477
 
497
 
-
 
498
	/*
-
 
499
	 * Skip all OTHERWIN windows and descend to the first window
-
 
500
	 * in the userspace window buffer.
-
 
501
	 */
-
 
502
	sub %g1, %g2, %g3
-
 
503
	dec %g3
-
 
504
	and %g3, NWINDOW - 1, %g3
-
 
505
	wrpr %g3, 0, %cwp
-
 
506
 
-
 
507
	/*
-
 
508
	 * CWP is now in the window last saved in the userspace window buffer.
-
 
509
	 * Fill all windows stored in the buffer.
-
 
510
	 */
-
 
511
	clr %g4
-
 
512
0:	andcc %g7, PAGE_WIDTH - 1, %g0		! PAGE_SIZE alignment check
-
 
513
	bz 0f					! %g7 is page-aligned, no more windows to refill
-
 
514
	nop
-
 
515
 
-
 
516
	add %g7, -STACK_WINDOW_SAVE_AREA_SIZE, %g7
-
 
517
	ldx [%g7 + L0_OFFSET], %l0
-
 
518
	ldx [%g7 + L1_OFFSET], %l1
-
 
519
	ldx [%g7 + L2_OFFSET], %l2
-
 
520
	ldx [%g7 + L3_OFFSET], %l3
-
 
521
	ldx [%g7 + L4_OFFSET], %l4
-
 
522
	ldx [%g7 + L5_OFFSET], %l5
-
 
523
	ldx [%g7 + L6_OFFSET], %l6
-
 
524
	ldx [%g7 + L7_OFFSET], %l7
-
 
525
	ldx [%g7 + I0_OFFSET], %i0
-
 
526
	ldx [%g7 + I1_OFFSET], %i1
-
 
527
	ldx [%g7 + I2_OFFSET], %i2
-
 
528
	ldx [%g7 + I3_OFFSET], %i3
-
 
529
	ldx [%g7 + I4_OFFSET], %i4
-
 
530
	ldx [%g7 + I5_OFFSET], %i5
-
 
531
	ldx [%g7 + I6_OFFSET], %i6
-
 
532
	ldx [%g7 + I7_OFFSET], %i7
-
 
533
 
-
 
534
	dec %g3
-
 
535
	and %g3, NWINDOW - 1, %g3
-
 
536
	wrpr %g3, 0, %cwp			! switch to the preceeding window
-
 
537
 
-
 
538
	ba 0b
-
 
539
	inc %g4
-
 
540
 
-
 
541
0:
-
 
542
	/*
-
 
543
	 * Switch back to the proper current window and adjust
-
 
544
	 * OTHERWIN, CANRESTORE, CANSAVE and CLEANWIN.
-
 
545
	 */
-
 
546
	wrpr %g1, 0, %cwp
-
 
547
	add %g4, %g2, %g2
-
 
548
	mov NWINDOW - 2, %g1
-
 
549
	sub %g1, %g2, %g1
-
 
550
	
-
 
551
	wrpr %g0, 0, %otherwin
-
 
552
	wrpr %g1, 0, %cansave			! NWINDOW - 2 - CANRESTORE
-
 
553
	wrpr %g2, 0, %canrestore		! OTHERWIN + windows in the buffer
-
 
554
	wrpr %g2, 0, %cleanwin			! avoid information leak
-
 
555
 
-
 
556
	/*
-
 
557
	 * Spills and fills will be processed by the {spill,fill}_1_normal
-
 
558
	 * handlers.
-
 
559
	 */
-
 
560
	wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(1), %wstate
-
 
561
 
-
 
562
1:
478
	restore
563
	restore
479
	retry
564
	retry