xref: /minix3/lib/libc/compat/arch/arm/gen/compat_setjmp.S (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc/*	$NetBSD: compat_setjmp.S,v 1.4 2013/11/30 20:54:14 joerg Exp $	*/
22fe8fb19SBen Gras
32fe8fb19SBen Gras/*
42fe8fb19SBen Gras * Copyright (c) 1997 Mark Brinicombe
52fe8fb19SBen Gras * All rights reserved.
62fe8fb19SBen Gras *
72fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without
82fe8fb19SBen Gras * modification, are permitted provided that the following conditions
92fe8fb19SBen Gras * are met:
102fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright
112fe8fb19SBen Gras *    notice, this list of conditions and the following disclaimer.
122fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
132fe8fb19SBen Gras *    notice, this list of conditions and the following disclaimer in the
142fe8fb19SBen Gras *    documentation and/or other materials provided with the distribution.
152fe8fb19SBen Gras * 3. All advertising materials mentioning features or use of this software
162fe8fb19SBen Gras *    must display the following acknowledgement:
172fe8fb19SBen Gras *	This product includes software developed by Mark Brinicombe
182fe8fb19SBen Gras * 4. Neither the name of the University nor the names of its contributors
192fe8fb19SBen Gras *    may be used to endorse or promote products derived from this software
202fe8fb19SBen Gras *    without specific prior written permission.
212fe8fb19SBen Gras *
222fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
232fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
242fe8fb19SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
252fe8fb19SBen Gras * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
262fe8fb19SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
272fe8fb19SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
282fe8fb19SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
292fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
302fe8fb19SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
312fe8fb19SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
322fe8fb19SBen Gras * SUCH DAMAGE.
332fe8fb19SBen Gras */
342fe8fb19SBen Gras
352fe8fb19SBen Gras#include <machine/asm.h>
362fe8fb19SBen Gras#include <machine/setjmp.h>
372fe8fb19SBen Gras
382fe8fb19SBen Gras/*
392fe8fb19SBen Gras * C library -- setjmp, longjmp
402fe8fb19SBen Gras *
412fe8fb19SBen Gras *	longjmp(a,v)
422fe8fb19SBen Gras * will generate a "return(v)" from the last call to
432fe8fb19SBen Gras *	setjmp(a)
442fe8fb19SBen Gras * by restoring registers from the stack.
452fe8fb19SBen Gras * The previous signal state is restored.
462fe8fb19SBen Gras */
472fe8fb19SBen Gras
482fe8fb19SBen GrasENTRY(setjmp)
492fe8fb19SBen Gras	/* Block all signals and retrieve the old signal mask */
50*84d9c625SLionel Sambuc	push	{r0, lr}
51*84d9c625SLionel Sambuc	movs	r0, #0x00000000
522fe8fb19SBen Gras
53*84d9c625SLionel Sambuc	bl	PLT_SYM(_C_LABEL(sigblock))
542fe8fb19SBen Gras	mov	r1, r0
552fe8fb19SBen Gras
562fe8fb19SBen Gras	/* Store signal mask */
57*84d9c625SLionel Sambuc	str	r1, [r0, #(_JB_SIGMASK * 4)]
582fe8fb19SBen Gras
592fe8fb19SBen Gras	ldr	r1, .Lsetjmp_magic
60*84d9c625SLionel Sambuc	str	r1, [r0]
612fe8fb19SBen Gras
622fe8fb19SBen Gras	/* Store integer registers */
63*84d9c625SLionel Sambuc	adds	r0, r0, #(_JB_REG_R4 * 4)
64*84d9c625SLionel Sambuc#ifdef __thumb__
65*84d9c625SLionel Sambuc#ifdef _ARM_ARCH_7
66*84d9c625SLionel Sambuc        stmia	r0!, {r4-r12}
67*84d9c625SLionel Sambuc	str	sp, [r0, #0]
68*84d9c625SLionel Sambuc	str	lr, [r0, #4]
69*84d9c625SLionel Sambuc#else
70*84d9c625SLionel Sambuc        stmia	r0!, {r4-r7}
71*84d9c625SLionel Sambuc	mov	r2, r8
72*84d9c625SLionel Sambuc	mov	r3, r9
73*84d9c625SLionel Sambuc	stmia	r0!, {r2-r3}
74*84d9c625SLionel Sambuc	mov	r1, r10
75*84d9c625SLionel Sambuc	mov	r2, r11
76*84d9c625SLionel Sambuc	mov	r3, r12
77*84d9c625SLionel Sambuc	stmia	r0!, {r1-r3}
78*84d9c625SLionel Sambuc	mov	r2, sp
79*84d9c625SLionel Sambuc	mov	r3, lr
80*84d9c625SLionel Sambuc	stmia	r0!, {r2-r3}
81*84d9c625SLionel Sambuc#endif
82*84d9c625SLionel Sambuc#else
83*84d9c625SLionel Sambuc        stmia	r0, {r4-lr}
84*84d9c625SLionel Sambuc#endif
85*84d9c625SLionel Sambuc        movs	r0, #0
86*84d9c625SLionel Sambuc	pop	{r3, pc}
87*84d9c625SLionel SambucEND(setjmp)
882fe8fb19SBen Gras
892fe8fb19SBen GrasENTRY(longjmp)
902fe8fb19SBen Gras	ldr	r2, .Lsetjmp_magic
912fe8fb19SBen Gras	ldr	r3, [r0]
92*84d9c625SLionel Sambuc	cmp	r2, r3
932fe8fb19SBen Gras	bne	botch
942fe8fb19SBen Gras
952fe8fb19SBen Gras	/* Fetch signal mask */
96*84d9c625SLionel Sambuc	ldr	r2, [r0, #(_JB_SIGMASK * 4)]
972fe8fb19SBen Gras
982fe8fb19SBen Gras	/* Set signal mask */
99*84d9c625SLionel Sambuc	push	{r0, r1}	/* don't care about lr */
1002fe8fb19SBen Gras
1012fe8fb19SBen Gras	mov	r0, r2
102*84d9c625SLionel Sambuc	bl	PLT_SYM(_C_LABEL(sigsetmask))
1032fe8fb19SBen Gras
104*84d9c625SLionel Sambuc	pop	{r0, r1}
1052fe8fb19SBen Gras
1062fe8fb19SBen Gras	/* Restore integer registers */
107*84d9c625SLionel Sambuc	adds	r0, r0, #(_JB_REG_R4 * 4)
108*84d9c625SLionel Sambuc#if !defined(__thumb__) || defined(_ARM_ARCH_7)
109*84d9c625SLionel Sambuc        ldmia	r0!, {r4-r12}
110*84d9c625SLionel Sambuc#else
111*84d9c625SLionel Sambuc        ldmia	r0!, {r4-r7}
112*84d9c625SLionel Sambuc        ldmia	r0!, {r2-r3}
113*84d9c625SLionel Sambuc	mov	r8, r2
114*84d9c625SLionel Sambuc	mov	r9, r3
115*84d9c625SLionel Sambuc        ldmia	r0!, {r1-r3}
116*84d9c625SLionel Sambuc	mov	r10, r2
117*84d9c625SLionel Sambuc	mov	r11, r3
118*84d9c625SLionel Sambuc        ldmia	r0!, {r2}
119*84d9c625SLionel Sambuc	mov	r12, r2
120*84d9c625SLionel Sambuc#endif
1212fe8fb19SBen Gras
122*84d9c625SLionel Sambuc	ldmia	r0!, {r2-r3}	/* r2 = sp, r3 = lr */
123*84d9c625SLionel Sambuc
124*84d9c625SLionel Sambuc	/* Validate sp */
125*84d9c625SLionel Sambuc	cmp	r2, #0
1262fe8fb19SBen Gras	beq	botch
127*84d9c625SLionel Sambuc	mov	sp, r2
128*84d9c625SLionel Sambuc
129*84d9c625SLionel Sambuc	/* Validate lr */
130*84d9c625SLionel Sambuc	cmp	r3, #0
131*84d9c625SLionel Sambuc	beq	botch
132*84d9c625SLionel Sambuc	mov	lr, r3
1332fe8fb19SBen Gras
1342fe8fb19SBen Gras	/* Set return value */
1352fe8fb19SBen Gras	mov	r0, r1
136*84d9c625SLionel Sambuc	cmp	r0, #0
137*84d9c625SLionel Sambuc#ifdef __thumb__
138*84d9c625SLionel Sambuc	bne	1f
139*84d9c625SLionel Sambuc	movs	r0, #1
140*84d9c625SLionel Sambuc1:
141*84d9c625SLionel Sambuc#else
142*84d9c625SLionel Sambuc	moveq	r0, #1
143*84d9c625SLionel Sambuc#endif
1442fe8fb19SBen Gras	RET
1452fe8fb19SBen Gras
1462fe8fb19SBen Gras	/* validation failed, die die die. */
1472fe8fb19SBen Grasbotch:
148*84d9c625SLionel Sambuc	bl	PLT_SYM(_C_LABEL(longjmperror))
149*84d9c625SLionel Sambuc	bl	PLT_SYM(_C_LABEL(abort))
150*84d9c625SLionel Sambuc2:	b	2b		/* Cannot get here */
151*84d9c625SLionel Sambuc
152*84d9c625SLionel Sambuc	.align	0
153*84d9c625SLionel Sambuc.Lsetjmp_magic:
154*84d9c625SLionel Sambuc	.word	_JB_MAGIC_SETJMP
155*84d9c625SLionel SambucEND(longjmp)
156