setjmp.S revision 231044
167754Smsmith/*- 267754Smsmith * Copyright (c) 2002 Peter Grehan. 377424Smsmith * All rights reserved. 467754Smsmith * 567754Smsmith * Redistribution and use in source and binary forms, with or without 667754Smsmith * modification, are permitted provided that the following conditions 767754Smsmith * are met: 867754Smsmith * 1. Redistributions of source code must retain the above copyright 967754Smsmith * notice, this list of conditions and the following disclaimer. 1067754Smsmith * 2. Redistributions in binary form must reproduce the above copyright 11193267Sjkim * notice, this list of conditions and the following disclaimer in the 1270243Smsmith * documentation and/or other materials provided with the distribution. 1367754Smsmith * 1467754Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1567754Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1667754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1767754Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1867754Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1967754Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2067754Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2167754Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2267754Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2367754Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2467754Smsmith * SUCH DAMAGE. 2567754Smsmith */ 2667754Smsmith/* $NetBSD: setjmp.S,v 1.3 1998/10/03 12:30:38 tsubai Exp $ */ 2767754Smsmith 2867754Smsmith#include <machine/asm.h> 2967754Smsmith__FBSDID("$FreeBSD: head/lib/libc/powerpc/gen/setjmp.S 231044 2012-02-05 20:04:43Z andreast $"); 3067754Smsmith 3167754Smsmith#include <sys/syscall.h> 3267754Smsmith 3367754Smsmith/* 3467754Smsmith * C library -- setjmp, longjmp 3567754Smsmith * 3667754Smsmith * longjmp(a,v) 3767754Smsmith * will generate a "return(v?v:1)" from the last call to 3867754Smsmith * setjmp(a) 3967754Smsmith * by restoring registers from the stack. 4067754Smsmith * The previous signal state is restored. 4167754Smsmith * 4267754Smsmith * jmpbuf layout: 4367754Smsmith * +------------+ 4467754Smsmith * | unused | 4567754Smsmith * +------------+ 4667754Smsmith * | sig state | 4767754Smsmith * | | 4867754Smsmith * | (4 words) | 4967754Smsmith * | | 5067754Smsmith * +------------+ 5167754Smsmith * | saved regs | 5267754Smsmith * | ... | 5367754Smsmith */ 5467754Smsmith 5567754SmsmithENTRY(setjmp) 5667754Smsmith mr %r6,%r3 5767754Smsmith li %r3,1 /* SIG_BLOCK, but doesn't matter */ 5867754Smsmith /* since set == NULL */ 5967754Smsmith li %r4,0 /* set = NULL */ 6067754Smsmith mr %r5,%r6 /* &oset */ 6167754Smsmith addi %r5,%r5,4 6267754Smsmith li %r0, SYS_sigprocmask /*sigprocmask(SIG_BLOCK, NULL, &oset)*/ 6367754Smsmith sc /*assume no error XXX */ 6467754Smsmith mflr %r11 /* r11 <- link reg */ 6567754Smsmith mfcr %r12 /* r12 <- condition reg */ 6667754Smsmith mr %r10,%r1 /* r10 <- stackptr */ 6767754Smsmith mr %r9,%r2 /* r9 <- global ptr */ 6867754Smsmith stmw %r9,20(%r6) 6967754Smsmith li %r3,0 /* return (0) */ 7067754Smsmith blr 7167754Smsmith 7267754Smsmith WEAK_REFERENCE(CNAME(__longjmp), longjmp) 7367754SmsmithENTRY(__longjmp) 7467754Smsmith lmw %r9,20(%r3) /* restore regs */ 7567754Smsmith mr %r6,%r4 /* save val param */ 7667754Smsmith mtlr %r11 /* r11 -> link reg */ 7767754Smsmith mtcr %r12 /* r12 -> condition reg */ 7867754Smsmith mr %r2,%r9 /* r9 -> global ptr */ 7967754Smsmith mr %r1,%r10 /* r10 -> stackptr */ 8067754Smsmith mr %r4,%r3 8167754Smsmith li %r3,3 /* SIG_SETMASK */ 8267754Smsmith addi %r4,%r4,4 /* &set */ 8367754Smsmith li %r5,0 /* oset = NULL */ 8467754Smsmith li %r0,SYS_sigprocmask /* sigprocmask(SIG_SET, &set, NULL) */ 8567754Smsmith sc /* assume no error XXX */ 8667754Smsmith or. %r3,%r6,%r6 8767754Smsmith bnelr 8867754Smsmith li %r3,1 8967754Smsmith blr 9067754Smsmith 9167754Smsmith .section .note.GNU-stack,"",%progbits 9267754Smsmith