13584Ssos/*-
23584Ssos * Copyright (c) 2002 Peter Grehan.
3230132Suqs * All rights reserved.
411397Sswallace *
53584Ssos * Redistribution and use in source and binary forms, with or without
63584Ssos * modification, are permitted provided that the following conditions
73584Ssos * are met:
83584Ssos * 1. Redistributions of source code must retain the above copyright
93584Ssos *    notice, this list of conditions and the following disclaimer.
103584Ssos * 2. Redistributions in binary form must reproduce the above copyright
113584Ssos *    notice, this list of conditions and the following disclaimer in the
123584Ssos *    documentation and/or other materials provided with the distribution.
133584Ssos *
143584Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
153584Ssos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
163584Ssos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1797748Sschweikh * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
183584Ssos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
193584Ssos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
203584Ssos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
213584Ssos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
223584Ssos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
233584Ssos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
243584Ssos * SUCH DAMAGE.
253584Ssos */
263584Ssos/*      $NetBSD: setjmp.S,v 1.3 1998/10/03 12:30:38 tsubai Exp $        */
273584Ssos
283584Ssos#include <machine/asm.h>
293584Ssos__FBSDID("$FreeBSD$");
303584Ssos
31115684Sobrien#include <sys/syscall.h>
32115684Sobrien
33115684Sobrien/*
343584Ssos * C library -- setjmp, longjmp
3511397Sswallace *
3614885Sswallace *      longjmp(a,v)
3711397Sswallace * will generate a "return(v?v:1)" from the last call to
38162954Sphk *      setjmp(a)
3991388Srobert * by restoring registers from the stack.
4011397Sswallace * The previous signal state is restored.
41141488Sjhb *
4224205Sbde * jmpbuf layout:
4311397Sswallace *     +------------+
44141488Sjhb *     |   unused   |
4511397Sswallace *     +------------+
46160241Sjhb *     | sig state  |
47141488Sjhb *     |            |
4811397Sswallace *     | (4 words)  |
493584Ssos *     |            |
503584Ssos *     +------------+
5111397Sswallace *     | saved regs |
5214885Sswallace *     |    ...     |
5311397Sswallace */
5411397Sswallace
5511397SswallaceENTRY(setjmp)
5611397Sswallace	mr	%r6,%r3
5711397Sswallace	li	%r3,1			/* SIG_BLOCK, but doesn't matter */
583584Ssos					/*            since set == NULL  */
5954655Seivind	li	%r4,0			/* set = NULL */
6011397Sswallace	mr	%r5,%r6			/* &oset */
6111397Sswallace	addi	%r5,%r5,4
6211397Sswallace	li	%r0, SYS_sigprocmask	/*sigprocmask(SIG_BLOCK, NULL, &oset)*/
6383366Sjulian	sc				/*assume no error       XXX */
643584Ssos	mflr	%r11			/* r11 <- link reg */
6583366Sjulian	mfcr	%r12			/* r12 <- condition reg */
6611397Sswallace	mr	%r10,%r1		/* r10 <- stackptr */
67147820Sjhb	mr	%r9,%r2			/*  r9 <- global ptr */
68147820Sjhb	stmw	%r9,20(%r6)
693584Ssos
7011397Sswallace	/* FPRs */
7111397Sswallace	stfd	%f14,112+0*8(%r6)
7211397Sswallace	stfd	%f15,112+1*8(%r6)
73160798Sjhb	stfd	%f16,112+2*8(%r6)
74147820Sjhb	stfd	%f17,112+3*8(%r6)
75160798Sjhb	stfd	%f18,112+4*8(%r6)
76147820Sjhb	stfd	%f19,112+5*8(%r6)
77147820Sjhb	stfd	%f20,112+6*8(%r6)
783584Ssos	stfd	%f21,112+7*8(%r6)
793584Ssos	stfd	%f22,112+8*8(%r6)
8011397Sswallace	stfd	%f23,112+9*8(%r6)
8183366Sjulian	stfd	%f24,112+10*8(%r6)
8283366Sjulian	stfd	%f25,112+11*8(%r6)
8311397Sswallace	stfd	%f26,112+12*8(%r6)
8411397Sswallace	stfd	%f27,112+13*8(%r6)
85160192Sjhb	stfd	%f28,112+14*8(%r6)
863584Ssos	stfd	%f29,112+15*8(%r6)
8711397Sswallace	stfd	%f30,112+16*8(%r6)
88160192Sjhb	stfd	%f31,112+17*8(%r6)
89160192Sjhb
90160192Sjhb	li	%r3,0			/* return (0) */
91160192Sjhb	blr
92160192SjhbEND(setjmp)
93160192Sjhb
9411397Sswallace	WEAK_REFERENCE(CNAME(__longjmp), longjmp)
9511397SswallaceENTRY(__longjmp)
9611397Sswallace	lmw	%r9,20(%r3)		/* restore regs */
9783366Sjulian
9883366Sjulian	/* FPRs */
9911397Sswallace	lfd	%f14,112+0*8(%r3)
1003584Ssos	lfd	%f15,112+1*8(%r3)
10111397Sswallace	lfd	%f16,112+2*8(%r3)
1023584Ssos	lfd	%f17,112+3*8(%r3)
10311397Sswallace	lfd	%f18,112+4*8(%r3)
104107849Salfred	lfd	%f19,112+5*8(%r3)
105107849Salfred	lfd	%f20,112+6*8(%r3)
106225617Skmacy	lfd	%f21,112+7*8(%r3)
1073584Ssos	lfd	%f22,112+8*8(%r3)
1083584Ssos	lfd	%f23,112+9*8(%r3)
1093584Ssos	lfd	%f24,112+10*8(%r3)
11011397Sswallace	lfd	%f25,112+11*8(%r3)
11183366Sjulian	lfd	%f26,112+12*8(%r3)
11283366Sjulian	lfd	%f27,112+13*8(%r3)
11311397Sswallace	lfd	%f28,112+14*8(%r3)
1143584Ssos	lfd	%f29,112+15*8(%r3)
11511397Sswallace	lfd	%f30,112+16*8(%r3)
11626819Ssef	lfd	%f31,112+17*8(%r3)
117103870Salfred
11826819Ssef	mr	%r6,%r4			/* save val param */
11926819Ssef	mtlr	%r11			/* r11 -> link reg */
12026819Ssef	mtcr	%r12			/* r12 -> condition reg */
12126819Ssef	mr	%r1,%r10		/* r10 -> stackptr */
12211397Sswallace	mr	%r4,%r3
12311397Sswallace	li	%r3,3			/* SIG_SETMASK */
12411397Sswallace	addi	%r4,%r4,4		/* &set */
12511397Sswallace	li	%r5,0			/* oset = NULL */
12611397Sswallace	li	%r0,SYS_sigprocmask	/* sigprocmask(SIG_SET, &set, NULL) */
127110299Sphk	sc                              /* assume no error       XXX */
128110299Sphk	or.	%r3,%r6,%r6
12911397Sswallace	bnelr
130107849Salfred	li	%r3,1
13126819Ssef	blr
13211397SswallaceEND(__longjmp)
13311397Sswallace
13411397Sswallace	.section .note.GNU-stack,"",%progbits
13583366Sjulian