1/* $NetBSD: setjmp.S,v 1.17 2005/09/17 11:49:39 tsutsui Exp $ */ 2 3/*- 4 * Copyright (c) 1991, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Ralph Campbell. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. 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 REGENTS 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 REGENTS 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>
| 1/* $NetBSD: setjmp.S,v 1.17 2005/09/17 11:49:39 tsutsui Exp $ */ 2 3/*- 4 * Copyright (c) 1991, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Ralph Campbell. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. 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 REGENTS 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 REGENTS 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__FBSDID("$FreeBSD: head/lib/libc/mips/gen/setjmp.S 178580 2008-04-26 12:08:02Z imp $");
| 36__FBSDID("$FreeBSD: head/lib/libc/mips/gen/setjmp.S 209231 2010-06-16 12:55:14Z jchandra $");
|
37#include <machine/regnum.h> 38 39#if defined(LIBC_SCCS) && !defined(lint) 40 ASMSTR("from: @(#)setjmp.s 8.1 (Berkeley) 6/4/93") 41 ASMSTR("$NetBSD: setjmp.S,v 1.17 2005/09/17 11:49:39 tsutsui Exp $") 42#endif /* LIBC_SCCS and not lint */ 43
| 37#include <machine/regnum.h> 38 39#if defined(LIBC_SCCS) && !defined(lint) 40 ASMSTR("from: @(#)setjmp.s 8.1 (Berkeley) 6/4/93") 41 ASMSTR("$NetBSD: setjmp.S,v 1.17 2005/09/17 11:49:39 tsutsui Exp $") 42#endif /* LIBC_SCCS and not lint */ 43
|
| 44#include "SYS.h" 45
|
44#ifdef __ABICALLS__ 45 .abicalls 46#endif 47 48/* 49 * C library -- setjmp, longjmp 50 * 51 * longjmp(a,v) 52 * will generate a "return(v)" from 53 * the last call to 54 * setjmp(a) 55 * by restoring registers from the stack, 56 * and a struct sigcontext, see <signal.h> 57 */ 58 59#define SETJMP_FRAME_SIZE (CALLFRAME_SIZ + (SZREG * 2)) 60 61 62NESTED(setjmp, SETJMP_FRAME_SIZE, ra) 63 .mask 0x80000000, (CALLFRAME_RA - CALLFRAME_SIZ)
| 46#ifdef __ABICALLS__ 47 .abicalls 48#endif 49 50/* 51 * C library -- setjmp, longjmp 52 * 53 * longjmp(a,v) 54 * will generate a "return(v)" from 55 * the last call to 56 * setjmp(a) 57 * by restoring registers from the stack, 58 * and a struct sigcontext, see <signal.h> 59 */ 60 61#define SETJMP_FRAME_SIZE (CALLFRAME_SIZ + (SZREG * 2)) 62 63 64NESTED(setjmp, SETJMP_FRAME_SIZE, ra) 65 .mask 0x80000000, (CALLFRAME_RA - CALLFRAME_SIZ)
|
64 .set noreorder 65#ifdef __ABICALLS__ 66 .cpload t9 67#endif 68 subu sp, sp, SETJMP_FRAME_SIZE # allocate stack frame 69#ifdef __ABICALLS__ 70 .cprestore 16 71#endif 72 sw ra, CALLFRAME_RA(sp) # save RA 73 sw a0, CALLFRAME_SIZ(sp) # store env
| 66 SETUP_GP 67 PTR_SUBU sp, sp, SETJMP_FRAME_SIZE # allocate stack frame 68 SAVE_GP(CALLFRAME_GP) 69 SETUP_GP64(CALLFRAME_GP, setjmp)
|
74
| 70
|
| 71 REG_S ra, CALLFRAME_RA(sp) # save RA 72 REG_S a0, CALLFRAME_SIZ(sp) # store env 73
|
75 /* Get the signal mask. */
| 74 /* Get the signal mask. */
|
76 addu a2, a0, _JB_SIGMASK * SZREG # &oenv
| 75 PTR_ADDU a2, a0, _JB_SIGMASK * SZREG # &oenv
|
77 li a0, 1 # SIG_SETBLOCK 78 move a1, zero # &env == 0
| 76 li a0, 1 # SIG_SETBLOCK 77 move a1, zero # &env == 0
|
79 la t9, _C_LABEL(sigprocmask) # get current signal mask 80 jal t9 81 nop
| 78 PTR_LA t9, _C_LABEL(sigprocmask) # get current signal mask 79 jalr t9
|
82
| 80
|
83 lw a0, CALLFRAME_SIZ(sp) # restore env pointer 84 lw ra, CALLFRAME_RA(sp) # restore RA 85 addu sp, sp, SETJMP_FRAME_SIZE # pop stack frame
| 81 RESTORE_GP64 82 REG_L a0, CALLFRAME_SIZ(sp) # restore env pointer 83 REG_L ra, CALLFRAME_RA(sp) # restore RA 84 PTR_ADDU sp, sp, SETJMP_FRAME_SIZE # pop stack frame
|
86
| 85
|
87 li v0, _JB_MAGIC_SETJMP 88 sw v0, (_JB_MAGIC * SZREG)(a0) 89 sw ra, (_JB_REG_RA * SZREG)(a0) 90 sw s0, (_JB_REG_S0 * SZREG)(a0) 91 sw s1, (_JB_REG_S1 * SZREG)(a0) 92 sw s2, (_JB_REG_S2 * SZREG)(a0) 93 sw s3, (_JB_REG_S3 * SZREG)(a0) 94 sw s4, (_JB_REG_S4 * SZREG)(a0) 95 sw s5, (_JB_REG_S5 * SZREG)(a0) 96 sw s6, (_JB_REG_S6 * SZREG)(a0) 97 sw s7, (_JB_REG_S7 * SZREG)(a0) 98 sw sp, (_JB_REG_SP * SZREG)(a0) 99 sw s8, (_JB_REG_S8 * SZREG)(a0)
| 86 REG_LI v0, _JB_MAGIC_SETJMP 87 REG_S v0, (_JB_MAGIC * SZREG)(a0) 88 REG_S ra, (_JB_REG_RA * SZREG)(a0) 89 REG_S s0, (_JB_REG_S0 * SZREG)(a0) 90 REG_S s1, (_JB_REG_S1 * SZREG)(a0) 91 REG_S s2, (_JB_REG_S2 * SZREG)(a0) 92 REG_S s3, (_JB_REG_S3 * SZREG)(a0) 93 REG_S s4, (_JB_REG_S4 * SZREG)(a0) 94 REG_S s5, (_JB_REG_S5 * SZREG)(a0) 95 REG_S s6, (_JB_REG_S6 * SZREG)(a0) 96 REG_S s7, (_JB_REG_S7 * SZREG)(a0) 97 REG_S sp, (_JB_REG_SP * SZREG)(a0) 98 REG_S s8, (_JB_REG_S8 * SZREG)(a0) 99#if defined(__mips_n32) || defined(__mips_n64) 100 REG_S gp, (_JB_REG_GP * SZREG)(a0) 101#endif
|
100 101 move v0, zero
| 102 103 move v0, zero
|
102 j ra
| 104 jr ra
|
103END(setjmp) 104 105#define LONGJMP_FRAME_SIZE (CALLFRAME_SIZ + (SZREG * 2)) 106 107NESTED(longjmp, LONGJMP_FRAME_SIZE, ra) 108 .mask 0x80000000, (CALLFRAME_RA - CALLFRAME_SIZ)
| 105END(setjmp) 106 107#define LONGJMP_FRAME_SIZE (CALLFRAME_SIZ + (SZREG * 2)) 108 109NESTED(longjmp, LONGJMP_FRAME_SIZE, ra) 110 .mask 0x80000000, (CALLFRAME_RA - CALLFRAME_SIZ)
|
109 .set noreorder 110#ifdef __ABICALLS__ 111 .cpload t9 112#endif 113 subu sp, sp, LONGJMP_FRAME_SIZE # allocate stack frame 114#ifdef __ABICALLS__ 115 .cprestore 16 116#endif 117 sw ra, CALLFRAME_RA(sp) # save RA 118 lw v0, (_JB_MAGIC * SZREG)(a0) 119 li t0, _JB_MAGIC_SETJMP
| 111 PIC_PROLOGUE(longjmp) 112 PTR_SUBU sp, sp, LONGJMP_FRAME_SIZE # allocate stack frame 113 SAVE_GP(CALLFRAME_GP) 114 115 REG_S ra, CALLFRAME_RA(sp) # save RA 116 REG_L v0, (_JB_MAGIC * SZREG)(a0) 117 REG_LI t0, _JB_MAGIC_SETJMP
|
120 bne v0, t0, botch # jump if error 121 nop 122
| 118 bne v0, t0, botch # jump if error 119 nop 120
|
123 sw a0, CALLFRAME_SIZ(sp) # save env 124 sw a1, (CALLFRAME_SIZ + SZREG)(sp) # save return value
| 121 REG_S a0, CALLFRAME_SIZ(sp) # save env 122 REG_S a1, (CALLFRAME_SIZ + SZREG)(sp) # save return value
|
125 126 # set sigmask
| 123 124 # set sigmask
|
127 addu a1, a0, _JB_SIGMASK * SZREG # &set
| 125 PTR_ADDU a1, a0, _JB_SIGMASK * SZREG # &set
|
128 move a2, zero # &oset == NULL 129 li a0, 3 # SIG_SETMASK
| 126 move a2, zero # &oset == NULL 127 li a0, 3 # SIG_SETMASK
|
130 la t9,_C_LABEL(sigprocmask) # set current signal mask
| 128 PTR_LA t9,_C_LABEL(sigprocmask) # set current signal mask
|
131 jal t9 132 nop 133
| 129 jal t9 130 nop 131
|
134 lw a0, CALLFRAME_SIZ(sp) # restore env 135 lw a1, (CALLFRAME_SIZ + SZREG)(sp) # restore return value
| 132 REG_L a0, CALLFRAME_SIZ(sp) # restore env 133 REG_L a1, (CALLFRAME_SIZ + SZREG)(sp) # restore return value
|
136
| 134
|
137 lw ra, (_JB_REG_RA * SZREG)(a0) 138 lw s0, (_JB_REG_S0 * SZREG)(a0) 139 lw s1, (_JB_REG_S1 * SZREG)(a0) 140 lw s2, (_JB_REG_S2 * SZREG)(a0) 141 lw s3, (_JB_REG_S3 * SZREG)(a0) 142 lw s4, (_JB_REG_S4 * SZREG)(a0) 143 lw s5, (_JB_REG_S5 * SZREG)(a0) 144 lw s6, (_JB_REG_S6 * SZREG)(a0) 145 lw s7, (_JB_REG_S7 * SZREG)(a0) 146 lw sp, (_JB_REG_SP * SZREG)(a0) 147 lw s8, (_JB_REG_S8 * SZREG)(a0)
| 135 REG_L ra, (_JB_REG_RA * SZREG)(a0) 136 REG_L s0, (_JB_REG_S0 * SZREG)(a0) 137 REG_L s1, (_JB_REG_S1 * SZREG)(a0) 138 REG_L s2, (_JB_REG_S2 * SZREG)(a0) 139 REG_L s3, (_JB_REG_S3 * SZREG)(a0) 140 REG_L s4, (_JB_REG_S4 * SZREG)(a0) 141 REG_L s5, (_JB_REG_S5 * SZREG)(a0) 142 REG_L s6, (_JB_REG_S6 * SZREG)(a0) 143 REG_L s7, (_JB_REG_S7 * SZREG)(a0) 144 REG_L sp, (_JB_REG_SP * SZREG)(a0) 145 REG_L s8, (_JB_REG_S8 * SZREG)(a0) 146#if defined(__mips_n32) || defined(__mips_n64) 147 REG_L gp, (_JB_REG_GP * SZREG)(a0) 148#endif 149
|
148 move v0, a1 149 j ra 150 nop 151 152botch:
| 150 move v0, a1 151 j ra 152 nop 153 154botch:
|
153 la t9, _C_LABEL(longjmperror) 154 jal t9
| 155 /* 156 * We know we aren't returning so we don't care about restoring 157 * our caller's GP. 158 */ 159 PTR_LA t9, _C_LABEL(longjmperror) 160 jalr t9
|
155 nop 156
| 161 nop 162
|
157 la t9, _C_LABEL(abort) 158 jal t9 159 nop
| 163 PIC_TAILCALL(abort)
|
160END(longjmp)
| 164END(longjmp)
|