1 1.12 skrll /* $NetBSD: setjmp.S,v 1.12 2023/10/11 09:12:21 skrll Exp $ */ 2 1.1 eeh 3 1.1 eeh /* 4 1.1 eeh * Copyright (c) 1992, 1993 5 1.1 eeh * The Regents of the University of California. All rights reserved. 6 1.1 eeh * 7 1.1 eeh * This software was developed by the Computer Systems Engineering group 8 1.1 eeh * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 9 1.1 eeh * contributed to Berkeley. 10 1.1 eeh * 11 1.1 eeh * Redistribution and use in source and binary forms, with or without 12 1.1 eeh * modification, are permitted provided that the following conditions 13 1.1 eeh * are met: 14 1.1 eeh * 1. Redistributions of source code must retain the above copyright 15 1.1 eeh * notice, this list of conditions and the following disclaimer. 16 1.1 eeh * 2. Redistributions in binary form must reproduce the above copyright 17 1.1 eeh * notice, this list of conditions and the following disclaimer in the 18 1.1 eeh * documentation and/or other materials provided with the distribution. 19 1.5 agc * 3. Neither the name of the University nor the names of its contributors 20 1.1 eeh * may be used to endorse or promote products derived from this software 21 1.1 eeh * without specific prior written permission. 22 1.1 eeh * 23 1.1 eeh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 1.1 eeh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 1.1 eeh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 1.1 eeh * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 1.1 eeh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 1.1 eeh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 1.1 eeh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 1.1 eeh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 1.1 eeh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 1.1 eeh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 1.1 eeh * SUCH DAMAGE. 34 1.1 eeh * 35 1.1 eeh * from: Header: setjmp.s,v 1.2 92/06/25 03:18:43 torek Exp 36 1.1 eeh */ 37 1.1 eeh 38 1.3 eeh #define _LOCORE 39 1.1 eeh #include <machine/asm.h> 40 1.3 eeh #include <machine/frame.h> 41 1.1 eeh #if defined(LIBC_SCCS) && !defined(lint) 42 1.1 eeh #if 0 43 1.1 eeh .asciz "@(#)setjmp.s 8.1 (Berkeley) 6/4/93" 44 1.1 eeh #else 45 1.12 skrll RCSID("$NetBSD: setjmp.S,v 1.12 2023/10/11 09:12:21 skrll Exp $") 46 1.1 eeh #endif 47 1.1 eeh #endif /* LIBC_SCCS and not lint */ 48 1.1 eeh 49 1.1 eeh /* 50 1.7 christos * C library -- setjmp 51 1.1 eeh * 52 1.7 christos * __longjmp14(a,v) 53 1.1 eeh * will generate a "return(v)" from 54 1.1 eeh * the last call to 55 1.1 eeh * setjmp(a) 56 1.1 eeh * by restoring registers from the stack, 57 1.1 eeh * and a struct sigcontext, see <signal.h> 58 1.1 eeh */ 59 1.1 eeh 60 1.1 eeh #include "SYS.h" 61 1.1 eeh 62 1.7 christos .register %g2,#ignore 63 1.7 christos .register %g3,#ignore 64 1.7 christos .register %g6,#ignore 65 1.7 christos 66 1.7 christos ENTRY(__setjmp14) 67 1.7 christos save %sp, -CC64FSZ, %sp 68 1.7 christos 69 1.7 christos /* save globals into locals */ 70 1.7 christos mov %g1, %l1 71 1.7 christos mov %g2, %l2 72 1.7 christos mov %g3, %l3 73 1.7 christos mov %g4, %l4 74 1.7 christos mov %g5, %l5 75 1.7 christos mov %g6, %l6 76 1.7 christos mov %g7, %l7 77 1.7 christos 78 1.10 joerg #ifdef __PIC__ 79 1.7 christos PIC_PROLOGUE(%i1, %o4) 80 1.7 christos #endif 81 1.7 christos 82 1.7 christos /* now get sigmask and onstack flag */ 83 1.7 christos add %i0, 0x38, %o2 /* build sigcontext in [%o2]->sc.sc_mask */ 84 1.12 skrll mov 0, %o0 /* 0 - is ignored. */ 85 1.12 skrll /* sigprocmask(0, (sigset_t *)NULL, (sigset_t *)a) */ 86 1.10 joerg #if __PIC__ - 0 >= 2 87 1.7 christos set _C_LABEL(__sigprocmask14), %o4 88 1.7 christos ldx [%i1 + %o4], %g2 89 1.10 joerg call %g2 90 1.10 joerg #elif __PIC__ - 0 >= 1 91 1.7 christos ldx [%i1 + _C_LABEL(__sigprocmask14)], %g2 92 1.7 christos call %g2 93 1.7 christos #else 94 1.7 christos call _C_LABEL(__sigprocmask14) 95 1.7 christos #endif 96 1.7 christos clr %o1 97 1.7 christos 98 1.3 eeh clr %o0 /* sigstack(NULL, &foo) */ 99 1.10 joerg #if __PIC__ - 0 >= 2 100 1.7 christos set _C_LABEL(__sigaltstack14), %o4 101 1.7 christos ldx [%i1 + %o4], %g2 102 1.10 joerg call %g2 103 1.10 joerg #elif __PIC__ - 0 >= 1 104 1.7 christos ldx [%i1 + _C_LABEL(__sigaltstack14)], %g2 105 1.7 christos call %g2 106 1.7 christos #else 107 1.7 christos call _C_LABEL(__sigaltstack14) 108 1.7 christos #endif 109 1.7 christos add %i0, 8, %o1 /* (foo being part of the sigcontext we're overwriting) */ 110 1.11 skrll 111 1.7 christos lduw [%i0 + 8 + 0x10], %o0 /* foo.ss_flags */ 112 1.7 christos and %o0, 1, %o1 /* onstack = foo.ss_flags & SS_ONSTACK; */ 113 1.7 christos st %o1, [%i0 + 0x00] /* sc.sc_onstack = current onstack; */ 114 1.7 christos 115 1.7 christos /* store essential state */ 116 1.7 christos stx %fp, [%i0 + 0x08] /* sc.sc_sp = sp */ 117 1.7 christos add %i7, 8, %o0 118 1.7 christos stx %o0, [%i0 + 0x10] /* sc.sc_pc = return_pc */ 119 1.7 christos stx %g0, [%i0 + 0x20] /* sc.sc_tstate = (clean ccr) */ 120 1.7 christos stx %l1, [%i0 + 0x28] /* sc.sc_g1 */ 121 1.7 christos stx %l2, [%i0 + 0x30] /* sc.sc_o0, set in longjmp, use as %g2 */ 122 1.8 martin /* 0x38: 4x32bit */ /* sc.sc_mask was already saved above */ 123 1.7 christos 124 1.7 christos /* save additional registers needed to fill a complete mcontext */ 125 1.9 martin stx %l3, [%i0 + 0x48] /* adjust asserts in longjmp.c */ 126 1.9 martin stx %l6, [%i0 + 0x50] /* if you change any of these */ 127 1.9 martin stx %l7, [%i0 + 0x58] /* offsets! */ 128 1.1 eeh 129 1.7 christos ret /* return 0 */ 130 1.7 christos restore %g0, 0, %o0 131