[BACK]Return to setjmp.S CVS log [TXT][DIR] Up to [local] / sys / lib / libkern / arch / sparc

Annotation of sys/lib/libkern/arch/sparc/setjmp.S, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: setjmp.S,v 1.3 2003/06/02 23:28:09 millert Exp $      */
        !             2: /*     $NetBSD: setjmp.S,v 1.2 1994/10/26 06:40:08 cgd Exp $   */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1992, 1993
        !             6:  *     The Regents of the University of California.  All rights reserved.
        !             7:  *
        !             8:  * This software was developed by the Computer Systems Engineering group
        !             9:  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
        !            10:  * contributed to Berkeley.
        !            11:  *
        !            12:  * Redistribution and use in source and binary forms, with or without
        !            13:  * modification, are permitted provided that the following conditions
        !            14:  * are met:
        !            15:  * 1. Redistributions of source code must retain the above copyright
        !            16:  *    notice, this list of conditions and the following disclaimer.
        !            17:  * 2. Redistributions in binary form must reproduce the above copyright
        !            18:  *    notice, this list of conditions and the following disclaimer in the
        !            19:  *    documentation and/or other materials provided with the distribution.
        !            20:  * 3. Neither the name of the University nor the names of its contributors
        !            21:  *    may be used to endorse or promote products derived from this software
        !            22:  *    without specific prior written permission.
        !            23:  *
        !            24:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            25:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            26:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            27:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            28:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            29:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            30:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            31:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            32:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            33:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            34:  * SUCH DAMAGE.
        !            35:  *
        !            36:  * Header: setjmp.s,v 1.2 92/06/25 03:18:43 torek Exp
        !            37:  */
        !            38:
        !            39: #if defined(LIBC_SCCS) && !defined(lint)
        !            40: #ifdef notdef
        !            41:        .asciz "@(#)setjmp.s    8.1 (Berkeley) 6/4/93"
        !            42: #endif
        !            43:        .asciz "$OpenBSD: setjmp.S,v 1.3 2003/06/02 23:28:09 millert Exp $"
        !            44: #endif /* LIBC_SCCS and not lint */
        !            45:
        !            46: /*
        !            47:  * C library -- setjmp, longjmp
        !            48:  *
        !            49:  *     longjmp(a,v)
        !            50:  * will generate a "return(v)" from
        !            51:  * the last call to
        !            52:  *     setjmp(a)
        !            53:  * by restoring registers from the stack,
        !            54:  * and a struct sigcontext, see <signal.h>
        !            55:  */
        !            56:
        !            57: #include "SYS.h"
        !            58:
        !            59: ENTRY(setjmp)
        !            60:        /*
        !            61:         * We use the caller's `arg dump' area (%sp+0x44; there are 6 ints
        !            62:         * reserved there for us) to avoid having to allocate stack space
        !            63:         * here.
        !            64:         */
        !            65:        mov     %o0, %o2        /* build sigcontext in [%o2] */
        !            66:        mov     1, %o0          /* SIG_BLOCK */
        !            67:        mov     SYS_sigprocmask, %g1
        !            68:        clr     %o1             /* sigprocmask(SIG_BLOCK, (sigset_t *)NULL) */
        !            69:        t       ST_SYSCALL
        !            70:        st      %o0, [%o2 + 4]  /* sc.sc_mask = current mask; */
        !            71:        mov     SYS_sigaltstack, %g1
        !            72:        clr     %o0             /* sigstack(NULL, &foo) */
        !            73:        add     %sp, 0x48, %o1  /* (foo being in arg dump area) */
        !            74:        t       ST_SYSCALL
        !            75:        ld      [%sp + 0x50], %o0       /* foo.ss_flags */
        !            76:        and     %o0, 1, %o1     /* onstack = foo.ss_flags & 1; */
        !            77:        st      %o0, [%o2 + 0]  /* sc.sc_onstack = current onstack; */
        !            78:        st      %sp, [%o2 + 8]  /* sc.sc_sp = sp (both ours and caller's) */
        !            79:        add     %o7, 8, %o0
        !            80:        st      %o0, [%o2 + 12] /* sc.sc_pc = return_pc */
        !            81:        add     %o7, 12, %o0
        !            82:        st      %o0, [%o2 + 16] /* sc.sc_npc = return_pc + 4 */
        !            83:        st      %g0, [%o2 + 20] /* sc.sc_psr = (clean psr) */
        !            84:        st      %fp, [%o2 + 24] /* sc.sc_g1 = %fp (misuse, but what the heck) */
        !            85:                                /* sc.sc_o0 = random(), set in longjmp */
        !            86:        retl                    /* return 0 */
        !            87:         clr    %o0
        !            88:
        !            89: /*
        !            90:  * All we need to do here is force sigreturn to load a new stack pointer,
        !            91:  * new <pc,npc>, and appropriate %o0 return value from the sigcontext built
        !            92:  * in setjmp.  The %i and %l registers will be reloaded from the place to
        !            93:  * which %sp points, due to sigreturn() semantics (sigreturn does not modify
        !            94:  * the window pointer in the psr, hence it must force all windows to reload).
        !            95:  */
        !            96: ENTRY(longjmp)
        !            97:        save    %sp, -96, %sp
        !            98:        ld      [%i0 + 8], %o2  /* make sure sc->sc_sp, sc->sc_fp nonzero */
        !            99:        ld      [%i0 + 24], %o3
        !           100:        orcc    %o2, %o3, %g0
        !           101:        bz      Lbotch
        !           102:         tst    %i1             /* if (v == 0) v = 1; */
        !           103:        bz,a    1f
        !           104:         mov    1, %i1
        !           105: 1:
        !           106:        st      %i1, [%i0 + 28] /* sc.sc_o0 = v; */
        !           107:        mov     SYS_sigreturn, %g1
        !           108:        mov     %i0, %o0
        !           109:        t       ST_SYSCALL      /* sigreturn(scp); */
        !           110:
        !           111: Lbotch:
        !           112:        /* oops, caller botched it */
        !           113:        call    _longjmperror
        !           114:         nop
        !           115:        unimp   0

CVSweb