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