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