1/*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * the Systems Programming Group of the University of Utah Computer 7 * Science Department. 8 * 9 * %sccs.include.redist.c% 10 */ 11 12#if defined(LIBC_SCCS) && !defined(lint) 13 .asciz "@(#)setjmp.s 5.1 (Berkeley) 05/12/90" 14#endif /* LIBC_SCCS and not lint */ 15 16/* 17 * C library -- setjmp, longjmp 18 * 19 * longjmp(a,v) 20 * will generate a "return(v)" from 21 * the last call to 22 * setjmp(a) 23 * by restoring registers from the stack, 24 * and a struct sigcontext, see <signal.h> 25 */ 26 27#include "DEFS.h" 28 29ENTRY(setjmp) 30 subql #8,sp /* space for sigstack args/rvals */ 31 clrl sp@ /* don't change it... */ 32 movl sp,sp@(4) /* ...but return the current val */ 33 jsr _sigstack /* note: onstack returned in sp@(4) */ 34 clrl sp@ /* don't change mask, just return */ 35 jsr _sigblock /* old value */ 36 movl sp@(4),d1 /* old onstack value */ 37 addql #8,sp 38 movl sp@(4),a0 /* save area pointer */ 39 movl d1,a0@+ /* save old onstack value */ 40 movl d0,a0@+ /* save old signal mask */ 41 lea sp@(4),a1 /* adjust saved SP since we won't rts */ 42 movl a1,a0@+ /* save old SP */ 43 movl a6,a0@+ /* save old FP */ 44 clrl a0@+ /* no AP */ 45 movl sp@,a0@+ /* save old PC */ 46 clrl a0@+ /* clean PS */ 47 moveml #0x3CFC,a0@ /* save remaining non-scratch regs */ 48 clrl d0 /* return 0 */ 49 rts 50 51ENTRY(longjmp) 52 movl sp@(4),a0 /* save area pointer */ 53 tstl a0@(8) /* ensure non-zero SP */ 54 jeq botch /* oops! */ 55 movl sp@(8),d0 /* grab return value */ 56 jne ok /* non-zero ok */ 57 moveq #1,d0 /* else make non-zero */ 58ok: 59 moveml a0@(28),#0x3CFC /* restore non-scratch regs */ 60 movl a0,sp@- /* let sigreturn */ 61 jsr _sigreturn /* finish for us */ 62 63botch: 64 jsr _longjmperror 65 stop #0 66