xref: /openbsd-src/lib/libc/arch/sh/gen/_setjmp.S (revision 243b5df446d5f4ce83bb376b1240a8a96ea22b23)
1*243b5df4Smiod/*	$OpenBSD: _setjmp.S,v 1.2 2007/03/02 06:11:54 miod Exp $	*/
2cf252584Smiod/*	$NetBSD: _setjmp.S,v 1.7 2006/01/05 02:04:41 uwe Exp $	*/
3cf252584Smiod
4cf252584Smiod/*-
5cf252584Smiod * Copyright (c) 1990 The Regents of the University of California.
6cf252584Smiod * All rights reserved.
7cf252584Smiod *
8cf252584Smiod * This code is derived from software contributed to Berkeley by
9cf252584Smiod * William Jolitz.
10cf252584Smiod *
11cf252584Smiod * Redistribution and use in source and binary forms, with or without
12cf252584Smiod * modification, are permitted provided that the following conditions
13cf252584Smiod * are met:
14cf252584Smiod * 1. Redistributions of source code must retain the above copyright
15cf252584Smiod *    notice, this list of conditions and the following disclaimer.
16cf252584Smiod * 2. Redistributions in binary form must reproduce the above copyright
17cf252584Smiod *    notice, this list of conditions and the following disclaimer in the
18cf252584Smiod *    documentation and/or other materials provided with the distribution.
19cf252584Smiod * 3. Neither the name of the University nor the names of its contributors
20cf252584Smiod *    may be used to endorse or promote products derived from this software
21cf252584Smiod *    without specific prior written permission.
22cf252584Smiod *
23cf252584Smiod * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24cf252584Smiod * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25cf252584Smiod * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26cf252584Smiod * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27cf252584Smiod * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28cf252584Smiod * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29cf252584Smiod * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30cf252584Smiod * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31cf252584Smiod * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32cf252584Smiod * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33cf252584Smiod * SUCH DAMAGE.
34cf252584Smiod *
35cf252584Smiod *	from: @(#)_setjmp.s	5.1 (Berkeley) 4/23/90
36cf252584Smiod */
37cf252584Smiod
38cf252584Smiod#include <machine/asm.h>
39cf252584Smiod#include <machine/setjmp.h>
40cf252584Smiod
41cf252584Smiod/*
42cf252584Smiod * C library -- _setjmp, _longjmp
43cf252584Smiod *
44cf252584Smiod *	_longjmp(a,v)
45cf252584Smiod * will generate a "return(v)" from the last call to
46cf252584Smiod *	_setjmp(a)
47cf252584Smiod * by restoring registers from the stack.
48cf252584Smiod * The previous signal state is NOT restored.
49cf252584Smiod */
50cf252584Smiod
51cf252584SmiodENTRY(_setjmp)
52*243b5df4Smiod	xor	r0,	r0
53*243b5df4Smiod#if defined(__SH4__) && !defined(__SH4_NOFPU__)
54*243b5df4Smiod	add	#(_JBLEN * 4), r4
55*243b5df4Smiod	sts	fpscr,	r1
56*243b5df4Smiod	mov.l	r1,	@-r4
57*243b5df4Smiod	lds	r0,	fpscr
58*243b5df4Smiod	sts.l	fpul,	@-r4
59*243b5df4Smiod	fmov.s	fr15,	@-r4
60*243b5df4Smiod	fmov.s	fr14,	@-r4
61*243b5df4Smiod	fmov.s	fr13,	@-r4
62*243b5df4Smiod	fmov.s	fr12,	@-r4
63*243b5df4Smiod	frchg
64*243b5df4Smiod	fmov.s	fr15,	@-r4
65*243b5df4Smiod	fmov.s	fr14,	@-r4
66*243b5df4Smiod	fmov.s	fr13,	@-r4
67*243b5df4Smiod	fmov.s	fr12,	@-r4
68*243b5df4Smiod	lds	r1,	fpscr
69*243b5df4Smiod#else
70*243b5df4Smiod	add	#((_JBLEN - 10) * 4), r4
71*243b5df4Smiod#endif
72*243b5df4Smiod	sts.l	mach,	@-r4
73*243b5df4Smiod	sts.l	macl,	@-r4
74cf252584Smiod	mov.l	r15,	@-r4
75cf252584Smiod	mov.l	r14,	@-r4
76cf252584Smiod	mov.l	r13,	@-r4
77cf252584Smiod	mov.l	r12,	@-r4
78cf252584Smiod	mov.l	r11,	@-r4
79cf252584Smiod	mov.l	r10,	@-r4
80cf252584Smiod	mov.l	r9,	@-r4
81cf252584Smiod	mov.l	r8,	@-r4
82cf252584Smiod	sts.l	pr,	@-r4
83*243b5df4Smiod	mov.l	r0,	@-r4		/* dummy signal mask */
84cf252584Smiod	rts
85*243b5df4Smiod	 mov.l	r0,	@-r4		/* no saved signal mask */
86cf252584Smiod	SET_ENTRY_SIZE(_setjmp)
87cf252584Smiod
88cf252584SmiodENTRY(_longjmp)
89*243b5df4Smiod	add	#8,	r4
90cf252584Smiod	lds.l	@r4+,	pr
91cf252584Smiod	mov.l	@r4+,	r8
92cf252584Smiod	mov.l	@r4+,	r9
93cf252584Smiod	mov.l	@r4+,	r10
94cf252584Smiod	mov.l	@r4+,	r11
95cf252584Smiod	mov.l	@r4+,	r12
96cf252584Smiod	mov.l	@r4+,	r13
97cf252584Smiod	mov.l	@r4+,	r14
98cf252584Smiod	mov.l	@r4+,	r15
99*243b5df4Smiod	lds.l	@r4+,	macl
100*243b5df4Smiod	lds.l	@r4+,	mach
101*243b5df4Smiod#if defined(__SH4__) && !defined(__SH4_NOFPU__)
102*243b5df4Smiod	xor	r0, 	r0
103*243b5df4Smiod	lds	r0,	fpscr
104*243b5df4Smiod	frchg
105*243b5df4Smiod	fmov.s	@r4+,	fr12
106*243b5df4Smiod	fmov.s	@r4+,	fr13
107*243b5df4Smiod	fmov.s	@r4+,	fr14
108*243b5df4Smiod	fmov.s	@r4+,	fr15
109*243b5df4Smiod	frchg
110*243b5df4Smiod	fmov.s	@r4+,	fr12
111*243b5df4Smiod	fmov.s	@r4+,	fr13
112*243b5df4Smiod	fmov.s	@r4+,	fr14
113*243b5df4Smiod	fmov.s	@r4+,	fr15
114*243b5df4Smiod	lds.l	@r4+,	fpul
115*243b5df4Smiod	lds.l	@r4+,	fpscr
116*243b5df4Smiod#endif
117cf252584Smiod
118cf252584Smiod	mov	r5,	r0
119cf252584Smiod	tst	r0,	r0
120cf252584Smiod	bf	.L0
121cf252584Smiod	add	#1,	r0
122cf252584Smiod.L0:
123cf252584Smiod	rts
124cf252584Smiod	 nop
125cf252584Smiod	SET_ENTRY_SIZE(_longjmp)
126