xref: /freebsd/lib/libc/arm/gen/setjmp.S (revision 31489a9a2653e123121e8ca39b4be802013d2b50)
12357939bSOlivier Houchard/*	$NetBSD: setjmp.S,v 1.5 2003/04/05 23:08:51 bjh21 Exp $	*/
22357939bSOlivier Houchard
32357939bSOlivier Houchard/*
42357939bSOlivier Houchard * Copyright (c) 1997 Mark Brinicombe
52357939bSOlivier Houchard * All rights reserved.
62357939bSOlivier Houchard *
72357939bSOlivier Houchard * Redistribution and use in source and binary forms, with or without
82357939bSOlivier Houchard * modification, are permitted provided that the following conditions
92357939bSOlivier Houchard * are met:
102357939bSOlivier Houchard * 1. Redistributions of source code must retain the above copyright
112357939bSOlivier Houchard *    notice, this list of conditions and the following disclaimer.
122357939bSOlivier Houchard * 2. Redistributions in binary form must reproduce the above copyright
132357939bSOlivier Houchard *    notice, this list of conditions and the following disclaimer in the
142357939bSOlivier Houchard *    documentation and/or other materials provided with the distribution.
152357939bSOlivier Houchard * 3. All advertising materials mentioning features or use of this software
162357939bSOlivier Houchard *    must display the following acknowledgement:
172357939bSOlivier Houchard *	This product includes software developed by Mark Brinicombe
182357939bSOlivier Houchard * 4. Neither the name of the University nor the names of its contributors
192357939bSOlivier Houchard *    may be used to endorse or promote products derived from this software
202357939bSOlivier Houchard *    without specific prior written permission.
212357939bSOlivier Houchard *
222357939bSOlivier Houchard * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
232357939bSOlivier Houchard * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
242357939bSOlivier Houchard * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
252357939bSOlivier Houchard * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
262357939bSOlivier Houchard * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
272357939bSOlivier Houchard * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
282357939bSOlivier Houchard * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
292357939bSOlivier Houchard * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
302357939bSOlivier Houchard * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
312357939bSOlivier Houchard * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
322357939bSOlivier Houchard * SUCH DAMAGE.
332357939bSOlivier Houchard */
342357939bSOlivier Houchard
352357939bSOlivier Houchard#include <machine/asm.h>
362357939bSOlivier Houchard__FBSDID("$FreeBSD$");
372357939bSOlivier Houchard/*
382357939bSOlivier Houchard * C library -- setjmp, longjmp
392357939bSOlivier Houchard *
402357939bSOlivier Houchard *	longjmp(a,v)
412357939bSOlivier Houchard * will generate a "return(v)" from the last call to
422357939bSOlivier Houchard *	setjmp(a)
432357939bSOlivier Houchard * by restoring registers from the stack.
442357939bSOlivier Houchard * The previous signal state is restored.
452357939bSOlivier Houchard */
462357939bSOlivier Houchard
472357939bSOlivier HouchardENTRY(setjmp)
482357939bSOlivier Houchard	/* Block all signals and retrieve the old signal mask */
492357939bSOlivier Houchard	stmfd	sp!, {r0, r14}
5031489a9aSOlivier Houchard	add	r2, r0, #(25 * 4) /* oset */
513d90a3cdSOlivier Houchard	mov	r0, #0x00000001 /* SIG_BLOCK */
523d90a3cdSOlivier Houchard	mov	r1, #0 /* set */
532357939bSOlivier Houchard
543d90a3cdSOlivier Houchard	bl	PIC_SYM(_C_LABEL(sigprocmask), PLT)
552357939bSOlivier Houchard
562357939bSOlivier Houchard	ldmfd	sp!, {r0, r14}
572357939bSOlivier Houchard
582357939bSOlivier Houchard	ldr	r1, .Lsetjmp_magic
592357939bSOlivier Houchard	str	r1, [r0], #4
602357939bSOlivier Houchard
612357939bSOlivier Houchard#ifdef SOFTFLOAT
622357939bSOlivier Houchard	add	r0, r0, #52
632357939bSOlivier Houchard#else
642357939bSOlivier Houchard	/* Store fp registers */
652357939bSOlivier Houchard	sfm	f4, 4, [r0], #48
662357939bSOlivier Houchard	/* Store fpsr */
672357939bSOlivier Houchard	rfs	r1
682357939bSOlivier Houchard	str	r1, [r0], #0x0004
692357939bSOlivier Houchard#endif	/*SOFTFLOAT*/
702357939bSOlivier Houchard	/* Store integer registers */
712357939bSOlivier Houchard        stmia	r0, {r4-r14}
722357939bSOlivier Houchard        mov	r0, #0x00000000
7331489a9aSOlivier Houchard	RET
742357939bSOlivier Houchard
752357939bSOlivier Houchard.Lsetjmp_magic:
762357939bSOlivier Houchard	.word	_JB_MAGIC_SETJMP
772357939bSOlivier Houchard
782357939bSOlivier Houchard
792357939bSOlivier Houchard.weak _C_LABEL(longjmp)
802357939bSOlivier Houchard.set _C_LABEL(longjmp), _C_LABEL(__longjmp)
812357939bSOlivier HouchardENTRY(__longjmp)
822357939bSOlivier Houchard	ldr	r2, .Lsetjmp_magic
832357939bSOlivier Houchard	ldr	r3, [r0]
842357939bSOlivier Houchard	teq	r2, r3
852357939bSOlivier Houchard	bne	botch
862357939bSOlivier Houchard
872357939bSOlivier Houchard
882357939bSOlivier Houchard	/* Set signal mask */
892357939bSOlivier Houchard	stmfd	sp!, {r0, r1, r14}
902357939bSOlivier Houchard	sub	sp, sp, #4	/* align the stack */
912357939bSOlivier Houchard
9231489a9aSOlivier Houchard	add	r1, r0, #(25 * 4) /* Signal mask */
933d90a3cdSOlivier Houchard	mov	r0, #3 /* SIG_SETMASK */
943d90a3cdSOlivier Houchard	mov	r2, #0
953d90a3cdSOlivier Houchard	bl	PIC_SYM(_C_LABEL(sigprocmask), PLT)
962357939bSOlivier Houchard
972357939bSOlivier Houchard	add	sp, sp, #4	/* unalign the stack */
982357939bSOlivier Houchard	ldmfd	sp!, {r0, r1, r14}
992357939bSOlivier Houchard
1002357939bSOlivier Houchard	add	r0, r0, #4
1012357939bSOlivier Houchard#ifdef SOFTFLOAT
1022357939bSOlivier Houchard	add	r0, r0, #52
1032357939bSOlivier Houchard#else
1042357939bSOlivier Houchard	/* Restore fp registers */
1052357939bSOlivier Houchard	lfm	f4, 4, [r0], #48
1062357939bSOlivier Houchard	/* Restore FPSR */
1072357939bSOlivier Houchard	ldr	r4, [r0], #0x0004
1082357939bSOlivier Houchard	wfs	r4
1092357939bSOlivier Houchard#endif	/* SOFTFLOAT */
1102357939bSOlivier Houchard	/* Restore integer registers */
1112357939bSOlivier Houchard        ldmia	r0, {r4-r14}
1122357939bSOlivier Houchard
1132357939bSOlivier Houchard	/* Validate sp and r14 */
1142357939bSOlivier Houchard	teq	sp, #0
1152357939bSOlivier Houchard	teqne	r14, #0
1162357939bSOlivier Houchard	beq	botch
1172357939bSOlivier Houchard
1182357939bSOlivier Houchard	/* Set return value */
1192357939bSOlivier Houchard
1202357939bSOlivier Houchard	mov	r0, r1
1212357939bSOlivier Houchard	teq	r0, #0x00000000
1222357939bSOlivier Houchard	moveq	r0, #0x00000001
12331489a9aSOlivier Houchard	RET
1242357939bSOlivier Houchard
1252357939bSOlivier Houchard	/* validation failed, die die die. */
1262357939bSOlivier Houchardbotch:
1272357939bSOlivier Houchard	bl	PIC_SYM(_C_LABEL(longjmperror), PLT)
1282357939bSOlivier Houchard	bl	PIC_SYM(_C_LABEL(abort), PLT)
1292357939bSOlivier Houchard	b	. - 8		/* Cannot get here */
130