xref: /minix3/lib/libc/arch/or1k/gen/_setjmp.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc/*	$NetBSD: _setjmp.S,v 1.1 2014/09/03 19:34:25 matt Exp $	*/
2*0a6a1f1dSLionel Sambuc
3*0a6a1f1dSLionel Sambuc/*-
4*0a6a1f1dSLionel Sambuc * Copyright (c) 2014 The NetBSD Foundation, Inc.
5*0a6a1f1dSLionel Sambuc * All rights reserved.
6*0a6a1f1dSLionel Sambuc *
7*0a6a1f1dSLionel Sambuc * This code is derived from software contributed to The NetBSD Foundation
8*0a6a1f1dSLionel Sambuc * by Matt Thomas of 3am Software Foundry.
9*0a6a1f1dSLionel Sambuc *
10*0a6a1f1dSLionel Sambuc * Redistribution and use in source and binary forms, with or without
11*0a6a1f1dSLionel Sambuc * modification, are permitted provided that the following conditions
12*0a6a1f1dSLionel Sambuc * are met:
13*0a6a1f1dSLionel Sambuc * 1. Redistributions of source code must retain the above copyright
14*0a6a1f1dSLionel Sambuc *    notice, this list of conditions and the following disclaimer.
15*0a6a1f1dSLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
16*0a6a1f1dSLionel Sambuc *    notice, this list of conditions and the following disclaimer in the
17*0a6a1f1dSLionel Sambuc *    documentation and/or other materials provided with the distribution.
18*0a6a1f1dSLionel Sambuc *
19*0a6a1f1dSLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*0a6a1f1dSLionel Sambuc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*0a6a1f1dSLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*0a6a1f1dSLionel Sambuc * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*0a6a1f1dSLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*0a6a1f1dSLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*0a6a1f1dSLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*0a6a1f1dSLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*0a6a1f1dSLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*0a6a1f1dSLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*0a6a1f1dSLionel Sambuc * POSSIBILITY OF SUCH DAMAGE.
30*0a6a1f1dSLionel Sambuc */
31*0a6a1f1dSLionel Sambuc
32*0a6a1f1dSLionel Sambuc#include <machine/asm.h>
33*0a6a1f1dSLionel Sambuc#include "assym.h"
34*0a6a1f1dSLionel Sambuc
35*0a6a1f1dSLionel Sambuc#if defined(LIBC_SCCS)
36*0a6a1f1dSLionel Sambuc__RCSID("$NetBSD: _setjmp.S,v 1.1 2014/09/03 19:34:25 matt Exp $")
37*0a6a1f1dSLionel Sambuc#endif
38*0a6a1f1dSLionel Sambuc
39*0a6a1f1dSLionel Sambuc/*
40*0a6a1f1dSLionel Sambuc * C library -- _setjmp, _longjmp
41*0a6a1f1dSLionel Sambuc *
42*0a6a1f1dSLionel Sambuc *	_longjmp(a,v)
43*0a6a1f1dSLionel Sambuc * will generate a "return(v?v:1)" from the last call to
44*0a6a1f1dSLionel Sambuc *	_setjmp(a)
45*0a6a1f1dSLionel Sambuc * by restoring registers from the stack.
46*0a6a1f1dSLionel Sambuc * The previous signal state is NOT restored.
47*0a6a1f1dSLionel Sambuc */
48*0a6a1f1dSLionel Sambuc
49*0a6a1f1dSLionel SambucENTRY(_setjmp)
50*0a6a1f1dSLionel Sambuc	l.sw	JB_MAGIC(r3), r0	/* indicate no sigmask */
51*0a6a1f1dSLionel Sambuc	l.sw	JB_PC(r3), lr		/* save return address */
52*0a6a1f1dSLionel Sambuc	l.sw	JB_LR(r3), lr		/* save return address */
53*0a6a1f1dSLionel Sambuc	l.sw	JB_SP(r3), r1		/* save stack pointer */
54*0a6a1f1dSLionel Sambuc	l.sw	JB_FP(r3), r2		/* save frame pointer */
55*0a6a1f1dSLionel Sambuc	l.sw	JB_R10(r3), r10		/* save callee saved register */
56*0a6a1f1dSLionel Sambuc	l.sw	JB_R14(r3), r14		/* save callee saved register */
57*0a6a1f1dSLionel Sambuc	l.sw	JB_R16(r3), r16		/* save callee saved register */
58*0a6a1f1dSLionel Sambuc	l.sw	JB_R18(r3), r18		/* save callee saved register */
59*0a6a1f1dSLionel Sambuc	l.sw	JB_R20(r3), r20		/* save callee saved register */
60*0a6a1f1dSLionel Sambuc	l.sw	JB_R22(r3), r22		/* save callee saved register */
61*0a6a1f1dSLionel Sambuc	l.sw	JB_R24(r3), r24		/* save callee saved register */
62*0a6a1f1dSLionel Sambuc	l.sw	JB_R26(r3), r26		/* save callee saved register */
63*0a6a1f1dSLionel Sambuc	l.sw	JB_R28(r3), r28		/* save callee saved register */
64*0a6a1f1dSLionel Sambuc	l.sw	JB_R30(r3), r30		/* save callee saved register */
65*0a6a1f1dSLionel Sambuc	l.xor	r11, r11, r11		/* indicate success */
66*0a6a1f1dSLionel Sambuc	l.jr	lr			/* return */
67*0a6a1f1dSLionel Sambuc	l.nop
68*0a6a1f1dSLionel SambucEND(_setjmp)
69*0a6a1f1dSLionel Sambuc
70*0a6a1f1dSLionel SambucENTRY(_longjmp)
71*0a6a1f1dSLionel Sambuc	l.lwz	lr, JB_LR(r3)		/* get return address */
72*0a6a1f1dSLionel Sambuc	l.lwz	r1, JB_SP(r3)		/* get stack pointer */
73*0a6a1f1dSLionel Sambuc	l.lwz	r2, JB_FP(r3)		/* get frame pointer */
74*0a6a1f1dSLionel Sambuc	l.lwz	r10, JB_R10(r3)		/* get callee saved register */
75*0a6a1f1dSLionel Sambuc	l.lwz	r14, JB_R14(r3)		/* get callee saved register */
76*0a6a1f1dSLionel Sambuc	l.lwz	r16, JB_R16(r3)		/* get callee saved register */
77*0a6a1f1dSLionel Sambuc	l.lwz	r18, JB_R18(r3)		/* get callee saved register */
78*0a6a1f1dSLionel Sambuc	l.lwz	r20, JB_R20(r3)		/* get callee saved register */
79*0a6a1f1dSLionel Sambuc	l.lwz	r22, JB_R22(r3)		/* get callee saved register */
80*0a6a1f1dSLionel Sambuc	l.lwz	r24, JB_R24(r3)		/* get callee saved register */
81*0a6a1f1dSLionel Sambuc	l.lwz	r26, JB_R26(r3)		/* get callee saved register */
82*0a6a1f1dSLionel Sambuc	l.lwz	r28, JB_R28(r3)		/* get callee saved register */
83*0a6a1f1dSLionel Sambuc	l.lwz	r30, JB_R30(r3)		/* get callee saved register */
84*0a6a1f1dSLionel Sambuc	l.ori	r11, r0, 1		/* default return value */
85*0a6a1f1dSLionel Sambuc	l.sfeqi	r4, 0			/* test return value */
86*0a6a1f1dSLionel Sambuc	l.cmov	r11, r11, r4		/* use it if not 0 */
87*0a6a1f1dSLionel Sambuc	l.jr	lr			/* return */
88*0a6a1f1dSLionel Sambuc	l.nop
89*0a6a1f1dSLionel SambucEND(_longjmp)
90