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)  * wuf.S: Window underflow trap handler for the Sparc.
^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
^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) /* Just like the overflow handler we define macros for registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * with fixed meanings in this routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define t_psr       l0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define t_pc        l1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define t_npc       l2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define t_wim       l3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /* Don't touch the above registers or else you die horribly... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /* Now macros for the available scratch registers in this routine. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define twin_tmp1    l4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define twin_tmp2    l5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define curptr       g6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	.text
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	.align	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	/* The trap entry point has executed the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	 * rd    %psr, %l0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	 * rd    %wim, %l3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	 * b     fill_window_entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	 * andcc %l0, PSR_PS, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	/* Datum current_thread_info->uwinmask contains at all times a bitmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	 * where if any user windows are active, at least one bit will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	 * be set in to mask.  If no user windows are active, the bitmask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	 * will be all zeroes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	/* To get an idea of what has just happened to cause this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	 * trap take a look at this diagram:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	 *      1  2  3  4     <--  Window number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	 *      ----------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	 *      T  O  W  I     <--  Symbolic name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 *      O == the window that execution was in when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	 *           the restore was attempted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	 *      T == the trap itself has save'd us into this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	 *           window
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	 *      W == this window is the one which is now invalid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	 *           and must be made valid plus loaded from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	 *           stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	 *      I == this window will be the invalid one when we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	 *           are done and return from trap if successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	/* BEGINNING OF PATCH INSTRUCTIONS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	/* On 7-window Sparc the boot code patches fnwin_patch1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	 * with the following instruction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.globl	fnwin_patch1_7win, fnwin_patch2_7win
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) fnwin_patch1_7win:	srl	%t_wim, 6, %twin_tmp2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) fnwin_patch2_7win:	and	%twin_tmp1, 0x7f, %twin_tmp1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	/* END OF PATCH INSTRUCTIONS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	.globl	fill_window_entry, fnwin_patch1, fnwin_patch2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) fill_window_entry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	/* LOCATION: Window 'T' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	/* Compute what the new %wim is going to be if we retrieve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	 * the proper window off of the stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		sll	%t_wim, 1, %twin_tmp1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) fnwin_patch1:	srl	%t_wim, 7, %twin_tmp2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		or	%twin_tmp1, %twin_tmp2, %twin_tmp1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) fnwin_patch2:	and	%twin_tmp1, 0xff, %twin_tmp1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	wr	%twin_tmp1, 0x0, %wim	/* Make window 'I' invalid */
^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	fwin_from_user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	 restore	%g0, %g0, %g0		/* Restore to window 'O' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	/* Trapped from kernel, we trust that the kernel does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	 * 'over restore' sorta speak and just grab the window
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	 * from the stack and return.  Easy enough.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) fwin_from_kernel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	/* LOCATION: Window 'O' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	restore %g0, %g0, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	/* LOCATION: Window 'W' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	LOAD_WINDOW(sp)	                /* Load it up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	/* Spin the wheel... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	save	%g0, %g0, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	save	%g0, %g0, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	/* I'd like to buy a vowel please... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	/* LOCATION: Window 'T' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/* Now preserve the condition codes in %psr, pause, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	 * return from trap.  This is the simplest case of all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	wr	%t_psr, 0x0, %psr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	WRITE_PAUSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	jmp	%t_pc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	rett	%t_npc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) fwin_from_user:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	/* LOCATION: Window 'O' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	restore	%g0, %g0, %g0		/* Restore to window 'W' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	/* LOCATION: Window 'W' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/* Branch to the stack validation routine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	b	srmmu_fwin_stackchk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 andcc	%sp, 0x7, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #define STACK_OFFSET (THREAD_SIZE - TRACEREG_SZ - STACKFRAME_SZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) fwin_user_stack_is_bolixed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	/* LOCATION: Window 'W' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	/* Place a pt_regs frame on the kernel stack, save back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	 * to the trap window and call c-code to deal with this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	LOAD_CURRENT(l4, l5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	sethi	%hi(STACK_OFFSET), %l5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	or	%l5, %lo(STACK_OFFSET), %l5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	add	%l4, %l5, %l5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	/* Store globals into pt_regs frame. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	STORE_PT_GLOBALS(l5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	STORE_PT_YREG(l5, g3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/* Save current in a global while we change windows. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	mov	%l4, %curptr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	save	%g0, %g0, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/* LOCATION: Window 'O' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	rd	%psr, %g3		/* Read %psr in live user window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	mov	%fp, %g4		/* Save bogus frame pointer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	save	%g0, %g0, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	/* LOCATION: Window 'T' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	sethi	%hi(STACK_OFFSET), %l5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	or	%l5, %lo(STACK_OFFSET), %l5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	add	%curptr, %l5, %sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	/* Build rest of pt_regs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	STORE_PT_INS(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	STORE_PT_PRIV(sp, t_psr, t_pc, t_npc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	/* re-set trap time %wim value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	wr	%t_wim, 0x0, %wim
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	/* Fix users window mask and buffer save count. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	mov	0x1, %g5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	sll	%g5, %g3, %g5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	st	%g5, [%curptr + TI_UWINMASK]		! one live user window still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	st	%g0, [%curptr + TI_W_SAVED]		! no windows in the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	wr	%t_psr, PSR_ET, %psr			! enable traps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	call	window_underflow_fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	 mov	%g4, %o0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	b	ret_trap_entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	 clr	%l6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) fwin_user_stack_is_ok:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	/* LOCATION: Window 'W' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	/* The users stack area is kosher and mapped, load the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	 * window and fall through to the finish up routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	LOAD_WINDOW(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	/* Round and round she goes... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	save	%g0, %g0, %g0		/* Save to window 'O' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	save	%g0, %g0, %g0		/* Save to window 'T' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	/* Where she'll trap nobody knows... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	/* LOCATION: Window 'T' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) fwin_user_finish_up:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	/* LOCATION: Window 'T' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	wr	%t_psr, 0x0, %psr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	WRITE_PAUSE	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	jmp	%t_pc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	rett	%t_npc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	/* Here come the architecture specific checks for stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	 * mappings.  Note that unlike the window overflow handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	 * we only need to check whether the user can read from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	 * the appropriate addresses.  Also note that we are in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	 * an invalid window which will be loaded, and this means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	 * that until we actually load the window up we are free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	 * to use any of the local registers contained within.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	 * On success these routine branch to fwin_user_stack_is_ok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	 * if the area at %sp is user readable and the window still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	 * needs to be loaded, else fwin_user_finish_up if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	 * routine has done the loading itself.  On failure (bogus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	 * user stack) the routine shall branch to the label called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	 * fwin_user_stack_is_bolixed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	 * Contrary to the arch-specific window overflow stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	 * check routines in wof.S, these routines are free to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	 * any of the local registers they want to as this window
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	 * does not belong to anyone at this point, however the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	 * outs and ins are still verboten as they are part of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	 * 'someone elses' window possibly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	.globl	srmmu_fwin_stackchk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) srmmu_fwin_stackchk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	/* LOCATION: Window 'W' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	/* Caller did 'andcc %sp, 0x7, %g0' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	bne	fwin_user_stack_is_bolixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 sethi   %hi(PAGE_OFFSET), %l5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	/* Check if the users stack is in kernel vma, then our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	 * trial and error technique below would succeed for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	 * the 'wrong' reason.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	mov	AC_M_SFSR, %l4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	cmp	%l5, %sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	bleu	fwin_user_stack_is_bolixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) LEON_PI( lda	[%l4] ASI_LEON_MMUREGS, %g0)	! clear fault status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) SUN_PI_( lda	[%l4] ASI_M_MMUREGS, %g0)	! clear fault status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	/* The technique is, turn off faults on this processor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	 * just let the load rip, then check the sfsr to see if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	 * a fault did occur.  Then we turn on fault traps again
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	 * and branch conditionally based upon what happened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) LEON_PI(lda	[%g0] ASI_LEON_MMUREGS, %l5)	! read mmu-ctrl reg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) SUN_PI_(lda	[%g0] ASI_M_MMUREGS, %l5)	! read mmu-ctrl reg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	or	%l5, 0x2, %l5			! turn on no-fault bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) LEON_PI(sta	%l5, [%g0] ASI_LEON_MMUREGS)	! store it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) SUN_PI_(sta	%l5, [%g0] ASI_M_MMUREGS)	! store it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	/* Cross fingers and go for it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	LOAD_WINDOW(sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	/* A penny 'saved'... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	save	%g0, %g0, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	save	%g0, %g0, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	/* Is a BADTRAP earned... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	/* LOCATION: Window 'T' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) LEON_PI(lda	[%g0] ASI_LEON_MMUREGS, %twin_tmp1)	! load mmu-ctrl again
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) SUN_PI_(lda	[%g0] ASI_M_MMUREGS, %twin_tmp1)	! load mmu-ctrl again
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	andn	%twin_tmp1, 0x2, %twin_tmp1		! clear no-fault bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) LEON_PI(sta	%twin_tmp1, [%g0] ASI_LEON_MMUREGS)	! store it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) SUN_PI_(sta	%twin_tmp1, [%g0] ASI_M_MMUREGS)	! store it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	mov	AC_M_SFAR, %twin_tmp2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) LEON_PI(lda	[%twin_tmp2] ASI_LEON_MMUREGS, %g0)	! read fault address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) SUN_PI_(lda	[%twin_tmp2] ASI_M_MMUREGS, %g0)	! read fault address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	mov	AC_M_SFSR, %twin_tmp2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) LEON_PI(lda	[%twin_tmp2] ASI_LEON_MMUREGS, %twin_tmp2) ! read fault status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) SUN_PI_(lda	[%twin_tmp2] ASI_M_MMUREGS, %twin_tmp2)	   ! read fault status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	andcc	%twin_tmp2, 0x2, %g0			   ! did fault occur?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	bne	1f					   ! yep, cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	 nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	wr	%t_psr, 0x0, %psr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	b	fwin_user_finish_up + 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	 nop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	/* Did I ever tell you about my window lobotomy?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	 * anyways... fwin_user_stack_is_bolixed expects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	 * to be in window 'W' so make it happy or else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	 * we watchdog badly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	restore	%g0, %g0, %g0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	b	fwin_user_stack_is_bolixed	! oh well
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	 restore	%g0, %g0, %g0