compat_setjmp.S revision 1.2
11.2Smatt/*	$NetBSD: compat_setjmp.S,v 1.2 2013/01/11 13:55:26 matt 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.2Smatt	str	r1, [r0, #(_JB_SIGMASK * 4)]
601.1Schristos
611.1Schristos	ldr	r1, .Lsetjmp_magic
621.2Smatt	str	r1, [r0]
631.1Schristos
641.1Schristos	/* Store integer registers */
651.2Smatt	add	r0, r0, #(_JB_REG_R4 * 4)
661.1Schristos        stmia	r0, {r4-r14}
671.1Schristos        mov	r0, #0x00000000
681.1Schristos        RET
691.1Schristos
701.1Schristos.Lsetjmp_magic:
711.1Schristos	.word	_JB_MAGIC_SETJMP
721.1Schristos
731.1Schristos
741.1SchristosENTRY(longjmp)
751.1Schristos	ldr	r2, .Lsetjmp_magic
761.1Schristos	ldr	r3, [r0]
771.1Schristos	teq	r2, r3
781.1Schristos	bne	botch
791.1Schristos
801.1Schristos	/* Fetch signal mask */
811.2Smatt	ldr	r2, [r0, #(_JB_SIGMASK * 4)]
821.1Schristos
831.1Schristos	/* Set signal mask */
841.1Schristos	stmfd	sp!, {r0, r1, r14}
851.1Schristos	sub	sp, sp, #4	/* align the stack */
861.1Schristos
871.1Schristos	mov	r0, r2
881.1Schristos	bl	PIC_SYM(_C_LABEL(sigsetmask), PLT)
891.1Schristos
901.1Schristos	add	sp, sp, #4	/* unalign the stack */
911.1Schristos	ldmfd	sp!, {r0, r1, r14}
921.1Schristos
931.1Schristos	/* Restore integer registers */
941.2Smatt	add	r0, r0, #(_JB_REG_R4 * 4)
951.1Schristos        ldmia	r0, {r4-r14}
961.1Schristos
971.1Schristos	/* Validate sp and r14 */
981.1Schristos	teq	sp, #0
991.1Schristos	teqne	r14, #0
1001.1Schristos	beq	botch
1011.1Schristos
1021.1Schristos	/* Set return value */
1031.1Schristos
1041.1Schristos	mov	r0, r1
1051.1Schristos	teq	r0, #0x00000000
1061.1Schristos	moveq	r0, #0x00000001
1071.1Schristos	RET
1081.1Schristos
1091.1Schristos	/* validation failed, die die die. */
1101.1Schristosbotch:
1111.1Schristos	bl	PIC_SYM(_C_LABEL(longjmperror), PLT)
1121.1Schristos	bl	PIC_SYM(_C_LABEL(abort), PLT)
1131.1Schristos	b	. - 8		/* Cannot get here */
114