xref: /netbsd-src/lib/libc/arch/sh3/gen/sigsetjmp.S (revision d5e6e0f5aa59e3fa0532ded5e86a7be567df07ef)
1*d5e6e0f5Suwe/*	$NetBSD: sigsetjmp.S,v 1.11 2024/07/17 07:11:57 uwe Exp $	*/
295d875fbSmsaitoh
395d875fbSmsaitoh/*-
495d875fbSmsaitoh * Copyright (c) 1990 The Regents of the University of California.
595d875fbSmsaitoh * All rights reserved.
695d875fbSmsaitoh *
795d875fbSmsaitoh * This code is derived from software contributed to Berkeley by
895d875fbSmsaitoh * William Jolitz.
995d875fbSmsaitoh *
1095d875fbSmsaitoh * Redistribution and use in source and binary forms, with or without
1195d875fbSmsaitoh * modification, are permitted provided that the following conditions
1295d875fbSmsaitoh * are met:
1395d875fbSmsaitoh * 1. Redistributions of source code must retain the above copyright
1495d875fbSmsaitoh *    notice, this list of conditions and the following disclaimer.
1595d875fbSmsaitoh * 2. Redistributions in binary form must reproduce the above copyright
1695d875fbSmsaitoh *    notice, this list of conditions and the following disclaimer in the
1795d875fbSmsaitoh *    documentation and/or other materials provided with the distribution.
18eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
1995d875fbSmsaitoh *    may be used to endorse or promote products derived from this software
2095d875fbSmsaitoh *    without specific prior written permission.
2195d875fbSmsaitoh *
2295d875fbSmsaitoh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2395d875fbSmsaitoh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2495d875fbSmsaitoh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2595d875fbSmsaitoh * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2695d875fbSmsaitoh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2795d875fbSmsaitoh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2895d875fbSmsaitoh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2995d875fbSmsaitoh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3095d875fbSmsaitoh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3195d875fbSmsaitoh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3295d875fbSmsaitoh * SUCH DAMAGE.
3395d875fbSmsaitoh *
344890707aSuwe *	from: @(#)setjmp.s	5.1 (Berkeley) 4/23/90
3595d875fbSmsaitoh */
3695d875fbSmsaitoh
3795d875fbSmsaitoh#include <machine/asm.h>
380aa62ed4Suwe#include <machine/setjmp.h>
390aa62ed4Suwe
4095d875fbSmsaitoh#if defined(LIBC_SCCS)
41*d5e6e0f5Suwe	RCSID("$NetBSD: sigsetjmp.S,v 1.11 2024/07/17 07:11:57 uwe Exp $")
4295d875fbSmsaitoh#endif
4395d875fbSmsaitoh
444890707aSuweENTRY(__sigsetjmp14)
4595d875fbSmsaitoh	tst	r5, r5
460aa62ed4Suwe	bt	2f			/* if (savemask == 0) */
4795d875fbSmsaitoh
480aa62ed4Suwe	/* identical to longjmp except that _JB_HAS_MASK is in the argument */
490aa62ed4Suwe	PIC_PROLOGUE(.L_got_1)
500aa62ed4Suwe	sts.l	pr, @-sp
510aa62ed4Suwe	mov.l	r4, @-sp
520aa62ed4Suwe	mov.l	r5, @-sp
530aa62ed4Suwe
540aa62ed4Suwe	mov.l	.L___sigprocmask14_1, r0
554890707aSuwe	mov	r4, r6
56ea952cb8Sskrll	mov	#0, r4			/* how is ignored */
57ea952cb8Sskrll	mov	#0, r5			/* set = NULL */
580aa62ed4Suwe1:	CALL	r0
59ea952cb8Sskrll	 add	#(_JB_SIGMASK * 4), r6	/* oset = &sigmask */
604890707aSuwe
610aa62ed4Suwe	mov.l	@sp+, r5
620aa62ed4Suwe	mov.l	@sp+, r4
630aa62ed4Suwe	lds.l	@sp+, pr
640aa62ed4Suwe	PIC_EPILOGUE
654890707aSuwe
660aa62ed4Suwe2:	/* identical to _setjmp except that _JB_HAS_MASK is in the argument */
670aa62ed4Suwe	add	#((_JB_HAS_MASK + 1) * 4), r4
680aa62ed4Suwe	mov.l	r5, @-r4		/* has signal mask? */
6995d875fbSmsaitoh	mov.l	r15, @-r4
7095d875fbSmsaitoh	mov.l	r14, @-r4
7195d875fbSmsaitoh	mov.l	r13, @-r4
7295d875fbSmsaitoh	mov.l	r12, @-r4
7395d875fbSmsaitoh	mov.l	r11, @-r4
7495d875fbSmsaitoh	mov.l	r10, @-r4
7595d875fbSmsaitoh	mov.l	r9, @-r4
7695d875fbSmsaitoh	mov.l	r8, @-r4
7795d875fbSmsaitoh	sts.l	pr, @-r4
7895d875fbSmsaitoh	rts
7995d875fbSmsaitoh	 xor	r0, r0
8095d875fbSmsaitoh
810aa62ed4Suwe	.align	2
820aa62ed4Suwe.L_got_1:		PIC_GOT_DATUM
830aa62ed4Suwe.L___sigprocmask14_1:	CALL_DATUM(_C_LABEL(__sigprocmask14), 1b)
840aa62ed4Suwe	SET_ENTRY_SIZE(__sigsetjmp14)
850aa62ed4Suwe
860aa62ed4Suwe
874890707aSuweENTRY(__siglongjmp14)
88*d5e6e0f5Suwe	// return value can't be zero, adjust to 1 if it is
89*d5e6e0f5Suwe	tst	r5, r5
90*d5e6e0f5Suwe	bf/s	0f
91*d5e6e0f5Suwe	 mov.l	@(_JB_REG_PR * 4, r4), r0
92*d5e6e0f5Suwe	mov	#1, r5
93*d5e6e0f5Suwe0:
94*d5e6e0f5Suwe	// restore context first (callee-saved regs)
95*d5e6e0f5Suwe	mov.l	@(_JB_REG_R8  * 4, r4), r8
96*d5e6e0f5Suwe	mov.l	@(_JB_REG_R9  * 4, r4), r9
97*d5e6e0f5Suwe	mov.l	@(_JB_REG_R10 * 4, r4), r10
98*d5e6e0f5Suwe	mov.l	@(_JB_REG_R11 * 4, r4), r11
99*d5e6e0f5Suwe	mov.l	@(_JB_REG_R12 * 4, r4), r12
100*d5e6e0f5Suwe	mov.l	@(_JB_REG_R13 * 4, r4), r13
101*d5e6e0f5Suwe	mov.l	@(_JB_REG_R14 * 4, r4), r14
102*d5e6e0f5Suwe	mov.l	@(_JB_REG_R15 * 4, r4), r15
10395d875fbSmsaitoh
104*d5e6e0f5Suwe	// do we need to restore signal mask?
105*d5e6e0f5Suwe	mov.l	@(_JB_HAS_MASK * 4, r4), r7
106*d5e6e0f5Suwe	tst	r7, r7
107*d5e6e0f5Suwe	bf/s	0f
108*d5e6e0f5Suwe	 mov	#0, r6		// sigprocmask: oset = NULL
109*d5e6e0f5Suwe	// ... no, just the registers
110*d5e6e0f5Suwe	lds	r0, pr
11195d875fbSmsaitoh	rts
112*d5e6e0f5Suwe	 mov	r5, r0
113*d5e6e0f5Suwe0:
114*d5e6e0f5Suwe	// create a frame
115*d5e6e0f5Suwe	mov.l	r5, @-sp	// future return value (pre-adjusted)
116*d5e6e0f5Suwe	mov.l	r0, @-sp	// caller's PR from the jumpbuf
117*d5e6e0f5Suwe	PIC_PROLOGUE(.L_got_2)
118*d5e6e0f5Suwe
119*d5e6e0f5Suwe	// restore signal mask from &a[_JB_SIGMASK]
120*d5e6e0f5Suwe	mov	r4, r5
121*d5e6e0f5Suwe	mov.l	.L___sigprocmask14_2, r0
122*d5e6e0f5Suwe	add	#(_JB_SIGMASK * 4), r5	// set = &a[_JB_SIGMASK]
123*d5e6e0f5Suwe1:	CALL	r0
124*d5e6e0f5Suwe	 mov	#3, r4			// how = SIG_SETMASK
125*d5e6e0f5Suwe
126*d5e6e0f5Suwe	// return "from" setjmp
127*d5e6e0f5Suwe	PIC_EPILOGUE
128*d5e6e0f5Suwe	lds.l	@sp+, pr
129*d5e6e0f5Suwe	rts
130*d5e6e0f5Suwe	 mov.l	@sp+, r0
13195d875fbSmsaitoh
13295d875fbSmsaitoh	.align	2
1330aa62ed4Suwe.L_got_2:		PIC_GOT_DATUM
1340aa62ed4Suwe.L___sigprocmask14_2:	CALL_DATUM(_C_LABEL(__sigprocmask14), 1b)
1350aa62ed4Suwe	SET_ENTRY_SIZE(__siglongjmp14)
136