setjmp.S revision 279784
1193323Sed/*-
2193323Sed * Copyright (c) 2002 Peter Grehan.
3193323Sed * All rights reserved.
4193323Sed *
5193323Sed * Redistribution and use in source and binary forms, with or without
6193323Sed * modification, are permitted provided that the following conditions
7193323Sed * are met:
8193323Sed * 1. Redistributions of source code must retain the above copyright
9193323Sed *    notice, this list of conditions and the following disclaimer.
10193323Sed * 2. Redistributions in binary form must reproduce the above copyright
11193323Sed *    notice, this list of conditions and the following disclaimer in the
12193323Sed *    documentation and/or other materials provided with the distribution.
13193323Sed *
14193323Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15193323Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16193323Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17193323Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18193323Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19193323Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20193323Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21193323Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22193323Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23193323Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24193323Sed * SUCH DAMAGE.
25193323Sed */
26193323Sed/*      $NetBSD: setjmp.S,v 1.3 1998/10/03 12:30:38 tsubai Exp $        */
27193323Sed
28193323Sed#include <machine/asm.h>
29193323Sed__FBSDID("$FreeBSD: head/lib/libc/powerpc/gen/setjmp.S 279784 2015-03-08 19:37:08Z nwhitehorn $");
30193323Sed
31193323Sed#include <sys/syscall.h>
32193323Sed
33193323Sed/*
34193323Sed * C library -- setjmp, longjmp
35193323Sed *
36193323Sed *      longjmp(a,v)
37193323Sed * will generate a "return(v?v:1)" from the last call to
38193323Sed *      setjmp(a)
39193323Sed * by restoring registers from the stack.
40193323Sed * The previous signal state is restored.
41193323Sed *
42193323Sed * jmpbuf layout:
43193323Sed *     +------------+
44193323Sed *     |   unused   |
45193323Sed *     +------------+
46193323Sed *     | sig state  |
47193323Sed *     |            |
48193323Sed *     | (4 words)  |
49193323Sed *     |            |
50193323Sed *     +------------+
51193323Sed *     | saved regs |
52193323Sed *     |    ...     |
53193323Sed */
54193323Sed
55193323SedENTRY(setjmp)
56193323Sed	mr	%r6,%r3
57193323Sed	li	%r3,1			/* SIG_BLOCK, but doesn't matter */
58193323Sed					/*            since set == NULL  */
59193323Sed	li	%r4,0			/* set = NULL */
60193323Sed	mr	%r5,%r6			/* &oset */
61193323Sed	addi	%r5,%r5,4
62193323Sed	li	%r0, SYS_sigprocmask	/*sigprocmask(SIG_BLOCK, NULL, &oset)*/
63193323Sed	sc				/*assume no error       XXX */
64193323Sed	mflr	%r11			/* r11 <- link reg */
65193323Sed	mfcr	%r12			/* r12 <- condition reg */
66193323Sed	mr	%r10,%r1		/* r10 <- stackptr */
67193323Sed	mr	%r9,%r2			/*  r9 <- global ptr */
68193323Sed	stmw	%r9,20(%r6)
69193323Sed
70193323Sed	/* FPRs */
71193323Sed	stfd	%f14,92+0*8(%r6)
72193323Sed	stfd	%f15,92+1*8(%r6)
73193323Sed	stfd	%f16,92+2*8(%r6)
74193323Sed	stfd	%f17,92+3*8(%r6)
75193323Sed	stfd	%f18,92+4*8(%r6)
76193323Sed	stfd	%f19,92+5*8(%r6)
77193323Sed	stfd	%f20,92+6*8(%r6)
78193323Sed	stfd	%f21,92+7*8(%r6)
79193323Sed	stfd	%f22,92+8*8(%r6)
80193323Sed	stfd	%f23,92+9*8(%r6)
81193323Sed	stfd	%f24,92+10*8(%r6)
82193323Sed	stfd	%f25,92+11*8(%r6)
83193323Sed	stfd	%f26,92+12*8(%r6)
84193323Sed	stfd	%f27,92+13*8(%r6)
85	stfd	%f28,93+13*8(%r6)
86	stfd	%f29,93+14*8(%r6)
87	stfd	%f30,93+15*8(%r6)
88	stfd	%f31,93+16*8(%r6)
89
90	li	%r3,0			/* return (0) */
91	blr
92END(setjmp)
93
94	WEAK_REFERENCE(CNAME(__longjmp), longjmp)
95ENTRY(__longjmp)
96	lmw	%r9,20(%r3)		/* restore regs */
97
98	/* FPRs */
99	lfd	%f14,92+0*8(%r3)
100	lfd	%f15,92+1*8(%r3)
101	lfd	%f16,92+2*8(%r3)
102	lfd	%f17,92+3*8(%r3)
103	lfd	%f18,92+4*8(%r3)
104	lfd	%f19,92+5*8(%r3)
105	lfd	%f20,92+6*8(%r3)
106	lfd	%f21,92+7*8(%r3)
107	lfd	%f22,92+8*8(%r3)
108	lfd	%f23,92+9*8(%r3)
109	lfd	%f24,92+10*8(%r3)
110	lfd	%f25,92+11*8(%r3)
111	lfd	%f26,92+12*8(%r3)
112	lfd	%f27,92+13*8(%r3)
113	lfd	%f28,93+13*8(%r3)
114	lfd	%f29,93+14*8(%r3)
115	lfd	%f30,93+15*8(%r3)
116	lfd	%f31,93+16*8(%r3)
117
118	mr	%r6,%r4			/* save val param */
119	mtlr	%r11			/* r11 -> link reg */
120	mtcr	%r12			/* r12 -> condition reg */
121	mr	%r1,%r10		/* r10 -> stackptr */
122	mr	%r4,%r3
123	li	%r3,3			/* SIG_SETMASK */
124	addi	%r4,%r4,4		/* &set */
125	li	%r5,0			/* oset = NULL */
126	li	%r0,SYS_sigprocmask	/* sigprocmask(SIG_SET, &set, NULL) */
127	sc                              /* assume no error       XXX */
128	or.	%r3,%r6,%r6
129	bnelr
130	li	%r3,1
131	blr
132END(__longjmp)
133
134	.section .note.GNU-stack,"",%progbits
135