sigsetjmp.S revision 1.10
1/* $OpenBSD: sigsetjmp.S,v 1.10 2005/08/07 16:40:14 espie Exp $ */
2/*-
3 * Copyright (c) 2002 Steve Murphree, Jr.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *      This product includes software developed by Steve Murphree, Jr.
17 * 4. The name of the author may not be used to endorse or promote products
18 *    derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include "SYS.h"
33
34/*
35 * C library -- sigsetjmp, siglongjmp
36 *
37 *	siglongjmp(a,v)
38 * will generate a "return(v)" from
39 * the last call to
40 *	sigsetjmp(a,m)
41 * by restoring registers from the stack,
42 * The previous signal state is restored if 'm' was non-zero.
43 *
44 * For m88k, we define our jmp_buf length
45 * to be the size of 21 longs.  <machine/setjmp.h>
46 * The buffer's usage is as follows:
47 *
48 * jmp_buf[0]		return address
49 * jmp_buf[1]		signal set (if used)
50 * jmp_buf[2 to 19]	r14 to r31
51 * jmp_buf[20]		setjmp type
52 *
53 */
54
55#include <machine/setjmp.h>
56
57#define	SIGSETJMP_SIG	0x582e
58
59/*
60int sigsetjmp(jmp_buf env, int savemask);
61 */
62ENTRY(sigsetjmp)
63	st	r1, r2,0	/* save registers to the environment buffer */
64	st	r14,r2,8
65	st	r15,r2,12
66	st	r16,r2,16
67	st	r17,r2,20
68	st	r18,r2,24
69	st	r19,r2,28
70	st	r20,r2,32
71	st	r21,r2,36
72	st	r22,r2,40
73	st	r23,r2,44
74	st	r24,r2,48
75	st	r25,r2,52
76	st	r26,r2,56
77	st	r27,r2,60
78	st	r28,r2,64
79	st	r29,r2,68
80	st	r30,r2,72
81	st	r31,r2,76
82	or	r4,r0,0		/* clear r4 */
83	or	r4,r0,SIGSETJMP_SIG	/* r4 now contains setjmp type */
84	st	r4,r2,80	/* setjmp type to _setjmp */
85
86	or	r15,r1,0	/* store return address in r15 */
87	or	r14,r2,0	/* store address of env in r14 */
88	or	r13,r3,0	/* store savemask in r13 */
89
90	cmp	r11,r13,r0	/* see if sigmask == 0 */
91	bb1.n	eq,r11,1f	/* skip sig stuff */
92	 st	r0,r14,4	/* but save 0 set in offset 4 of env first */
93
94	bsr.n	_C_LABEL(sigblock) /* r2 = sigblock(0) */
95	 or	r2,r0,r0
96	st	r2,r14,4	/* save signal set in offset 4 of env */
97
981:	or	r1,r15,0
99	ld	r15,r14,12
100	ld	r14,r14,8
101	jmp.n	r1		/* return 0 */
102	 or	r2,r0,0
103
104/*
105void siglongjmp(sigjmp_buf env, int val);
106 */
107ENTRY(siglongjmp)
108	cmp	r4,r2,r0	/* check for bad environment buffer address. */
109	bb1	eq,r4,3f	/* if == 0, abort. */
110	ld	r4,r2,80	/* check setjmp type. */
111	cmp	r4,r4,SIGSETJMP_SIG	/* should be SIGSETJMP_SIG */
112	bb1	ne,r4,3f	/* if != SIGSETJMP_SIG, abort. */
113
114	subu	r31,r31,16	/* get a temporary stack */
115	ld	r14,r2,8	/* restore registers from the environment buffer */
116	ld	r15,r2,12
117	ld	r16,r2,16
118	ld	r17,r2,20
119	ld	r18,r2,24
120	ld	r19,r2,28
121	ld	r20,r2,32
122	ld	r21,r2,36
123	ld	r22,r2,40
124	ld	r23,r2,44
125	ld	r24,r2,48
126	ld	r25,r2,52
127	ld	r26,r2,56
128	ld	r27,r2,60
129	ld	r28,r2,64
130	ld	r29,r2,68
131
132	ld	r4,r2,4		/* get the signal set from env */
133	cmp	r4,r4,r0	/* if r2 == 0 then skip signal stuff */
134	bb1	eq,r4,1f
135
136	st.d	r2,r31,0	/* save r2 and r3 on stack (env + return val) */
137	bsr.n	_C_LABEL(sigsetmask) /* restore the signal set */
138	 ld	r2,r2,4
139	ld.d	r2,r31,0	/* restore r2 and r3 from stack */
1401:	ld	r30,r2,72	/* restore r30 */
141	ld	r31,r2,76	/* restore r31 (sp)*/
142	ld	r1,r2,0		/* restore r1 */
143	bcnd.n	ne0,r3,3f
144	 or	r2,r3,r0
145	or	r2,r0,1		/* never return zero! */
1463:	jmp	r1
147
1482:	subu	r31,r31,16	/* get a temporary stack */
149	st	r1,r31,0	/* save r1 on stack (return address) */
150	bsr	_C_LABEL(longjmperror)
151	bsr	_C_LABEL(abort)	/* NO RETURN */
152	ld	r1,r31,0	/* restore r1 from stack */
153	jmp.n	r1	/* this should not happen but we are prepared */
154	 addu	r31,r31,16	/* restore the stack */
155