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