1/* $NetBSD: sunos_sigcode.s,v 1.2 2002/05/05 08:21:40 thorpej 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 .register %g2,#scratch 66 .register %g3,#scratch 67 68/* 69 * The following code is copied to the top of the user stack when each 70 * process is exec'ed, and signals are `trampolined' off it. 71 * 72 * When this code is run, the stack looks like: 73 * [%sp] 64 bytes to which registers can be dumped 74 * [%sp + 64] signal number (goes in %o0) 75 * [%sp + 64 + 4] signal code (goes in %o1) 76 * [%sp + 64 + 8] placeholder 77 * [%sp + 64 + 12] argument for %o3, currently unsupported (always 0) 78 * [%sp + 64 + 16] first word of saved state (sigcontext) 79 * . 80 * . 81 * . 82 * [%sp + NNN] last word of saved state 83 * (followed by previous stack contents or top of signal stack). 84 * The address of the function to call is in %g1; the old %g1 and %o0 85 * have already been saved in the sigcontext. We are running in a clean 86 * window, all previous windows now being saved to the stack. 87 * 88 * Note that [%sp + 64 + 8] == %sp + 64 + 16. The copy at %sp+64+8 89 * will eventually be removed, with a hole left in its place, if things 90 * work out. 91 */ 92 .globl sunos_sigcode 93 .globl sunos_esigcode 94sunos_sigcode: 95 /* 96 * XXX the `save' and `restore' below are unnecessary: should 97 * replace with simple arithmetic on %sp 98 * 99 * Make room on the stack for 32 %f registers + %fsr. This comes 100 * out to 33*4 or 132 bytes, but this must be aligned to a multiple 101 * of 8, or 136 bytes. 102 */ 103 save %sp, -CCFSZ - 136, %sp 104 mov %g2, %l2 ! save globals in %l registers 105 mov %g3, %l3 106 mov %g4, %l4 107 mov %g5, %l5 108 mov %g6, %l6 109 mov %g7, %l7 110 /* 111 * Saving the fpu registers is expensive, so do it iff the fsr 112 * stored in the sigcontext shows that the fpu is enabled. 113 */ 114 ld [%fp + 64 + 16 + SC_PSR_OFFSET], %l0 115 sethi %hi(PSR_EF), %l1 ! FPU enable bit is too high for andcc 116 andcc %l0, %l1, %l0 ! %l0 = fpu enable bit 117 be 1f ! if not set, skip the saves 118 rd %y, %l1 ! in any case, save %y 119 120 ! fpu is enabled, oh well 121 st %fsr, [%sp + CCFSZ + 0] 122 std %f0, [%sp + CCFSZ + 8] 123 std %f2, [%sp + CCFSZ + 16] 124 std %f4, [%sp + CCFSZ + 24] 125 std %f6, [%sp + CCFSZ + 32] 126 std %f8, [%sp + CCFSZ + 40] 127 std %f10, [%sp + CCFSZ + 48] 128 std %f12, [%sp + CCFSZ + 56] 129 std %f14, [%sp + CCFSZ + 64] 130 std %f16, [%sp + CCFSZ + 72] 131 std %f18, [%sp + CCFSZ + 80] 132 std %f20, [%sp + CCFSZ + 88] 133 std %f22, [%sp + CCFSZ + 96] 134 std %f24, [%sp + CCFSZ + 104] 135 std %f26, [%sp + CCFSZ + 112] 136 std %f28, [%sp + CCFSZ + 120] 137 std %f30, [%sp + CCFSZ + 128] 138 1391: 140 ldd [%fp + 64], %o0 ! sig, code 141 ld [%fp + 76], %o3 ! arg3 142 call %g1 ! (*sa->sa_handler)(sig,code,scp,arg3) 143 add %fp, 64 + 16, %o2 ! scp 144 145 /* 146 * Now that the handler has returned, re-establish all the state 147 * we just saved above, then do a sigreturn. 148 */ 149 tst %l0 ! reload fpu registers? 150 be 1f ! if not, skip the loads 151 wr %l1, %g0, %y ! in any case, restore %y 152 153 ld [%sp + CCFSZ + 0], %fsr 154 ldd [%sp + CCFSZ + 8], %f0 155 ldd [%sp + CCFSZ + 16], %f2 156 ldd [%sp + CCFSZ + 24], %f4 157 ldd [%sp + CCFSZ + 32], %f6 158 ldd [%sp + CCFSZ + 40], %f8 159 ldd [%sp + CCFSZ + 48], %f10 160 ldd [%sp + CCFSZ + 56], %f12 161 ldd [%sp + CCFSZ + 64], %f14 162 ldd [%sp + CCFSZ + 72], %f16 163 ldd [%sp + CCFSZ + 80], %f18 164 ldd [%sp + CCFSZ + 88], %f20 165 ldd [%sp + CCFSZ + 96], %f22 166 ldd [%sp + CCFSZ + 104], %f24 167 ldd [%sp + CCFSZ + 112], %f26 168 ldd [%sp + CCFSZ + 120], %f28 169 ldd [%sp + CCFSZ + 128], %f30 170 1711: 172 mov %l2, %g2 173 mov %l3, %g3 174 mov %l4, %g4 175 mov %l5, %g5 176 mov %l6, %g6 177 mov %l7, %g7 178 179 ! get registers back & set syscall # 180 restore %g0, SUNOS_SYS_sigreturn, %g1 181 add %sp, 64 + 16, %o0 ! compute scp 182 t ST_SYSCALL ! sigreturn(scp) 183 ! sigreturn does not return unless it fails 184 mov SUNOS_SYS_exit, %g1 ! exit(errno) 185 t ST_SYSCALL 186sunos_esigcode: 187