1*f31d8e57Smrg/* $NetBSD: compat___sigtramp1.S,v 1.2 2011/07/12 07:51:33 mrg Exp $ */ 2180e99b5Schristos 3180e99b5Schristos/* 4180e99b5Schristos * Copyright (c) 1996-2002 Eduardo Horvath 5180e99b5Schristos * Copyright (c) 1996 Paul Kranenburg 6180e99b5Schristos * Copyright (c) 1996 7180e99b5Schristos * The President and Fellows of Harvard College. All rights reserved. 8180e99b5Schristos * Copyright (c) 1992, 1993 9180e99b5Schristos * The Regents of the University of California. All rights reserved. 10180e99b5Schristos * 11180e99b5Schristos * This software was developed by the Computer Systems Engineering group 12180e99b5Schristos * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 13180e99b5Schristos * contributed to Berkeley. 14180e99b5Schristos * 15180e99b5Schristos * All advertising materials mentioning features or use of this software 16180e99b5Schristos * must display the following acknowledgement: 17180e99b5Schristos * This product includes software developed by the University of 18180e99b5Schristos * California, Lawrence Berkeley Laboratory. 19180e99b5Schristos * This product includes software developed by Harvard University. 20180e99b5Schristos * 21180e99b5Schristos * Redistribution and use in source and binary forms, with or without 22180e99b5Schristos * modification, are permitted provided that the following conditions 23180e99b5Schristos * are met: 24180e99b5Schristos * 1. Redistributions of source code must retain the above copyright 25180e99b5Schristos * notice, this list of conditions and the following disclaimer. 26180e99b5Schristos * 2. Redistributions in binary form must reproduce the above copyright 27180e99b5Schristos * notice, this list of conditions and the following disclaimer in the 28180e99b5Schristos * documentation and/or other materials provided with the distribution. 29180e99b5Schristos * 3. All advertising materials mentioning features or use of this software 30180e99b5Schristos * must display the following acknowledgement: 31180e99b5Schristos * This product includes software developed by Harvard University. 32180e99b5Schristos * This product includes software developed by Paul Kranenburg. 33180e99b5Schristos * 4. Neither the name of the University nor the names of its contributors 34180e99b5Schristos * may be used to endorse or promote products derived from this software 35180e99b5Schristos * without specific prior written permission. 36180e99b5Schristos * 37180e99b5Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 38180e99b5Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 39180e99b5Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 40180e99b5Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 41180e99b5Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 42180e99b5Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 43180e99b5Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44180e99b5Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 45180e99b5Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 46180e99b5Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 47180e99b5Schristos * SUCH DAMAGE. 48180e99b5Schristos */ 49180e99b5Schristos 50180e99b5Schristos#include "SYS.h" 51180e99b5Schristos 52180e99b5Schristos#define _LOCORE 53180e99b5Schristos#include <machine/frame.h> 54180e99b5Schristos#include <machine/fsr.h> 55180e99b5Schristos#include <machine/ctlreg.h> 56180e99b5Schristos#include <machine/psl.h> 57180e99b5Schristos 58180e99b5Schristos .register %g2,#ignore 59180e99b5Schristos .register %g3,#ignore 60180e99b5Schristos 61*f31d8e57Smrg#define BLOCK_SIZE SPARC64_BLOCK_SIZE 62*f31d8e57Smrg#define BLOCK_ALIGN SPARC64_BLOCK_ALIGN 63*f31d8e57Smrg 64180e99b5Schristos/* 65180e99b5Schristos * When this code is run, the stack looks like: 66180e99b5Schristos * [%sp] 128 bytes to which registers can be dumped 67180e99b5Schristos * [%sp + 128] signal number (goes in %o0) 68180e99b5Schristos * [%sp + 128 + 4] signal code (goes in %o1) 69180e99b5Schristos * [%sp + 128 + 8] first word of saved state (sigcontext) 70180e99b5Schristos * . 71180e99b5Schristos * . 72180e99b5Schristos * . 73180e99b5Schristos * [%sp + NNN] last word of saved state 74180e99b5Schristos * (followed by previous stack contents or top of signal stack). 75180e99b5Schristos * The address of the function to call is in %g1; the old %g1 and %o0 76180e99b5Schristos * have already been saved in the sigcontext. We are running in a clean 77180e99b5Schristos * window, all previous windows now being saved to the stack. 78180e99b5Schristos * 79180e99b5Schristos * Note that [%sp + 128 + 8] == %sp + 128 + 16. The copy at %sp+128+8 80180e99b5Schristos * will eventually be removed, with a hole left in its place, if things 81180e99b5Schristos * work out. 82180e99b5Schristos */ 83180e99b5SchristosENTRY_NOPROFILE(__sigtramp_sigcontext_1) 84180e99b5Schristos /* 85180e99b5Schristos * XXX the `save' and `restore' below are unnecessary: should 86180e99b5Schristos * replace with simple arithmetic on %sp 87180e99b5Schristos * 88180e99b5Schristos * Make room on the stack for 64 %f registers + %fsr. This comes 89180e99b5Schristos * out to 64*4+8 or 264 bytes, but this must be aligned to a multiple 90180e99b5Schristos * of 64, or 320 bytes. 91180e99b5Schristos */ 92180e99b5Schristos save %sp, -CC64FSZ - 320, %sp 93180e99b5Schristos mov %g2, %l2 /* save globals in %l registers */ 94180e99b5Schristos mov %g3, %l3 95180e99b5Schristos mov %g4, %l4 96180e99b5Schristos mov %g5, %l5 97180e99b5Schristos mov %g6, %l6 98180e99b5Schristos mov %g7, %l7 99180e99b5Schristos /* 100180e99b5Schristos * Saving the fpu registers is expensive, so do it iff it is 101180e99b5Schristos * enabled and dirty. 102180e99b5Schristos */ 103180e99b5Schristos rd %fprs, %l0 104180e99b5Schristos btst FPRS_DL|FPRS_DU, %l0 /* All clean? */ 105180e99b5Schristos bz,pt %icc, 2f 106180e99b5Schristos btst FPRS_DL, %l0 /* test dl */ 107180e99b5Schristos bz,pt %icc, 1f 108180e99b5Schristos btst FPRS_DU, %l0 /* test du */ 109180e99b5Schristos 110180e99b5Schristos /* fpu is enabled, oh well */ 111180e99b5Schristos stx %fsr, [%sp + CC64FSZ + BIAS + 0] 112180e99b5Schristos add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */ 113180e99b5Schristos andn %l0, BLOCK_ALIGN, %l0 /* we can do a block store */ 114180e99b5Schristos stda %f0, [%l0] ASI_BLK_P 115180e99b5Schristos inc BLOCK_SIZE, %l0 116180e99b5Schristos stda %f16, [%l0] ASI_BLK_P 117180e99b5Schristos1: 118180e99b5Schristos bz,pt %icc, 2f 119180e99b5Schristos add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */ 120180e99b5Schristos andn %l0, BLOCK_ALIGN, %l0 /* we can do a block store */ 121180e99b5Schristos add %l0, 2*BLOCK_SIZE, %l0 /* and skip what we already stored */ 122180e99b5Schristos stda %f32, [%l0] ASI_BLK_P 123180e99b5Schristos inc BLOCK_SIZE, %l0 124180e99b5Schristos stda %f48, [%l0] ASI_BLK_P 125180e99b5Schristos2: 126180e99b5Schristos membar #Sync 127180e99b5Schristos rd %y, %l1 /* in any case, save %y */ 128180e99b5Schristos lduw [%fp + BIAS + 128], %o0 /* sig */ 129180e99b5Schristos lduw [%fp + BIAS + 128 + 4], %o1 /* code */ 130180e99b5Schristos call %g1 /* call handler */ 131180e99b5Schristos add %fp, BIAS + 128 + 8, %o2 /* scp */ 132180e99b5Schristos 133180e99b5Schristos /* 134180e99b5Schristos * Now that the handler has returned, re-establish all the state 135180e99b5Schristos * we just saved above, then do a sigreturn. 136180e99b5Schristos */ 137180e99b5Schristos btst 3, %l0 /* All clean? */ 138180e99b5Schristos bz,pt %icc, 2f 139180e99b5Schristos btst 1, %l0 /* test dl */ 140180e99b5Schristos bz,pt %icc, 1f 141180e99b5Schristos btst 2, %l0 /* test du */ 142180e99b5Schristos 143180e99b5Schristos ldx [%sp + CC64FSZ + BIAS + 0], %fsr 144180e99b5Schristos add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */ 145180e99b5Schristos andn %l0, BLOCK_ALIGN, %l0 /* we can do a block load */ 146180e99b5Schristos ldda [%l0] ASI_BLK_P, %f0 147180e99b5Schristos inc BLOCK_SIZE, %l0 148180e99b5Schristos ldda [%l0] ASI_BLK_P, %f16 149180e99b5Schristos1: 150180e99b5Schristos bz,pt %icc, 2f 151180e99b5Schristos wr %l1, %g0, %y /* in any case, restore %y */ 152180e99b5Schristos add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */ 153180e99b5Schristos andn %l0, BLOCK_ALIGN, %l0 /* we can do a block load */ 154180e99b5Schristos inc 2*BLOCK_SIZE, %l0 /* and skip what we already loaded */ 155180e99b5Schristos ldda [%l0] ASI_BLK_P, %f32 156180e99b5Schristos inc BLOCK_SIZE, %l0 157180e99b5Schristos ldda [%l0] ASI_BLK_P, %f48 158180e99b5Schristos2: 159180e99b5Schristos mov %l2, %g2 160180e99b5Schristos mov %l3, %g3 161180e99b5Schristos mov %l4, %g4 162180e99b5Schristos mov %l5, %g5 163180e99b5Schristos mov %l6, %g6 164180e99b5Schristos mov %l7, %g7 165180e99b5Schristos membar #Sync 166180e99b5Schristos 167180e99b5Schristos /* get registers back and set syscall # */ 168180e99b5Schristos restore %g0, SYS_compat_16___sigreturn14, %g1 169180e99b5Schristos add %sp, BIAS + 128 + 8, %o0 /* compute scp */ 170180e99b5Schristos t ST_SYSCALL /* call sigreturn */ 171180e99b5Schristos mov SYS_exit, %g1 /* exit with errno */ 172180e99b5Schristos t ST_SYSCALL /* if sigreturn fails */ 173