summaryrefslogtreecommitdiff
path: root/lib/libc/arch/riscv64/gen/sigsetjmp.S
blob: 74e4c390a001633151eaa7b33df91133795ae05d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*	$OpenBSD: sigsetjmp.S,v 1.3 2021/05/17 15:06:09 deraadt Exp $	*/
/* 
 * Copyright (c) 2020 Dale Rahn <drahn@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include "SYS.h"
#include <machine/setjmp.h>

ENTRY(sigsetjmp)
	RETGUARD_SETUP(setjmp, t6)
	mv	a2, a0 				/* save jmpbuf in a2 */
	li	a0, 0
	beqz	a1, 1f
	/* Store the signal mask */
	li	a1, 0
	li	a0, 1				/* SIG_BLOCK */
	SYSTRAP(sigprocmask)
1:
	sw	a0, (_JB_SIGMASK * 8)(a2)	/* oset */

	mv	a0, a2
	sd	sp, (1 * 8)(a0)

	/* Store the general purpose registers and ra */
	sd	s0, (2 * 8)(a0)
	sd	s1, (3 * 8)(a0)
	sd	s2, (4 * 8)(a0)
	sd	s3, (5 * 8)(a0)
	sd	s4, (6 * 8)(a0)
	sd	s5, (7 * 8)(a0)
	sd	s6, (8 * 8)(a0)
	sd	s7, (9 * 8)(a0)
	sd	s8, (10 * 8)(a0)
	sd	s9, (11 * 8)(a0)
	sd	s10, (12 * 8)(a0)
	sd	s11, (13 * 8)(a0)
	sd	ra, (14 * 8)(a0)

	/* Store the fp registers */
	fsd	fs0, (15 * 8)(a0)
	fsd	fs1, (16 * 8)(a0)
	fsd	fs2, (17 * 8)(a0)
	fsd	fs3, (18 * 8)(a0)
	fsd	fs4, (19 * 8)(a0)
	fsd	fs5, (20 * 8)(a0)
	fsd	fs6, (21 * 8)(a0)
	fsd	fs7, (22 * 8)(a0)
	fsd	fs8, (23 * 8)(a0)
	fsd	fs9, (24 * 8)(a0)
	fsd	fs10, (25 * 8)(a0)
	fsd	fs11, (26 * 8)(a0)
	frcsr	t0	
	sd	t0, (27 * 8)(a0)

	/* Return value */
	li	a0, 0
	RETGUARD_CHECK(setjmp, t6)
	ret

END_STRONG(sigsetjmp)

ENTRY(siglongjmp)
	RETGUARD_SYMBOL(longjmp)
	RETGUARD_LOAD_RANDOM(longjmp, t6)
	mv	a2, a0				/* move jmpbuf */
	mv	a3, a1				/* final return value */

	/* Restore the signal mask */
	lw	a1, (_JB_SIGMASK * 8)(a2)	/* set */
	beqz	a1, 1f

	li	a0, 3				/* SIG_SETMASK */
	SYSTRAP(sigprocmask)
1:

	mv	a0, a2
	mv	a1, a3

	/* Restore the stack pointer */
	ld	t0, (1 * 8)(a0)
	mv	sp, t0

	/* Store the general purpose registers and ra */
	ld	s0, (2 * 8)(a0)
	ld	s1, (3 * 8)(a0)
	ld	s2, (4 * 8)(a0)
	ld	s3, (5 * 8)(a0)
	ld	s4, (6 * 8)(a0)
	ld	s5, (7 * 8)(a0)
	ld	s6, (8 * 8)(a0)
	ld	s7, (9 * 8)(a0)
	ld	s8, (10 * 8)(a0)
	ld	s9, (11 * 8)(a0)
	ld	s10, (12 * 8)(a0)
	ld	s11, (13 * 8)(a0)
	ld	ra, (14 * 8)(a0)

	/* Store the fp registers */
	fld	fs0, (15 * 8)(a0)
	fld	fs1, (16 * 8)(a0)
	fld	fs2, (17 * 8)(a0)
	fld	fs3, (18 * 8)(a0)
	fld	fs4, (19 * 8)(a0)
	fld	fs5, (20 * 8)(a0)
	fld	fs6, (21 * 8)(a0)
	fld	fs7, (22 * 8)(a0)
	fld	fs8, (23 * 8)(a0)
	fld	fs9, (24 * 8)(a0)
	fld	fs10, (25 * 8)(a0)
	fld	fs11, (26 * 8)(a0)
	ld	t0, (27 * 8)(a0)
	fscsr	t0	

	/* Load the return value */
	li	a0, 1
	beqz	a1, 1f
	mv	a0, a1
1:
	RETGUARD_CHECK(longjmp, t6)
	ret

END_STRONG(siglongjmp)