1/* $NetBSD: _setjmp.S,v 1.1 2002/06/06 20:31:21 fredette Exp $ */ 2 3/*- 4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Matthew Fredette. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39#include <machine/asm.h> 40/* XXX fredette - this is awful */ 41#define _LOCORE 42#include <machine/frame.h> 43#undef _LOCORE 44 45#if defined(LIBC_SCCS) && !defined(lint) 46 RCSID("$NetBSD: _setjmp.S,v 1.1 2002/06/06 20:31:21 fredette Exp $") 47#endif /* LIBC_SCCS and not lint */ 48 49/* 50 * C library -- setjmp, longjmp 51 * 52 * longjmp(a,v) 53 * will generate a "return(v)" from 54 * the last call to 55 * setjmp(a) 56 * by restoring registers from the stack, 57 * and a struct sigcontext, see <signal.h> 58 */ 59 60ENTRY(_setjmp,0) 61 /* A sigcontext is at the beginning of our jmp_buf. */ 62 stw %r0, 0(%arg0) ; no onstack 63 stw %r0, 4(%arg0) ; unused word (old style signal mask) 64 stw %sp, 8(%arg0) ; sc.sc_sp = %sp 65 stw %r0, 16(%arg0) ; sc.sc_ap = NULL 66 mfsp %sr0, %r1 67 stw %r1, 20(%arg0) ; sc.sc_pcsqh = %sr0 68 stw %rp, 24(%arg0) ; sc.sc_pcoqh = %rp 69 stw %r1, 28(%arg0) ; sc.sc_pcsqh = %sr0 70 ldo 4(%rp), %r1 71 stw %r1, 32(%arg0) ; sc.sc_pcoqt = %rp + 4 72 stw %r0, 36(%arg0) ; set sc.sc_ps 73 74 /* We store all callee-saved registers after the sigcontext. */ 75 ldo 56(%arg0), %r1 76 stwm %r3, 4(%r1) 77 stwm %r4, 4(%r1) 78 stwm %r5, 4(%r1) 79 stwm %r6, 4(%r1) 80 stwm %r7, 4(%r1) 81 stwm %r8, 4(%r1) 82 stwm %r9, 4(%r1) 83 stwm %r10, 4(%r1) 84 stwm %r11, 4(%r1) 85 stwm %r12, 4(%r1) 86 stwm %r13, 4(%r1) 87 stwm %r14, 4(%r1) 88 stwm %r15, 4(%r1) 89 stwm %r16, 4(%r1) 90 stwm %r17, 4(%r1) 91 stwm %r18, 4(%r1) 92 93 /* Return 0. */ 94 bv %r0(%rp) 95 copy %r0, %ret0 96EXIT(_setjmp) 97 98ENTRY(_longjmp,0) 99 ldw 8(%arg0), %r1 ; ensure non-zero SP 100 combt,=,n %r0, %r1, botch ; oops! 101 add,<> %r0, %arg1, %ret0 ; ensure return value non-zero 102 ldi 1, %ret0 103 104 /* restore callee-saved registers */ 105 ldo 56(%arg0), %r1 106 ldwm 4(%r1), %r3 107 ldwm 4(%r1), %r4 108 ldwm 4(%r1), %r5 109 ldwm 4(%r1), %r6 110 ldwm 4(%r1), %r7 111 ldwm 4(%r1), %r8 112 ldwm 4(%r1), %r9 113 ldwm 4(%r1), %r10 114 ldwm 4(%r1), %r11 115 ldwm 4(%r1), %r12 116 ldwm 4(%r1), %r13 117 ldwm 4(%r1), %r14 118 ldwm 4(%r1), %r15 119 ldwm 4(%r1), %r16 120 ldwm 4(%r1), %r17 121 ldwm 4(%r1), %r18 122 123 /* restore the rest */ 124 ldw 8(%arg0), %sp 125 ldw 24(%arg0), %rp 126 bv %r0(%rp) 127 nop 128botch 129 bl longjmperror, %rp 130 nop 131EXIT(_longjmp) 132 133 .end 134