1*2fe8fb19SBen Gras/* $NetBSD: __setjmp14.S,v 1.5 2008/04/28 20:22:55 martin Exp $ */ 2*2fe8fb19SBen Gras 3*2fe8fb19SBen Gras/*- 4*2fe8fb19SBen Gras * Copyright (c) 2002 The NetBSD Foundation, Inc. 5*2fe8fb19SBen Gras * All rights reserved. 6*2fe8fb19SBen Gras * 7*2fe8fb19SBen Gras * This code is derived from software contributed to The NetBSD Foundation 8*2fe8fb19SBen Gras * by Matthew Fredette. 9*2fe8fb19SBen Gras * 10*2fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without 11*2fe8fb19SBen Gras * modification, are permitted provided that the following conditions 12*2fe8fb19SBen Gras * are met: 13*2fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright 14*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer. 15*2fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 16*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the 17*2fe8fb19SBen Gras * documentation and/or other materials provided with the distribution. 18*2fe8fb19SBen Gras * 19*2fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20*2fe8fb19SBen Gras * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21*2fe8fb19SBen Gras * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22*2fe8fb19SBen Gras * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23*2fe8fb19SBen Gras * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24*2fe8fb19SBen Gras * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25*2fe8fb19SBen Gras * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26*2fe8fb19SBen Gras * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27*2fe8fb19SBen Gras * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28*2fe8fb19SBen Gras * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29*2fe8fb19SBen Gras * POSSIBILITY OF SUCH DAMAGE. 30*2fe8fb19SBen Gras */ 31*2fe8fb19SBen Gras 32*2fe8fb19SBen Gras#include <machine/asm.h> 33*2fe8fb19SBen Gras/* XXX fredette - this is awful */ 34*2fe8fb19SBen Gras#define _LOCORE 35*2fe8fb19SBen Gras#include <machine/frame.h> 36*2fe8fb19SBen Gras#undef _LOCORE 37*2fe8fb19SBen Gras#include <machine/psl.h> 38*2fe8fb19SBen Gras 39*2fe8fb19SBen Gras#if defined(LIBC_SCCS) && !defined(lint) 40*2fe8fb19SBen Gras RCSID("$NetBSD: __setjmp14.S,v 1.5 2008/04/28 20:22:55 martin Exp $") 41*2fe8fb19SBen Gras#endif /* LIBC_SCCS and not lint */ 42*2fe8fb19SBen Gras 43*2fe8fb19SBen Gras/* 44*2fe8fb19SBen Gras * C library -- setjmp, longjmp 45*2fe8fb19SBen Gras * 46*2fe8fb19SBen Gras * longjmp(a,v) 47*2fe8fb19SBen Gras * will generate a "return(v)" from 48*2fe8fb19SBen Gras * the last call to 49*2fe8fb19SBen Gras * setjmp(a) 50*2fe8fb19SBen Gras * by restoring registers from the stack, 51*2fe8fb19SBen Gras * and a struct sigcontext, see <signal.h> 52*2fe8fb19SBen Gras */ 53*2fe8fb19SBen Gras 54*2fe8fb19SBen GrasENTRY(__setjmp14,0) 55*2fe8fb19SBen Gras /* Finish our stack frame. */ 56*2fe8fb19SBen Gras stw %rp, HPPA_FRAME_CRP(%sp) 57*2fe8fb19SBen Gras stw %arg0, HPPA_FRAME_ARG(0)(%sp) 58*2fe8fb19SBen Gras 59*2fe8fb19SBen Gras /* A sigcontext is at the beginning of our jmp_buf. */ 60*2fe8fb19SBen Gras stw %r0, 4(%arg0) ; unused word (old style signal mask) 61*2fe8fb19SBen Gras stw %sp, 8(%arg0) ; sc.sc_sp = %sp 62*2fe8fb19SBen Gras stw %r0, 16(%arg0) ; sc.sc_ap = NULL 63*2fe8fb19SBen Gras mfsp %sr0, %r1 64*2fe8fb19SBen Gras stw %r1, 20(%arg0) ; sc.sc_pcsqh = %sr0 65*2fe8fb19SBen Gras stw %rp, 24(%arg0) ; sc.sc_pcoqh = %rp 66*2fe8fb19SBen Gras stw %r1, 28(%arg0) ; sc.sc_pcsqh = %sr0 67*2fe8fb19SBen Gras ldo 4(%rp), %r1 68*2fe8fb19SBen Gras stw %r1, 32(%arg0) ; sc.sc_pcoqt = %rp + 4 69*2fe8fb19SBen Gras#define PSW_MBS (PSW_C|PSW_Q|PSW_P|PSW_D|PSW_I) 70*2fe8fb19SBen Gras ldil L%PSW_MBS, %r1 71*2fe8fb19SBen Gras ldo R%PSW_MBS(%r1), %r1 72*2fe8fb19SBen Gras stw %r1, 36(%arg0) ; set sc.sc_ps 73*2fe8fb19SBen Gras 74*2fe8fb19SBen Gras /* We store all callee-saved registers after the sigcontext. */ 75*2fe8fb19SBen Gras ldo 56(%arg0), %r1 76*2fe8fb19SBen Gras stwm %r3, 4(%r1) 77*2fe8fb19SBen Gras stwm %r4, 4(%r1) 78*2fe8fb19SBen Gras stwm %r5, 4(%r1) 79*2fe8fb19SBen Gras stwm %r6, 4(%r1) 80*2fe8fb19SBen Gras stwm %r7, 4(%r1) 81*2fe8fb19SBen Gras stwm %r8, 4(%r1) 82*2fe8fb19SBen Gras stwm %r9, 4(%r1) 83*2fe8fb19SBen Gras stwm %r10, 4(%r1) 84*2fe8fb19SBen Gras stwm %r11, 4(%r1) 85*2fe8fb19SBen Gras stwm %r12, 4(%r1) 86*2fe8fb19SBen Gras stwm %r13, 4(%r1) 87*2fe8fb19SBen Gras stwm %r14, 4(%r1) 88*2fe8fb19SBen Gras stwm %r15, 4(%r1) 89*2fe8fb19SBen Gras stwm %r16, 4(%r1) 90*2fe8fb19SBen Gras stwm %r17, 4(%r1) 91*2fe8fb19SBen Gras stwm %r18, 4(%r1) 92*2fe8fb19SBen Gras 93*2fe8fb19SBen Gras /* 94*2fe8fb19SBen Gras * Start the stack frame for the calls we will make. 95*2fe8fb19SBen Gras * The minimum frame is 48 bytes, but the stack must 96*2fe8fb19SBen Gras * always be 64-byte aligned; we use the top 4 bytes 97*2fe8fb19SBen Gras * to save our caller's %r3, and the following 12 bytes 98*2fe8fb19SBen Gras * as the stack_t for our sigaltstack call. 99*2fe8fb19SBen Gras * XXX - this assumes that sizeof(stack_t) <= 12 100*2fe8fb19SBen Gras */ 101*2fe8fb19SBen Gras copy %r3, %r1 102*2fe8fb19SBen Gras copy %sp, %r3 103*2fe8fb19SBen Gras stwm %r1, HPPA_FRAME_SIZE(%sp) 104*2fe8fb19SBen Gras 105*2fe8fb19SBen Gras /* Get signal stack info. */ 106*2fe8fb19SBen Gras ldo 4(%r3), %arg1 ; set up oss 107*2fe8fb19SBen Gras bl __sigaltstack14, %rp 108*2fe8fb19SBen Gras copy %r0, %arg0 ; set up ss 109*2fe8fb19SBen Gras 110*2fe8fb19SBen Gras /* Recover our jmp_buf and extract SS_ONSTACK */ 111*2fe8fb19SBen Gras ldw HPPA_FRAME_ARG(0)(%r3), %arg0 112*2fe8fb19SBen Gras ldw 12(%r3), %r1 ; get ss_flags 113*2fe8fb19SBen Gras ldi 1, %r20 ; SS_ONSTACK 114*2fe8fb19SBen Gras and %r1, %r20, %r1 115*2fe8fb19SBen Gras stw %r1, 0(%arg0) ; sc.sc_onstack 116*2fe8fb19SBen Gras 117*2fe8fb19SBen Gras /* Get the signal mask. */ 118*2fe8fb19SBen Gras ldo 40(%arg0), %arg2 ; oset = &sc.sc_mask 119*2fe8fb19SBen Gras copy %r0, %arg1 ; set = NULL 120*2fe8fb19SBen Gras bl __sigprocmask14, %rp 121*2fe8fb19SBen Gras copy %r0, %arg0 ; action = 0 <ignored> 122*2fe8fb19SBen Gras 123*2fe8fb19SBen Gras /* Return 0. */ 124*2fe8fb19SBen Gras ldo HPPA_FRAME_SIZE(%r3),%sp 125*2fe8fb19SBen Gras ldwm -HPPA_FRAME_SIZE(%sp),%r3 126*2fe8fb19SBen Gras ldw HPPA_FRAME_CRP(%sp), %rp 127*2fe8fb19SBen Gras bv %r0(%rp) 128*2fe8fb19SBen Gras copy %r0, %ret0 129*2fe8fb19SBen GrasEXIT(__setjmp14) 130*2fe8fb19SBen Gras 131*2fe8fb19SBen Gras .end 132