/* $NetBSD: setjmp.S,v 1.14 2013/04/19 13:45:45 matt Exp $ */12/*3* Copyright (c) 1997 Mark Brinicombe4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. All advertising materials mentioning features or use of this software15* must display the following acknowledgement:16* This product includes software developed by Mark Brinicombe17* 4. Neither the name of the University nor the names of its contributors18* may be used to endorse or promote products derived from this software19* without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND22* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE23* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE24* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE25* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL26* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS27* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)28* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT29* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY30* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF31* SUCH DAMAGE.32*/3334#if !defined(__SOFTFP__) && !defined(__VFP_FP__) && !defined(__ARM_PCS)35#error FPA is not supported anymore36#endif3738.fpu vfp3940#include <machine/asm.h>41#include <machine/setjmp.h>42/*43* C library -- setjmp, longjmp44*45* longjmp(a,v)46* will generate a "return(v)" from the last call to47* setjmp(a)48* by restoring registers from the stack.49* The previous signal state is restored.50*/5152ENTRY(setjmp)53/* Block all signals and retrieve the old signal mask */54stmfd sp!, {r0, r14}55add r2, r0, #(_JB_SIGMASK * 4) /* oset */56mov r1, #0x00000000 /* set */57mov r0, #0x00000001 /* SIG_BLOCK */58bl PIC_SYM(_C_LABEL(sigprocmask), PLT)59ldmfd sp!, {r0, r14}6061ldr r1, .Lsetjmp_magic6263#if !defined(SOFTFLOAT_FOR_GCC)64add r2, r0, #(_JB_REG_D8 * 4)65vstmia r2, {d8-d15}66vmrs r2, fpscr67str r2, [r0, #(_JB_REG_FPSCR * 4)]68#endif6970str r1, [r0] /* store magic */7172/* Store integer registers */73add r0, r0, #(_JB_REG_R4 * 4)74#ifndef __thumb__75stmia r0, {r4-r14}76#else77stmia r0, {r4-r12}78str r13, [r0, #((_JB_REG_R13 - _JB_REG_R4) * 4)]79str r14, [r0, #((_JB_REG_R14 - _JB_REG_R4) * 4)]80#endif81mov r0, #0x0000000082RET8384.Lsetjmp_magic:85.word _JB_MAGIC_SETJMP86END(setjmp)8788.weak _C_LABEL(longjmp)89.set _C_LABEL(longjmp), _C_LABEL(__longjmp)90ENTRY(__longjmp)91ldr r2, [r0]92ldr ip, .Lsetjmp_magic93teq r2, ip94bne .Lbotch9596/* Restore the signal mask. */97stmfd sp!, {r0-r2, r14}98mov r2, #0x0000000099add r1, r0, #(_JB_SIGMASK * 4) /* Signal mask */100mov r0, #3 /* SIG_SETMASK */101bl PIC_SYM(_C_LABEL(sigprocmask), PLT)102ldmfd sp!, {r0-r2, r14}103104#if !defined(SOFTFLOAT_FOR_GCC)105add ip, r0, #(_JB_REG_D8 * 4)106vldmia ip, {d8-d15}107ldr ip, [r0, #(_JB_REG_FPSCR * 4)]108vmsr fpscr, ip109#endif110111add r0, r0, #(_JB_REG_R4 * 4)112/* Restore integer registers */113#ifndef __thumb__114ldmia r0, {r4-r14}115#else116ldmia r0, {r4-r12}117ldr r13, [r0, #((_JB_REG_R13 - _JB_REG_R4) * 4)]118ldr r14, [r0, #((_JB_REG_R14 - _JB_REG_R4) * 4)]119#endif120121/* Validate sp and r14 */122teq sp, #0123it ne124teqne r14, #0125it eq126beq .Lbotch127128/* Set return value */129movs r0, r1130it eq131moveq r0, #0x00000001132RET133134/* validation failed, die die die. */135.Lbotch:136bl PIC_SYM(_C_LABEL(longjmperror), PLT)137bl PIC_SYM(_C_LABEL(abort), PLT)1381: b 1b /* Cannot get here */139END(__longjmp)140141.section .note.GNU-stack,"",%progbits142143144