1/* $NetBSD: sigcode32.s,v 1.1 2001/06/06 21:19:50 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/* 60 * This module designed to be #include'ed by another assembly language 61 * source file, such as locore.s, which must provide these #defines: 62 * SIGCODE_NAME 63 * ESIGCODE_NAME 64 * SIGRETURN_NAME 65 * EXIT_NAME 66 * for the sigcode, esigcode, sigreturn & exit symbol names. 67 */ 68 69/* 70 * The following code is copied to the top of the user stack when each 71 * process is exec'ed, and signals are `trampolined' off it. 72 * 73 * When this code is run, the stack looks like: 74 * [%sp] 64 bytes to which registers can be dumped 75 * [%sp + 64] signal number (goes in %o0) 76 * [%sp + 64 + 4] signal code (goes in %o1) 77 * [%sp + 64 + 8] placeholder 78 * [%sp + 64 + 12] argument for %o3, currently unsupported (always 0) 79 * [%sp + 64 + 16] first word of saved state (sigcontext) 80 * . 81 * . 82 * . 83 * [%sp + NNN] last word of saved state 84 * (followed by previous stack contents or top of signal stack). 85 * The address of the function to call is in %g1; the old %g1 and %o0 86 * have already been saved in the sigcontext. We are running in a clean 87 * window, all previous windows now being saved to the stack. 88 * 89 * Note that [%sp + 64 + 8] == %sp + 64 + 16. The copy at %sp+64+8 90 * will eventually be removed, with a hole left in its place, if things 91 * work out. 92 */ 93 .globl SIGCODE_NAME 94 .globl ESIGCODE_NAME 95SIGCODE_NAME: 96 /* 97 * XXX the `save' and `restore' below are unnecessary: should 98 * replace with simple arithmetic on %sp 99 * 100 * Make room on the stack for 32 %f registers + %fsr. This comes 101 * out to 33*4 or 132 bytes, but this must be aligned to a multiple 102 * of 8, or 136 bytes. 103 */ 104 save %sp, -CCFSZ - 136, %sp 105 mov %g2, %l2 ! save globals in %l registers 106 mov %g3, %l3 107 mov %g4, %l4 108 mov %g5, %l5 109 mov %g6, %l6 110 mov %g7, %l7 111 /* 112 * Saving the fpu registers is expensive, so do it iff it is 113 * enabled and dirty. We only deal w/lower 32 regs 114 */ 115 rd %fprs, %l0 116 btst FPRS_DL, %l0 ! test dl 117 bz,pt %icc, 1f 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] 1381: 139 ldd [%fp + 64], %o0 ! sig, code 140 ld [%fp + 76], %o3 ! arg3 141 call %g1 ! (*sa->sa_handler)(sig,code,scp,arg3) 142 add %fp, 64 + 16, %o2 ! scp 143 144 /* 145 * Now that the handler has returned, re-establish all the state 146 * we just saved above, then do a sigreturn. 147 */ 148 btst FPRS_DL, %l0 ! test dl 149 bz,pt %icc, 1f 150 wr %l1, %g0, %y ! in any case, restore %y 151 152 ld [%sp + CCFSZ + 0], %fsr 153 ldd [%sp + CCFSZ + 8], %f0 154 ldd [%sp + CCFSZ + 16], %f2 155 ldd [%sp + CCFSZ + 24], %f4 156 ldd [%sp + CCFSZ + 32], %f6 157 ldd [%sp + CCFSZ + 40], %f8 158 ldd [%sp + CCFSZ + 48], %f10 159 ldd [%sp + CCFSZ + 56], %f12 160 ldd [%sp + CCFSZ + 64], %f14 161 ldd [%sp + CCFSZ + 72], %f16 162 ldd [%sp + CCFSZ + 80], %f18 163 ldd [%sp + CCFSZ + 88], %f20 164 ldd [%sp + CCFSZ + 96], %f22 165 ldd [%sp + CCFSZ + 104], %f24 166 ldd [%sp + CCFSZ + 112], %f26 167 ldd [%sp + CCFSZ + 120], %f28 168 ldd [%sp + CCFSZ + 128], %f30 169 1701: 171 mov %l2, %g2 172 mov %l3, %g3 173 mov %l4, %g4 174 mov %l5, %g5 175 mov %l6, %g6 176 mov %l7, %g7 177 178 restore %g0, SIGRETURN_NAME, %g1 ! get registers back & set syscall # 179 add %sp, 64 + 16, %o0 ! compute scp 180 t ST_SYSCALL ! sigreturn(scp) 181 mov EXIT_NAME, %g1 ! exit(errno) 182 t ST_SYSCALL 183ESIGCODE_NAME: 184