xref: /minix3/lib/libc/arch/riscv/gen/_setjmp.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1/*	$NetBSD: _setjmp.S,v 1.2 2015/03/27 06:44:28 matt Exp $	*/
2
3/*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include <machine/asm.h>
33#include "assym.h"
34
35#if defined(LIBC_SCCS)
36__RCSID("$NetBSD: _setjmp.S,v 1.2 2015/03/27 06:44:28 matt Exp $")
37#endif
38
39/*
40 * C library -- _setjmp, _longjmp
41 *
42 *	_longjmp(a,v)
43 * will generate a "return(v?v:1)" from the last call to
44 *	_setjmp(a)
45 * by restoring registers from the stack.
46 * The previous signal state is NOT restored.
47 */
48
49ENTRY(_setjmp)
50	REG_S	zero, JB_MAGIC(a0)	/* indicate no sigmask */
51	REG_S	ra, JB_RA(a0)		/* save return address */
52	REG_S	sp, JB_SP(a0)		/* save stack pointer */
53	REG_S	gp, JB_GP(a0)		/* save global pointer */
54	REG_S	tp, JB_TP(a0)		/* save thread pointer */
55	REG_S	s0, JB_S0(a0)		/* save callee saved register */
56	REG_S	s1, JB_S1(a0)		/* save callee saved register */
57	REG_S	s2, JB_S2(a0)		/* save callee saved register */
58	REG_S	s3, JB_S3(a0)		/* save callee saved register */
59	REG_S	s4, JB_S4(a0)		/* save callee saved register */
60	REG_S	s5, JB_S5(a0)		/* save callee saved register */
61	REG_S	s6, JB_S6(a0)		/* save callee saved register */
62	REG_S	s7, JB_S7(a0)		/* save callee saved register */
63	REG_S	s8, JB_S8(a0)		/* save callee saved register */
64	REG_S	s9, JB_S9(a0)		/* save callee saved register */
65	REG_S	s10, JB_S10(a0)		/* save callee saved register */
66	REG_S	s11, JB_S11(a0)		/* save callee saved register */
67#ifndef _SOFT_FLOAT
68	frcsr	t2			/* get FSCR */
69	REG_S	t2, JB_FCSR(a0)		/* save it */
70	fsd	fs0, JB_FS0(a0)		/* save callee saved register */
71	fsd	fs1, JB_FS1(a0)		/* save callee saved register */
72	fsd	fs2, JB_FS2(a0)		/* save callee saved register */
73	fsd	fs3, JB_FS3(a0)		/* save callee saved register */
74	fsd	fs4, JB_FS4(a0)		/* save callee saved register */
75	fsd	fs5, JB_FS5(a0)		/* save callee saved register */
76	fsd	fs6, JB_FS6(a0)		/* save callee saved register */
77	fsd	fs7, JB_FS7(a0)		/* save callee saved register */
78	fsd	fs8, JB_FS8(a0)		/* save callee saved register */
79	fsd	fs9, JB_FS9(a0)		/* save callee saved register */
80	fsd	fs10, JB_FS10(a0)	/* save callee saved register */
81	fsd	fs11, JB_FS11(a0)	/* save callee saved register */
82#endif
83	li	a0, 0			/* indicate success */
84	ret				/* return */
85END(_setjmp)
86
87ENTRY(_longjmp)
88	REG_L	ra, JB_RA(a0)		/* save return address */
89	REG_L	sp, JB_SP(a0)		/* save stack pointer */
90	REG_L	gp, JB_GP(a0)		/* save global pointer */
91	#REG_L	tp, JB_TP(a0)		/* save thread pointer */
92	REG_L	s0, JB_S0(a0)		/* save callee saved register */
93	REG_L	s1, JB_S1(a0)		/* save callee saved register */
94	REG_L	s2, JB_S2(a0)		/* save callee saved register */
95	REG_L	s3, JB_S3(a0)		/* save callee saved register */
96	REG_L	s4, JB_S4(a0)		/* save callee saved register */
97	REG_L	s5, JB_S5(a0)		/* save callee saved register */
98	REG_L	s6, JB_S6(a0)		/* save callee saved register */
99	REG_L	s7, JB_S7(a0)		/* save callee saved register */
100	REG_L	s8, JB_S8(a0)		/* save callee saved register */
101	REG_L	s9, JB_S9(a0)		/* save callee saved register */
102	REG_L	s10, JB_S10(a0)		/* save callee saved register */
103	REG_L	s11, JB_S11(a0)		/* save callee saved register */
104#ifndef _SOFT_FLOAT
105	REG_L	t2, JB_FCSR(a0)		/* get it */
106	fscsr	t2			/* restore FSCR */
107	fld	fs0, JB_FS0(a0)		/* restore callee saved register */
108	fld	fs1, JB_FS1(a0)		/* restore callee saved register */
109	fld	fs2, JB_FS2(a0)		/* restore callee saved register */
110	fld	fs3, JB_FS3(a0)		/* restore callee saved register */
111	fld	fs4, JB_FS4(a0)		/* restore callee saved register */
112	fld	fs5, JB_FS5(a0)		/* restore callee saved register */
113	fld	fs6, JB_FS6(a0)		/* restore callee saved register */
114	fld	fs7, JB_FS7(a0)		/* restore callee saved register */
115	fld	fs8, JB_FS8(a0)		/* restore callee saved register */
116	fld	fs9, JB_FS9(a0)		/* restore callee saved register */
117	fld	fs10, JB_FS10(a0)	/* restore callee saved register */
118	fld	fs11, JB_FS11(a0)	/* restore callee saved register */
119#endif
120	li	a0, 1			/* default return value */
121	beqz	a1, 1f			/* test return value */
122	move	a0, a1			/* use it if not 0 */
1231:	ret
124END(_longjmp)
125