11.15Smatt/*	$NetBSD: setjmp.S,v 1.15 2013/07/17 03:05:41 matt Exp $	*/
21.5Sthorpej
31.1Spaulus/*-
41.1Spaulus * Copyright (c) 1990 The Regents of the University of California.
51.1Spaulus * All rights reserved.
61.1Spaulus *
71.1Spaulus * This code is derived from software contributed to Berkeley by
81.1Spaulus * the Systems Programming Group of the University of Utah Computer
91.1Spaulus * Science Department.
101.1Spaulus *
111.1Spaulus * Redistribution and use in source and binary forms, with or without
121.1Spaulus * modification, are permitted provided that the following conditions
131.1Spaulus * are met:
141.1Spaulus * 1. Redistributions of source code must retain the above copyright
151.1Spaulus *    notice, this list of conditions and the following disclaimer.
161.1Spaulus * 2. Redistributions in binary form must reproduce the above copyright
171.1Spaulus *    notice, this list of conditions and the following disclaimer in the
181.1Spaulus *    documentation and/or other materials provided with the distribution.
191.11Sagc * 3. Neither the name of the University nor the names of its contributors
201.1Spaulus *    may be used to endorse or promote products derived from this software
211.1Spaulus *    without specific prior written permission.
221.1Spaulus *
231.1Spaulus * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
241.1Spaulus * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
251.1Spaulus * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
261.1Spaulus * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
271.1Spaulus * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
281.1Spaulus * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
291.1Spaulus * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
301.1Spaulus * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
311.1Spaulus * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
321.1Spaulus * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
331.1Spaulus * SUCH DAMAGE.
341.1Spaulus */
351.1Spaulus
361.6Sthorpej#include <machine/asm.h>
371.15Smatt#include "assym.h"
381.5Sthorpej
391.1Spaulus#if defined(LIBC_SCCS) && !defined(lint)
401.5Sthorpej#if 0
411.5Sthorpej	RCSID("from: @(#)setjmp.s	5.1 (Berkeley) 5/12/90")
421.5Sthorpej#else
431.15Smatt	RCSID("$NetBSD: setjmp.S,v 1.15 2013/07/17 03:05:41 matt Exp $")
441.5Sthorpej#endif
451.1Spaulus#endif /* LIBC_SCCS and not lint */
461.1Spaulus
471.1Spaulus/*
481.1Spaulus * C library -- setjmp, longjmp
491.1Spaulus *
501.1Spaulus *	longjmp(a,v)
511.1Spaulus * will generate a "return(v)" from
521.1Spaulus * the last call to
531.1Spaulus *	setjmp(a)
541.1Spaulus * by restoring registers from the stack,
551.1Spaulus * and a struct sigcontext, see <signal.h>
561.1Spaulus */
571.1Spaulus
581.12SchristosENTRY(__setjmp14)
591.12Schristos	/* Get signal stack info.  Note overlay of ss_sp and ss_size! */
601.13Smatt	lea	-12(%sp),%sp	/* sizeof(stack_t) */
611.13Smatt	clrl	(%sp)		/* ss = NULL */
621.13Smatt	movl	%sp,4(%sp)	/* oss = stack_t on stack */
631.9Sitohy	jbsr	PIC_PLT(_C_LABEL(__sigaltstack14))
641.12Schristos
651.13Smatt	movl	8(%sp),%d0	/* ss_flags */
661.12Schristos	andl	#1,%d0		/* extract SS_ONSTACK */
671.13Smatt	lea	12(%sp),%sp	/* pop stack_t */
681.12Schristos
691.12Schristos	/* Get pointer to jmp_buf; a sigcontext is at the beginning. */
701.13Smatt	movl	4(%sp),%a0
711.15Smatt	movl	%d0,SC_ONSTACK(%a0) /* store onstack */
721.15Smatt	clrl	SC___MASK13(%a0) /* unused word (old style signal mask) */
731.12Schristos
741.12Schristos	/* Get the signal mask. */
751.15Smatt	pea	SC_MASK(%a0)	/* oset = &sc.sc_mask */
761.13Smatt	movl	#0,-(%sp)	/* set = NULL */
771.13Smatt	movl	#0,-(%sp)	/* action = 0 <ignored> */
781.12Schristos	jbsr	PIC_PLT(_C_LABEL(__sigprocmask14))
791.12Schristos	addl	#12,%sp
801.12Schristos
811.13Smatt	movl	4(%sp),%a0	/* get jmp_buf pointer again */
821.13Smatt	lea	4(%sp),%a1	/* adjust SP since we won't rts */
831.15Smatt	movl	%a1,SC_SP(%a0)	/* save SP */
841.15Smatt	movl	%a6,SC_FP(%a0)	/* save FP */
851.15Smatt	clrl	SC_AP(%a0)	/* no AP */
861.15Smatt	movl	(%sp),SC_PC(%a0)/* save return PC */
871.15Smatt	clrl	SC_PS(%a0)	/* clear PS */
881.12Schristos
891.12Schristos	/* Save remaining non-scratch regs after signal mask. */
901.15Smatt	moveml	#0x3CFC,SC_SIZE(%a0)
911.12Schristos
921.10Sthorpej	clrl	%d0		/* return 0 */
931.1Spaulus	rts
941.14SmattEND(__setjmp14)
95