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