1 /* $NetBSD: compat___sigtramp1.S,v 1.2 2011/07/12 07:51:33 mrg 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>
61 #define BLOCK_SIZE SPARC64_BLOCK_SIZE
62 #define BLOCK_ALIGN SPARC64_BLOCK_ALIGN
65 * When this code is run, the stack looks like:
66 * [%sp] 128 bytes to which registers can be dumped
67 * [%sp + 128] signal number (goes in %o0)
68 * [%sp + 128 + 4] signal code (goes in %o1)
69 * [%sp + 128 + 8] first word of saved state (sigcontext)
73 * [%sp + NNN] last word of saved state
74 * (followed by previous stack contents or top of signal stack).
75 * The address of the function to call is in %g1; the old %g1 and %o0
76 * have already been saved in the sigcontext. We are running in a clean
77 * window, all previous windows now being saved to the stack.
79 * Note that [%sp + 128 + 8] == %sp + 128 + 16. The copy at %sp+128+8
80 * will eventually be removed, with a hole left in its place, if things
83 ENTRY_NOPROFILE(__sigtramp_sigcontext_1)
85 * XXX the `save' and `restore' below are unnecessary: should
86 * replace with simple arithmetic on %sp
88 * Make room on the stack for 64 %f registers + %fsr. This comes
89 * out to 64*4+8 or 264 bytes, but this must be aligned to a multiple
90 * of 64, or 320 bytes.
92 save %sp, -CC64FSZ - 320, %sp
93 mov %g2, %l2 /* save globals in %l registers */
100 * Saving the fpu registers is expensive, so do it iff it is
104 btst FPRS_DL|FPRS_DU, %l0 /* All clean? */
106 btst FPRS_DL, %l0 /* test dl */
108 btst FPRS_DU, %l0 /* test du */
110 /* fpu is enabled, oh well */
111 stx %fsr, [%sp + CC64FSZ + BIAS + 0]
112 add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */
113 andn %l0, BLOCK_ALIGN, %l0 /* we can do a block store */
114 stda %f0, [%l0] ASI_BLK_P
116 stda %f16, [%l0] ASI_BLK_P
119 add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */
120 andn %l0, BLOCK_ALIGN, %l0 /* we can do a block store */
121 add %l0, 2*BLOCK_SIZE, %l0 /* and skip what we already stored */
122 stda %f32, [%l0] ASI_BLK_P
124 stda %f48, [%l0] ASI_BLK_P
127 rd %y, %l1 /* in any case, save %y */
128 lduw [%fp + BIAS + 128], %o0 /* sig */
129 lduw [%fp + BIAS + 128 + 4], %o1 /* code */
130 call %g1 /* call handler */
131 add %fp, BIAS + 128 + 8, %o2 /* scp */
134 * Now that the handler has returned, re-establish all the state
135 * we just saved above, then do a sigreturn.
137 btst 3, %l0 /* All clean? */
139 btst 1, %l0 /* test dl */
141 btst 2, %l0 /* test du */
143 ldx [%sp + CC64FSZ + BIAS + 0], %fsr
144 add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */
145 andn %l0, BLOCK_ALIGN, %l0 /* we can do a block load */
146 ldda [%l0] ASI_BLK_P, %f0
148 ldda [%l0] ASI_BLK_P, %f16
151 wr %l1, %g0, %y /* in any case, restore %y */
152 add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */
153 andn %l0, BLOCK_ALIGN, %l0 /* we can do a block load */
154 inc 2*BLOCK_SIZE, %l0 /* and skip what we already loaded */
155 ldda [%l0] ASI_BLK_P, %f32
157 ldda [%l0] ASI_BLK_P, %f48
167 /* get registers back and set syscall # */
168 restore %g0, SYS_compat_16___sigreturn14, %g1
169 add %sp, BIAS + 128 + 8, %o0 /* compute scp */
170 t ST_SYSCALL /* call sigreturn */
171 mov SYS_exit, %g1 /* exit with errno */
172 t ST_SYSCALL /* if sigreturn fails */