1: /*
   2:  * Copyright (c) 1987 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #if     defined(LIBC_SCCS) && !defined(lint)
   8:         <@(#)setjmp.s	1.5 (2.11BSD GTE) 1997/9/7\0>
   9:         .even
  10: #endif
  11: 
  12: /*
  13:  * val = setjmp(env)
  14:  *	int	val;
  15:  *	jmp_buf	*env;
  16:  *
  17:  * longjmp(env, val)
  18:  *	jmp_buf	*env;
  19:  *	int	val;
  20:  *
  21:  * Overlaid version of setjmp and longjmp.  MUST BE LOADED IN BASE SEGMENT!!!
  22:  *
  23:  * Longjmp(env,val) will generate a "return(val)" from the last call to
  24:  * setjmp(env) by restoring the general registers r2, r3, and r4 from the
  25:  * stack and performing a sigreturn on the sigcontext constructed in env by
  26:  * setjmp, see <signal.h>.
  27:  */
  28: #include "DEFS.h"
  29: 
  30: SIG_SETMASK = 3                         / XXX - from signal.h
  31: 
  32: .globl  _sigaltstack, _sigprocmask      / needed to create sigcontext
  33: .globl  __ovno
  34: 
  35: ENTRY(setjmp)
  36:         mov     r2,-(sp)        / save r2
  37:         mov     4(sp),r2        / r2 = env
  38:         sub     $6.,sp          / allocate sizeof(struct sigaltstack)
  39:         mov     sp,r0           /   and get current sigaltstack via
  40:         mov     r0,-(sp)        /   sigaltstack(0, sp) (cant use "mov sp,-(sp)")
  41:         clr     -(sp)
  42:         jsr     pc,_sigaltstack
  43:         add     $8.,sp          / toss 0, &oss, ss_sp, ss_size,
  44:         mov     (sp)+,(r2)+     /   save ss_flags of caller
  45: 
  46:         sub     $4,sp           / sizeof (sigset_t) - oset
  47:         mov     sp,r0           / can't use mov sp,-(sp)
  48:         mov     r0,-(sp)        / 'oset'
  49:         clr     -(sp)           / 'set'
  50:         mov     $SIG_SETMASK,-(sp)      / 'how'
  51:         jsr     pc,_sigprocmask / sigprocmask(SIG_SETMASK, NULL, &oset)
  52:         add     $6,sp           / toss how, set, &oset
  53:         mov     (sp)+,(r2)+     / oset(hi) to env
  54:         mov     (sp)+,(r2)+     / oset(lo) to env
  55: 
  56:         mov     sp,(r2)         / calculate caller's pre jsr pc,setjmp
  57:         add     $4,(r2)+        /   sp as (sp + saved r2 + ret addr)
  58:         mov     r5,(r2)+        / save caller's frame pointer
  59:         cmp     (r2)+,(r2)+     /   fake r0 & r1
  60:         mov     2(sp),(r2)+     /   return pc,
  61:         mov     $0170000,(r2)+  /   fake (but appropriate) ps, and
  62:         mov     __ovno,(r2)     /   current overlay
  63:         mov     (sp)+,r2        / restore r2
  64:         clr     r0              / and return a zero
  65:         rts     pc
  66: 
  67: SC_FP   = 8.                    / offset of sc_fp in sigcontext
  68: SC_R0   = 12.                   / offset of sc_r0 in sigcontext
  69: 
  70: .globl  rollback, _sigreturn, _longjmperror
  71: ENTRY(longjmp)
  72:         mov     2(sp),r1        / r1 = env
  73:         mov     SC_FP(r1),r0    / r0 = env->sc_fp
  74:         jsr     pc,rollback     / attempt stack frame rollback
  75:         mov     4(sp),r0        / r0 = val
  76:         bne     1f              / if (val == 0)
  77:         inc     r0              /   r0 = 1
  78: 1:
  79:         mov     r0,SC_R0(r1)    / env->sc_r0 = r0 (`return' val)
  80:         mov     2(sp),-(sp)     / push env
  81:         jsr     pc,_sigreturn   / perform sigreturn(env)
  82:         jsr     pc,_longjmperror / if sigreturn returns, it's an error
  83:         iot                     / and die if longjmperror returns

Defined functions

SC_FP defined in line 67; used 1 times
  • in line 73
SC_R0 defined in line 68; used 1 times
  • in line 79
SIG_SETMASK defined in line 30; used 1 times
  • in line 50
_longjmp defined in line 71; used 174 times
_setjmp defined in line 35; used 213 times
Last modified: 1997-09-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1136
Valid CSS Valid XHTML 1.0 Strict