setjmp.S revision 231044
118316Swollman/*-
218316Swollman * Copyright (c) 2002 Peter Grehan.
318316Swollman * All rights reserved.
418316Swollman *
518316Swollman * Redistribution and use in source and binary forms, with or without
618316Swollman * modification, are permitted provided that the following conditions
718316Swollman * are met:
818316Swollman * 1. Redistributions of source code must retain the above copyright
918316Swollman *    notice, this list of conditions and the following disclaimer.
1018316Swollman * 2. Redistributions in binary form must reproduce the above copyright
1118316Swollman *    notice, this list of conditions and the following disclaimer in the
1218316Swollman *    documentation and/or other materials provided with the distribution.
1318316Swollman *
1418316Swollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1518316Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1618316Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1718316Swollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1818316Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1918316Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2018316Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2118316Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2218316Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2318316Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2418316Swollman * SUCH DAMAGE.
2518316Swollman */
2618316Swollman/*      $NetBSD: setjmp.S,v 1.3 1998/10/03 12:30:38 tsubai Exp $        */
2718316Swollman
2818316Swollman#include <machine/asm.h>
2918316Swollman__FBSDID("$FreeBSD: head/lib/libc/powerpc/gen/setjmp.S 231044 2012-02-05 20:04:43Z andreast $");
3046303Smarkm
3150476Speter#include <sys/syscall.h>
3218316Swollman
3318316Swollman/*
3418316Swollman * C library -- setjmp, longjmp
3518316Swollman *
3618316Swollman *      longjmp(a,v)
3718316Swollman * will generate a "return(v?v:1)" from the last call to
3818316Swollman *      setjmp(a)
3918316Swollman * by restoring registers from the stack.
4018316Swollman * The previous signal state is restored.
41126250Sbms *
42126250Sbms * jmpbuf layout:
43126250Sbms *     +------------+
4418316Swollman *     |   unused   |
4518316Swollman *     +------------+
4618316Swollman *     | sig state  |
4718316Swollman *     |            |
4846303Smarkm *     | (4 words)  |
4946303Smarkm *     |            |
5046303Smarkm *     +------------+
5146303Smarkm *     | saved regs |
5218323Swollman *     |    ...     |
53 */
54
55ENTRY(setjmp)
56	mr	%r6,%r3
57	li	%r3,1			/* SIG_BLOCK, but doesn't matter */
58					/*            since set == NULL  */
59	li	%r4,0			/* set = NULL */
60	mr	%r5,%r6			/* &oset */
61	addi	%r5,%r5,4
62	li	%r0, SYS_sigprocmask	/*sigprocmask(SIG_BLOCK, NULL, &oset)*/
63	sc				/*assume no error       XXX */
64	mflr	%r11			/* r11 <- link reg */
65	mfcr	%r12			/* r12 <- condition reg */
66	mr	%r10,%r1		/* r10 <- stackptr */
67	mr	%r9,%r2			/*  r9 <- global ptr */
68	stmw	%r9,20(%r6)
69	li	%r3,0			/* return (0) */
70	blr
71
72	WEAK_REFERENCE(CNAME(__longjmp), longjmp)
73ENTRY(__longjmp)
74	lmw	%r9,20(%r3)		/* restore regs */
75	mr	%r6,%r4			/* save val param */
76	mtlr	%r11			/* r11 -> link reg */
77	mtcr	%r12			/* r12 -> condition reg */
78	mr	%r2,%r9			/* r9  -> global ptr */
79	mr	%r1,%r10		/* r10 -> stackptr */
80	mr	%r4,%r3
81	li	%r3,3			/* SIG_SETMASK */
82	addi	%r4,%r4,4		/* &set */
83	li	%r5,0			/* oset = NULL */
84	li	%r0,SYS_sigprocmask	/* sigprocmask(SIG_SET, &set, NULL) */
85	sc                              /* assume no error       XXX */
86	or.	%r3,%r6,%r6
87	bnelr
88	li	%r3,1
89	blr
90
91	.section .note.GNU-stack,"",%progbits
92