Home | History | Annotate | Line # | Download | only in gen
setjmp.S revision 1.8.10.1
      1 /*	$NetBSD: setjmp.S,v 1.8.10.1 2007/08/28 17:36:30 matt Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Mark Brinicombe
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by Mark Brinicombe
     18  * 4. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  */
     34 
     35 #include <machine/asm.h>
     36 #include <machine/setjmp.h>
     37 
     38 /*
     39  * C library -- setjmp, longjmp
     40  *
     41  *	longjmp(a,v)
     42  * will generate a "return(v)" from the last call to
     43  *	setjmp(a)
     44  * by restoring registers from the stack.
     45  * The previous signal state is restored.
     46  */
     47 
     48 ENTRY(__setjmp14)
     49 #ifdef __thumb__
     50 	/* Get the signal mask. */
     51 	push	{r0, r4-r7, lr}
     52 	add	r0, r0, #(_JB_SIGMASK * 4)
     53 	mov	r2, r0
     54 	mov	r1, #0
     55 	mov	r0, #0
     56 	bl	PLT_SYM(_C_LABEL(__sigprocmask14))
     57 	pop	{r0}
     58 
     59 	ldr	r2, .Lsetjmp_magic
     60 	str	r2, [r0]
     61 
     62 	add	r0, r0, #56	/* skip magic and floating point */
     63 
     64 	/* Store integer registers */
     65         stmia	r0!, {r4-r7}
     66 
     67 	mov	r4, r8
     68 	mov	r5, r9
     69 	mov	r6, r10
     70 	mov	r7, r11
     71         stmia	r0!, {r4-r7}
     72 
     73 	mov	r4, r12
     74 	mov	r5, r13
     75 	mov	r6, r14
     76         stmia	r0!, {r4-r6}
     77 
     78         mov	r0, #0
     79         pop	{r4-r7, pc}
     80 #else
     81 	/* Get the signal mask. */
     82 	stmfd	sp!, {r0-r2, r14}
     83 	add	r2, r0, #(_JB_SIGMASK * 4)
     84 	mov	r1, #0x00000000
     85 	mov	r0, #0x00000000
     86 	bl	PLT_SYM(_C_LABEL(__sigprocmask14))
     87 	ldmfd	sp!, {r0-r2, r14}
     88 
     89 	ldr	r1, .Lsetjmp_magic
     90 	str	r1, [r0]
     91 
     92 #ifdef SOFTFLOAT
     93 	add	r0, r0, #52
     94 #else
     95 	/* Store fp registers */
     96 	sfm	f4, 4, [r0], #48
     97 	/* Store fpsr */
     98 	rfs	r1
     99 	str	r1, [r0], #0x0004
    100 #endif	/*SOFTFLOAT*/
    101 	/* Store integer registers */
    102         stmia	r0, {r4-r14}
    103         mov	r0, #0x00000000
    104         RET
    105 #endif /* __thumb__ */
    106 
    107 ENTRY(__longjmp14)
    108 #ifdef __thumb__
    109 	ldr	r2, .Lsetjmp_magic
    110 	ldr	r3, [r0]
    111 	cmp	r2, r3
    112 	bne	.Lbotch
    113 
    114 	/* Restore the signal mask. */
    115 	push	{r0, lr}
    116 	mov	r2, #0
    117 	add	r0, r0, #(_JB_SIGMASK * 4)
    118 	mov	r1, r0
    119 	mov	r0, #3				/* SIG_SETMASK */
    120 	bl	PLT_SYM(_C_LABEL(__sigprocmask14))
    121 	pop	{r0}
    122 
    123 	add	r0, r0, #56
    124 	/* Restore integer registers */
    125         ldmia	r0!, {r4-r7}
    126 	push	{r4-r7}
    127 
    128         ldmia	r0!, {r4-r7}
    129 	mov	r8, r4
    130 	mov	r9, r5
    131 	mov	r10, r6
    132 	mov	r11, r7
    133 
    134         ldmia	r0!, {r4-r6}
    135 	mov	r12, r4
    136 	mov	sp, r5
    137 	mov	lr, r6
    138 
    139 	/* Validate sp and lr */
    140 	cmp	r5, #0		/* sp */
    141 	beq	.Lbotch
    142 	cmp	r6, #0		/* lr */
    143 	beq	.Lbotch
    144 
    145 	/* Set return value */
    146 
    147 	mov	r0, r1
    148 	bne	1f
    149 	mov	r0, #1
    150 1:	pop	{r4-r7, pc}
    151 #else
    152 	ldr	r2, .Lsetjmp_magic
    153 	ldr	r3, [r0]
    154 	teq	r2, r3
    155 	bne	.Lbotch
    156 
    157 	/* Restore the signal mask. */
    158 	stmfd	sp!, {r0-r2, r14}
    159 	mov	r2, #0x00000000
    160 	add	r1, r0, #(_JB_SIGMASK * 4)
    161 	mov	r0, #3				/* SIG_SETMASK */
    162 	bl	PLT_SYM(_C_LABEL(__sigprocmask14))
    163 	ldmfd	sp!, {r0-r2, r14}
    164 
    165 	add	r0, r0, #4
    166 #ifdef SOFTFLOAT
    167 	add	r0, r0, #52
    168 #else
    169 	/* Restore fp registers */
    170 	lfm	f4, 4, [r0], #48
    171 	/* Restore FPSR */
    172 	ldr	r4, [r0], #0x0004
    173 	wfs	r4
    174 #endif	/* SOFTFLOAT */
    175 	/* Restore integer registers */
    176         ldmia	r0, {r4-r14}
    177 
    178 	/* Validate sp and r14 */
    179 	teq	sp, #0
    180 	teqne	r14, #0
    181 	beq	.Lbotch
    182 
    183 	/* Set return value */
    184 
    185 	mov	r0, r1
    186 	teq	r0, #0x00000000
    187 	moveq	r0, #0x00000001
    188 	RET
    189 #endif
    190 
    191 	/* validation failed, die die die. */
    192 .Lbotch:
    193 	bl	PLT_SYM(_C_LABEL(longjmperror))
    194 	bl	PLT_SYM(_C_LABEL(abort))
    195 	b	. - 8		/* Cannot get here */
    196 
    197 	.p2align 2
    198 .Lsetjmp_magic:
    199 	.word	_JB_MAGIC_SETJMP
    200