1107571Sgrehan/*-
2107571Sgrehan * Copyright (c) 2002 Peter Grehan.
3107571Sgrehan * All rights reserved.
4107571Sgrehan *
5107571Sgrehan * Redistribution and use in source and binary forms, with or without
6107571Sgrehan * modification, are permitted provided that the following conditions
7107571Sgrehan * are met:
8107571Sgrehan * 1. Redistributions of source code must retain the above copyright
9107571Sgrehan *    notice, this list of conditions and the following disclaimer.
10107571Sgrehan * 2. Redistributions in binary form must reproduce the above copyright
11107571Sgrehan *    notice, this list of conditions and the following disclaimer in the
12107571Sgrehan *    documentation and/or other materials provided with the distribution.
13107571Sgrehan *
14107571Sgrehan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15107571Sgrehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16107571Sgrehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17107571Sgrehan * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18107571Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19107571Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20107571Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21107571Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22107571Sgrehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23107571Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24107571Sgrehan * SUCH DAMAGE.
25107571Sgrehan */
26107571Sgrehan/*      $NetBSD: sigsetjmp.S,v 1.4 1998/10/03 12:30:38 tsubai Exp $     */
27107571Sgrehan
28107571Sgrehan#include <machine/asm.h>
29107571Sgrehan__FBSDID("$FreeBSD$");
30107571Sgrehan
31107571Sgrehan/*
32107571Sgrehan * C library -- sigsetjmp, siglongjmp
33107571Sgrehan *
34107571Sgrehan *      siglongjmp(a,v)
35107571Sgrehan * will generate a "return(v?v:1)" from the last call to
36107571Sgrehan *      sigsetjmp(a, savemask)
37107571Sgrehan * by restoring registers from the stack.
38107571Sgrehan * The previous signal state is restored if savemask is non-zero
39107571Sgrehan *
40107571Sgrehan * jmpbuf layout:
41107571Sgrehan *     +------------+
42107571Sgrehan *     |  savemask  |
43107571Sgrehan *     +------------+
44107571Sgrehan *     | sig state  |
45107571Sgrehan *     |            |
46107571Sgrehan *     | (4 words)  |
47107571Sgrehan *     |            |
48107571Sgrehan *     +------------+
49107571Sgrehan *     | saved regs |
50107571Sgrehan *     |    ...     |
51107571Sgrehan */
52107571Sgrehan
53107571Sgrehan
54107571Sgrehan#include <sys/syscall.h>
55107571Sgrehan
56107571SgrehanENTRY(sigsetjmp)
57107571Sgrehan	mr	%r6,%r3
58107571Sgrehan	stw	%r4,0(%r3)
59107571Sgrehan	or.	%r7,%r4,%r4
60107571Sgrehan	beq	1f
61107571Sgrehan	li	%r3,1			/* SIG_BLOCK, but doesn't matter */
62107571Sgrehan					/*            since set == NULL  */
63107571Sgrehan	li	%r4,0			/* set = NULL */
64107571Sgrehan	mr	%r5,%r6			/* &oset */
65107571Sgrehan	addi	%r5,%r5,4
66107571Sgrehan	li	%r0, SYS_sigprocmask   /* sigprocmask(SIG_BLOCK, NULL, &oset)*/
67107571Sgrehan	sc				/* assume no error       XXX */
68107571Sgrehan1:
69107571Sgrehan	mflr	%r11
70107571Sgrehan	mfcr	%r12
71107571Sgrehan	mr	%r10,%r1
72107571Sgrehan	mr	%r9,%r2
73107571Sgrehan	stmw	%r9,20(%r6)
74107571Sgrehan	li	%r3,0
75107571Sgrehan	blr
76107571Sgrehan
77107571SgrehanENTRY(siglongjmp)
78107571Sgrehan	lmw	%r9,20(%r3)
79107571Sgrehan	lwz	%r7,0(%r3)
80107571Sgrehan	mr	%r6,%r4
81107571Sgrehan	mtlr	%r11
82107571Sgrehan	mtcr	%r12
83107571Sgrehan	mr	%r1,%r10
84107571Sgrehan	or.	%r7,%r7,%r7
85107571Sgrehan	beq	1f
86107571Sgrehan	mr	%r4,%r3
87107571Sgrehan	li	%r3,3			/* SIG_SETMASK */
88107571Sgrehan	addi	%r4,%r4,4		/* &set */
89107571Sgrehan	li	%r5,0			/* oset = NULL */
90107571Sgrehan	li	%r0,SYS_sigprocmask	/* sigprocmask(SIG_SET, &set, NULL) */
91107571Sgrehan	sc				/* assume no error       XXX */
92107571Sgrehan1:
93107571Sgrehan	or.	%r3,%r6,%r6
94107571Sgrehan	bnelr
95107571Sgrehan	li	%r3,1
96107571Sgrehan	blr
97217398Skib
98217398Skib	.section .note.GNU-stack,"",%progbits
99