1 /* $OpenBSD: setjmp.S,v 1.2 2007/03/02 06:11:54 miod Exp $ */ 2 /* $NetBSD: setjmp.S,v 1.10 2006/01/05 19:21:37 uwe Exp $ */ 3 4 /*- 5 * Copyright (c) 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * William Jolitz. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * from: @(#)setjmp.s 5.1 (Berkeley) 4/23/90 36 */ 37 38 #include <machine/asm.h> 39 #include <machine/setjmp.h> 40 41 /* 42 * C library -- setjmp, longjmp 43 * 44 * longjmp(a,v) 45 * will generate a "return(v)" from the last call to 46 * setjmp(a) 47 * by restoring registers from the stack. 48 * The previous signal state is restored. 49 */ 50 51 ENTRY(setjmp) 52 PIC_PROLOGUE(.L_got_1) 53 sts.l pr, @-sp 54 mov.l r4, @-sp 55 56 mov.l .L_sigprocmask_1, r0 57 mov r4, r6 58 mov #1, r4 /* how = SIG_BLOCK */ 59 mov #0, r5 /* new = NULL */ 60 1: CALL r0 61 add #4, r6 /* old = &sigmask */ 62 63 mov.l @sp+, r4 64 lds.l @sp+, pr 65 PIC_EPILOGUE 66 67 /* identical to _setjmp except that the first word is non-zero */ 68 #if defined(__SH4__) && !defined(__SH4_NOFPU__) 69 add #(_JBLEN * 4), r4 70 sts fpscr, r1 71 xor r0, r0 72 mov.l r1, @-r4 73 lds r0, fpscr 74 sts.l fpul, @-r4 75 fmov.s fr15, @-r4 76 fmov.s fr14, @-r4 77 fmov.s fr13, @-r4 78 fmov.s fr12, @-r4 79 frchg 80 fmov.s fr15, @-r4 81 fmov.s fr14, @-r4 82 fmov.s fr13, @-r4 83 fmov.s fr12, @-r4 84 lds r1, fpscr 85 #else 86 add #((_JBLEN - 10) * 4), r4 87 #endif 88 sts.l mach, @-r4 89 sts.l macl, @-r4 90 mov.l r15, @-r4 91 mov.l r14, @-r4 92 mov.l r13, @-r4 93 mov.l r12, @-r4 94 mov.l r11, @-r4 95 mov.l r10, @-r4 96 mov.l r9, @-r4 97 mov.l r8, @-r4 98 sts.l pr, @-r4 99 add #-4, r4 /* skip signal mask */ 100 mov #1, r0 101 mov.l r0, @-r4 /* has signal mask */ 102 rts 103 xor r0, r0 104 105 .align 2 106 .L_got_1: PIC_GOT_DATUM 107 .L_sigprocmask_1: CALL_DATUM(_C_LABEL(sigprocmask), 1b) 108 SET_ENTRY_SIZE(setjmp) 109 110 ENTRY(longjmp) 111 /* we won't return here, so we don't need to save pr and r12 */ 112 PIC_PROLOGUE_NOSAVE(.L_got_2) 113 mov.l r5, @-sp 114 mov.l r4, @-sp 115 116 mov.l .L_sigprocmask_2, r0 117 mov r4, r5 118 mov #3, r4 /* how = SIG_SETMASK */ 119 add #4, r5 /* new = &sigmask */ 120 1: CALL r0 121 mov #0, r6 /* old = NULL */ 122 123 mov.l @sp+, r4 124 mov.l @sp+, r5 125 126 /* identical to _longjmp */ 127 add #8, r4 128 lds.l @r4+, pr 129 mov.l @r4+, r8 130 mov.l @r4+, r9 131 mov.l @r4+, r10 132 mov.l @r4+, r11 133 mov.l @r4+, r12 134 mov.l @r4+, r13 135 mov.l @r4+, r14 136 mov.l @r4+, r15 137 lds.l @r4+, macl 138 lds.l @r4+, mach 139 #if defined(__SH4__) && !defined(__SH4_NOFPU__) 140 xor r0, r0 141 lds r0, fpscr 142 frchg 143 fmov.s @r4+, fr12 144 fmov.s @r4+, fr13 145 fmov.s @r4+, fr14 146 fmov.s @r4+, fr15 147 frchg 148 fmov.s @r4+, fr12 149 fmov.s @r4+, fr13 150 fmov.s @r4+, fr14 151 fmov.s @r4+, fr15 152 lds.l @r4+, fpul 153 lds.l @r4+, fpscr 154 #endif 155 156 mov r5, r0 157 tst r0, r0 /* make sure return value is non-zero */ 158 bf .L0 159 add #1, r0 160 .L0: 161 rts 162 nop 163 164 .align 2 165 .L_got_2: PIC_GOT_DATUM 166 .L_sigprocmask_2: CALL_DATUM(_C_LABEL(sigprocmask), 1b) 167 SET_ENTRY_SIZE(longjmp) 168