xref: /minix3/lib/libc/arch/riscv/gen/__setjmp14.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc/*	$NetBSD: __setjmp14.S,v 1.2 2015/03/27 06:44:28 matt Exp $	*/
2*0a6a1f1dSLionel Sambuc
3*0a6a1f1dSLionel Sambuc#include "SYS.h"
4*0a6a1f1dSLionel Sambuc#include "assym.h"
5*0a6a1f1dSLionel Sambuc
6*0a6a1f1dSLionel Sambuc#if defined(LIBC_SCCS)
7*0a6a1f1dSLionel Sambuc__RCSID("$NetBSD: __setjmp14.S,v 1.2 2015/03/27 06:44:28 matt Exp $")
8*0a6a1f1dSLionel Sambuc#endif
9*0a6a1f1dSLionel Sambuc
10*0a6a1f1dSLionel Sambuc/*
11*0a6a1f1dSLionel Sambuc * C library -- _setjmp, _longjmp
12*0a6a1f1dSLionel Sambuc *
13*0a6a1f1dSLionel Sambuc *	longjmp(a,v)
14*0a6a1f1dSLionel Sambuc * will generate a "return(v?v:1)" from the last call to
15*0a6a1f1dSLionel Sambuc *	setjmp(a)
16*0a6a1f1dSLionel Sambuc * by restoring registers from the stack.
17*0a6a1f1dSLionel Sambuc * The previous signal state is restored.
18*0a6a1f1dSLionel Sambuc */
19*0a6a1f1dSLionel Sambuc
20*0a6a1f1dSLionel SambucENTRY(__setjmp14)
21*0a6a1f1dSLionel Sambuc	li	a1, 1
22*0a6a1f1dSLionel Sambuc	REG_S	a1, JB_MAGIC(a0)	/* indicate sigmask */
23*0a6a1f1dSLionel Sambuc	REG_S	ra, JB_RA(a0)		/* save return address */
24*0a6a1f1dSLionel Sambuc	REG_S	sp, JB_SP(a0)		/* save stack pointer */
25*0a6a1f1dSLionel Sambuc	REG_S	gp, JB_GP(a0)		/* save global pointer */
26*0a6a1f1dSLionel Sambuc	REG_S	tp, JB_TP(a0)		/* save thread pointer */
27*0a6a1f1dSLionel Sambuc	REG_S	s0, JB_S0(a0)		/* save callee saved register */
28*0a6a1f1dSLionel Sambuc	REG_S	s1, JB_S1(a0)		/* save callee saved register */
29*0a6a1f1dSLionel Sambuc	REG_S	s2, JB_S2(a0)		/* save callee saved register */
30*0a6a1f1dSLionel Sambuc	REG_S	s3, JB_S3(a0)		/* save callee saved register */
31*0a6a1f1dSLionel Sambuc	REG_S	s4, JB_S4(a0)		/* save callee saved register */
32*0a6a1f1dSLionel Sambuc	REG_S	s5, JB_S5(a0)		/* save callee saved register */
33*0a6a1f1dSLionel Sambuc	REG_S	s6, JB_S6(a0)		/* save callee saved register */
34*0a6a1f1dSLionel Sambuc	REG_S	s7, JB_S7(a0)		/* save callee saved register */
35*0a6a1f1dSLionel Sambuc	REG_S	s8, JB_S8(a0)		/* save callee saved register */
36*0a6a1f1dSLionel Sambuc	REG_S	s9, JB_S9(a0)		/* save callee saved register */
37*0a6a1f1dSLionel Sambuc	REG_S	s10, JB_S10(a0)		/* save callee saved register */
38*0a6a1f1dSLionel Sambuc	REG_S	s11, JB_S11(a0)		/* save callee saved register */
39*0a6a1f1dSLionel Sambuc#ifndef _SOFT_FLOAT
40*0a6a1f1dSLionel Sambuc	frcsr	t2			/* get FSCR */
41*0a6a1f1dSLionel Sambuc	REG_S	t2, JB_FCSR(a0)		/* save it */
42*0a6a1f1dSLionel Sambuc	fsd	fs0, JB_FS0(a0)		/* save callee saved register */
43*0a6a1f1dSLionel Sambuc	fsd	fs1, JB_FS1(a0)		/* save callee saved register */
44*0a6a1f1dSLionel Sambuc	fsd	fs2, JB_FS2(a0)		/* save callee saved register */
45*0a6a1f1dSLionel Sambuc	fsd	fs3, JB_FS3(a0)		/* save callee saved register */
46*0a6a1f1dSLionel Sambuc	fsd	fs4, JB_FS4(a0)		/* save callee saved register */
47*0a6a1f1dSLionel Sambuc	fsd	fs5, JB_FS5(a0)		/* save callee saved register */
48*0a6a1f1dSLionel Sambuc	fsd	fs6, JB_FS6(a0)		/* save callee saved register */
49*0a6a1f1dSLionel Sambuc	fsd	fs7, JB_FS7(a0)		/* save callee saved register */
50*0a6a1f1dSLionel Sambuc	fsd	fs8, JB_FS8(a0)		/* save callee saved register */
51*0a6a1f1dSLionel Sambuc	fsd	fs9, JB_FS9(a0)		/* save callee saved register */
52*0a6a1f1dSLionel Sambuc	fsd	fs10, JB_FS10(a0)	/* save callee saved register */
53*0a6a1f1dSLionel Sambuc	fsd	fs11, JB_FS11(a0)	/* save callee saved register */
54*0a6a1f1dSLionel Sambuc#endif
55*0a6a1f1dSLionel Sambuc
56*0a6a1f1dSLionel Sambuc	addi	a2, a0, JB_SIGMASK	/* &sigmask */
57*0a6a1f1dSLionel Sambuc	li	a1, 0
58*0a6a1f1dSLionel Sambuc	li	a0, SIG_BLOCK
59*0a6a1f1dSLionel Sambuc	SYSTRAP(__sigprocmask14)	/* assume no error */
60*0a6a1f1dSLionel Sambuc	li	a0, 0	/* success */	/* indicate success */
61*0a6a1f1dSLionel Sambuc	ret		/* error */	/* return */
62*0a6a1f1dSLionel SambucEND(__setjmp14)
63*0a6a1f1dSLionel Sambuc
64*0a6a1f1dSLionel SambucENTRY(__longjmp14)
65*0a6a1f1dSLionel Sambuc	REG_L	ra, JB_RA(a0)		/* restore return address */
66*0a6a1f1dSLionel Sambuc	REG_L	sp, JB_SP(a0)		/* restore stack pointer */
67*0a6a1f1dSLionel Sambuc	REG_L	gp, JB_GP(a0)		/* restore global pointer */
68*0a6a1f1dSLionel Sambuc	#REG_L	tp, JB_TP(a0)		/* restore thread pointer */
69*0a6a1f1dSLionel Sambuc	REG_L	s0, JB_S0(a0)		/* restore callee saved register */
70*0a6a1f1dSLionel Sambuc	REG_L	s1, JB_S1(a0)		/* restore callee saved register */
71*0a6a1f1dSLionel Sambuc	REG_L	s2, JB_S2(a0)		/* restore callee saved register */
72*0a6a1f1dSLionel Sambuc	REG_L	s3, JB_S3(a0)		/* restore callee saved register */
73*0a6a1f1dSLionel Sambuc	REG_L	s4, JB_S4(a0)		/* restore callee saved register */
74*0a6a1f1dSLionel Sambuc	REG_L	s5, JB_S5(a0)		/* restore callee saved register */
75*0a6a1f1dSLionel Sambuc	REG_L	s6, JB_S6(a0)		/* restore callee saved register */
76*0a6a1f1dSLionel Sambuc	REG_L	s7, JB_S7(a0)		/* restore callee saved register */
77*0a6a1f1dSLionel Sambuc	REG_L	s8, JB_S8(a0)		/* restore callee saved register */
78*0a6a1f1dSLionel Sambuc	REG_L	s9, JB_S9(a0)		/* restore callee saved register */
79*0a6a1f1dSLionel Sambuc	REG_L	s10, JB_S10(a0)		/* restore callee saved register */
80*0a6a1f1dSLionel Sambuc	REG_L	s11, JB_S11(a0)		/* restore callee saved register */
81*0a6a1f1dSLionel Sambuc#ifndef _SOFT_FLOAT
82*0a6a1f1dSLionel Sambuc	REG_L	t2, JB_FCSR(a0)		/* get it */
83*0a6a1f1dSLionel Sambuc	fscsr	t2			/* restore FSCR */
84*0a6a1f1dSLionel Sambuc	fld	fs0, JB_FS0(a0)		/* restore callee saved register */
85*0a6a1f1dSLionel Sambuc	fld	fs1, JB_FS1(a0)		/* restore callee saved register */
86*0a6a1f1dSLionel Sambuc	fld	fs2, JB_FS2(a0)		/* restore callee saved register */
87*0a6a1f1dSLionel Sambuc	fld	fs3, JB_FS3(a0)		/* restore callee saved register */
88*0a6a1f1dSLionel Sambuc	fld	fs4, JB_FS4(a0)		/* restore callee saved register */
89*0a6a1f1dSLionel Sambuc	fld	fs5, JB_FS5(a0)		/* restore callee saved register */
90*0a6a1f1dSLionel Sambuc	fld	fs6, JB_FS6(a0)		/* restore callee saved register */
91*0a6a1f1dSLionel Sambuc	fld	fs7, JB_FS7(a0)		/* restore callee saved register */
92*0a6a1f1dSLionel Sambuc	fld	fs8, JB_FS8(a0)		/* restore callee saved register */
93*0a6a1f1dSLionel Sambuc	fld	fs9, JB_FS9(a0)		/* restore callee saved register */
94*0a6a1f1dSLionel Sambuc	fld	fs10, JB_FS10(a0)	/* restore callee saved register */
95*0a6a1f1dSLionel Sambuc	fld	fs11, JB_FS11(a0)	/* restore callee saved register */
96*0a6a1f1dSLionel Sambuc#endif
97*0a6a1f1dSLionel Sambuc	move	t1, a1			/* save return value */
98*0a6a1f1dSLionel Sambuc	li	a2, 0
99*0a6a1f1dSLionel Sambuc	addi	a1, a0, JB_SIGMASK	/* &sigmask */
100*0a6a1f1dSLionel Sambuc	li	a0, SIG_SETMASK
101*0a6a1f1dSLionel Sambuc	SYSTRAP(__sigprocmask14)	/* assume no error */
102*0a6a1f1dSLionel Sambuc	nop		/* error */
103*0a6a1f1dSLionel Sambuc	li	a0, 1	/* success */	/* default return value */
104*0a6a1f1dSLionel Sambuc	beqz	t1, 1f			/* test return value */
105*0a6a1f1dSLionel Sambuc	move	a0, t1			/* use it if not 0 */
106*0a6a1f1dSLionel Sambuc1:	ret
107*0a6a1f1dSLionel SambucEND(__longjmp14)
108