compat_setjmp.S revision 1.1
11.1Schristos/*	$NetBSD: compat_setjmp.S,v 1.1 2005/10/16 17:27:50 christos Exp $	*/
21.1Schristos
31.1Schristos/*
41.1Schristos * Copyright (c) 1997 Mark Brinicombe
51.1Schristos * All rights reserved.
61.1Schristos *
71.1Schristos * Redistribution and use in source and binary forms, with or without
81.1Schristos * modification, are permitted provided that the following conditions
91.1Schristos * are met:
101.1Schristos * 1. Redistributions of source code must retain the above copyright
111.1Schristos *    notice, this list of conditions and the following disclaimer.
121.1Schristos * 2. Redistributions in binary form must reproduce the above copyright
131.1Schristos *    notice, this list of conditions and the following disclaimer in the
141.1Schristos *    documentation and/or other materials provided with the distribution.
151.1Schristos * 3. All advertising materials mentioning features or use of this software
161.1Schristos *    must display the following acknowledgement:
171.1Schristos *	This product includes software developed by Mark Brinicombe
181.1Schristos * 4. Neither the name of the University nor the names of its contributors
191.1Schristos *    may be used to endorse or promote products derived from this software
201.1Schristos *    without specific prior written permission.
211.1Schristos *
221.1Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
231.1Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241.1Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251.1Schristos * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
261.1Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271.1Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281.1Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291.1Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301.1Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311.1Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321.1Schristos * SUCH DAMAGE.
331.1Schristos */
341.1Schristos
351.1Schristos#include <machine/asm.h>
361.1Schristos#include <machine/setjmp.h>
371.1Schristos
381.1Schristos/*
391.1Schristos * C library -- setjmp, longjmp
401.1Schristos *
411.1Schristos *	longjmp(a,v)
421.1Schristos * will generate a "return(v)" from the last call to
431.1Schristos *	setjmp(a)
441.1Schristos * by restoring registers from the stack.
451.1Schristos * The previous signal state is restored.
461.1Schristos */
471.1Schristos
481.1SchristosENTRY(setjmp)
491.1Schristos	/* Block all signals and retrieve the old signal mask */
501.1Schristos	stmfd	sp!, {r0, r14}
511.1Schristos	mov	r0, #0x00000000
521.1Schristos
531.1Schristos	bl	PIC_SYM(_C_LABEL(sigblock), PLT)
541.1Schristos	mov	r1, r0
551.1Schristos
561.1Schristos	ldmfd	sp!, {r0, r14}
571.1Schristos
581.1Schristos	/* Store signal mask */
591.1Schristos	str	r1, [r0, #(25 * 4)]
601.1Schristos
611.1Schristos	ldr	r1, .Lsetjmp_magic
621.1Schristos	str	r1, [r0], #4
631.1Schristos
641.1Schristos#ifdef SOFTFLOAT
651.1Schristos	add	r0, r0, #52
661.1Schristos#else
671.1Schristos	/* Store fp registers */
681.1Schristos	sfm	f4, 4, [r0], #48
691.1Schristos	/* Store fpsr */
701.1Schristos	rfs	r1
711.1Schristos	str	r1, [r0], #0x0004
721.1Schristos#endif	/*SOFTFLOAT*/
731.1Schristos	/* Store integer registers */
741.1Schristos        stmia	r0, {r4-r14}
751.1Schristos        mov	r0, #0x00000000
761.1Schristos        RET
771.1Schristos
781.1Schristos.Lsetjmp_magic:
791.1Schristos	.word	_JB_MAGIC_SETJMP
801.1Schristos
811.1Schristos
821.1SchristosENTRY(longjmp)
831.1Schristos	ldr	r2, .Lsetjmp_magic
841.1Schristos	ldr	r3, [r0]
851.1Schristos	teq	r2, r3
861.1Schristos	bne	botch
871.1Schristos
881.1Schristos	/* Fetch signal mask */
891.1Schristos	ldr	r2, [r0, #(25 * 4)]
901.1Schristos
911.1Schristos	/* Set signal mask */
921.1Schristos	stmfd	sp!, {r0, r1, r14}
931.1Schristos	sub	sp, sp, #4	/* align the stack */
941.1Schristos
951.1Schristos	mov	r0, r2
961.1Schristos	bl	PIC_SYM(_C_LABEL(sigsetmask), PLT)
971.1Schristos
981.1Schristos	add	sp, sp, #4	/* unalign the stack */
991.1Schristos	ldmfd	sp!, {r0, r1, r14}
1001.1Schristos
1011.1Schristos	add	r0, r0, #4
1021.1Schristos#ifdef SOFTFLOAT
1031.1Schristos	add	r0, r0, #52
1041.1Schristos#else
1051.1Schristos	/* Restore fp registers */
1061.1Schristos	lfm	f4, 4, [r0], #48
1071.1Schristos	/* Restore FPSR */
1081.1Schristos	ldr	r4, [r0], #0x0004
1091.1Schristos	wfs	r4
1101.1Schristos#endif	/* SOFTFLOAT */
1111.1Schristos	/* Restore integer registers */
1121.1Schristos        ldmia	r0, {r4-r14}
1131.1Schristos
1141.1Schristos	/* Validate sp and r14 */
1151.1Schristos	teq	sp, #0
1161.1Schristos	teqne	r14, #0
1171.1Schristos	beq	botch
1181.1Schristos
1191.1Schristos	/* Set return value */
1201.1Schristos
1211.1Schristos	mov	r0, r1
1221.1Schristos	teq	r0, #0x00000000
1231.1Schristos	moveq	r0, #0x00000001
1241.1Schristos	RET
1251.1Schristos
1261.1Schristos	/* validation failed, die die die. */
1271.1Schristosbotch:
1281.1Schristos	bl	PIC_SYM(_C_LABEL(longjmperror), PLT)
1291.1Schristos	bl	PIC_SYM(_C_LABEL(abort), PLT)
1301.1Schristos	b	. - 8		/* Cannot get here */
131