1*2fe8fb19SBen Gras/* $NetBSD: _setjmp.S,v 1.4 2008/04/28 20:22:56 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 38*2fe8fb19SBen Gras#if defined(LIBC_SCCS) && !defined(lint) 39*2fe8fb19SBen Gras RCSID("$NetBSD: _setjmp.S,v 1.4 2008/04/28 20:22:56 martin Exp $") 40*2fe8fb19SBen Gras#endif /* LIBC_SCCS and not lint */ 41*2fe8fb19SBen Gras 42*2fe8fb19SBen Gras/* 43*2fe8fb19SBen Gras * C library -- setjmp, longjmp 44*2fe8fb19SBen Gras * 45*2fe8fb19SBen Gras * longjmp(a,v) 46*2fe8fb19SBen Gras * will generate a "return(v)" from 47*2fe8fb19SBen Gras * the last call to 48*2fe8fb19SBen Gras * setjmp(a) 49*2fe8fb19SBen Gras * by restoring registers from the stack, 50*2fe8fb19SBen Gras * and a struct sigcontext, see <signal.h> 51*2fe8fb19SBen Gras */ 52*2fe8fb19SBen Gras 53*2fe8fb19SBen GrasENTRY(_setjmp,0) 54*2fe8fb19SBen Gras /* A sigcontext is at the beginning of our jmp_buf. */ 55*2fe8fb19SBen Gras stw %r0, 0(%arg0) ; no onstack 56*2fe8fb19SBen Gras stw %r0, 4(%arg0) ; unused word (old style signal mask) 57*2fe8fb19SBen Gras stw %sp, 8(%arg0) ; sc.sc_sp = %sp 58*2fe8fb19SBen Gras stw %r0, 16(%arg0) ; sc.sc_ap = NULL 59*2fe8fb19SBen Gras mfsp %sr0, %r1 60*2fe8fb19SBen Gras stw %r1, 20(%arg0) ; sc.sc_pcsqh = %sr0 61*2fe8fb19SBen Gras stw %rp, 24(%arg0) ; sc.sc_pcoqh = %rp 62*2fe8fb19SBen Gras stw %r1, 28(%arg0) ; sc.sc_pcsqh = %sr0 63*2fe8fb19SBen Gras ldo 4(%rp), %r1 64*2fe8fb19SBen Gras stw %r1, 32(%arg0) ; sc.sc_pcoqt = %rp + 4 65*2fe8fb19SBen Gras stw %r0, 36(%arg0) ; set sc.sc_ps 66*2fe8fb19SBen Gras 67*2fe8fb19SBen Gras /* We store all callee-saved registers after the sigcontext. */ 68*2fe8fb19SBen Gras ldo 56(%arg0), %r1 69*2fe8fb19SBen Gras stwm %r3, 4(%r1) 70*2fe8fb19SBen Gras stwm %r4, 4(%r1) 71*2fe8fb19SBen Gras stwm %r5, 4(%r1) 72*2fe8fb19SBen Gras stwm %r6, 4(%r1) 73*2fe8fb19SBen Gras stwm %r7, 4(%r1) 74*2fe8fb19SBen Gras stwm %r8, 4(%r1) 75*2fe8fb19SBen Gras stwm %r9, 4(%r1) 76*2fe8fb19SBen Gras stwm %r10, 4(%r1) 77*2fe8fb19SBen Gras stwm %r11, 4(%r1) 78*2fe8fb19SBen Gras stwm %r12, 4(%r1) 79*2fe8fb19SBen Gras stwm %r13, 4(%r1) 80*2fe8fb19SBen Gras stwm %r14, 4(%r1) 81*2fe8fb19SBen Gras stwm %r15, 4(%r1) 82*2fe8fb19SBen Gras stwm %r16, 4(%r1) 83*2fe8fb19SBen Gras stwm %r17, 4(%r1) 84*2fe8fb19SBen Gras stwm %r18, 4(%r1) 85*2fe8fb19SBen Gras 86*2fe8fb19SBen Gras /* Return 0. */ 87*2fe8fb19SBen Gras bv %r0(%rp) 88*2fe8fb19SBen Gras copy %r0, %ret0 89*2fe8fb19SBen GrasEXIT(_setjmp) 90*2fe8fb19SBen Gras 91*2fe8fb19SBen GrasENTRY(_longjmp,0) 92*2fe8fb19SBen Gras ldw 8(%arg0), %r1 ; ensure non-zero SP 93*2fe8fb19SBen Gras combt,=,n %r0, %r1, botch ; oops! 94*2fe8fb19SBen Gras add,<> %r0, %arg1, %ret0 ; ensure return value non-zero 95*2fe8fb19SBen Gras ldi 1, %ret0 96*2fe8fb19SBen Gras 97*2fe8fb19SBen Gras /* restore callee-saved registers */ 98*2fe8fb19SBen Gras ldo 56(%arg0), %r1 99*2fe8fb19SBen Gras ldwm 4(%r1), %r3 100*2fe8fb19SBen Gras ldwm 4(%r1), %r4 101*2fe8fb19SBen Gras ldwm 4(%r1), %r5 102*2fe8fb19SBen Gras ldwm 4(%r1), %r6 103*2fe8fb19SBen Gras ldwm 4(%r1), %r7 104*2fe8fb19SBen Gras ldwm 4(%r1), %r8 105*2fe8fb19SBen Gras ldwm 4(%r1), %r9 106*2fe8fb19SBen Gras ldwm 4(%r1), %r10 107*2fe8fb19SBen Gras ldwm 4(%r1), %r11 108*2fe8fb19SBen Gras ldwm 4(%r1), %r12 109*2fe8fb19SBen Gras ldwm 4(%r1), %r13 110*2fe8fb19SBen Gras ldwm 4(%r1), %r14 111*2fe8fb19SBen Gras ldwm 4(%r1), %r15 112*2fe8fb19SBen Gras ldwm 4(%r1), %r16 113*2fe8fb19SBen Gras ldwm 4(%r1), %r17 114*2fe8fb19SBen Gras ldwm 4(%r1), %r18 115*2fe8fb19SBen Gras 116*2fe8fb19SBen Gras /* restore the rest */ 117*2fe8fb19SBen Gras ldw 8(%arg0), %sp 118*2fe8fb19SBen Gras ldw 24(%arg0), %rp 119*2fe8fb19SBen Gras bv %r0(%rp) 120*2fe8fb19SBen Gras nop 121*2fe8fb19SBen Grasbotch: 122*2fe8fb19SBen Gras bl longjmperror, %rp 123*2fe8fb19SBen Gras nop 124*2fe8fb19SBen Gras bl abort, %rp 125*2fe8fb19SBen Gras nop 126*2fe8fb19SBen GrasEXIT(_longjmp) 127*2fe8fb19SBen Gras 128*2fe8fb19SBen Gras .end 129