Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * wof.S: Sparc window overflow handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <asm/contregs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <asm/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <asm/psr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/asi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/winmacro.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/asmmacro.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/thread_info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /* WARNING: This routine is hairy and _very_ complicated, but it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *          must be as fast as possible as it handles the allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *          of register windows to the user and kernel.  If you touch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *          this code be _very_ careful as many other pieces of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *          kernel depend upon how this code behaves.  You have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *          duly warned...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /* We define macro's for registers which have a fixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * meaning throughout this entire routine.  The 'T' in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * the comments mean that the register can only be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * accessed when in the 'trap' window, 'G' means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * accessible in any window.  Do not change these registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * after they have been set, until you are ready to return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * from the trap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define t_psr       l0 /* %psr at trap time                     T */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define t_pc        l1 /* PC for trap return                    T */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define t_npc       l2 /* NPC for trap return                   T */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define t_wim       l3 /* %wim at trap time                     T */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define saved_g5    l5 /* Global save register                  T */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define saved_g6    l6 /* Global save register                  T */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define curptr      g6 /* Gets set to 'current' then stays      G */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /* Now registers whose values can change within the handler.      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define twin_tmp    l4 /* Temp reg, only usable in trap window  T */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define glob_tmp    g5 /* Global temporary reg, usable anywhere G */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	.text
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	.align	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	/* BEGINNING OF PATCH INSTRUCTIONS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	/* On a 7-window Sparc the boot code patches spnwin_*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	 * instructions with the following ones.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.globl	spnwin_patch1_7win, spnwin_patch2_7win, spnwin_patch3_7win
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) spnwin_patch1_7win:	sll	%t_wim, 6, %glob_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) spnwin_patch2_7win:	and	%glob_tmp, 0x7f, %glob_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) spnwin_patch3_7win:	and	%twin_tmp, 0x7f, %twin_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	/* END OF PATCH INSTRUCTIONS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	/* The trap entry point has done the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	 * rd    %psr, %l0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	 * rd    %wim, %l3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	 * b     spill_window_entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	 * andcc %l0, PSR_PS, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/* Datum current_thread_info->uwinmask contains at all times a bitmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	 * where if any user windows are active, at least one bit will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	 * be set in to mask.  If no user windows are active, the bitmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	 * will be all zeroes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	.globl	spill_window_entry 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	.globl	spnwin_patch1, spnwin_patch2, spnwin_patch3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) spill_window_entry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	/* LOCATION: Trap Window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	mov	%g5, %saved_g5		! save away global temp register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	mov	%g6, %saved_g6		! save away 'current' ptr register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	/* Compute what the new %wim will be if we save the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	 * window properly in this trap handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	 * newwim = ((%wim>>1) | (%wim<<(nwindows - 1)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		srl	%t_wim, 0x1, %twin_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) spnwin_patch1:	sll	%t_wim, 7, %glob_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		or	%glob_tmp, %twin_tmp, %glob_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) spnwin_patch2:	and	%glob_tmp, 0xff, %glob_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	/* The trap entry point has set the condition codes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	 * up for us to see if this is from user or kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	 * Get the load of 'curptr' out of the way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	LOAD_CURRENT(curptr, twin_tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	andcc	%t_psr, PSR_PS, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	be,a	spwin_fromuser				! all user wins, branch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	 save	%g0, %g0, %g0				! Go where saving will occur
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	/* See if any user windows are active in the set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	ld	[%curptr + TI_UWINMASK], %twin_tmp	! grab win mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	orcc	%g0, %twin_tmp, %g0			! check for set bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	bne	spwin_exist_uwins			! yep, there are some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	 andn	%twin_tmp, %glob_tmp, %twin_tmp		! compute new uwinmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	/* Save into the window which must be saved and do it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	 * Basically if we are here, this means that we trapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	 * from kernel mode with only kernel windows in the register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	 * file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	save	%g0, %g0, %g0		! save into the window to stash away
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	wr	%glob_tmp, 0x0, %wim	! set new %wim, this is safe now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) spwin_no_userwins_from_kernel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	/* LOCATION: Window to be saved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	STORE_WINDOW(sp)		! stash the window
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	restore	%g0, %g0, %g0		! go back into trap window
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/* LOCATION: Trap window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	mov	%saved_g5, %g5		! restore %glob_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	mov	%saved_g6, %g6		! restore %curptr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	wr	%t_psr, 0x0, %psr	! restore condition codes in %psr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	WRITE_PAUSE			! waste some time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	jmp	%t_pc			! Return from trap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	rett	%t_npc			! we are done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) spwin_exist_uwins:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	/* LOCATION: Trap window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	/* Wow, user windows have to be dealt with, this is dirty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	 * and messy as all hell.  And difficult to follow if you
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	 * are approaching the infamous register window trap handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	 * problem for the first time. DON'T LOOK!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	 * Note that how the execution path works out, the new %wim
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	 * will be left for us in the global temporary register,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 * %glob_tmp.  We cannot set the new %wim first because we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	 * need to save into the appropriate window without inducing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	 * a trap (traps are off, we'd get a watchdog wheee)...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	 * But first, store the new user window mask calculated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	 * above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	st	%twin_tmp, [%curptr + TI_UWINMASK]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	save	%g0, %g0, %g0		! Go to where the saving will occur
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) spwin_fromuser:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	/* LOCATION: Window to be saved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	wr	%glob_tmp, 0x0, %wim	! Now it is safe to set new %wim
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	/* LOCATION: Window to be saved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	/* This instruction branches to a routine which will check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	 * to validity of the users stack pointer by whatever means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	 * are necessary.  This means that this is architecture
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	 * specific and thus this branch instruction will need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	 * be patched at boot time once the machine type is known.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	 * This routine _shall not_ touch %curptr under any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	 * circumstances whatsoever!  It will branch back to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 * label 'spwin_good_ustack' if the stack is ok but still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 * needs to be dumped (SRMMU for instance will not need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	 * do this) or 'spwin_finish_up' if the stack is ok and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	 * registers have already been saved.  If the stack is found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 * to be bogus for some reason the routine shall branch to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	 * the label 'spwin_user_stack_is_bolixed' which will take
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	 * care of things at that point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	b	spwin_srmmu_stackchk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	 andcc	%sp, 0x7, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) spwin_good_ustack:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	/* LOCATION: Window to be saved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	/* The users stack is ok and we can safely save it at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	 * %sp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	STORE_WINDOW(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) spwin_finish_up:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	restore	%g0, %g0, %g0		/* Back to trap window. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	/* LOCATION: Trap window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	/* We have spilled successfully, and we have properly stored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	 * the appropriate window onto the stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	/* Restore saved globals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	mov	%saved_g5, %g5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	mov	%saved_g6, %g6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	wr	%t_psr, 0x0, %psr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	WRITE_PAUSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	jmp	%t_pc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	rett	%t_npc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) spwin_user_stack_is_bolixed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	/* LOCATION: Window to be saved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	/* Wheee, user has trashed his/her stack.  We have to decide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	 * how to proceed based upon whether we came from kernel mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	 * or not.  If we came from kernel mode, toss the window into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	 * a special buffer and proceed, the kernel _needs_ a window
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	 * and we could be in an interrupt handler so timing is crucial.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	 * If we came from user land we build a full stack frame and call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	 * c-code to gun down the process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	rd	%psr, %glob_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	andcc	%glob_tmp, PSR_PS, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	bne	spwin_bad_ustack_from_kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	 nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	/* Oh well, throw this one window into the per-task window
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	 * buffer, the first one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	st	%sp, [%curptr + TI_RWIN_SPTRS]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	STORE_WINDOW(curptr + TI_REG_WINDOW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	restore	%g0, %g0, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	/* LOCATION: Trap Window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	/* Back in the trap window, update winbuffer save count. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	mov	1, %twin_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	st	%twin_tmp, [%curptr + TI_W_SAVED]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		/* Compute new user window mask.  What we are basically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		 * doing is taking two windows, the invalid one at trap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		 * time and the one we attempted to throw onto the users
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		 * stack, and saying that everything else is an ok user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		 * window.  umask = ((~(%t_wim | %wim)) & valid_wim_bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		rd	%wim, %twin_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		or	%twin_tmp, %t_wim, %twin_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		not	%twin_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) spnwin_patch3:	and	%twin_tmp, 0xff, %twin_tmp	! patched on 7win Sparcs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		st	%twin_tmp, [%curptr + TI_UWINMASK]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #define STACK_OFFSET (THREAD_SIZE - TRACEREG_SZ - STACKFRAME_SZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	sethi	%hi(STACK_OFFSET), %sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	or	%sp, %lo(STACK_OFFSET), %sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	add	%curptr, %sp, %sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	/* Restore the saved globals and build a pt_regs frame. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	mov	%saved_g5, %g5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	mov	%saved_g6, %g6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	STORE_PT_ALL(sp, t_psr, t_pc, t_npc, g1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	sethi	%hi(STACK_OFFSET), %g6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	or	%g6, %lo(STACK_OFFSET), %g6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	sub	%sp, %g6, %g6		! curptr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	/* Turn on traps and call c-code to deal with it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	wr	%t_psr, PSR_ET, %psr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	call	window_overflow_fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	 nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	/* Return from trap if C-code actually fixes things, if it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	 * doesn't then we never get this far as the process will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	 * be given the look of death from Commander Peanut.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	b	ret_trap_entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	 clr	%l6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) spwin_bad_ustack_from_kernel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	/* LOCATION: Window to be saved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	/* The kernel provoked a spill window trap, but the window we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	 * need to save is a user one and the process has trashed its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	 * stack pointer.  We need to be quick, so we throw it into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	 * a per-process window buffer until we can properly handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	 * this later on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	SAVE_BOLIXED_USER_STACK(curptr, glob_tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	restore	%g0, %g0, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	/* LOCATION: Trap window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	/* Restore globals, condition codes in the %psr and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	 * return from trap.  Note, restoring %g6 when returning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	 * to kernel mode is not necessarily these days. ;-)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	mov	%saved_g5, %g5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	mov	%saved_g6, %g6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	wr	%t_psr, 0x0, %psr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	WRITE_PAUSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	jmp	%t_pc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	rett	%t_npc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /* Undefine the register macros which would only cause trouble
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  * if used below.  This helps find 'stupid' coding errors that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)  * produce 'odd' behavior.  The routines below are allowed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  * make usage of glob_tmp and t_psr so we leave them defined.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) #undef twin_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) #undef curptr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) #undef t_pc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) #undef t_npc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) #undef t_wim
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) #undef saved_g5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) #undef saved_g6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /* Now come the per-architecture window overflow stack checking routines.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * As noted above %curptr cannot be touched by this routine at all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	/* This is a generic SRMMU routine.  As far as I know this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	 * works for all current v8/srmmu implementations, we'll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	 * see...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	.globl	spwin_srmmu_stackchk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) spwin_srmmu_stackchk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	/* LOCATION: Window to be saved on the stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	/* Because of SMP concerns and speed we play a trick.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	 * We disable fault traps in the MMU control register,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	 * Execute the stores, then check the fault registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	 * to see what happens.  I can hear Linus now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	 * "disgusting... broken hardware...".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	 * But first, check to see if the users stack has ended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	 * up in kernel vma, then we would succeed for the 'wrong'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	 * reason... ;(  Note that the 'sethi' below assumes the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	 * kernel is page aligned, which should always be the case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	/* Check results of callers andcc %sp, 0x7, %g0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	bne	spwin_user_stack_is_bolixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	 sethi   %hi(PAGE_OFFSET), %glob_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	cmp	%glob_tmp, %sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	bleu	spwin_user_stack_is_bolixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	 mov	AC_M_SFSR, %glob_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	/* Clear the fault status and turn on the no_fault bit. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) LEON_PI(lda	[%glob_tmp] ASI_LEON_MMUREGS, %g0)	! eat SFSR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) SUN_PI_(lda	[%glob_tmp] ASI_M_MMUREGS, %g0)		! eat SFSR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) LEON_PI(lda	[%g0] ASI_LEON_MMUREGS, %glob_tmp)	! read MMU control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) SUN_PI_(lda	[%g0] ASI_M_MMUREGS, %glob_tmp)		! read MMU control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	or	%glob_tmp, 0x2, %glob_tmp		! or in no_fault bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) LEON_PI(sta	%glob_tmp, [%g0] ASI_LEON_MMUREGS)	! set it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) SUN_PI_(sta	%glob_tmp, [%g0] ASI_M_MMUREGS)		! set it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	/* Dump the registers and cross fingers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	STORE_WINDOW(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	/* Clear the no_fault bit and check the status. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	andn	%glob_tmp, 0x2, %glob_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) LEON_PI(sta	%glob_tmp, [%g0] ASI_LEON_MMUREGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) SUN_PI_(sta	%glob_tmp, [%g0] ASI_M_MMUREGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	mov	AC_M_SFAR, %glob_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) LEON_PI(lda	[%glob_tmp] ASI_LEON_MMUREGS, %g0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) SUN_PI_(lda	[%glob_tmp] ASI_M_MMUREGS, %g0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	mov	AC_M_SFSR, %glob_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) LEON_PI(lda	[%glob_tmp] ASI_LEON_MMUREGS, %glob_tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) SUN_PI_(lda	[%glob_tmp] ASI_M_MMUREGS, %glob_tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	andcc	%glob_tmp, 0x2, %g0			! did we fault?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	be,a	spwin_finish_up + 0x4			! cool beans, success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	 restore %g0, %g0, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	rd	%psr, %glob_tmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	b	spwin_user_stack_is_bolixed + 0x4	! we faulted, ugh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	 nop