1 /* $NetBSD: __sigtramp1.S,v 1.5 2004/03/26 19:36:40 drochner Exp $ */
4 * Copyright (c) 1996-2002 Eduardo Horvath
5 * Copyright (c) 1996 Paul Kranenburg
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.
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.
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.
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
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.
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
53 #include <machine/frame.h>
54 #include <machine/fsr.h>
55 #include <machine/ctlreg.h>
56 #include <machine/psl.h>
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)
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.
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
80 ENTRY_NOPROFILE(__sigtramp_sigcontext_1)
82 * XXX the `save' and `restore' below are unnecessary: should
83 * replace with simple arithmetic on %sp
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.
89 save %sp, -CC64FSZ - 320, %sp
90 mov %g2, %l2 /* save globals in %l registers */
97 * Saving the fpu registers is expensive, so do it iff it is
101 btst FPRS_DL|FPRS_DU, %l0 /* All clean? */
103 btst FPRS_DL, %l0 /* test dl */
105 btst FPRS_DU, %l0 /* test du */
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
113 stda %f16, [%l0] ASI_BLK_P
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
121 stda %f48, [%l0] ASI_BLK_P
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 */
131 * Now that the handler has returned, re-establish all the state
132 * we just saved above, then do a sigreturn.
134 btst 3, %l0 /* All clean? */
136 btst 1, %l0 /* test dl */
138 btst 2, %l0 /* test du */
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
145 ldda [%l0] ASI_BLK_P, %f16
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
154 ldda [%l0] ASI_BLK_P, %f48
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 */