1*2fe8fb19SBen Gras/* $NetBSD: setjmp.S,v 1.8 2005/10/16 17:26:24 christos Exp $ */ 2*2fe8fb19SBen Gras 3*2fe8fb19SBen Gras/* 4*2fe8fb19SBen Gras * Copyright (c) 1997 Mark Brinicombe 5*2fe8fb19SBen Gras * All rights reserved. 6*2fe8fb19SBen Gras * 7*2fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without 8*2fe8fb19SBen Gras * modification, are permitted provided that the following conditions 9*2fe8fb19SBen Gras * are met: 10*2fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright 11*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer. 12*2fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 13*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the 14*2fe8fb19SBen Gras * documentation and/or other materials provided with the distribution. 15*2fe8fb19SBen Gras * 3. All advertising materials mentioning features or use of this software 16*2fe8fb19SBen Gras * must display the following acknowledgement: 17*2fe8fb19SBen Gras * This product includes software developed by Mark Brinicombe 18*2fe8fb19SBen Gras * 4. Neither the name of the University nor the names of its contributors 19*2fe8fb19SBen Gras * may be used to endorse or promote products derived from this software 20*2fe8fb19SBen Gras * without specific prior written permission. 21*2fe8fb19SBen Gras * 22*2fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23*2fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*2fe8fb19SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*2fe8fb19SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26*2fe8fb19SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*2fe8fb19SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*2fe8fb19SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*2fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*2fe8fb19SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*2fe8fb19SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*2fe8fb19SBen Gras * SUCH DAMAGE. 33*2fe8fb19SBen Gras */ 34*2fe8fb19SBen Gras 35*2fe8fb19SBen Gras#include <machine/asm.h> 36*2fe8fb19SBen Gras#include <machine/setjmp.h> 37*2fe8fb19SBen Gras 38*2fe8fb19SBen Gras/* 39*2fe8fb19SBen Gras * C library -- setjmp, longjmp 40*2fe8fb19SBen Gras * 41*2fe8fb19SBen Gras * longjmp(a,v) 42*2fe8fb19SBen Gras * will generate a "return(v)" from the last call to 43*2fe8fb19SBen Gras * setjmp(a) 44*2fe8fb19SBen Gras * by restoring registers from the stack. 45*2fe8fb19SBen Gras * The previous signal state is restored. 46*2fe8fb19SBen Gras */ 47*2fe8fb19SBen Gras 48*2fe8fb19SBen GrasENTRY(__setjmp14) 49*2fe8fb19SBen Gras /* Get the signal mask. */ 50*2fe8fb19SBen Gras stmfd sp!, {r0-r2, r14} 51*2fe8fb19SBen Gras add r2, r0, #(_JB_SIGMASK * 4) 52*2fe8fb19SBen Gras mov r1, #0x00000000 53*2fe8fb19SBen Gras mov r0, #0x00000000 54*2fe8fb19SBen Gras bl PIC_SYM(_C_LABEL(__sigprocmask14), PLT) 55*2fe8fb19SBen Gras ldmfd sp!, {r0-r2, r14} 56*2fe8fb19SBen Gras 57*2fe8fb19SBen Gras ldr r1, .Lsetjmp_magic 58*2fe8fb19SBen Gras str r1, [r0], #4 59*2fe8fb19SBen Gras 60*2fe8fb19SBen Gras#ifdef SOFTFLOAT 61*2fe8fb19SBen Gras add r0, r0, #52 62*2fe8fb19SBen Gras#else 63*2fe8fb19SBen Gras /* Store fp registers */ 64*2fe8fb19SBen Gras sfm f4, 4, [r0], #48 65*2fe8fb19SBen Gras /* Store fpsr */ 66*2fe8fb19SBen Gras rfs r1 67*2fe8fb19SBen Gras str r1, [r0], #0x0004 68*2fe8fb19SBen Gras#endif /*SOFTFLOAT*/ 69*2fe8fb19SBen Gras /* Store integer registers */ 70*2fe8fb19SBen Gras stmia r0, {r4-r14} 71*2fe8fb19SBen Gras mov r0, #0x00000000 72*2fe8fb19SBen Gras RET 73*2fe8fb19SBen Gras 74*2fe8fb19SBen Gras.Lsetjmp_magic: 75*2fe8fb19SBen Gras .word _JB_MAGIC_SETJMP 76*2fe8fb19SBen Gras 77*2fe8fb19SBen Gras 78*2fe8fb19SBen GrasENTRY(__longjmp14) 79*2fe8fb19SBen Gras ldr r2, .Lsetjmp_magic 80*2fe8fb19SBen Gras ldr r3, [r0] 81*2fe8fb19SBen Gras teq r2, r3 82*2fe8fb19SBen Gras bne .Lbotch 83*2fe8fb19SBen Gras 84*2fe8fb19SBen Gras /* Restore the signal mask. */ 85*2fe8fb19SBen Gras stmfd sp!, {r0-r2, r14} 86*2fe8fb19SBen Gras mov r2, #0x00000000 87*2fe8fb19SBen Gras add r1, r0, #(_JB_SIGMASK * 4) 88*2fe8fb19SBen Gras mov r0, #3 /* SIG_SETMASK */ 89*2fe8fb19SBen Gras bl PIC_SYM(_C_LABEL(__sigprocmask14), PLT) 90*2fe8fb19SBen Gras ldmfd sp!, {r0-r2, r14} 91*2fe8fb19SBen Gras 92*2fe8fb19SBen Gras add r0, r0, #4 93*2fe8fb19SBen Gras#ifdef SOFTFLOAT 94*2fe8fb19SBen Gras add r0, r0, #52 95*2fe8fb19SBen Gras#else 96*2fe8fb19SBen Gras /* Restore fp registers */ 97*2fe8fb19SBen Gras lfm f4, 4, [r0], #48 98*2fe8fb19SBen Gras /* Restore FPSR */ 99*2fe8fb19SBen Gras ldr r4, [r0], #0x0004 100*2fe8fb19SBen Gras wfs r4 101*2fe8fb19SBen Gras#endif /* SOFTFLOAT */ 102*2fe8fb19SBen Gras /* Restore integer registers */ 103*2fe8fb19SBen Gras ldmia r0, {r4-r14} 104*2fe8fb19SBen Gras 105*2fe8fb19SBen Gras /* Validate sp and r14 */ 106*2fe8fb19SBen Gras teq sp, #0 107*2fe8fb19SBen Gras teqne r14, #0 108*2fe8fb19SBen Gras beq .Lbotch 109*2fe8fb19SBen Gras 110*2fe8fb19SBen Gras /* Set return value */ 111*2fe8fb19SBen Gras 112*2fe8fb19SBen Gras mov r0, r1 113*2fe8fb19SBen Gras teq r0, #0x00000000 114*2fe8fb19SBen Gras moveq r0, #0x00000001 115*2fe8fb19SBen Gras RET 116*2fe8fb19SBen Gras 117*2fe8fb19SBen Gras /* validation failed, die die die. */ 118*2fe8fb19SBen Gras.Lbotch: 119*2fe8fb19SBen Gras bl PIC_SYM(_C_LABEL(longjmperror), PLT) 120*2fe8fb19SBen Gras bl PIC_SYM(_C_LABEL(abort), PLT) 121*2fe8fb19SBen Gras b . - 8 /* Cannot get here */ 122