home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / lib / libc / vax / gen / setjmp.s < prev    next >
Encoding:
Text File  |  1991-04-12  |  3.2 KB  |  97 lines

  1. /*
  2.  * Copyright (c) 1983 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #if defined(LIBC_SCCS) && !defined(lint)
  35.     .asciz "@(#)setjmp.s    5.9 (Berkeley) 6/1/90"
  36. #endif /* LIBC_SCCS and not lint */
  37.  
  38. /*
  39.  * C library -- setjmp, longjmp
  40.  *
  41.  *    longjmp(a,v)
  42.  * will generate a "return(v)" from
  43.  * the last call to
  44.  *    setjmp(a)
  45.  * by restoring registers from the stack,
  46.  * and a struct sigcontext, see <signal.h>
  47.  */
  48.  
  49. #include "DEFS.h"
  50.  
  51. ENTRY(setjmp, R6)
  52.     movl    4(ap),r6        # construct sigcontext
  53.     subl2    $8,sp            # space for current struct sigstack
  54.     pushl    sp            # get current values
  55.     pushl    $0            # no new values
  56.     calls    $3,_sigstack        # pop args plus signal stack value
  57.     movl    (sp)+,(r6)+        # save onsigstack status of caller
  58.     pushl    $0
  59.     calls    $1,_sigblock        # get signal mask
  60.     movl    r0,(r6)+        # save signal mask of caller
  61.     movl    (ap),r0
  62.     moval    4(ap)[r0],(r6)+        # save sp of caller
  63.     movl    12(fp),(r6)+        # save frame pointer of caller
  64.     movl    8(fp),(r6)+        # save argument pointer of caller
  65.     movl    16(fp),(r6)+        # save pc of caller
  66.     movpsl    (r6)            # save psl of caller
  67.     movw    4(fp),(r6)
  68.     clrl    r0
  69.     ret
  70.  
  71. ENTRY(longjmp, 0)
  72.     movl    8(ap),r0        # return(v)
  73.     movl    4(ap),r1        # fetch buffer
  74.     tstl    12(r1)
  75.     beql    botch
  76. loop:
  77.     cmpl    12(r1),fp        # are we there yet?
  78.     beql    done
  79.     blssu    botch
  80.     moval    20(fp),r2
  81.     blbc    6(fp),1f        # was r0 saved?
  82.     movl    r0,(r2)+
  83. 1:
  84.     bbc    $1,6(fp),2f        # was r1 saved?
  85.     movl    r1,(r2)
  86. 2:
  87.     movl    $loop,16(fp)
  88.     ret                # pop another frame
  89.  
  90. done:
  91.     pushl    r1            # pointer to sigcontext
  92.     calls    $1,_sigreturn        # restore previous context
  93.                     # we should never return
  94. botch:
  95.     calls    $0,_longjmperror
  96.     halt
  97.