Home | History | Annotate | Line # | Download | only in sun3x
locore.s revision 1.48.6.4
      1  1.48.6.4  nathanw /*	$NetBSD: locore.s,v 1.48.6.4 2002/06/24 22:08:42 nathanw Exp $	*/
      2  1.48.6.2      scw 
      3  1.48.6.2      scw /*
      4  1.48.6.2      scw  * Copyright (c) 1988 University of Utah.
      5  1.48.6.2      scw  * Copyright (c) 1980, 1990, 1993
      6  1.48.6.2      scw  *	The Regents of the University of California.  All rights reserved.
      7  1.48.6.2      scw  *
      8  1.48.6.2      scw  * This code is derived from software contributed to Berkeley by
      9  1.48.6.2      scw  * the Systems Programming Group of the University of Utah Computer
     10  1.48.6.2      scw  * Science Department.
     11  1.48.6.2      scw  *
     12  1.48.6.2      scw  * Redistribution and use in source and binary forms, with or without
     13  1.48.6.2      scw  * modification, are permitted provided that the following conditions
     14  1.48.6.2      scw  * are met:
     15  1.48.6.2      scw  * 1. Redistributions of source code must retain the above copyright
     16  1.48.6.2      scw  *    notice, this list of conditions and the following disclaimer.
     17  1.48.6.2      scw  * 2. Redistributions in binary form must reproduce the above copyright
     18  1.48.6.2      scw  *    notice, this list of conditions and the following disclaimer in the
     19  1.48.6.2      scw  *    documentation and/or other materials provided with the distribution.
     20  1.48.6.2      scw  * 3. All advertising materials mentioning features or use of this software
     21  1.48.6.2      scw  *    must display the following acknowledgement:
     22  1.48.6.2      scw  *	This product includes software developed by the University of
     23  1.48.6.2      scw  *	California, Berkeley and its contributors.
     24  1.48.6.2      scw  * 4. Neither the name of the University nor the names of its contributors
     25  1.48.6.2      scw  *    may be used to endorse or promote products derived from this software
     26  1.48.6.2      scw  *    without specific prior written permission.
     27  1.48.6.2      scw  *
     28  1.48.6.2      scw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29  1.48.6.2      scw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30  1.48.6.2      scw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31  1.48.6.2      scw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32  1.48.6.2      scw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33  1.48.6.2      scw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34  1.48.6.2      scw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35  1.48.6.2      scw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36  1.48.6.2      scw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37  1.48.6.2      scw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38  1.48.6.2      scw  * SUCH DAMAGE.
     39  1.48.6.2      scw  *
     40  1.48.6.2      scw  *	from: Utah $Hdr: locore.s 1.66 92/12/22$
     41  1.48.6.2      scw  *	@(#)locore.s	8.6 (Berkeley) 5/27/94
     42  1.48.6.2      scw  */
     43  1.48.6.2      scw 
     44  1.48.6.2      scw #include "opt_compat_netbsd.h"
     45  1.48.6.2      scw #include "opt_compat_svr4.h"
     46  1.48.6.2      scw #include "opt_compat_sunos.h"
     47  1.48.6.2      scw #include "opt_kgdb.h"
     48  1.48.6.2      scw #include "opt_lockdebug.h"
     49  1.48.6.2      scw 
     50  1.48.6.2      scw #include "assym.h"
     51  1.48.6.2      scw #include <machine/asm.h>
     52  1.48.6.2      scw #include <machine/trap.h>
     53  1.48.6.2      scw 
     54  1.48.6.2      scw | Remember this is a fun project!
     55  1.48.6.2      scw 
     56  1.48.6.2      scw 	.data
     57  1.48.6.2      scw GLOBAL(mon_crp)
     58  1.48.6.2      scw 	.long	0,0
     59  1.48.6.2      scw 
     60  1.48.6.2      scw | This is for kvm_mkdb, and should be the address of the beginning
     61  1.48.6.2      scw | of the kernel text segment (not necessarily the same as kernbase).
     62  1.48.6.2      scw 	.text
     63  1.48.6.2      scw GLOBAL(kernel_text)
     64  1.48.6.2      scw 
     65  1.48.6.2      scw | This is the entry point, as well as the end of the temporary stack
     66  1.48.6.2      scw | used during process switch (one 8K page ending at start)
     67  1.48.6.2      scw ASGLOBAL(tmpstk)
     68  1.48.6.2      scw ASGLOBAL(start)
     69  1.48.6.2      scw 
     70  1.48.6.2      scw | The first step, after disabling interrupts, is to map enough of the kernel
     71  1.48.6.2      scw | into high virtual address space so that we can use position dependent code.
     72  1.48.6.2      scw | This is a tricky task on the sun3x because the MMU is already enabled and
     73  1.48.6.2      scw | the ROM monitor provides no indication of where the root MMU table is mapped.
     74  1.48.6.2      scw | Therefore we must use one of the 68030's 'transparent translation' registers
     75  1.48.6.2      scw | to define a range in the address space where the MMU translation is
     76  1.48.6.2      scw | turned off.  Once this is complete we can modify the MMU table directly
     77  1.48.6.2      scw | without the need for it to be mapped into virtual memory.
     78  1.48.6.2      scw | All code must be position independent until otherwise noted, as the
     79  1.48.6.2      scw | boot loader has loaded us into low memory but all the symbols in this
     80  1.48.6.2      scw | code have been linked high.
     81  1.48.6.2      scw 	movw	#PSL_HIGHIPL,%sr	| no interrupts
     82  1.48.6.2      scw 	movl	#KERNBASE,%a5		| for vtop conversion
     83  1.48.6.2      scw 	lea	_C_LABEL(mon_crp),%a0	| where to store the CRP
     84  1.48.6.2      scw 	subl	%a5,%a0
     85  1.48.6.2      scw 	| Note: borrowing mon_crp for tt0 setup...
     86  1.48.6.2      scw 	movl	#0x3F8107,%a0@		| map the low 1GB v=p with the
     87  1.48.6.2      scw 	.long	0xf0100800		| transparent translation reg0
     88  1.48.6.2      scw 					| [ pmove a0@, tt0 ]
     89  1.48.6.2      scw | In order to map the kernel into high memory we will copy the root table
     90  1.48.6.2      scw | entry which maps the 16 megabytes of memory starting at 0x0 into the
     91  1.48.6.2      scw | entry which maps the 16 megabytes starting at KERNBASE.
     92  1.48.6.2      scw 	pmove	%crp,%a0@		| Get monitor CPU root pointer
     93  1.48.6.2      scw 	movl	%a0@(4),%a1		| 2nd word is PA of level A table
     94  1.48.6.2      scw 
     95  1.48.6.2      scw 	movl	%a1,%a0			| compute the descriptor address
     96  1.48.6.2      scw 	addl	#0x3e0,%a1		| for VA starting at KERNBASE
     97  1.48.6.2      scw 	movl	%a0@,%a1@		| copy descriptor type
     98  1.48.6.2      scw 	movl	%a0@(4),%a1@(4)		| copy physical address
     99  1.48.6.2      scw 
    100  1.48.6.2      scw | Kernel is now double mapped at zero and KERNBASE.
    101  1.48.6.2      scw | Force a long jump to the relocated code (high VA).
    102  1.48.6.2      scw 	movl	#IC_CLEAR,%d0		| Flush the I-cache
    103  1.48.6.2      scw 	movc	%d0,%cacr
    104  1.48.6.2      scw 	jmp L_high_code:l		| long jump
    105  1.48.6.2      scw 
    106  1.48.6.2      scw L_high_code:
    107  1.48.6.2      scw | We are now running in the correctly relocated kernel, so
    108  1.48.6.2      scw | we are no longer restricted to position-independent code.
    109  1.48.6.2      scw | It is handy to leave transparent translation enabled while
    110  1.48.6.2      scw | for the low 1GB while _bootstrap() is doing its thing.
    111  1.48.6.2      scw 
    112  1.48.6.2      scw | Do bootstrap stuff needed before main() gets called.
    113  1.48.6.2      scw | Our boot loader leaves a copy of the kernel's exec header
    114  1.48.6.2      scw | just before the start of the kernel text segment, so the
    115  1.48.6.2      scw | kernel can sanity-check the DDB symbols at [end...esym].
    116  1.48.6.2      scw | Pass the struct exec at tmpstk-32 to _bootstrap().
    117  1.48.6.2      scw | Also, make sure the initial frame pointer is zero so that
    118  1.48.6.2      scw | the backtrace algorithm used by KGDB terminates nicely.
    119  1.48.6.2      scw 	lea	_ASM_LABEL(tmpstk)-32,%sp
    120  1.48.6.2      scw 	movl	#0,%a6
    121  1.48.6.2      scw 	jsr	_C_LABEL(_bootstrap)	| See locore2.c
    122  1.48.6.2      scw 
    123  1.48.6.2      scw | Now turn off the transparent translation of the low 1GB.
    124  1.48.6.2      scw | (this also flushes the ATC)
    125  1.48.6.2      scw 	clrl	%sp@-
    126  1.48.6.2      scw 	.long	0xf0170800		| pmove	sp@,tt0
    127  1.48.6.2      scw 	addql	#4,%sp
    128  1.48.6.2      scw 
    129  1.48.6.2      scw | Now that _bootstrap() is done using the PROM functions,
    130  1.48.6.2      scw | we can safely set the sfc/dfc to something != FC_CONTROL
    131  1.48.6.2      scw 	moveq	#FC_USERD,%d0		| make movs access "user data"
    132  1.48.6.2      scw 	movc	%d0,%sfc		| space for copyin/copyout
    133  1.48.6.2      scw 	movc	%d0,%dfc
    134  1.48.6.2      scw 
    135  1.48.6.2      scw | Setup process zero user/kernel stacks.
    136  1.48.6.2      scw 	movl	_C_LABEL(proc0paddr),%a1| get lwp0 pcb addr
    137  1.48.6.2      scw 	lea	%a1@(USPACE-4),%sp	| set SSP to last word
    138  1.48.6.2      scw 	movl	#USRSTACK-4,%a2
    139  1.48.6.2      scw 	movl	%a2,%usp		| init user SP
    140  1.48.6.2      scw 
    141  1.48.6.2      scw | Note curpcb was already set in _bootstrap().
    142  1.48.6.2      scw | Will do fpu initialization during autoconfig (see fpu.c)
    143  1.48.6.2      scw | The interrupt vector table and stack are now ready.
    144  1.48.6.2      scw | Interrupts will be enabled later, AFTER  autoconfiguration
    145  1.48.6.2      scw | is finished, to avoid spurrious interrupts.
    146  1.48.6.2      scw 
    147  1.48.6.2      scw /*
    148  1.48.6.2      scw  * Final preparation for calling main.
    149  1.48.6.2      scw  *
    150  1.48.6.2      scw  * Create a fake exception frame that returns to user mode,
    151  1.48.6.3  thorpej  * and save its address in p->p_md.md_regs for cpu_lwp_fork().
    152  1.48.6.2      scw  * The new frames for process 1 and 2 will be adjusted by
    153  1.48.6.2      scw  * cpu_set_kpc() to arrange for a call to a kernel function
    154  1.48.6.2      scw  * before the new process does its rte out to user mode.
    155  1.48.6.2      scw  */
    156  1.48.6.2      scw 	clrw	%sp@-			| tf_format,tf_vector
    157  1.48.6.2      scw 	clrl	%sp@-			| tf_pc (filled in later)
    158  1.48.6.2      scw 	movw	#PSL_USER,%sp@-		| tf_sr for user mode
    159  1.48.6.2      scw 	clrl	%sp@-			| tf_stackadj
    160  1.48.6.2      scw 	lea	%sp@(-64),%sp		| tf_regs[16]
    161  1.48.6.2      scw 	movl	%sp,%a1			| a1=trapframe
    162  1.48.6.2      scw 	lea	_C_LABEL(lwp0),%a0	| lwp0.l_md.md_regs =
    163  1.48.6.2      scw 	movl	%a1,%a0@(L_MD_REGS)	|   trapframe
    164  1.48.6.2      scw 	movl	%a2,%a1@(FR_SP)		| a2 == usp (from above)
    165  1.48.6.2      scw 	pea	%a1@			| push &trapframe
    166  1.48.6.2      scw 	jbsr	_C_LABEL(main)		| main(&trapframe)
    167  1.48.6.2      scw 	addql	#4,%sp			| help DDB backtrace
    168  1.48.6.2      scw 	trap	#15			| should not get here
    169  1.48.6.2      scw 
    170  1.48.6.3  thorpej | This is used by cpu_lwp_fork() to return to user mode.
    171  1.48.6.2      scw | It is called with SP pointing to a struct trapframe.
    172  1.48.6.2      scw GLOBAL(proc_do_uret)
    173  1.48.6.2      scw 	movl	%sp@(FR_SP),%a0		| grab and load
    174  1.48.6.2      scw 	movl	%a0,%usp		|   user SP
    175  1.48.6.2      scw 	moveml	%sp@+,#0x7FFF		| load most registers (all but SSP)
    176  1.48.6.2      scw 	addql	#8,%sp			| pop SSP and stack adjust count
    177  1.48.6.2      scw 	rte
    178  1.48.6.2      scw 
    179  1.48.6.2      scw /*
    180  1.48.6.2      scw  * proc_trampoline:
    181  1.48.6.2      scw  * This is used by cpu_set_kpc() to "push" a function call onto the
    182  1.48.6.2      scw  * kernel stack of some process, very much like a signal delivery.
    183  1.48.6.2      scw  * When we get here, the stack has:
    184  1.48.6.2      scw  *
    185  1.48.6.2      scw  * SP+8:	switchframe from before cpu_set_kpc
    186  1.48.6.2      scw  * SP+4:	void *arg;
    187  1.48.6.2      scw  * SP:  	u_long func;
    188  1.48.6.2      scw  *
    189  1.48.6.2      scw  * On entry, the switchframe pushed by cpu_set_kpc has already been
    190  1.48.6.2      scw  * popped off the stack, so all this needs to do is pop the function
    191  1.48.6.2      scw  * pointer into a register, call it, then pop the arg, and finally
    192  1.48.6.2      scw  * return using the switchframe that remains on the stack.
    193  1.48.6.2      scw  */
    194  1.48.6.2      scw GLOBAL(proc_trampoline)
    195  1.48.6.2      scw 	movl	%sp@+,%a0		| function pointer
    196  1.48.6.2      scw 	jbsr	%a0@			| (*func)(arg)
    197  1.48.6.2      scw 	addql	#4,%sp			| toss the arg
    198  1.48.6.2      scw 	rts				| as cpu_switch would do
    199  1.48.6.2      scw 
    200  1.48.6.2      scw | That is all the assembly startup code we need on the sun3x!
    201  1.48.6.2      scw | The rest of this is like the hp300/locore.s where possible.
    202  1.48.6.2      scw 
    203  1.48.6.2      scw /*
    204  1.48.6.2      scw  * Trap/interrupt vector routines
    205  1.48.6.2      scw  */
    206  1.48.6.2      scw #include <m68k/m68k/trap_subr.s>
    207  1.48.6.2      scw 
    208  1.48.6.2      scw GLOBAL(buserr)
    209  1.48.6.2      scw 	tstl	_C_LABEL(nofault)	| device probe?
    210  1.48.6.2      scw 	jeq	_C_LABEL(addrerr)	| no, handle as usual
    211  1.48.6.2      scw 	movl	_C_LABEL(nofault),%sp@-	| yes,
    212  1.48.6.2      scw 	jbsr	_C_LABEL(longjmp)	|  longjmp(nofault)
    213  1.48.6.2      scw GLOBAL(addrerr)
    214  1.48.6.2      scw 	clrl	%sp@-			| stack adjust count
    215  1.48.6.2      scw 	moveml	#0xFFFF,%sp@-		| save user registers
    216  1.48.6.2      scw 	movl	%usp,%a0		| save the user SP
    217  1.48.6.2      scw 	movl	%a0,%sp@(FR_SP)		|   in the savearea
    218  1.48.6.2      scw 	lea	%sp@(FR_HW),%a1		| grab base of HW berr frame
    219  1.48.6.2      scw 	moveq	#0,%d0
    220  1.48.6.2      scw 	movw	%a1@(10),%d0		| grab SSW for fault processing
    221  1.48.6.2      scw 	btst	#12,%d0			| RB set?
    222  1.48.6.2      scw 	jeq	LbeX0			| no, test RC
    223  1.48.6.2      scw 	bset	#14,%d0			| yes, must set FB
    224  1.48.6.2      scw 	movw	%d0,%a1@(10)		| for hardware too
    225  1.48.6.2      scw LbeX0:
    226  1.48.6.2      scw 	btst	#13,%d0			| RC set?
    227  1.48.6.2      scw 	jeq	LbeX1			| no, skip
    228  1.48.6.2      scw 	bset	#15,%d0			| yes, must set FC
    229  1.48.6.2      scw 	movw	%d0,%a1@(10)		| for hardware too
    230  1.48.6.2      scw LbeX1:
    231  1.48.6.2      scw 	btst	#8,%d0			| data fault?
    232  1.48.6.2      scw 	jeq	Lbe0			| no, check for hard cases
    233  1.48.6.2      scw 	movl	%a1@(16),%d1		| fault address is as given in frame
    234  1.48.6.2      scw 	jra	Lbe10			| thats it
    235  1.48.6.2      scw Lbe0:
    236  1.48.6.2      scw 	btst	#4,%a1@(6)		| long (type B) stack frame?
    237  1.48.6.2      scw 	jne	Lbe4			| yes, go handle
    238  1.48.6.2      scw 	movl	%a1@(2),%d1		| no, can use save PC
    239  1.48.6.2      scw 	btst	#14,%d0			| FB set?
    240  1.48.6.2      scw 	jeq	Lbe3			| no, try FC
    241  1.48.6.2      scw 	addql	#4,%d1			| yes, adjust address
    242  1.48.6.2      scw 	jra	Lbe10			| done
    243  1.48.6.2      scw Lbe3:
    244  1.48.6.2      scw 	btst	#15,%d0			| FC set?
    245  1.48.6.2      scw 	jeq	Lbe10			| no, done
    246  1.48.6.2      scw 	addql	#2,%d1			| yes, adjust address
    247  1.48.6.2      scw 	jra	Lbe10			| done
    248  1.48.6.2      scw Lbe4:
    249  1.48.6.2      scw 	movl	%a1@(36),%d1		| long format, use stage B address
    250  1.48.6.2      scw 	btst	#15,%d0			| FC set?
    251  1.48.6.2      scw 	jeq	Lbe10			| no, all done
    252  1.48.6.2      scw 	subql	#2,%d1			| yes, adjust address
    253  1.48.6.2      scw Lbe10:
    254  1.48.6.2      scw 	movl	%d1,%sp@-		| push fault VA
    255  1.48.6.2      scw 	movl	%d0,%sp@-		| and padded SSW
    256  1.48.6.2      scw 	movw	%a1@(6),%d0		| get frame format/vector offset
    257  1.48.6.2      scw 	andw	#0x0FFF,%d0		| clear out frame format
    258  1.48.6.2      scw 	cmpw	#12,%d0			| address error vector?
    259  1.48.6.2      scw 	jeq	Lisaerr			| yes, go to it
    260  1.48.6.2      scw 
    261  1.48.6.2      scw /* MMU-specific code to determine reason for bus error. */
    262  1.48.6.2      scw 	movl	%d1,%a0			| fault address
    263  1.48.6.2      scw 	movl	%sp@,%d0		| function code from ssw
    264  1.48.6.2      scw 	btst	#8,%d0			| data fault?
    265  1.48.6.2      scw 	jne	Lbe10a
    266  1.48.6.2      scw 	movql	#1,%d0			| user program access FC
    267  1.48.6.2      scw 					| (we dont separate data/program)
    268  1.48.6.2      scw 	btst	#5,%a1@			| supervisor mode?
    269  1.48.6.2      scw 	jeq	Lbe10a			| if no, done
    270  1.48.6.2      scw 	movql	#5,%d0			| else supervisor program access
    271  1.48.6.2      scw Lbe10a:
    272  1.48.6.2      scw 	ptestr	%d0,%a0@,#7		| do a table search
    273  1.48.6.2      scw 	pmove	%psr,%sp@		| save result
    274  1.48.6.2      scw 	movb	%sp@,%d1
    275  1.48.6.2      scw 	btst	#2,%d1			| invalid? (incl. limit viol and berr)
    276  1.48.6.2      scw 	jeq	Lmightnotbemerr		| no -> wp check
    277  1.48.6.2      scw 	btst	#7,%d1			| is it MMU table berr?
    278  1.48.6.2      scw 	jeq	Lismerr			| no, must be fast
    279  1.48.6.2      scw 	jra	Lisberr1		| real bus err needs not be fast
    280  1.48.6.2      scw Lmightnotbemerr:
    281  1.48.6.2      scw 	btst	#3,%d1			| write protect bit set?
    282  1.48.6.2      scw 	jeq	Lisberr1		| no, must be bus error
    283  1.48.6.2      scw 	movl	%sp@,%d0		| ssw into low word of d0
    284  1.48.6.2      scw 	andw	#0xc0,%d0		| write protect is set on page:
    285  1.48.6.2      scw 	cmpw	#0x40,%d0		| was it read cycle?
    286  1.48.6.2      scw 	jeq	Lisberr1		| yes, was not WPE, must be bus err
    287  1.48.6.2      scw /* End of MMU-specific bus error code. */
    288  1.48.6.2      scw 
    289  1.48.6.2      scw Lismerr:
    290  1.48.6.2      scw 	movl	#T_MMUFLT,%sp@-		| show that we are an MMU fault
    291  1.48.6.2      scw 	jra	_ASM_LABEL(faultstkadj)	| and deal with it
    292  1.48.6.2      scw Lisaerr:
    293  1.48.6.2      scw 	movl	#T_ADDRERR,%sp@-	| mark address error
    294  1.48.6.2      scw 	jra	_ASM_LABEL(faultstkadj)	| and deal with it
    295  1.48.6.2      scw Lisberr1:
    296  1.48.6.2      scw 	clrw	%sp@			| re-clear pad word
    297  1.48.6.2      scw Lisberr:
    298  1.48.6.2      scw 	movl	#T_BUSERR,%sp@-		| mark bus error
    299  1.48.6.2      scw 	jra	_ASM_LABEL(faultstkadj)	| and deal with it
    300  1.48.6.2      scw 
    301  1.48.6.2      scw /*
    302  1.48.6.2      scw  * FP exceptions.
    303  1.48.6.2      scw  */
    304  1.48.6.2      scw GLOBAL(fpfline)
    305  1.48.6.2      scw 	clrl	%sp@-			| stack adjust count
    306  1.48.6.2      scw 	moveml	#0xFFFF,%sp@-		| save registers
    307  1.48.6.2      scw 	moveq	#T_FPEMULI,%d0		| denote as FP emulation trap
    308  1.48.6.2      scw 	jra	_ASM_LABEL(fault)	| do it
    309  1.48.6.2      scw 
    310  1.48.6.2      scw GLOBAL(fpunsupp)
    311  1.48.6.2      scw 	clrl	%sp@-			| stack adjust count
    312  1.48.6.2      scw 	moveml	#0xFFFF,%sp@-		| save registers
    313  1.48.6.2      scw 	moveq	#T_FPEMULD,%d0		| denote as FP emulation trap
    314  1.48.6.2      scw 	jra	_ASM_LABEL(fault)	| do it
    315  1.48.6.2      scw 
    316  1.48.6.2      scw /*
    317  1.48.6.2      scw  * Handles all other FP coprocessor exceptions.
    318  1.48.6.2      scw  * Note that since some FP exceptions generate mid-instruction frames
    319  1.48.6.2      scw  * and may cause signal delivery, we need to test for stack adjustment
    320  1.48.6.2      scw  * after the trap call.
    321  1.48.6.2      scw  */
    322  1.48.6.2      scw GLOBAL(fpfault)
    323  1.48.6.2      scw 	clrl	%sp@-		| stack adjust count
    324  1.48.6.2      scw 	moveml	#0xFFFF,%sp@-	| save user registers
    325  1.48.6.2      scw 	movl	%usp,%a0	| and save
    326  1.48.6.2      scw 	movl	%a0,%sp@(FR_SP)	|   the user stack pointer
    327  1.48.6.2      scw 	clrl	%sp@-		| no VA arg
    328  1.48.6.2      scw 	movl	_C_LABEL(curpcb),%a0	| current pcb
    329  1.48.6.2      scw 	lea	%a0@(PCB_FPCTX),%a0 | address of FP savearea
    330  1.48.6.2      scw 	fsave	%a0@		| save state
    331  1.48.6.2      scw 	tstb	%a0@		| null state frame?
    332  1.48.6.2      scw 	jeq	Lfptnull	| yes, safe
    333  1.48.6.2      scw 	clrw	%d0		| no, need to tweak BIU
    334  1.48.6.2      scw 	movb	%a0@(1),%d0	| get frame size
    335  1.48.6.2      scw 	bset	#3,%a0@(0,%d0:w) | set exc_pend bit of BIU
    336  1.48.6.2      scw Lfptnull:
    337  1.48.6.2      scw 	fmovem	%fpsr,%sp@-	| push fpsr as code argument
    338  1.48.6.2      scw 	frestore %a0@		| restore state
    339  1.48.6.2      scw 	movl	#T_FPERR,%sp@-	| push type arg
    340  1.48.6.2      scw 	jra	_ASM_LABEL(faultstkadj) | call trap and deal with stack cleanup
    341  1.48.6.2      scw 
    342  1.48.6.2      scw /*
    343  1.48.6.2      scw  * Other exceptions only cause four and six word stack frame and require
    344  1.48.6.2      scw  * no post-trap stack adjustment.
    345  1.48.6.2      scw  */
    346  1.48.6.2      scw GLOBAL(badtrap)
    347  1.48.6.2      scw 	clrl	%sp@-			| stack adjust count
    348  1.48.6.2      scw 	moveml	#0xFFFF,%sp@-		| save std frame regs
    349  1.48.6.2      scw 	jbsr	_C_LABEL(straytrap)	| report
    350  1.48.6.2      scw 	moveml	%sp@+,#0xFFFF		| restore regs
    351  1.48.6.2      scw 	addql	#4,%sp			| stack adjust count
    352  1.48.6.2      scw 	jra	_ASM_LABEL(rei)		| all done
    353  1.48.6.2      scw 
    354  1.48.6.2      scw /*
    355  1.48.6.2      scw  * Trap 0 is for system calls
    356  1.48.6.2      scw  */
    357  1.48.6.2      scw GLOBAL(trap0)
    358  1.48.6.2      scw 	clrl	%sp@-			| stack adjust count
    359  1.48.6.2      scw 	moveml	#0xFFFF,%sp@-		| save user registers
    360  1.48.6.2      scw 	movl	%usp,%a0		| save the user SP
    361  1.48.6.2      scw 	movl	%a0,%sp@(FR_SP)		|   in the savearea
    362  1.48.6.2      scw 	movl	%d0,%sp@-		| push syscall number
    363  1.48.6.2      scw 	jbsr	_C_LABEL(syscall)	| handle it
    364  1.48.6.2      scw 	addql	#4,%sp			| pop syscall arg
    365  1.48.6.2      scw 	movl	%sp@(FR_SP),%a0		| grab and restore
    366  1.48.6.2      scw 	movl	%a0,%usp		|   user SP
    367  1.48.6.2      scw 	moveml	%sp@+,#0x7FFF		| restore most registers
    368  1.48.6.2      scw 	addql	#8,%sp			| pop SP and stack adjust
    369  1.48.6.2      scw 	jra	_ASM_LABEL(rei)		| all done
    370  1.48.6.2      scw 
    371  1.48.6.2      scw /*
    372  1.48.6.2      scw  * Trap 12 is the entry point for the cachectl "syscall"
    373  1.48.6.2      scw  *	cachectl(command, addr, length)
    374  1.48.6.2      scw  * command in d0, addr in a1, length in d1
    375  1.48.6.2      scw  */
    376  1.48.6.2      scw GLOBAL(trap12)
    377  1.48.6.4  nathanw 	movl	_C_LABEL(curlwp),%a0
    378  1.48.6.2      scw 	movl	%a0@(L_PROC),%sp@-	| push curproc pointer
    379  1.48.6.2      scw 	movl	%d1,%sp@-		| push length
    380  1.48.6.2      scw 	movl	%a1,%sp@-		| push addr
    381  1.48.6.2      scw 	movl	%d0,%sp@-		| push command
    382  1.48.6.2      scw 	jbsr	_C_LABEL(cachectl1)	| do it
    383  1.48.6.2      scw 	lea	%sp@(16),%sp		| pop args
    384  1.48.6.2      scw 	jra	_ASM_LABEL(rei)		| all done
    385  1.48.6.2      scw 
    386  1.48.6.2      scw /*
    387  1.48.6.2      scw  * Trace (single-step) trap.  Kernel-mode is special.
    388  1.48.6.2      scw  * User mode traps are simply passed on to trap().
    389  1.48.6.2      scw  */
    390  1.48.6.2      scw GLOBAL(trace)
    391  1.48.6.2      scw 	clrl	%sp@-			| stack adjust count
    392  1.48.6.2      scw 	moveml	#0xFFFF,%sp@-
    393  1.48.6.2      scw 	moveq	#T_TRACE,%d0
    394  1.48.6.2      scw 
    395  1.48.6.2      scw 	| Check PSW and see what happen.
    396  1.48.6.2      scw 	|   T=0 S=0	(should not happen)
    397  1.48.6.2      scw 	|   T=1 S=0	trace trap from user mode
    398  1.48.6.2      scw 	|   T=0 S=1	trace trap on a trap instruction
    399  1.48.6.2      scw 	|   T=1 S=1	trace trap from system mode (kernel breakpoint)
    400  1.48.6.2      scw 
    401  1.48.6.2      scw 	movw	%sp@(FR_HW),%d1		| get PSW
    402  1.48.6.2      scw 	notw	%d1			| XXX no support for T0 on 680[234]0
    403  1.48.6.2      scw 	andw	#PSL_TS,%d1		| from system mode (T=1, S=1)?
    404  1.48.6.2      scw 	jeq	_ASM_LABEL(kbrkpt)	|  yes, kernel brkpt
    405  1.48.6.2      scw 	jra	_ASM_LABEL(fault)	| no, user-mode fault
    406  1.48.6.2      scw 
    407  1.48.6.2      scw /*
    408  1.48.6.2      scw  * Trap 15 is used for:
    409  1.48.6.2      scw  *	- GDB breakpoints (in user programs)
    410  1.48.6.2      scw  *	- KGDB breakpoints (in the kernel)
    411  1.48.6.2      scw  *	- trace traps for SUN binaries (not fully supported yet)
    412  1.48.6.2      scw  * User mode traps are simply passed to trap().
    413  1.48.6.2      scw  */
    414  1.48.6.2      scw GLOBAL(trap15)
    415  1.48.6.2      scw 	clrl	%sp@-			| stack adjust count
    416  1.48.6.2      scw 	moveml	#0xFFFF,%sp@-
    417  1.48.6.2      scw 	moveq	#T_TRAP15,%d0
    418  1.48.6.2      scw 	btst	#5,%sp@(FR_HW)		| was supervisor mode?
    419  1.48.6.2      scw 	jne	_ASM_LABEL(kbrkpt)	|  yes, kernel brkpt
    420  1.48.6.2      scw 	jra	_ASM_LABEL(fault)	| no, user-mode fault
    421  1.48.6.2      scw 
    422  1.48.6.2      scw ASLOCAL(kbrkpt)
    423  1.48.6.2      scw 	| Kernel-mode breakpoint or trace trap. (%d0=trap_type)
    424  1.48.6.2      scw 	| Save the system sp rather than the user sp.
    425  1.48.6.2      scw 	movw	#PSL_HIGHIPL,%sr	| lock out interrupts
    426  1.48.6.2      scw 	lea	%sp@(FR_SIZE),%a6	| Save stack pointer
    427  1.48.6.2      scw 	movl	%a6,%sp@(FR_SP)		|  from before trap
    428  1.48.6.2      scw 
    429  1.48.6.2      scw 	| If we are not on tmpstk switch to it.
    430  1.48.6.2      scw 	| (so debugger can change the stack pointer)
    431  1.48.6.2      scw 	movl	%a6,%d1
    432  1.48.6.2      scw 	cmpl	#_ASM_LABEL(tmpstk),%d1
    433  1.48.6.2      scw 	jls	Lbrkpt2 		| already on tmpstk
    434  1.48.6.2      scw 	| Copy frame to the temporary stack
    435  1.48.6.2      scw 	movl	%sp,%a0			| %a0=src
    436  1.48.6.2      scw 	lea	_ASM_LABEL(tmpstk)-96,%a1 | %a1=dst
    437  1.48.6.2      scw 	movl	%a1,%sp			| sp=new frame
    438  1.48.6.2      scw 	moveq	#FR_SIZE,%d1
    439  1.48.6.2      scw Lbrkpt1:
    440  1.48.6.2      scw 	movl	%a0@+,%a1@+
    441  1.48.6.2      scw 	subql	#4,%d1
    442  1.48.6.2      scw 	bgt	Lbrkpt1
    443  1.48.6.2      scw 
    444  1.48.6.2      scw Lbrkpt2:
    445  1.48.6.2      scw 	| Call the trap handler for the kernel debugger.
    446  1.48.6.2      scw 	| Do not call trap() to handle it, so that we can
    447  1.48.6.2      scw 	| set breakpoints in trap() if we want.  We know
    448  1.48.6.2      scw 	| the trap type is either T_TRACE or T_BREAKPOINT.
    449  1.48.6.2      scw 	movl	%d0,%sp@-		| push trap type
    450  1.48.6.2      scw 	jbsr	_C_LABEL(trap_kdebug)
    451  1.48.6.2      scw 	addql	#4,%sp			| pop args
    452  1.48.6.2      scw 
    453  1.48.6.2      scw 	| The stack pointer may have been modified, or
    454  1.48.6.2      scw 	| data below it modified (by kgdb push call),
    455  1.48.6.2      scw 	| so push the hardware frame at the current sp
    456  1.48.6.2      scw 	| before restoring registers and returning.
    457  1.48.6.2      scw 	movl	%sp@(FR_SP),%a0		| modified sp
    458  1.48.6.2      scw 	lea	%sp@(FR_SIZE),%a1	| end of our frame
    459  1.48.6.2      scw 	movl	%a1@-,%a0@-		| copy 2 longs with
    460  1.48.6.2      scw 	movl	%a1@-,%a0@-		| ... predecrement
    461  1.48.6.2      scw 	movl	%a0,%sp@(FR_SP)		| sp = h/w frame
    462  1.48.6.2      scw 	moveml	%sp@+,#0x7FFF		| restore all but sp
    463  1.48.6.2      scw 	movl	%sp@,%sp		| ... and sp
    464  1.48.6.2      scw 	rte				| all done
    465  1.48.6.2      scw 
    466  1.48.6.2      scw /* Use common m68k sigreturn */
    467  1.48.6.2      scw #include <m68k/m68k/sigreturn.s>
    468  1.48.6.2      scw 
    469  1.48.6.2      scw /*
    470  1.48.6.2      scw  * Interrupt handlers.  Most are auto-vectored,
    471  1.48.6.2      scw  * and hard-wired the same way on all sun3 models.
    472  1.48.6.2      scw  * Format in the stack is:
    473  1.48.6.2      scw  *   %d0,%d1,%a0,%a1, sr, pc, vo
    474  1.48.6.2      scw  */
    475  1.48.6.2      scw 
    476  1.48.6.2      scw #define INTERRUPT_SAVEREG \
    477  1.48.6.2      scw 	moveml	#0xC0C0,%sp@-
    478  1.48.6.2      scw 
    479  1.48.6.2      scw #define INTERRUPT_RESTORE \
    480  1.48.6.2      scw 	moveml	%sp@+,#0x0303
    481  1.48.6.2      scw 
    482  1.48.6.2      scw /*
    483  1.48.6.2      scw  * This is the common auto-vector interrupt handler,
    484  1.48.6.2      scw  * for which the CPU provides the vector=0x18+level.
    485  1.48.6.2      scw  * These are installed in the interrupt vector table.
    486  1.48.6.2      scw  */
    487  1.48.6.2      scw #ifdef __ELF__
    488  1.48.6.2      scw 	.align	4
    489  1.48.6.2      scw #else
    490  1.48.6.2      scw 	.align	2
    491  1.48.6.2      scw #endif
    492  1.48.6.2      scw GLOBAL(_isr_autovec)
    493  1.48.6.2      scw 	INTERRUPT_SAVEREG
    494  1.48.6.2      scw 	jbsr	_C_LABEL(isr_autovec)
    495  1.48.6.2      scw 	INTERRUPT_RESTORE
    496  1.48.6.2      scw 	jra	_ASM_LABEL(rei)
    497  1.48.6.2      scw 
    498  1.48.6.2      scw /* clock: see clock.c */
    499  1.48.6.2      scw #ifdef __ELF__
    500  1.48.6.2      scw 	.align	4
    501  1.48.6.2      scw #else
    502  1.48.6.2      scw 	.align	2
    503  1.48.6.2      scw #endif
    504  1.48.6.2      scw GLOBAL(_isr_clock)
    505  1.48.6.2      scw 	INTERRUPT_SAVEREG
    506  1.48.6.2      scw 	jbsr	_C_LABEL(clock_intr)
    507  1.48.6.2      scw 	INTERRUPT_RESTORE
    508  1.48.6.2      scw 	jra	_ASM_LABEL(rei)
    509  1.48.6.2      scw 
    510  1.48.6.2      scw | Handler for all vectored interrupts (i.e. VME interrupts)
    511  1.48.6.2      scw #ifdef __ELF__
    512  1.48.6.2      scw 	.align	4
    513  1.48.6.2      scw #else
    514  1.48.6.2      scw 	.align	2
    515  1.48.6.2      scw #endif
    516  1.48.6.2      scw GLOBAL(_isr_vectored)
    517  1.48.6.2      scw 	INTERRUPT_SAVEREG
    518  1.48.6.2      scw 	jbsr	_C_LABEL(isr_vectored)
    519  1.48.6.2      scw 	INTERRUPT_RESTORE
    520  1.48.6.2      scw 	jra	_ASM_LABEL(rei)
    521  1.48.6.2      scw 
    522  1.48.6.2      scw #undef	INTERRUPT_SAVEREG
    523  1.48.6.2      scw #undef	INTERRUPT_RESTORE
    524  1.48.6.2      scw 
    525  1.48.6.2      scw /* interrupt counters (needed by vmstat) */
    526  1.48.6.2      scw GLOBAL(intrnames)
    527  1.48.6.2      scw 	.asciz	"spur"	| 0
    528  1.48.6.2      scw 	.asciz	"lev1"	| 1
    529  1.48.6.2      scw 	.asciz	"lev2"	| 2
    530  1.48.6.2      scw 	.asciz	"lev3"	| 3
    531  1.48.6.2      scw 	.asciz	"lev4"	| 4
    532  1.48.6.2      scw 	.asciz	"clock"	| 5
    533  1.48.6.2      scw 	.asciz	"lev6"	| 6
    534  1.48.6.2      scw 	.asciz	"nmi"	| 7
    535  1.48.6.2      scw GLOBAL(eintrnames)
    536  1.48.6.2      scw 
    537  1.48.6.2      scw 	.data
    538  1.48.6.2      scw 	.even
    539  1.48.6.2      scw GLOBAL(intrcnt)
    540  1.48.6.2      scw 	.long	0,0,0,0,0,0,0,0,0,0
    541  1.48.6.2      scw GLOBAL(eintrcnt)
    542  1.48.6.2      scw 	.text
    543  1.48.6.2      scw 
    544  1.48.6.2      scw /*
    545  1.48.6.2      scw  * Emulation of VAX REI instruction.
    546  1.48.6.2      scw  *
    547  1.48.6.2      scw  * This code is (mostly) un-altered from the hp300 code,
    548  1.48.6.2      scw  * except that sun machines do not need a simulated SIR
    549  1.48.6.2      scw  * because they have a real software interrupt register.
    550  1.48.6.2      scw  *
    551  1.48.6.2      scw  * This code deals with checking for and servicing ASTs
    552  1.48.6.2      scw  * (profiling, scheduling) and software interrupts (network, softclock).
    553  1.48.6.2      scw  * We check for ASTs first, just like the VAX.  To avoid excess overhead
    554  1.48.6.2      scw  * the T_ASTFLT handling code will also check for software interrupts so we
    555  1.48.6.2      scw  * do not have to do it here.  After identifying that we need an AST we
    556  1.48.6.2      scw  * drop the IPL to allow device interrupts.
    557  1.48.6.2      scw  *
    558  1.48.6.2      scw  * This code is complicated by the fact that sendsig may have been called
    559  1.48.6.2      scw  * necessitating a stack cleanup.
    560  1.48.6.2      scw  */
    561  1.48.6.2      scw 
    562  1.48.6.2      scw ASGLOBAL(rei)
    563  1.48.6.2      scw #ifdef	DIAGNOSTIC
    564  1.48.6.2      scw 	tstl	_C_LABEL(panicstr)	| have we paniced?
    565  1.48.6.2      scw 	jne	Ldorte			| yes, do not make matters worse
    566  1.48.6.2      scw #endif
    567  1.48.6.2      scw 	tstl	_C_LABEL(astpending)	| AST pending?
    568  1.48.6.2      scw 	jeq	Ldorte			| no, done
    569  1.48.6.2      scw Lrei1:
    570  1.48.6.2      scw 	btst	#5,%sp@			| yes, are we returning to user mode?
    571  1.48.6.2      scw 	jne	Ldorte			| no, done
    572  1.48.6.2      scw 	movw	#PSL_LOWIPL,%sr		| lower SPL
    573  1.48.6.2      scw 	clrl	%sp@-			| stack adjust
    574  1.48.6.2      scw 	moveml	#0xFFFF,%sp@-		| save all registers
    575  1.48.6.2      scw 	movl	%usp,%a1		| including
    576  1.48.6.2      scw 	movl	%a1,%sp@(FR_SP)		|    the users SP
    577  1.48.6.2      scw 	clrl	%sp@-			| VA == none
    578  1.48.6.2      scw 	clrl	%sp@-			| code == none
    579  1.48.6.2      scw 	movl	#T_ASTFLT,%sp@-		| type == async system trap
    580  1.48.6.2      scw 	jbsr	_C_LABEL(trap)		| go handle it
    581  1.48.6.2      scw 	lea	%sp@(12),%sp		| pop value args
    582  1.48.6.2      scw 	movl	%sp@(FR_SP),%a0		| restore user SP
    583  1.48.6.2      scw 	movl	%a0,%usp		|   from save area
    584  1.48.6.2      scw 	movw	%sp@(FR_ADJ),%d0	| need to adjust stack?
    585  1.48.6.2      scw 	jne	Laststkadj		| yes, go to it
    586  1.48.6.2      scw 	moveml	%sp@+,#0x7FFF		| no, restore most user regs
    587  1.48.6.2      scw 	addql	#8,%sp			| toss SP and stack adjust
    588  1.48.6.2      scw 	rte				| and do real RTE
    589  1.48.6.2      scw Laststkadj:
    590  1.48.6.2      scw 	lea	%sp@(FR_HW),%a1		| pointer to HW frame
    591  1.48.6.2      scw 	addql	#8,%a1			| source pointer
    592  1.48.6.2      scw 	movl	%a1,%a0			| source
    593  1.48.6.2      scw 	addw	%d0,%a0			|  + hole size = dest pointer
    594  1.48.6.2      scw 	movl	%a1@-,%a0@-		| copy
    595  1.48.6.2      scw 	movl	%a1@-,%a0@-		|  8 bytes
    596  1.48.6.2      scw 	movl	%a0,%sp@(FR_SP)		| new SSP
    597  1.48.6.2      scw 	moveml	%sp@+,#0x7FFF		| restore user registers
    598  1.48.6.2      scw 	movl	%sp@,%sp		| and our SP
    599  1.48.6.2      scw Ldorte:
    600  1.48.6.2      scw 	rte				| real return
    601  1.48.6.2      scw 
    602  1.48.6.2      scw /*
    603  1.48.6.2      scw  * Initialization is at the beginning of this file, because the
    604  1.48.6.2      scw  * kernel entry point needs to be at zero for compatibility with
    605  1.48.6.2      scw  * the Sun boot loader.  This works on Sun machines because the
    606  1.48.6.2      scw  * interrupt vector table for reset is NOT at address zero.
    607  1.48.6.2      scw  * (The MMU has a "boot" bit that forces access to the PROM)
    608  1.48.6.2      scw  */
    609  1.48.6.2      scw 
    610  1.48.6.2      scw /*
    611  1.48.6.2      scw  * Use common m68k sigcode.
    612  1.48.6.2      scw  */
    613  1.48.6.2      scw #include <m68k/m68k/sigcode.s>
    614  1.48.6.2      scw #ifdef COMPAT_SUNOS
    615  1.48.6.2      scw #include <m68k/m68k/sunos_sigcode.s>
    616  1.48.6.2      scw #endif
    617  1.48.6.2      scw #ifdef COMPAT_SVR4
    618  1.48.6.2      scw #include <m68k/m68k/svr4_sigcode.s>
    619  1.48.6.2      scw #endif
    620  1.48.6.2      scw 
    621  1.48.6.2      scw 	.text
    622  1.48.6.2      scw 
    623  1.48.6.2      scw /*
    624  1.48.6.2      scw  * Primitives
    625  1.48.6.2      scw  */
    626  1.48.6.2      scw 
    627  1.48.6.2      scw /*
    628  1.48.6.2      scw  * Use common m68k support routines.
    629  1.48.6.2      scw  */
    630  1.48.6.2      scw #include <m68k/m68k/support.s>
    631  1.48.6.2      scw 
    632  1.48.6.2      scw BSS(want_resched,4)
    633  1.48.6.2      scw 
    634  1.48.6.2      scw /*
    635  1.48.6.2      scw  * Use common m68k process manipulation routines.
    636  1.48.6.2      scw  */
    637  1.48.6.2      scw #include <m68k/m68k/proc_subr.s>
    638  1.48.6.2      scw 
    639  1.48.6.2      scw /*
    640  1.48.6.2      scw  * Use common m68k process/lwp switch and context save subroutines.
    641  1.48.6.2      scw  */
    642  1.48.6.2      scw #define FPCOPROC	/* XXX: Temp. Reqd. */
    643  1.48.6.2      scw #include <m68k/m68k/switch_subr.s>
    644  1.48.6.2      scw 
    645  1.48.6.2      scw 
    646  1.48.6.2      scw /* suline() */
    647  1.48.6.2      scw 
    648  1.48.6.2      scw #ifdef DEBUG
    649  1.48.6.2      scw 	.data
    650  1.48.6.2      scw ASGLOBAL(fulltflush)
    651  1.48.6.2      scw 	.long	0
    652  1.48.6.2      scw ASGLOBAL(fullcflush)
    653  1.48.6.2      scw 	.long	0
    654  1.48.6.2      scw 	.text
    655  1.48.6.2      scw #endif
    656  1.48.6.2      scw 
    657  1.48.6.2      scw /*
    658  1.48.6.2      scw  * Invalidate entire TLB.
    659  1.48.6.2      scw  */
    660  1.48.6.2      scw ENTRY(TBIA)
    661  1.48.6.2      scw _C_LABEL(_TBIA):
    662  1.48.6.2      scw 	pflusha
    663  1.48.6.2      scw 	movl	#DC_CLEAR,%d0
    664  1.48.6.2      scw 	movc	%d0,%cacr			| invalidate on-chip d-cache
    665  1.48.6.2      scw 	rts
    666  1.48.6.2      scw 
    667  1.48.6.2      scw /*
    668  1.48.6.2      scw  * Invalidate any TLB entry for given VA (TB Invalidate Single)
    669  1.48.6.2      scw  */
    670  1.48.6.2      scw ENTRY(TBIS)
    671  1.48.6.2      scw #ifdef DEBUG
    672  1.48.6.2      scw 	tstl	_ASM_LABEL(fulltflush)	| being conservative?
    673  1.48.6.2      scw 	jne	_C_LABEL(_TBIA)		| yes, flush entire TLB
    674  1.48.6.2      scw #endif
    675  1.48.6.2      scw 	movl	%sp@(4),%a0
    676  1.48.6.2      scw 	pflush	#0,#0,%a0@		| flush address from both sides
    677  1.48.6.2      scw 	movl	#DC_CLEAR,%d0
    678  1.48.6.2      scw 	movc	%d0,%cacr			| invalidate on-chip data cache
    679  1.48.6.2      scw 	rts
    680  1.48.6.2      scw 
    681  1.48.6.2      scw /*
    682  1.48.6.2      scw  * Invalidate supervisor side of TLB
    683  1.48.6.2      scw  */
    684  1.48.6.2      scw ENTRY(TBIAS)
    685  1.48.6.2      scw #ifdef DEBUG
    686  1.48.6.2      scw 	tstl	_ASM_LABEL(fulltflush)	| being conservative?
    687  1.48.6.2      scw 	jne	_C_LABEL(_TBIA)		| yes, flush everything
    688  1.48.6.2      scw #endif
    689  1.48.6.2      scw 	pflush	#4,#4			| flush supervisor TLB entries
    690  1.48.6.2      scw 	movl	#DC_CLEAR,%d0
    691  1.48.6.2      scw 	movc	%d0,%cacr			| invalidate on-chip d-cache
    692  1.48.6.2      scw 	rts
    693  1.48.6.2      scw 
    694  1.48.6.2      scw /*
    695  1.48.6.2      scw  * Invalidate user side of TLB
    696  1.48.6.2      scw  */
    697  1.48.6.2      scw ENTRY(TBIAU)
    698  1.48.6.2      scw #ifdef DEBUG
    699  1.48.6.2      scw 	tstl	_ASM_LABEL(fulltflush)	| being conservative?
    700  1.48.6.2      scw 	jne	_C_LABEL(_TBIA)		| yes, flush everything
    701  1.48.6.2      scw #endif
    702  1.48.6.2      scw 	pflush	#0,#4			| flush user TLB entries
    703  1.48.6.2      scw 	movl	#DC_CLEAR,%d0
    704  1.48.6.2      scw 	movc	%d0,%cacr			| invalidate on-chip d-cache
    705  1.48.6.2      scw 	rts
    706  1.48.6.2      scw 
    707  1.48.6.2      scw /*
    708  1.48.6.2      scw  * Invalidate instruction cache
    709  1.48.6.2      scw  */
    710  1.48.6.2      scw ENTRY(ICIA)
    711  1.48.6.2      scw 	movl	#IC_CLEAR,%d0
    712  1.48.6.2      scw 	movc	%d0,%cacr			| invalidate i-cache
    713  1.48.6.2      scw 	rts
    714  1.48.6.2      scw 
    715  1.48.6.2      scw /*
    716  1.48.6.2      scw  * Invalidate data cache.
    717  1.48.6.2      scw  * NOTE: we do not flush 68030 on-chip cache as there are no aliasing
    718  1.48.6.2      scw  * problems with DC_WA.  The only cases we have to worry about are context
    719  1.48.6.2      scw  * switch and TLB changes, both of which are handled "in-line" in resume
    720  1.48.6.2      scw  * and TBI*.
    721  1.48.6.2      scw  */
    722  1.48.6.2      scw ENTRY(DCIA)
    723  1.48.6.2      scw __DCIA:
    724  1.48.6.2      scw 	rts
    725  1.48.6.2      scw 
    726  1.48.6.2      scw ENTRY(DCIS)
    727  1.48.6.2      scw __DCIS:
    728  1.48.6.2      scw 	rts
    729  1.48.6.2      scw 
    730  1.48.6.2      scw /*
    731  1.48.6.2      scw  * Invalidate data cache.
    732  1.48.6.2      scw  */
    733  1.48.6.2      scw ENTRY(DCIU)
    734  1.48.6.2      scw 	movl	#DC_CLEAR,%d0
    735  1.48.6.2      scw 	movc	%d0,%cacr			| invalidate on-chip d-cache
    736  1.48.6.2      scw 	rts
    737  1.48.6.2      scw 
    738  1.48.6.2      scw /* ICPL, ICPP, DCPL, DCPP, DCPA, DCFL, DCFP */
    739  1.48.6.2      scw 
    740  1.48.6.2      scw ENTRY(PCIA)
    741  1.48.6.2      scw 	movl	#DC_CLEAR,%d0
    742  1.48.6.2      scw 	movc	%d0,%cacr			| invalidate on-chip d-cache
    743  1.48.6.2      scw 	rts
    744  1.48.6.2      scw 
    745  1.48.6.2      scw ENTRY(ecacheon)
    746  1.48.6.2      scw 	rts
    747  1.48.6.2      scw 
    748  1.48.6.2      scw ENTRY(ecacheoff)
    749  1.48.6.2      scw 	rts
    750  1.48.6.2      scw 
    751  1.48.6.2      scw /*
    752  1.48.6.2      scw  * Get callers current SP value.
    753  1.48.6.2      scw  * Note that simply taking the address of a local variable in a C function
    754  1.48.6.2      scw  * doesn't work because callee saved registers may be outside the stack frame
    755  1.48.6.2      scw  * defined by A6 (e.g. GCC generated code).
    756  1.48.6.2      scw  *
    757  1.48.6.2      scw  * [I don't think the ENTRY() macro will do the right thing with this -- glass]
    758  1.48.6.2      scw  */
    759  1.48.6.2      scw GLOBAL(getsp)
    760  1.48.6.2      scw 	movl	%sp,%d0			| get current SP
    761  1.48.6.2      scw 	addql	#4,%d0			| compensate for return address
    762  1.48.6.2      scw 	movl	%d0,%a0
    763  1.48.6.2      scw 	rts
    764  1.48.6.2      scw 
    765  1.48.6.2      scw ENTRY(getsfc)
    766  1.48.6.2      scw 	movc	%sfc,%d0
    767  1.48.6.2      scw 	movl	%d0,%a0
    768  1.48.6.2      scw 	rts
    769  1.48.6.2      scw 
    770  1.48.6.2      scw ENTRY(getdfc)
    771  1.48.6.2      scw 	movc	%dfc,%d0
    772  1.48.6.2      scw 	movl	%d0,%a0
    773  1.48.6.2      scw 	rts
    774  1.48.6.2      scw 
    775  1.48.6.2      scw ENTRY(getvbr)
    776  1.48.6.2      scw 	movc	%vbr,%d0
    777  1.48.6.2      scw 	movl	%d0,%a0
    778  1.48.6.2      scw 	rts
    779  1.48.6.2      scw 
    780  1.48.6.2      scw ENTRY(setvbr)
    781  1.48.6.2      scw 	movl	%sp@(4),%d0
    782  1.48.6.2      scw 	movc	%d0,%vbr
    783  1.48.6.2      scw 	rts
    784  1.48.6.2      scw 
    785  1.48.6.2      scw /*
    786  1.48.6.2      scw  * Load a new CPU Root Pointer (CRP) into the MMU.
    787  1.48.6.2      scw  *	void	loadcrp(struct mmu_rootptr *);
    788  1.48.6.2      scw  */
    789  1.48.6.2      scw ENTRY(loadcrp)
    790  1.48.6.2      scw 	movl	%sp@(4),%a0		| arg1: &CRP
    791  1.48.6.2      scw 	movl	#CACHE_CLR,%d0
    792  1.48.6.2      scw 	movc	%d0,%cacr		| invalidate cache(s)
    793  1.48.6.2      scw 	pflusha				| flush entire TLB
    794  1.48.6.2      scw 	pmove	%a0@,%crp		| load new user root pointer
    795  1.48.6.2      scw 	rts
    796  1.48.6.2      scw 
    797  1.48.6.2      scw ENTRY(getcrp)
    798  1.48.6.2      scw 	movl	%sp@(4),%a0		| arg1: &crp
    799  1.48.6.2      scw 	pmove	%crp,%a0@		| *crpp = %crp
    800  1.48.6.2      scw 	rts
    801  1.48.6.2      scw 
    802  1.48.6.2      scw /*
    803  1.48.6.2      scw  * Get the physical address of the PTE for a given VA.
    804  1.48.6.2      scw  */
    805  1.48.6.2      scw ENTRY(ptest_addr)
    806  1.48.6.2      scw 	movl	%sp@(4),%a1		| VA
    807  1.48.6.2      scw 	ptestr	#5,%a1@,#7,%a0		| %a0 = addr of PTE
    808  1.48.6.2      scw 	movl	%a0,%d0			| Result in %d0 (not a pointer return)
    809  1.48.6.2      scw 	rts
    810  1.48.6.2      scw 
    811  1.48.6.2      scw /*
    812  1.48.6.2      scw  * Set processor priority level calls.  Most are implemented with
    813  1.48.6.2      scw  * inline asm expansions.  However, we need one instantiation here
    814  1.48.6.2      scw  * in case some non-optimized code makes external references.
    815  1.48.6.2      scw  * Most places will use the inlined functions param.h supplies.
    816  1.48.6.2      scw  */
    817  1.48.6.2      scw 
    818  1.48.6.2      scw ENTRY(_getsr)
    819  1.48.6.2      scw 	clrl	%d0
    820  1.48.6.2      scw 	movw	%sr,%d0
    821  1.48.6.2      scw 	movl	%a1,%d0
    822  1.48.6.2      scw 	rts
    823  1.48.6.2      scw 
    824  1.48.6.2      scw ENTRY(_spl)
    825  1.48.6.2      scw 	clrl	%d0
    826  1.48.6.2      scw 	movw	%sr,%d0
    827  1.48.6.2      scw 	movl	%sp@(4),%d1
    828  1.48.6.2      scw 	movw	%d1,%sr
    829  1.48.6.2      scw 	rts
    830  1.48.6.2      scw 
    831  1.48.6.2      scw ENTRY(_splraise)
    832  1.48.6.2      scw 	clrl	%d0
    833  1.48.6.2      scw 	movw	%sr,%d0
    834  1.48.6.2      scw 	movl	%d0,%d1
    835  1.48.6.2      scw 	andl	#PSL_HIGHIPL,%d1 	| old &= PSL_HIGHIPL
    836  1.48.6.2      scw 	cmpl	%sp@(4),%d1		| (old - new)
    837  1.48.6.2      scw 	bge	Lsplr
    838  1.48.6.2      scw 	movl	%sp@(4),%d1
    839  1.48.6.2      scw 	movw	%d1,%sr
    840  1.48.6.2      scw Lsplr:
    841  1.48.6.2      scw 	rts
    842  1.48.6.2      scw 
    843  1.48.6.2      scw /*
    844  1.48.6.2      scw  * Save and restore 68881 state.
    845  1.48.6.2      scw  */
    846  1.48.6.2      scw ENTRY(m68881_save)
    847  1.48.6.2      scw 	movl	%sp@(4),%a0		| save area pointer
    848  1.48.6.2      scw 	fsave	%a0@			| save state
    849  1.48.6.2      scw 	tstb	%a0@			| null state frame?
    850  1.48.6.2      scw 	jeq	Lm68881sdone		| yes, all done
    851  1.48.6.2      scw 	fmovem	%fp0-%fp7,%a0@(FPF_REGS)	| save FP general regs
    852  1.48.6.2      scw 	fmovem	%fpcr/%fpsr/%fpi,%a0@(FPF_FPCR)	| save FP control regs
    853  1.48.6.2      scw Lm68881sdone:
    854  1.48.6.2      scw 	rts
    855  1.48.6.2      scw 
    856  1.48.6.2      scw ENTRY(m68881_restore)
    857  1.48.6.2      scw 	movl	%sp@(4),%a0		| save area pointer
    858  1.48.6.2      scw 	tstb	%a0@			| null state frame?
    859  1.48.6.2      scw 	jeq	Lm68881rdone		| yes, easy
    860  1.48.6.2      scw 	fmovem	%a0@(FPF_FPCR),%fpcr/%fpsr/%fpi	| restore FP control regs
    861  1.48.6.2      scw 	fmovem	%a0@(FPF_REGS),%fp0-%fp7	| restore FP general regs
    862  1.48.6.2      scw Lm68881rdone:
    863  1.48.6.2      scw 	frestore %a0@			| restore state
    864  1.48.6.2      scw 	rts
    865  1.48.6.2      scw 
    866  1.48.6.2      scw /*
    867  1.48.6.2      scw  * _delay(unsigned N)
    868  1.48.6.2      scw  * Delay for at least (N/256) microseconds.
    869  1.48.6.2      scw  * This routine depends on the variable:  delay_divisor
    870  1.48.6.2      scw  * which should be set based on the CPU clock rate.
    871  1.48.6.2      scw  * XXX: Currently this is set based on the CPU model,
    872  1.48.6.2      scw  * XXX: but this should be determined at run time...
    873  1.48.6.2      scw  */
    874  1.48.6.2      scw GLOBAL(_delay)
    875  1.48.6.2      scw 	| %d0 = arg = (usecs << 8)
    876  1.48.6.2      scw 	movl	%sp@(4),%d0
    877  1.48.6.2      scw 	| %d1 = delay_divisor;
    878  1.48.6.2      scw 	movl	_C_LABEL(delay_divisor),%d1
    879  1.48.6.2      scw 	jra	L_delay			/* Jump into the loop! */
    880  1.48.6.2      scw 
    881  1.48.6.2      scw 	/*
    882  1.48.6.2      scw 	 * Align the branch target of the loop to a half-line (8-byte)
    883  1.48.6.2      scw 	 * boundary to minimize cache effects.  This guarantees both
    884  1.48.6.2      scw 	 * that there will be no prefetch stalls due to cache line burst
    885  1.48.6.2      scw 	 * operations and that the loop will run from a single cache
    886  1.48.6.2      scw 	 * half-line.
    887  1.48.6.2      scw 	 */
    888  1.48.6.2      scw #ifdef __ELF__
    889  1.48.6.2      scw 	.align	8
    890  1.48.6.2      scw #else
    891  1.48.6.2      scw 	.align	3
    892  1.48.6.2      scw #endif
    893  1.48.6.2      scw L_delay:
    894  1.48.6.2      scw 	subl	%d1,%d0
    895  1.48.6.2      scw 	jgt	L_delay
    896  1.48.6.2      scw 	rts
    897  1.48.6.2      scw 
    898  1.48.6.2      scw | Define some addresses, mostly so DDB can print useful info.
    899  1.48.6.2      scw | Not using _C_LABEL() here because these symbols are never
    900  1.48.6.2      scw | referenced by any C code, and if the leading underscore
    901  1.48.6.2      scw | ever goes away, these lines turn into syntax errors...
    902  1.48.6.2      scw 	.set	_KERNBASE,KERNBASE
    903  1.48.6.2      scw 	.set	_MONSTART,SUN3X_MONSTART
    904  1.48.6.2      scw 	.set	_PROM_BASE,SUN3X_PROM_BASE
    905  1.48.6.2      scw 	.set	_MONEND,SUN3X_MONEND
    906  1.48.6.2      scw 
    907  1.48.6.2      scw |The end!
    908