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 Houchard#define SOFTFLOAT /* XXX */ 482357939bSOlivier HouchardENTRY(setjmp) 492357939bSOlivier Houchard /* Block all signals and retrieve the old signal mask */ 502357939bSOlivier Houchard stmfd sp!, {r0, r14} 513d90a3cdSOlivier Houchard add r2, r0, #4 /* oset */ 523d90a3cdSOlivier Houchard mov r0, #0x00000001 /* SIG_BLOCK */ 533d90a3cdSOlivier Houchard mov r1, #0 /* set */ 542357939bSOlivier Houchard 553d90a3cdSOlivier Houchard bl PIC_SYM(_C_LABEL(sigprocmask), PLT) 562357939bSOlivier Houchard 572357939bSOlivier Houchard ldmfd sp!, {r0, r14} 582357939bSOlivier Houchard 592357939bSOlivier Houchard ldr r1, .Lsetjmp_magic 602357939bSOlivier Houchard str r1, [r0], #4 612357939bSOlivier Houchard 622357939bSOlivier Houchard#ifdef SOFTFLOAT 632357939bSOlivier Houchard add r0, r0, #52 642357939bSOlivier Houchard#else 652357939bSOlivier Houchard /* Store fp registers */ 662357939bSOlivier Houchard sfm f4, 4, [r0], #48 672357939bSOlivier Houchard /* Store fpsr */ 682357939bSOlivier Houchard rfs r1 692357939bSOlivier Houchard str r1, [r0], #0x0004 702357939bSOlivier Houchard#endif /*SOFTFLOAT*/ 712357939bSOlivier Houchard /* Store integer registers */ 722357939bSOlivier Houchard stmia r0, {r4-r14} 732357939bSOlivier Houchard mov r0, #0x00000000 742357939bSOlivier Houchard mov r15, r14 752357939bSOlivier Houchard 762357939bSOlivier Houchard.Lsetjmp_magic: 772357939bSOlivier Houchard .word _JB_MAGIC_SETJMP 782357939bSOlivier Houchard 792357939bSOlivier Houchard 802357939bSOlivier Houchard.weak _C_LABEL(longjmp) 812357939bSOlivier Houchard.set _C_LABEL(longjmp), _C_LABEL(__longjmp) 822357939bSOlivier HouchardENTRY(__longjmp) 832357939bSOlivier Houchard ldr r2, .Lsetjmp_magic 842357939bSOlivier Houchard ldr r3, [r0] 852357939bSOlivier Houchard teq r2, r3 862357939bSOlivier Houchard bne botch 872357939bSOlivier Houchard 882357939bSOlivier Houchard /* Fetch signal mask */ 893d90a3cdSOlivier Houchard add r2, r0, #4 902357939bSOlivier Houchard 912357939bSOlivier Houchard /* Set signal mask */ 922357939bSOlivier Houchard stmfd sp!, {r0, r1, r14} 932357939bSOlivier Houchard sub sp, sp, #4 /* align the stack */ 942357939bSOlivier Houchard 953d90a3cdSOlivier Houchard mov r1, r2 963d90a3cdSOlivier Houchard mov r0, #3 /* SIG_SETMASK */ 973d90a3cdSOlivier Houchard mov r2, #0 983d90a3cdSOlivier Houchard bl PIC_SYM(_C_LABEL(sigprocmask), PLT) 992357939bSOlivier Houchard 1002357939bSOlivier Houchard add sp, sp, #4 /* unalign the stack */ 1012357939bSOlivier Houchard ldmfd sp!, {r0, r1, r14} 1022357939bSOlivier Houchard 1032357939bSOlivier Houchard add r0, r0, #4 1042357939bSOlivier Houchard#ifdef SOFTFLOAT 1052357939bSOlivier Houchard add r0, r0, #52 1062357939bSOlivier Houchard#else 1072357939bSOlivier Houchard /* Restore fp registers */ 1082357939bSOlivier Houchard lfm f4, 4, [r0], #48 1092357939bSOlivier Houchard /* Restore FPSR */ 1102357939bSOlivier Houchard ldr r4, [r0], #0x0004 1112357939bSOlivier Houchard wfs r4 1122357939bSOlivier Houchard#endif /* SOFTFLOAT */ 1132357939bSOlivier Houchard /* Restore integer registers */ 1142357939bSOlivier Houchard ldmia r0, {r4-r14} 1152357939bSOlivier Houchard 1162357939bSOlivier Houchard /* Validate sp and r14 */ 1172357939bSOlivier Houchard teq sp, #0 1182357939bSOlivier Houchard teqne r14, #0 1192357939bSOlivier Houchard beq botch 1202357939bSOlivier Houchard 1212357939bSOlivier Houchard /* Set return value */ 1222357939bSOlivier Houchard 1232357939bSOlivier Houchard mov r0, r1 1242357939bSOlivier Houchard teq r0, #0x00000000 1252357939bSOlivier Houchard moveq r0, #0x00000001 1262357939bSOlivier Houchard mov r15, r14 1272357939bSOlivier Houchard 1282357939bSOlivier Houchard /* validation failed, die die die. */ 1292357939bSOlivier Houchardbotch: 1302357939bSOlivier Houchard bl PIC_SYM(_C_LABEL(longjmperror), PLT) 1312357939bSOlivier Houchard bl PIC_SYM(_C_LABEL(abort), PLT) 1322357939bSOlivier Houchard b . - 8 /* Cannot get here */ 133