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 are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18#if defined(LIBC_SCCS) && !defined(lint) 19 .asciz "@(#)setjmp.s 5.8 (Berkeley) 06/27/88" 20#endif /* LIBC_SCCS and not lint */ 21 22/* 23 * C library -- setjmp, longjmp 24 * 25 * longjmp(a,v) 26 * will generate a "return(v)" from 27 * the last call to 28 * setjmp(a) 29 * by restoring registers from the stack, 30 * and a struct sigcontext, see <signal.h> 31 */ 32 33#include "DEFS.h" 34 35ENTRY(setjmp, R6) 36 movl 4(ap),r6 # construct sigcontext 37 subl2 $8,sp # space for current struct sigstack 38 pushl sp # get current values 39 pushl $0 # no new values 40 calls $3,_sigstack # pop args plus signal stack value 41 movl (sp)+,(r6)+ # save onsigstack status of caller 42 pushl $0 43 calls $1,_sigblock # get signal mask 44 movl r0,(r6)+ # save signal mask of caller 45 movl (ap),r0 46 moval 4(ap)[r0],(r6)+ # save sp of caller 47 movl 12(fp),(r6)+ # save frame pointer of caller 48 movl 8(fp),(r6)+ # save argument pointer of caller 49 movl 16(fp),(r6)+ # save pc of caller 50 movpsl (r6) # save psl of caller 51 movw 4(fp),(r6) 52 clrl r0 53 ret 54 55ENTRY(longjmp, 0) 56 movl 8(ap),r0 # return(v) 57 movl 4(ap),r1 # fetch buffer 58 tstl 12(r1) 59 beql botch 60loop: 61 cmpl 12(r1),fp # are we there yet? 62 beql done 63 blssu botch 64 moval 20(fp),r2 65 blbc 6(fp),1f # was r0 saved? 66 movl r0,(r2)+ 671: 68 bbc $1,6(fp),2f # was r1 saved? 69 movl r1,(r2) 702: 71 movl $loop,16(fp) 72 ret # pop another frame 73 74done: 75 pushl r1 # pointer to sigcontext 76 calls $1,_sigreturn # restore previous context 77 # we should never return 78botch: 79 calls $0,_longjmperror 80 halt 81