xref: /netbsd-src/lib/libc/arch/hppa/gen/_setjmp.S (revision 221640878dc41ccb5a8b02a44c8bfe871b5c9adf)
1*22164087Sskrll/*	$NetBSD: _setjmp.S,v 1.7 2024/05/04 14:48:28 skrll Exp $	*/
202ac1ae2Sfredette
302ac1ae2Sfredette/*-
402ac1ae2Sfredette * Copyright (c) 2002 The NetBSD Foundation, Inc.
502ac1ae2Sfredette * All rights reserved.
602ac1ae2Sfredette *
702ac1ae2Sfredette * This code is derived from software contributed to The NetBSD Foundation
802ac1ae2Sfredette * by Matthew Fredette.
902ac1ae2Sfredette *
1002ac1ae2Sfredette * Redistribution and use in source and binary forms, with or without
1102ac1ae2Sfredette * modification, are permitted provided that the following conditions
1202ac1ae2Sfredette * are met:
1302ac1ae2Sfredette * 1. Redistributions of source code must retain the above copyright
1402ac1ae2Sfredette *    notice, this list of conditions and the following disclaimer.
1502ac1ae2Sfredette * 2. Redistributions in binary form must reproduce the above copyright
1602ac1ae2Sfredette *    notice, this list of conditions and the following disclaimer in the
1702ac1ae2Sfredette *    documentation and/or other materials provided with the distribution.
1802ac1ae2Sfredette *
1902ac1ae2Sfredette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2002ac1ae2Sfredette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2102ac1ae2Sfredette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2202ac1ae2Sfredette * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2302ac1ae2Sfredette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2402ac1ae2Sfredette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2502ac1ae2Sfredette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2602ac1ae2Sfredette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2702ac1ae2Sfredette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2802ac1ae2Sfredette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2902ac1ae2Sfredette * POSSIBILITY OF SUCH DAMAGE.
3002ac1ae2Sfredette */
3102ac1ae2Sfredette
32*22164087Sskrll#include "assym.h"
33*22164087Sskrll
3402ac1ae2Sfredette#include <machine/asm.h>
3502ac1ae2Sfredette#include <machine/frame.h>
3602ac1ae2Sfredette
3702ac1ae2Sfredette#if defined(LIBC_SCCS) && !defined(lint)
38*22164087Sskrll	RCSID("$NetBSD: _setjmp.S,v 1.7 2024/05/04 14:48:28 skrll Exp $")
3902ac1ae2Sfredette#endif /* LIBC_SCCS and not lint */
4002ac1ae2Sfredette
4102ac1ae2Sfredette/*
4202ac1ae2Sfredette * C library -- setjmp, longjmp
4302ac1ae2Sfredette *
4402ac1ae2Sfredette *	longjmp(a,v)
4502ac1ae2Sfredette * will generate a "return(v)" from
4602ac1ae2Sfredette * the last call to
4702ac1ae2Sfredette *	setjmp(a)
4802ac1ae2Sfredette * by restoring registers from the stack,
4902ac1ae2Sfredette * and a struct sigcontext, see <signal.h>
5002ac1ae2Sfredette */
5102ac1ae2Sfredette
5202ac1ae2SfredetteENTRY(_setjmp,0)
5302ac1ae2Sfredette	/* A sigcontext is at the beginning of our jmp_buf. */
54*22164087Sskrll	stw	%r0, _SC_ONSTACK(%arg0)		; no onstack
55*22164087Sskrll	stw	%r0, _SC_MASK13(%arg0)		; unused word (old style signal mask)
56*22164087Sskrll	stw	%sp, _SC_REGS_SP(%arg0)		; sc.sc_sp = %sp
57*22164087Sskrll	stw	%r0, _SC_REGS_AP(%arg0)		; sc.sc_ap = NULL
5802ac1ae2Sfredette	mfsp	%sr0, %r1
59*22164087Sskrll	stw	%r1, _SC_REGS_PCSQH(%arg0)	; sc.sc_pcsqh = %sr0
60*22164087Sskrll	stw	%rp, _SC_REGS_PCOQH(%arg0)	; sc.sc_pcoqh = %rp
61*22164087Sskrll	stw	%r1, _SC_REGS_PCSQT(%arg0)	; sc.sc_pcsqh = %sr0
6202ac1ae2Sfredette	ldo	4(%rp), %r1
63*22164087Sskrll	stw	%r1, _SC_REGS_PCOQT(%arg0)	; sc.sc_pcoqt = %rp + 4
64*22164087Sskrll	stw	%r0, _SC_REGS_PS(%arg0)		; set sc.sc_ps
6502ac1ae2Sfredette
6602ac1ae2Sfredette	/* We store all callee-saved registers after the sigcontext. */
67*22164087Sskrll	ldo	SIZEOF_SIGCONTEXT(%arg0), %r1
6802ac1ae2Sfredette	stwm	%r3, 4(%r1)
6902ac1ae2Sfredette	stwm	%r4, 4(%r1)
7002ac1ae2Sfredette	stwm	%r5, 4(%r1)
7102ac1ae2Sfredette	stwm	%r6, 4(%r1)
7202ac1ae2Sfredette	stwm	%r7, 4(%r1)
7302ac1ae2Sfredette	stwm	%r8, 4(%r1)
7402ac1ae2Sfredette	stwm	%r9, 4(%r1)
7502ac1ae2Sfredette	stwm	%r10, 4(%r1)
7602ac1ae2Sfredette	stwm	%r11, 4(%r1)
7702ac1ae2Sfredette	stwm	%r12, 4(%r1)
7802ac1ae2Sfredette	stwm	%r13, 4(%r1)
7902ac1ae2Sfredette	stwm	%r14, 4(%r1)
8002ac1ae2Sfredette	stwm	%r15, 4(%r1)
8102ac1ae2Sfredette	stwm	%r16, 4(%r1)
8202ac1ae2Sfredette	stwm	%r17, 4(%r1)
8302ac1ae2Sfredette	stwm	%r18, 4(%r1)
8402ac1ae2Sfredette
8502ac1ae2Sfredette	/* Return 0. */
8602ac1ae2Sfredette	bv	%r0(%rp)
8702ac1ae2Sfredette	 copy	%r0, %ret0
8802ac1ae2SfredetteEXIT(_setjmp)
8902ac1ae2Sfredette
9002ac1ae2SfredetteENTRY(_longjmp,0)
91*22164087Sskrll	ldw	_SC_REGS_SP(%arg0), %r1	; ensure non-zero SP
9202ac1ae2Sfredette	combt,=,n	%r0, %r1, botch	; oops!
9302ac1ae2Sfredette	add,<>	%r0, %arg1, %ret0	; ensure return value non-zero
9402ac1ae2Sfredette	ldi	1, %ret0
9502ac1ae2Sfredette
9602ac1ae2Sfredette	/* restore callee-saved registers */
97*22164087Sskrll	ldo	SIZEOF_SIGCONTEXT(%arg0), %r1
9802ac1ae2Sfredette	ldwm	4(%r1), %r3
9902ac1ae2Sfredette	ldwm	4(%r1), %r4
10002ac1ae2Sfredette	ldwm	4(%r1), %r5
10102ac1ae2Sfredette	ldwm	4(%r1), %r6
10202ac1ae2Sfredette	ldwm	4(%r1), %r7
10302ac1ae2Sfredette	ldwm	4(%r1), %r8
10402ac1ae2Sfredette	ldwm	4(%r1), %r9
10502ac1ae2Sfredette	ldwm	4(%r1), %r10
10602ac1ae2Sfredette	ldwm	4(%r1), %r11
10702ac1ae2Sfredette	ldwm	4(%r1), %r12
10802ac1ae2Sfredette	ldwm	4(%r1), %r13
10902ac1ae2Sfredette	ldwm	4(%r1), %r14
11002ac1ae2Sfredette	ldwm	4(%r1), %r15
11102ac1ae2Sfredette	ldwm	4(%r1), %r16
11202ac1ae2Sfredette	ldwm	4(%r1), %r17
11302ac1ae2Sfredette	ldwm	4(%r1), %r18
11402ac1ae2Sfredette
11502ac1ae2Sfredette	/* restore the rest */
116*22164087Sskrll	ldw	_SC_REGS_SP(%arg0), %sp
117*22164087Sskrll	ldw	_SC_REGS_PCOQH(%arg0), %rp
11802ac1ae2Sfredette	bv	%r0(%rp)
11902ac1ae2Sfredette	 nop
120ed9d4336Smattbotch:
12102ac1ae2Sfredette	bl	longjmperror, %rp
12202ac1ae2Sfredette	 nop
12332c9e25bSchs	bl	abort, %rp
12432c9e25bSchs	 nop
12502ac1ae2SfredetteEXIT(_longjmp)
12602ac1ae2Sfredette
12702ac1ae2Sfredette	.end
128