1/*	$OpenBSD: setjmp.S,v 1.4 2022/12/08 02:11:27 guenther Exp $	*/
2/*	$NetBSD: setjmp.S,v 1.10 2006/01/05 19:21:37 uwe Exp $	*/
3
4/*-
5 * Copyright (c) 1990 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * William Jolitz.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 *    may be used to endorse or promote products derived from this software
21 *    without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 *	from: @(#)setjmp.s	5.1 (Berkeley) 4/23/90
36 */
37
38#include "SYS.h"
39
40#include <machine/setjmp.h>
41
42/*
43 * C library -- setjmp, longjmp
44 *
45 *	longjmp(a,v)
46 * will generate a "return(v)" from the last call to
47 *	setjmp(a)
48 * by restoring registers from the stack.
49 * The previous signal state is restored.
50 */
51
52ENTRY(setjmp)
53	PIC_PROLOGUE(.L_got_1)
54	sts.l	pr,	@-sp
55	mov.l	r4,	@-sp
56
57	mov.l	.L_sigprocmask_1, r0
58	mov	r4,	r6
59	mov	#1,	r4		/* how = SIG_BLOCK */
60	mov	#0,	r5		/* new = NULL */
611:	CALL	r0
62	 add	#4,	r6		/* old = &sigmask */
63
64	mov.l	@sp+,	r4
65	lds.l	@sp+,	pr
66	PIC_EPILOGUE
67
68	/* identical to _setjmp except that the first word is non-zero */
69#if defined(__SH4__) && !defined(__SH4_NOFPU__)
70	add	#(_JBLEN * 4), r4
71	sts	fpscr,	r1
72	xor	r0,	r0
73	mov.l	r1,	@-r4
74	lds	r0,	fpscr
75	sts.l	fpul,	@-r4
76	fmov.s	fr15,	@-r4
77	fmov.s	fr14,	@-r4
78	fmov.s	fr13,	@-r4
79	fmov.s	fr12,	@-r4
80	frchg
81	fmov.s	fr15,	@-r4
82	fmov.s	fr14,	@-r4
83	fmov.s	fr13,	@-r4
84	fmov.s	fr12,	@-r4
85	lds	r1,	fpscr
86#else
87	add	#((_JBLEN - 10) * 4), r4
88#endif
89	sts.l	mach,	@-r4
90	sts.l	macl,	@-r4
91	mov.l	r15,	@-r4
92	mov.l	r14,	@-r4
93	mov.l	r13,	@-r4
94	mov.l	r12,	@-r4
95	mov.l	r11,	@-r4
96	mov.l	r10,	@-r4
97	mov.l	r9,	@-r4
98	mov.l	r8,	@-r4
99	sts.l	pr,	@-r4
100	add	#-4,	r4		/* skip signal mask */
101	mov	#1,	r0
102	mov.l	r0,	@-r4		/* has signal mask */
103	rts
104	 xor	r0,	r0
105
106	.align	2
107.L_got_1:		PIC_GOT_DATUM
108.L_sigprocmask_1:	CALL_DATUM(_HIDDEN(sigprocmask), 1b)
109	SET_ENTRY_SIZE(setjmp)
110
111ENTRY(longjmp)
112	/* we won't return here, so we don't need to save pr and r12 */
113	PIC_PROLOGUE_NOSAVE(.L_got_2)
114	mov.l	r5,	@-sp
115	mov.l	r4,	@-sp
116
117	mov.l	.L_sigprocmask_2, r0
118	mov	r4,	r5
119	mov	#3,	r4		/* how = SIG_SETMASK */
120	add	#4,	r5		/* new = &sigmask */
1211:	CALL	r0
122	 mov	#0,	r6		/* old = NULL */
123
124	mov.l	@sp+,	r4
125	mov.l	@sp+,	r5
126
127	/* identical to _longjmp */
128	add	#8,	r4
129	lds.l	@r4+,	pr
130	mov.l	@r4+,	r8
131	mov.l	@r4+,	r9
132	mov.l	@r4+,	r10
133	mov.l	@r4+,	r11
134	mov.l	@r4+,	r12
135	mov.l	@r4+,	r13
136	mov.l	@r4+,	r14
137	mov.l	@r4+,	r15
138	lds.l	@r4+,	macl
139	lds.l	@r4+,	mach
140#if defined(__SH4__) && !defined(__SH4_NOFPU__)
141	xor	r0, 	r0
142	lds	r0,	fpscr
143	frchg
144	fmov.s	@r4+,	fr12
145	fmov.s	@r4+,	fr13
146	fmov.s	@r4+,	fr14
147	fmov.s	@r4+,	fr15
148	frchg
149	fmov.s	@r4+,	fr12
150	fmov.s	@r4+,	fr13
151	fmov.s	@r4+,	fr14
152	fmov.s	@r4+,	fr15
153	lds.l	@r4+,	fpul
154	lds.l	@r4+,	fpscr
155#endif
156
157	mov	r5,	r0
158	tst	r0,	r0	/* make sure return value is non-zero */
159	bf	.L0
160	add	#1,	r0
161.L0:
162	rts
163	 nop
164
165	.align	2
166.L_got_2:		PIC_GOT_DATUM
167.L_sigprocmask_2:	CALL_DATUM(_HIDDEN(sigprocmask), 1b)
168	SET_ENTRY_SIZE(longjmp)
169