Home | History | Annotate | Line # | Download | only in sys
      1 /*	$NetBSD: compat___sigtramp1.S,v 1.2 2011/07/12 07:51:33 mrg Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1996-2002 Eduardo Horvath
      5  * Copyright (c) 1996 Paul Kranenburg
      6  * Copyright (c) 1996
      7  * 	The President and Fellows of Harvard College. All rights reserved.
      8  * Copyright (c) 1992, 1993
      9  *	The Regents of the University of California.  All rights reserved.
     10  *
     11  * This software was developed by the Computer Systems Engineering group
     12  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     13  * contributed to Berkeley.
     14  *
     15  * All advertising materials mentioning features or use of this software
     16  * must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Lawrence Berkeley Laboratory.
     19  *	This product includes software developed by Harvard University.
     20  *
     21  * Redistribution and use in source and binary forms, with or without
     22  * modification, are permitted provided that the following conditions
     23  * are met:
     24  * 1. Redistributions of source code must retain the above copyright
     25  *    notice, this list of conditions and the following disclaimer.
     26  * 2. Redistributions in binary form must reproduce the above copyright
     27  *    notice, this list of conditions and the following disclaimer in the
     28  *    documentation and/or other materials provided with the distribution.
     29  * 3. All advertising materials mentioning features or use of this software
     30  *    must display the following acknowledgement:
     31  *	This product includes software developed by Harvard University.
     32  *	This product includes software developed by Paul Kranenburg.
     33  * 4. Neither the name of the University nor the names of its contributors
     34  *    may be used to endorse or promote products derived from this software
     35  *    without specific prior written permission.
     36  *
     37  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     38  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     39  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     40  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     41  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     42  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     43  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     44  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     45  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     46  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     47  * SUCH DAMAGE.
     48  */
     49 
     50 #include "SYS.h"
     51 
     52 #define _LOCORE
     53 #include <machine/frame.h>
     54 #include <machine/fsr.h>
     55 #include <machine/ctlreg.h>
     56 #include <machine/psl.h>
     57 
     58 	.register	%g2,#ignore
     59 	.register	%g3,#ignore
     60 
     61 #define BLOCK_SIZE SPARC64_BLOCK_SIZE
     62 #define BLOCK_ALIGN SPARC64_BLOCK_ALIGN
     63 
     64 /*
     65  * When this code is run, the stack looks like:
     66  *	[%sp]			128 bytes to which registers can be dumped
     67  *	[%sp + 128]		signal number (goes in %o0)
     68  *	[%sp + 128 + 4]		signal code (goes in %o1)
     69  *	[%sp + 128 + 8]		first word of saved state (sigcontext)
     70  *	    .
     71  *	    .
     72  *	    .
     73  *	[%sp + NNN]	last word of saved state
     74  * (followed by previous stack contents or top of signal stack).
     75  * The address of the function to call is in %g1; the old %g1 and %o0
     76  * have already been saved in the sigcontext.  We are running in a clean
     77  * window, all previous windows now being saved to the stack.
     78  *
     79  * Note that [%sp + 128 + 8] == %sp + 128 + 16.  The copy at %sp+128+8
     80  * will eventually be removed, with a hole left in its place, if things
     81  * work out.
     82  */
     83 ENTRY_NOPROFILE(__sigtramp_sigcontext_1)
     84 	/*
     85 	 * XXX  the `save' and `restore' below are unnecessary: should
     86 	 *	replace with simple arithmetic on %sp
     87 	 *
     88 	 * Make room on the stack for 64 %f registers + %fsr.  This comes
     89 	 * out to 64*4+8 or 264 bytes, but this must be aligned to a multiple
     90 	 * of 64, or 320 bytes.
     91 	 */
     92 	save	%sp, -CC64FSZ - 320, %sp
     93 	mov	%g2, %l2		/* save globals in %l registers */
     94 	mov	%g3, %l3
     95 	mov	%g4, %l4
     96 	mov	%g5, %l5
     97 	mov	%g6, %l6
     98 	mov	%g7, %l7
     99 	/*
    100 	 * Saving the fpu registers is expensive, so do it iff it is
    101 	 * enabled and dirty.
    102 	 */
    103 	rd	%fprs, %l0
    104 	btst	FPRS_DL|FPRS_DU, %l0	/* All clean? */
    105 	bz,pt	%icc, 2f
    106 	 btst	FPRS_DL, %l0		/* test dl */
    107 	bz,pt	%icc, 1f
    108 	 btst	FPRS_DU, %l0		/* test du */
    109 
    110 	/* fpu is enabled, oh well */
    111 	stx	%fsr, [%sp + CC64FSZ + BIAS + 0]
    112 	add	%sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */
    113 	andn	%l0, BLOCK_ALIGN, %l0		  /* we can do a block store */
    114 	stda	%f0, [%l0] ASI_BLK_P
    115 	inc	BLOCK_SIZE, %l0
    116 	stda	%f16, [%l0] ASI_BLK_P
    117 1:
    118 	bz,pt	%icc, 2f
    119 	 add	%sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */
    120 	andn	%l0, BLOCK_ALIGN, %l0		  /* we can do a block store */
    121 	add	%l0, 2*BLOCK_SIZE, %l0	/* and skip what we already stored */
    122 	stda	%f32, [%l0] ASI_BLK_P
    123 	inc	BLOCK_SIZE, %l0
    124 	stda	%f48, [%l0] ASI_BLK_P
    125 2:
    126 	membar	#Sync
    127 	rd	%y, %l1				/* in any case, save %y */
    128 	lduw	[%fp + BIAS + 128], %o0		/* sig */
    129 	lduw	[%fp + BIAS + 128 + 4], %o1	/* code */
    130 	call	%g1				/* call handler */
    131 	 add	%fp, BIAS + 128 + 8, %o2	/* scp */
    132 
    133 	/*
    134 	 * Now that the handler has returned, re-establish all the state
    135 	 * we just saved above, then do a sigreturn.
    136 	 */
    137 	btst	3, %l0			/* All clean? */
    138 	bz,pt	%icc, 2f
    139 	 btst	1, %l0			/* test dl */
    140 	bz,pt	%icc, 1f
    141 	 btst	2, %l0			/* test du */
    142 
    143 	ldx	[%sp + CC64FSZ + BIAS + 0], %fsr
    144 	add	%sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */
    145 	andn	%l0, BLOCK_ALIGN, %l0		  /* we can do a block load */
    146 	ldda	[%l0] ASI_BLK_P, %f0
    147 	inc	BLOCK_SIZE, %l0
    148 	ldda	[%l0] ASI_BLK_P, %f16
    149 1:
    150 	bz,pt	%icc, 2f
    151 	 wr	%l1, %g0, %y		/* in any case, restore %y */
    152 	add	%sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */
    153 	andn	%l0, BLOCK_ALIGN, %l0		  /* we can do a block load */
    154 	inc	2*BLOCK_SIZE, %l0	/* and skip what we already loaded */
    155 	ldda	[%l0] ASI_BLK_P, %f32
    156 	inc	BLOCK_SIZE, %l0
    157 	ldda	[%l0] ASI_BLK_P, %f48
    158 2:
    159 	mov	%l2, %g2
    160 	mov	%l3, %g3
    161 	mov	%l4, %g4
    162 	mov	%l5, %g5
    163 	mov	%l6, %g6
    164 	mov	%l7, %g7
    165 	membar	#Sync
    166 
    167 	/* get registers back and set syscall # */
    168 	restore	%g0, SYS_compat_16___sigreturn14, %g1
    169 	add	%sp, BIAS + 128 + 8, %o0	/* compute scp */
    170 	t	ST_SYSCALL			/* call sigreturn */
    171 	mov	SYS_exit, %g1			/* exit with errno */
    172 	t	ST_SYSCALL			/* if sigreturn fails */
    173