xref: /freebsd/lib/libc/powerpc64/gen/setjmp.S (revision 8f861da99cb9865b2f1ef6098ad074150f368c23)
1840b91ccSNathan Whitehorn/*-
2840b91ccSNathan Whitehorn * Copyright (c) 2002 Peter Grehan.
3840b91ccSNathan Whitehorn * All rights reserved.
4840b91ccSNathan Whitehorn *
5840b91ccSNathan Whitehorn * Redistribution and use in source and binary forms, with or without
6840b91ccSNathan Whitehorn * modification, are permitted provided that the following conditions
7840b91ccSNathan Whitehorn * are met:
8840b91ccSNathan Whitehorn * 1. Redistributions of source code must retain the above copyright
9840b91ccSNathan Whitehorn *    notice, this list of conditions and the following disclaimer.
10840b91ccSNathan Whitehorn * 2. Redistributions in binary form must reproduce the above copyright
11840b91ccSNathan Whitehorn *    notice, this list of conditions and the following disclaimer in the
12840b91ccSNathan Whitehorn *    documentation and/or other materials provided with the distribution.
13840b91ccSNathan Whitehorn *
14840b91ccSNathan Whitehorn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15840b91ccSNathan Whitehorn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16840b91ccSNathan Whitehorn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17840b91ccSNathan Whitehorn * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18840b91ccSNathan Whitehorn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19840b91ccSNathan Whitehorn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20840b91ccSNathan Whitehorn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21840b91ccSNathan Whitehorn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22840b91ccSNathan Whitehorn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23840b91ccSNathan Whitehorn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24840b91ccSNathan Whitehorn * SUCH DAMAGE.
25840b91ccSNathan Whitehorn */
26840b91ccSNathan Whitehorn/*      $NetBSD: setjmp.S,v 1.3 1998/10/03 12:30:38 tsubai Exp $        */
27840b91ccSNathan Whitehorn
28840b91ccSNathan Whitehorn#include <machine/asm.h>
29840b91ccSNathan Whitehorn__FBSDID("$FreeBSD$");
30840b91ccSNathan Whitehorn
31840b91ccSNathan Whitehorn#include <sys/syscall.h>
32840b91ccSNathan Whitehorn
33840b91ccSNathan Whitehorn/*
34840b91ccSNathan Whitehorn * C library -- setjmp, longjmp
35840b91ccSNathan Whitehorn *
36840b91ccSNathan Whitehorn *      longjmp(a,v)
37840b91ccSNathan Whitehorn * will generate a "return(v?v:1)" from the last call to
38840b91ccSNathan Whitehorn *      setjmp(a)
39840b91ccSNathan Whitehorn * by restoring registers from the stack.
40840b91ccSNathan Whitehorn * The previous signal state is restored.
41840b91ccSNathan Whitehorn *
42840b91ccSNathan Whitehorn * jmpbuf layout:
43840b91ccSNathan Whitehorn *     +------------+
44840b91ccSNathan Whitehorn *     |   unused   |
45840b91ccSNathan Whitehorn *     +------------+
46840b91ccSNathan Whitehorn *     | sig state  |
47840b91ccSNathan Whitehorn *     |            |
48840b91ccSNathan Whitehorn *     | (4 words)  |
49840b91ccSNathan Whitehorn *     |            |
50840b91ccSNathan Whitehorn *     +------------+
51840b91ccSNathan Whitehorn *     | saved regs |
52840b91ccSNathan Whitehorn *     |    ...     |
53840b91ccSNathan Whitehorn */
54840b91ccSNathan Whitehorn
55840b91ccSNathan WhitehornENTRY(setjmp)
56840b91ccSNathan Whitehorn	mr	%r6,%r3
57840b91ccSNathan Whitehorn	li	%r3,1			/* SIG_BLOCK, but doesn't matter */
58840b91ccSNathan Whitehorn					/*            since set == NULL  */
59840b91ccSNathan Whitehorn	li	%r4,0			/* set = NULL */
60840b91ccSNathan Whitehorn	mr	%r5,%r6			/* &oset */
61840b91ccSNathan Whitehorn	addi	%r5,%r5,4
62840b91ccSNathan Whitehorn	li	%r0, SYS_sigprocmask	/*sigprocmask(SIG_BLOCK, NULL, &oset)*/
63840b91ccSNathan Whitehorn	sc				/*assume no error       XXX */
64840b91ccSNathan Whitehorn	mflr	%r11			/* r11 <- link reg */
65840b91ccSNathan Whitehorn	mfcr	%r12			/* r12 <- condition reg */
66840b91ccSNathan Whitehorn	mr	%r10,%r1		/* r10 <- stackptr */
67840b91ccSNathan Whitehorn	mr	%r9,%r2			/*  r9 <- global ptr */
68840b91ccSNathan Whitehorn
69840b91ccSNathan Whitehorn	std	%r9,40 + 0*8(%r6)
70840b91ccSNathan Whitehorn	std	%r10,40 + 1*8(%r6)
71840b91ccSNathan Whitehorn	std	%r11,40 + 2*8(%r6)
72840b91ccSNathan Whitehorn	std	%r12,40 + 3*8(%r6)
73840b91ccSNathan Whitehorn	std	%r13,40 + 4*8(%r6)
74840b91ccSNathan Whitehorn	std	%r14,40 + 5*8(%r6)
75840b91ccSNathan Whitehorn	std	%r15,40 + 6*8(%r6)
76840b91ccSNathan Whitehorn	std	%r16,40 + 7*8(%r6)
77840b91ccSNathan Whitehorn	std	%r17,40 + 8*8(%r6)
78840b91ccSNathan Whitehorn	std	%r18,40 + 9*8(%r6)
79840b91ccSNathan Whitehorn	std	%r19,40 + 10*8(%r6)
80840b91ccSNathan Whitehorn	std	%r20,40 + 11*8(%r6)
81840b91ccSNathan Whitehorn	std	%r21,40 + 12*8(%r6)
82840b91ccSNathan Whitehorn	std	%r22,40 + 13*8(%r6)
83840b91ccSNathan Whitehorn	std	%r23,40 + 14*8(%r6)
84840b91ccSNathan Whitehorn	std	%r24,40 + 15*8(%r6)
85840b91ccSNathan Whitehorn	std	%r25,40 + 16*8(%r6)
86840b91ccSNathan Whitehorn	std	%r26,40 + 17*8(%r6)
87840b91ccSNathan Whitehorn	std	%r27,40 + 18*8(%r6)
88840b91ccSNathan Whitehorn	std	%r28,40 + 19*8(%r6)
89840b91ccSNathan Whitehorn	std	%r29,40 + 20*8(%r6)
90840b91ccSNathan Whitehorn	std	%r30,40 + 21*8(%r6)
91840b91ccSNathan Whitehorn	std	%r31,40 + 22*8(%r6)
92840b91ccSNathan Whitehorn
93840b91ccSNathan Whitehorn	li	%r3,0			/* return (0) */
94840b91ccSNathan Whitehorn	blr
95840b91ccSNathan Whitehorn
96840b91ccSNathan Whitehorn	.weak CNAME(longjmp)
97840b91ccSNathan Whitehorn	.set CNAME(longjmp),CNAME(__longjmp)
98840b91ccSNathan Whitehorn	.weak CNAME(.longjmp)
99840b91ccSNathan Whitehorn	.set CNAME(.longjmp),CNAME(.__longjmp)
100840b91ccSNathan WhitehornENTRY(__longjmp)
101840b91ccSNathan Whitehorn	ld	%r9,40 + 0*8(%r3)
102840b91ccSNathan Whitehorn	ld	%r10,40 + 1*8(%r3)
103840b91ccSNathan Whitehorn	ld	%r11,40 + 2*8(%r3)
104840b91ccSNathan Whitehorn	ld	%r12,40 + 3*8(%r3)
105840b91ccSNathan Whitehorn	ld	%r13,40 + 4*8(%r3)
106840b91ccSNathan Whitehorn	ld	%r14,40 + 5*8(%r3)
107840b91ccSNathan Whitehorn	ld	%r15,40 + 6*8(%r3)
108840b91ccSNathan Whitehorn	ld	%r16,40 + 7*8(%r3)
109840b91ccSNathan Whitehorn	ld	%r17,40 + 8*8(%r3)
110840b91ccSNathan Whitehorn	ld	%r18,40 + 9*8(%r3)
111840b91ccSNathan Whitehorn	ld	%r19,40 + 10*8(%r3)
112840b91ccSNathan Whitehorn	ld	%r20,40 + 11*8(%r3)
113840b91ccSNathan Whitehorn	ld	%r21,40 + 12*8(%r3)
114840b91ccSNathan Whitehorn	ld	%r22,40 + 13*8(%r3)
115840b91ccSNathan Whitehorn	ld	%r23,40 + 14*8(%r3)
116840b91ccSNathan Whitehorn	ld	%r24,40 + 15*8(%r3)
117840b91ccSNathan Whitehorn	ld	%r25,40 + 16*8(%r3)
118840b91ccSNathan Whitehorn	ld	%r26,40 + 17*8(%r3)
119840b91ccSNathan Whitehorn	ld	%r27,40 + 18*8(%r3)
120840b91ccSNathan Whitehorn	ld	%r28,40 + 19*8(%r3)
121840b91ccSNathan Whitehorn	ld	%r29,40 + 20*8(%r3)
122840b91ccSNathan Whitehorn	ld	%r30,40 + 21*8(%r3)
123840b91ccSNathan Whitehorn	ld	%r31,40 + 22*8(%r3)
124840b91ccSNathan Whitehorn	mr	%r6,%r4			/* save val param */
125840b91ccSNathan Whitehorn	mtlr	%r11			/* r11 -> link reg */
126840b91ccSNathan Whitehorn	mtcr	%r12			/* r12 -> condition reg */
127840b91ccSNathan Whitehorn	mr	%r2,%r9			/* r9  -> global ptr */
128840b91ccSNathan Whitehorn	mr	%r1,%r10		/* r10 -> stackptr */
129840b91ccSNathan Whitehorn	mr	%r4,%r3
130840b91ccSNathan Whitehorn	li	%r3,3			/* SIG_SETMASK */
131840b91ccSNathan Whitehorn	addi	%r4,%r4,4		/* &set */
132840b91ccSNathan Whitehorn	li	%r5,0			/* oset = NULL */
133840b91ccSNathan Whitehorn	li	%r0,SYS_sigprocmask	/* sigprocmask(SIG_SET, &set, NULL) */
134840b91ccSNathan Whitehorn	sc                              /* assume no error       XXX */
135840b91ccSNathan Whitehorn	or.	%r3,%r6,%r6
136840b91ccSNathan Whitehorn	bnelr
137840b91ccSNathan Whitehorn	li	%r3,1
138840b91ccSNathan Whitehorn	blr
139840b91ccSNathan Whitehorn
140*8f861da9SKonstantin Belousov	.section .note.GNU-stack,"",%progbits
141