compat___sigtramp1.S revision 1.2 1 1.2 mrg /* $NetBSD: compat___sigtramp1.S,v 1.2 2011/07/12 07:51:33 mrg Exp $ */
2 1.1 christos
3 1.1 christos /*
4 1.1 christos * Copyright (c) 1996-2002 Eduardo Horvath
5 1.1 christos * Copyright (c) 1996 Paul Kranenburg
6 1.1 christos * Copyright (c) 1996
7 1.1 christos * The President and Fellows of Harvard College. All rights reserved.
8 1.1 christos * Copyright (c) 1992, 1993
9 1.1 christos * The Regents of the University of California. All rights reserved.
10 1.1 christos *
11 1.1 christos * This software was developed by the Computer Systems Engineering group
12 1.1 christos * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
13 1.1 christos * contributed to Berkeley.
14 1.1 christos *
15 1.1 christos * All advertising materials mentioning features or use of this software
16 1.1 christos * must display the following acknowledgement:
17 1.1 christos * This product includes software developed by the University of
18 1.1 christos * California, Lawrence Berkeley Laboratory.
19 1.1 christos * This product includes software developed by Harvard University.
20 1.1 christos *
21 1.1 christos * Redistribution and use in source and binary forms, with or without
22 1.1 christos * modification, are permitted provided that the following conditions
23 1.1 christos * are met:
24 1.1 christos * 1. Redistributions of source code must retain the above copyright
25 1.1 christos * notice, this list of conditions and the following disclaimer.
26 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
27 1.1 christos * notice, this list of conditions and the following disclaimer in the
28 1.1 christos * documentation and/or other materials provided with the distribution.
29 1.1 christos * 3. All advertising materials mentioning features or use of this software
30 1.1 christos * must display the following acknowledgement:
31 1.1 christos * This product includes software developed by Harvard University.
32 1.1 christos * This product includes software developed by Paul Kranenburg.
33 1.1 christos * 4. Neither the name of the University nor the names of its contributors
34 1.1 christos * may be used to endorse or promote products derived from this software
35 1.1 christos * without specific prior written permission.
36 1.1 christos *
37 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
38 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
41 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
43 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
45 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 1.1 christos * SUCH DAMAGE.
48 1.1 christos */
49 1.1 christos
50 1.1 christos #include "SYS.h"
51 1.1 christos
52 1.1 christos #define _LOCORE
53 1.1 christos #include <machine/frame.h>
54 1.1 christos #include <machine/fsr.h>
55 1.1 christos #include <machine/ctlreg.h>
56 1.1 christos #include <machine/psl.h>
57 1.1 christos
58 1.1 christos .register %g2,#ignore
59 1.1 christos .register %g3,#ignore
60 1.1 christos
61 1.2 mrg #define BLOCK_SIZE SPARC64_BLOCK_SIZE
62 1.2 mrg #define BLOCK_ALIGN SPARC64_BLOCK_ALIGN
63 1.2 mrg
64 1.1 christos /*
65 1.1 christos * When this code is run, the stack looks like:
66 1.1 christos * [%sp] 128 bytes to which registers can be dumped
67 1.1 christos * [%sp + 128] signal number (goes in %o0)
68 1.1 christos * [%sp + 128 + 4] signal code (goes in %o1)
69 1.1 christos * [%sp + 128 + 8] first word of saved state (sigcontext)
70 1.1 christos * .
71 1.1 christos * .
72 1.1 christos * .
73 1.1 christos * [%sp + NNN] last word of saved state
74 1.1 christos * (followed by previous stack contents or top of signal stack).
75 1.1 christos * The address of the function to call is in %g1; the old %g1 and %o0
76 1.1 christos * have already been saved in the sigcontext. We are running in a clean
77 1.1 christos * window, all previous windows now being saved to the stack.
78 1.1 christos *
79 1.1 christos * Note that [%sp + 128 + 8] == %sp + 128 + 16. The copy at %sp+128+8
80 1.1 christos * will eventually be removed, with a hole left in its place, if things
81 1.1 christos * work out.
82 1.1 christos */
83 1.1 christos ENTRY_NOPROFILE(__sigtramp_sigcontext_1)
84 1.1 christos /*
85 1.1 christos * XXX the `save' and `restore' below are unnecessary: should
86 1.1 christos * replace with simple arithmetic on %sp
87 1.1 christos *
88 1.1 christos * Make room on the stack for 64 %f registers + %fsr. This comes
89 1.1 christos * out to 64*4+8 or 264 bytes, but this must be aligned to a multiple
90 1.1 christos * of 64, or 320 bytes.
91 1.1 christos */
92 1.1 christos save %sp, -CC64FSZ - 320, %sp
93 1.1 christos mov %g2, %l2 /* save globals in %l registers */
94 1.1 christos mov %g3, %l3
95 1.1 christos mov %g4, %l4
96 1.1 christos mov %g5, %l5
97 1.1 christos mov %g6, %l6
98 1.1 christos mov %g7, %l7
99 1.1 christos /*
100 1.1 christos * Saving the fpu registers is expensive, so do it iff it is
101 1.1 christos * enabled and dirty.
102 1.1 christos */
103 1.1 christos rd %fprs, %l0
104 1.1 christos btst FPRS_DL|FPRS_DU, %l0 /* All clean? */
105 1.1 christos bz,pt %icc, 2f
106 1.1 christos btst FPRS_DL, %l0 /* test dl */
107 1.1 christos bz,pt %icc, 1f
108 1.1 christos btst FPRS_DU, %l0 /* test du */
109 1.1 christos
110 1.1 christos /* fpu is enabled, oh well */
111 1.1 christos stx %fsr, [%sp + CC64FSZ + BIAS + 0]
112 1.1 christos add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */
113 1.1 christos andn %l0, BLOCK_ALIGN, %l0 /* we can do a block store */
114 1.1 christos stda %f0, [%l0] ASI_BLK_P
115 1.1 christos inc BLOCK_SIZE, %l0
116 1.1 christos stda %f16, [%l0] ASI_BLK_P
117 1.1 christos 1:
118 1.1 christos bz,pt %icc, 2f
119 1.1 christos add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */
120 1.1 christos andn %l0, BLOCK_ALIGN, %l0 /* we can do a block store */
121 1.1 christos add %l0, 2*BLOCK_SIZE, %l0 /* and skip what we already stored */
122 1.1 christos stda %f32, [%l0] ASI_BLK_P
123 1.1 christos inc BLOCK_SIZE, %l0
124 1.1 christos stda %f48, [%l0] ASI_BLK_P
125 1.1 christos 2:
126 1.1 christos membar #Sync
127 1.1 christos rd %y, %l1 /* in any case, save %y */
128 1.1 christos lduw [%fp + BIAS + 128], %o0 /* sig */
129 1.1 christos lduw [%fp + BIAS + 128 + 4], %o1 /* code */
130 1.1 christos call %g1 /* call handler */
131 1.1 christos add %fp, BIAS + 128 + 8, %o2 /* scp */
132 1.1 christos
133 1.1 christos /*
134 1.1 christos * Now that the handler has returned, re-establish all the state
135 1.1 christos * we just saved above, then do a sigreturn.
136 1.1 christos */
137 1.1 christos btst 3, %l0 /* All clean? */
138 1.1 christos bz,pt %icc, 2f
139 1.1 christos btst 1, %l0 /* test dl */
140 1.1 christos bz,pt %icc, 1f
141 1.1 christos btst 2, %l0 /* test du */
142 1.1 christos
143 1.1 christos ldx [%sp + CC64FSZ + BIAS + 0], %fsr
144 1.1 christos add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */
145 1.1 christos andn %l0, BLOCK_ALIGN, %l0 /* we can do a block load */
146 1.1 christos ldda [%l0] ASI_BLK_P, %f0
147 1.1 christos inc BLOCK_SIZE, %l0
148 1.1 christos ldda [%l0] ASI_BLK_P, %f16
149 1.1 christos 1:
150 1.1 christos bz,pt %icc, 2f
151 1.1 christos wr %l1, %g0, %y /* in any case, restore %y */
152 1.1 christos add %sp, BIAS+CC64FSZ+BLOCK_SIZE, %l0 /* Generate a pointer so */
153 1.1 christos andn %l0, BLOCK_ALIGN, %l0 /* we can do a block load */
154 1.1 christos inc 2*BLOCK_SIZE, %l0 /* and skip what we already loaded */
155 1.1 christos ldda [%l0] ASI_BLK_P, %f32
156 1.1 christos inc BLOCK_SIZE, %l0
157 1.1 christos ldda [%l0] ASI_BLK_P, %f48
158 1.1 christos 2:
159 1.1 christos mov %l2, %g2
160 1.1 christos mov %l3, %g3
161 1.1 christos mov %l4, %g4
162 1.1 christos mov %l5, %g5
163 1.1 christos mov %l6, %g6
164 1.1 christos mov %l7, %g7
165 1.1 christos membar #Sync
166 1.1 christos
167 1.1 christos /* get registers back and set syscall # */
168 1.1 christos restore %g0, SYS_compat_16___sigreturn14, %g1
169 1.1 christos add %sp, BIAS + 128 + 8, %o0 /* compute scp */
170 1.1 christos t ST_SYSCALL /* call sigreturn */
171 1.1 christos mov SYS_exit, %g1 /* exit with errno */
172 1.1 christos t ST_SYSCALL /* if sigreturn fails */
173