1/* $NetBSD: compat___sigtramp1.S,v 1.1 2005/10/16 04:41:34 christos 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/* 62 * When this code is run, the stack looks like: 63 * [%sp] 128 bytes to which registers can be dumped 64 * [%sp + 128] signal number (goes in %o0) 65 * [%sp + 128 + 4] signal code (goes in %o1) 66 * [%sp + 128 + 8] first word of saved state (sigcontext) 67 * . 68 * . 69 * . 70 * [%sp + NNN] last word of saved state 71 * (followed by previous stack contents or top of signal stack). 72 * The address of the function to call is in %g1; the old %g1 and %o0 73 * have already been saved in the sigcontext. We are running in a clean 74 * window, all previous windows now being saved to the stack. 75 * 76 * Note that [%sp + 128 + 8] == %sp + 128 + 16. The copy at %sp+128+8 77 * will eventually be removed, with a hole left in its place, if things 78 * work out. 79 */ 80ENTRY_NOPROFILE(__sigtramp_sigcontext_1) 81 /* 82 * XXX the `save' and `restore' below are unnecessary: should 83 * replace with simple arithmetic on %sp 84 * 85 * Make room on the stack for 64 %f registers + %fsr. This comes 86 * out to 64*4+8 or 264 bytes, but this must be aligned to a multiple 87 * of 64, or 320 bytes. 88 */ 89 save %sp, -CC64FSZ - 320, %sp 90 mov %g2, %l2 /* save globals in %l registers */ 91 mov %g3, %l3 92 mov %g4, %l4 93 mov %g5, %l5 94 mov %g6, %l6 95 mov %g7, %l7 96 /* 97 * Saving the fpu registers is expensive, so do it iff it is 98 * enabled and dirty. 99 */ 100 rd %fprs, %l0 101 btst FPRS_DL|FPRS_DU, %l0 /* All clean? */ 102 bz,pt %icc, 2f 103 btst FPRS_DL, %l0 /* test dl */ 104 bz,pt %icc, 1f 105 btst FPRS_DU, %l0 /* test du */ 106 107 /* fpu is enabled, oh well */ 108 stx %fsr, [%sp + CC64FSZ + BIAS + 0] 109 add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */ 110 andn %l0, BLOCK_ALIGN, %l0 /* we can do a block store */ 111 stda %f0, [%l0] ASI_BLK_P 112 inc BLOCK_SIZE, %l0 113 stda %f16, [%l0] ASI_BLK_P 1141: 115 bz,pt %icc, 2f 116 add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */ 117 andn %l0, BLOCK_ALIGN, %l0 /* we can do a block store */ 118 add %l0, 2*BLOCK_SIZE, %l0 /* and skip what we already stored */ 119 stda %f32, [%l0] ASI_BLK_P 120 inc BLOCK_SIZE, %l0 121 stda %f48, [%l0] ASI_BLK_P 1222: 123 membar #Sync 124 rd %y, %l1 /* in any case, save %y */ 125 lduw [%fp + BIAS + 128], %o0 /* sig */ 126 lduw [%fp + BIAS + 128 + 4], %o1 /* code */ 127 call %g1 /* call handler */ 128 add %fp, BIAS + 128 + 8, %o2 /* scp */ 129 130 /* 131 * Now that the handler has returned, re-establish all the state 132 * we just saved above, then do a sigreturn. 133 */ 134 btst 3, %l0 /* All clean? */ 135 bz,pt %icc, 2f 136 btst 1, %l0 /* test dl */ 137 bz,pt %icc, 1f 138 btst 2, %l0 /* test du */ 139 140 ldx [%sp + CC64FSZ + BIAS + 0], %fsr 141 add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */ 142 andn %l0, BLOCK_ALIGN, %l0 /* we can do a block load */ 143 ldda [%l0] ASI_BLK_P, %f0 144 inc BLOCK_SIZE, %l0 145 ldda [%l0] ASI_BLK_P, %f16 1461: 147 bz,pt %icc, 2f 148 wr %l1, %g0, %y /* in any case, restore %y */ 149 add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */ 150 andn %l0, BLOCK_ALIGN, %l0 /* we can do a block load */ 151 inc 2*BLOCK_SIZE, %l0 /* and skip what we already loaded */ 152 ldda [%l0] ASI_BLK_P, %f32 153 inc BLOCK_SIZE, %l0 154 ldda [%l0] ASI_BLK_P, %f48 1552: 156 mov %l2, %g2 157 mov %l3, %g3 158 mov %l4, %g4 159 mov %l5, %g5 160 mov %l6, %g6 161 mov %l7, %g7 162 membar #Sync 163 164 /* get registers back and set syscall # */ 165 restore %g0, SYS_compat_16___sigreturn14, %g1 166 add %sp, BIAS + 128 + 8, %o0 /* compute scp */ 167 t ST_SYSCALL /* call sigreturn */ 168 mov SYS_exit, %g1 /* exit with errno */ 169 t ST_SYSCALL /* if sigreturn fails */ 170