1/* $OpenBSD: sigsetjmp.S,v 1.17 2016/09/22 18:23:58 guenther 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 the last call to
39 *	sigsetjmp(a,savemask)
40 * by restoring registers from the stack, as well as the signal mask if the
41 * `savemask' parameter was non-zero.
42 *
43 * For m88k, we define our sigjmp_buf length to be the size of 22 (_JBLEN + 1)
44 * longs.  The buffer layout is as follows:
45 *
46 * sigjmp_buf[0]		return address
47 * sigjmp_buf[1]		signal set (if used)
48 * sigjmp_buf[2 to 19]		r14 to r31
49 * sigjmp_buf[20]		setjmp type
50 * sigjmp_buf[21]		value of `savemask' parameter
51 */
52
53#define	SIGSETJMP_SIG	0x582e
54
55/*
56int sigsetjmp(sigjmp_buf env, int savemask);
57 */
58ENTRY(sigsetjmp)
59	st	%r1, %r2,0	/* save registers to the environment buffer */
60	st	%r14,%r2,8
61	st	%r15,%r2,12
62	st	%r16,%r2,16
63	st	%r17,%r2,20
64	st	%r18,%r2,24
65	st	%r19,%r2,28
66	st	%r20,%r2,32
67	st	%r21,%r2,36
68	st	%r22,%r2,40
69	st	%r23,%r2,44
70	st	%r24,%r2,48
71	st	%r25,%r2,52
72	st	%r26,%r2,56
73	st	%r27,%r2,60
74	st	%r28,%r2,64
75	st	%r29,%r2,68
76	st	%r30,%r2,72
77	st	%r31,%r2,76
78	or	%r4,%r0,SIGSETJMP_SIG	/* r4 now contains setjmp type */
79	st	%r4,%r2,80	/* setjmp type to _setjmp */
80	bcnd.n	eq0,%r3,1f	/* skip signal stuff if savemask == 0 */
81	 st	%r3,%r2,84	/* save `savemask' value */
82
83	or	%r4,%r2,0	/* save r2 in r4 */
84	or	%r3,%r0,0	/* set = empty */
85	or	%r2,%r0,1	/* how = SIG_BLOCK */
86	__DO_SYSCALL(sigprocmask)
87	or	%r0,%r0,%r0	/* NOP to fill error case of syscall */
88	st	%r2,%r4,4	/* save signal set in offset 4 of env */
89	ld	%r1,%r4,0
901:
91	jmp.n	%r1		/* return 0 */
92	 or	%r2,%r0,0
93END(sigsetjmp)
94
95/*
96void siglongjmp(sigjmp_buf env, int val);
97 */
98ENTRY(siglongjmp)
99	bcnd	eq0,%r2,2f	/* check for bad environment buffer address. */
100	ld	%r4,%r2,80	/* check setjmp type. */
101	cmp	%r4,%r4,SIGSETJMP_SIG	/* should be SIGSETJMP_SIG */
102	bb1	ne,%r4,2f	/* if != SIGSETJMP_SIG, abort. */
103
104	ld	%r14,%r2,8	/* restore registers from the environment buffer */
105	ld	%r15,%r2,12
106	ld	%r16,%r2,16
107	ld	%r17,%r2,20
108	ld	%r18,%r2,24
109	ld	%r19,%r2,28
110	ld	%r20,%r2,32
111	ld	%r21,%r2,36
112	ld	%r22,%r2,40
113	ld	%r23,%r2,44
114	ld	%r24,%r2,48
115	ld	%r25,%r2,52
116	ld	%r26,%r2,56
117	ld	%r27,%r2,60
118	ld	%r28,%r2,64
119	ld	%r29,%r2,68
120	ld	%r30,%r2,72
121	ld	%r4,%r2,84	/* get `savemask' value */
122	bcnd.n	eq0,%r4,1f
123	 ld	%r31,%r2,76
124
125	or	%r4,%r2,0	/* save r2 in r4 */
126	or	%r5,%r3,0	/* and r3 in r5 */
127	ld	%r3,%r2,4	/* load the saved mask into r3 */
128	or	%r2,%r0,3	/* how = SIG_SETMASK */
129	__DO_SYSCALL(sigprocmask)
130	or	%r0,%r0,%r0	/* NOP to fill error case of syscall */
131	or	%r2,%r4,0	/* restore r2 */
132	or	%r3,%r5,0	/* restore r3 */
133
1341:
135	bcnd.n	ne0,%r3,1f
136	 ld	%r1,%r2,0		/* restore r1 */
137	or	%r3,%r0,1		/* never return zero! */
1381:
139	jmp.n	%r1
140	 or	%r2,%r3,%r0
141
1422:	br	_HIDDEN(abort)	/* NO RETURN */
143END(siglongjmp)
144