setjmp.S revision 1.9
11.9Sitohy/* $NetBSD: setjmp.S,v 1.9 1999/10/18 03:22:14 itohy Exp $ */ 21.5Sthorpej 31.1Spaulus/*- 41.1Spaulus * Copyright (c) 1990 The Regents of the University of California. 51.1Spaulus * All rights reserved. 61.1Spaulus * 71.1Spaulus * This code is derived from software contributed to Berkeley by 81.1Spaulus * the Systems Programming Group of the University of Utah Computer 91.1Spaulus * Science Department. 101.1Spaulus * 111.1Spaulus * Redistribution and use in source and binary forms, with or without 121.1Spaulus * modification, are permitted provided that the following conditions 131.1Spaulus * are met: 141.1Spaulus * 1. Redistributions of source code must retain the above copyright 151.1Spaulus * notice, this list of conditions and the following disclaimer. 161.1Spaulus * 2. Redistributions in binary form must reproduce the above copyright 171.1Spaulus * notice, this list of conditions and the following disclaimer in the 181.1Spaulus * documentation and/or other materials provided with the distribution. 191.1Spaulus * 3. All advertising materials mentioning features or use of this software 201.1Spaulus * must display the following acknowledgement: 211.1Spaulus * This product includes software developed by the University of 221.1Spaulus * California, Berkeley and its contributors. 231.1Spaulus * 4. Neither the name of the University nor the names of its contributors 241.1Spaulus * may be used to endorse or promote products derived from this software 251.1Spaulus * without specific prior written permission. 261.1Spaulus * 271.1Spaulus * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 281.1Spaulus * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 291.1Spaulus * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 301.1Spaulus * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 311.1Spaulus * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 321.1Spaulus * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 331.1Spaulus * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 341.1Spaulus * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 351.1Spaulus * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 361.1Spaulus * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 371.1Spaulus * SUCH DAMAGE. 381.1Spaulus */ 391.1Spaulus 401.6Sthorpej#include <machine/asm.h> 411.5Sthorpej 421.1Spaulus#if defined(LIBC_SCCS) && !defined(lint) 431.5Sthorpej#if 0 441.5Sthorpej RCSID("from: @(#)setjmp.s 5.1 (Berkeley) 5/12/90") 451.5Sthorpej#else 461.9Sitohy RCSID("$NetBSD: setjmp.S,v 1.9 1999/10/18 03:22:14 itohy Exp $") 471.5Sthorpej#endif 481.1Spaulus#endif /* LIBC_SCCS and not lint */ 491.1Spaulus 501.1Spaulus/* 511.1Spaulus * C library -- setjmp, longjmp 521.1Spaulus * 531.1Spaulus * longjmp(a,v) 541.1Spaulus * will generate a "return(v)" from 551.1Spaulus * the last call to 561.1Spaulus * setjmp(a) 571.1Spaulus * by restoring registers from the stack, 581.1Spaulus * and a struct sigcontext, see <signal.h> 591.1Spaulus */ 601.1Spaulus 611.1SpaulusENTRY(setjmp) 621.9Sitohy lea sp@(-12),sp /* space for sigstack args/rvals */ 631.1Spaulus clrl sp@ /* don't change it... */ 641.1Spaulus movl sp,sp@(4) /* ...but return the current val */ 651.9Sitohy jbsr PIC_PLT(_C_LABEL(__sigaltstack14)) 661.9Sitohy /* note: flags returned in sp@(8) */ 671.1Spaulus clrl sp@ /* don't change mask, just return */ 681.9Sitohy jbsr PIC_PLT(_C_LABEL(sigblock)) /* old value */ 691.2Schopps movl sp@(8),d1 /* old flags value */ 701.2Schopps andl #1,d1 /* extract onstack flag */ 711.9Sitohy lea sp@(12),sp 721.1Spaulus movl sp@(4),a0 /* save area pointer */ 731.1Spaulus movl d1,a0@+ /* save old onstack value */ 741.1Spaulus movl d0,a0@+ /* save old signal mask */ 751.1Spaulus lea sp@(4),a1 /* adjust saved SP since we won't rts */ 761.1Spaulus movl a1,a0@+ /* save old SP */ 771.1Spaulus movl a6,a0@+ /* save old FP */ 781.1Spaulus clrl a0@+ /* no AP */ 791.1Spaulus movl sp@,a0@+ /* save old PC */ 801.1Spaulus clrl a0@+ /* clean PS */ 811.1Spaulus moveml #0x3CFC,a0@ /* save remaining non-scratch regs */ 821.1Spaulus clrl d0 /* return 0 */ 831.1Spaulus rts 841.1Spaulus 851.1SpaulusENTRY(longjmp) 861.1Spaulus movl sp@(4),a0 /* save area pointer */ 871.1Spaulus tstl a0@(8) /* ensure non-zero SP */ 881.1Spaulus jeq botch /* oops! */ 891.1Spaulus movl sp@(8),d0 /* grab return value */ 901.1Spaulus jne ok /* non-zero ok */ 911.1Spaulus moveq #1,d0 /* else make non-zero */ 921.1Spaulusok: 931.1Spaulus moveml a0@(28),#0x3CFC /* restore non-scratch regs */ 941.4Smycroft movl a0,sp@- /* let sigreturn */ 951.9Sitohy jbsr PIC_PLT(_C_LABEL(sigreturn)) /* finish for us */ 961.1Spaulus 971.1Spaulusbotch: 981.9Sitohy jbsr PIC_PLT(_C_LABEL(longjmperror)) 991.1Spaulus stop #0 100