1 |
13 |
serginhofr |
/* Save and set current context.
|
2 |
|
|
Copyright (C) 2009 Free Software Foundation, Inc.
|
3 |
|
|
This file is part of the GNU C Library.
|
4 |
|
|
Contributed by Maciej W. Rozycki .
|
5 |
|
|
|
6 |
|
|
The GNU C Library is free software; you can redistribute it and/or
|
7 |
|
|
modify it under the terms of the GNU Lesser General Public
|
8 |
|
|
License as published by the Free Software Foundation; either
|
9 |
|
|
version 2.1 of the License, or (at your option) any later version.
|
10 |
|
|
|
11 |
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
12 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
Lesser General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU Lesser General Public
|
17 |
|
|
License along with the GNU C Library; if not, write to the Free
|
18 |
|
|
Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
|
19 |
|
|
02110-1301, USA. */
|
20 |
|
|
|
21 |
|
|
#include
|
22 |
|
|
#include
|
23 |
|
|
|
24 |
|
|
#include "ucontext_i.h"
|
25 |
|
|
|
26 |
|
|
/* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
|
27 |
|
|
|
28 |
|
|
LEAF (__swapcontext)
|
29 |
|
|
mv t0, a1 /* t0 <- ucp */
|
30 |
|
|
|
31 |
|
|
REG_S ra, MCONTEXT_PC(a0)
|
32 |
|
|
REG_S ra, ( 1 * SZREG + MCONTEXT_GREGS)(a0)
|
33 |
|
|
REG_S sp, ( 2 * SZREG + MCONTEXT_GREGS)(a0)
|
34 |
|
|
REG_S s0, ( 8 * SZREG + MCONTEXT_GREGS)(a0)
|
35 |
|
|
REG_S s1, ( 9 * SZREG + MCONTEXT_GREGS)(a0)
|
36 |
|
|
REG_S x0, (10 * SZREG + MCONTEXT_GREGS)(a0) /* return 0 */
|
37 |
|
|
REG_S s2, (18 * SZREG + MCONTEXT_GREGS)(a0)
|
38 |
|
|
REG_S s3, (19 * SZREG + MCONTEXT_GREGS)(a0)
|
39 |
|
|
REG_S s4, (20 * SZREG + MCONTEXT_GREGS)(a0)
|
40 |
|
|
REG_S s5, (21 * SZREG + MCONTEXT_GREGS)(a0)
|
41 |
|
|
REG_S s6, (22 * SZREG + MCONTEXT_GREGS)(a0)
|
42 |
|
|
REG_S s7, (23 * SZREG + MCONTEXT_GREGS)(a0)
|
43 |
|
|
REG_S s8, (24 * SZREG + MCONTEXT_GREGS)(a0)
|
44 |
|
|
REG_S s9, (25 * SZREG + MCONTEXT_GREGS)(a0)
|
45 |
|
|
REG_S s10,(26 * SZREG + MCONTEXT_GREGS)(a0)
|
46 |
|
|
REG_S s11,(27 * SZREG + MCONTEXT_GREGS)(a0)
|
47 |
|
|
|
48 |
|
|
#ifdef __riscv_hard_float
|
49 |
|
|
frsr a1
|
50 |
|
|
|
51 |
|
|
fsd fs0, ( 8 * 8 + MCONTEXT_FPREGS)(a0)
|
52 |
|
|
fsd fs1, ( 9 * 8 + MCONTEXT_FPREGS)(a0)
|
53 |
|
|
fsd fs2, (18 * 8 + MCONTEXT_FPREGS)(a0)
|
54 |
|
|
fsd fs3, (19 * 8 + MCONTEXT_FPREGS)(a0)
|
55 |
|
|
fsd fs4, (20 * 8 + MCONTEXT_FPREGS)(a0)
|
56 |
|
|
fsd fs5, (21 * 8 + MCONTEXT_FPREGS)(a0)
|
57 |
|
|
fsd fs6, (22 * 8 + MCONTEXT_FPREGS)(a0)
|
58 |
|
|
fsd fs7, (23 * 8 + MCONTEXT_FPREGS)(a0)
|
59 |
|
|
fsd fs8, (24 * 8 + MCONTEXT_FPREGS)(a0)
|
60 |
|
|
fsd fs9, (25 * 8 + MCONTEXT_FPREGS)(a0)
|
61 |
|
|
fsd fs10,(26 * 8 + MCONTEXT_FPREGS)(a0)
|
62 |
|
|
fsd fs11,(27 * 8 + MCONTEXT_FPREGS)(a0)
|
63 |
|
|
|
64 |
|
|
sw a1, MCONTEXT_FSR(a0)
|
65 |
|
|
#endif /* __riscv_hard_float */
|
66 |
|
|
|
67 |
|
|
/* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */
|
68 |
|
|
li a3, _NSIG8
|
69 |
|
|
move a2, zero
|
70 |
|
|
add a1, a0, UCONTEXT_SIGMASK
|
71 |
|
|
li a0, SIG_SETMASK
|
72 |
|
|
|
73 |
|
|
li a7, SYS_ify (rt_sigprocmask)
|
74 |
|
|
scall
|
75 |
|
|
|
76 |
|
|
bltz a0, 99f
|
77 |
|
|
|
78 |
|
|
#ifdef __riscv_hard_float
|
79 |
|
|
lw t1, MCONTEXT_FSR(t0)
|
80 |
|
|
|
81 |
|
|
fld fs0, ( 8 * 8 + MCONTEXT_FPREGS)(t0)
|
82 |
|
|
fld fs1, ( 9 * 8 + MCONTEXT_FPREGS)(t0)
|
83 |
|
|
fld fs2, (18 * 8 + MCONTEXT_FPREGS)(t0)
|
84 |
|
|
fld fs3, (19 * 8 + MCONTEXT_FPREGS)(t0)
|
85 |
|
|
fld fs4, (20 * 8 + MCONTEXT_FPREGS)(t0)
|
86 |
|
|
fld fs5, (21 * 8 + MCONTEXT_FPREGS)(t0)
|
87 |
|
|
fld fs6, (22 * 8 + MCONTEXT_FPREGS)(t0)
|
88 |
|
|
fld fs7, (23 * 8 + MCONTEXT_FPREGS)(t0)
|
89 |
|
|
fld fs8, (24 * 8 + MCONTEXT_FPREGS)(t0)
|
90 |
|
|
fld fs9, (25 * 8 + MCONTEXT_FPREGS)(t0)
|
91 |
|
|
fld fs10,(26 * 8 + MCONTEXT_FPREGS)(t0)
|
92 |
|
|
fld fs11,(27 * 8 + MCONTEXT_FPREGS)(t0)
|
93 |
|
|
|
94 |
|
|
fssr t1
|
95 |
|
|
#endif /* __riscv_hard_float */
|
96 |
|
|
|
97 |
|
|
/* Note the contents of argument registers will be random
|
98 |
|
|
unless makecontext() has been called. */
|
99 |
|
|
REG_L t1, MCONTEXT_PC(t0)
|
100 |
|
|
REG_L ra, ( 1 * SZREG + MCONTEXT_GREGS)(t0)
|
101 |
|
|
REG_L sp, ( 2 * SZREG + MCONTEXT_GREGS)(t0)
|
102 |
|
|
REG_L s0, ( 8 * SZREG + MCONTEXT_GREGS)(t0)
|
103 |
|
|
REG_L s1, ( 9 * SZREG + MCONTEXT_GREGS)(t0)
|
104 |
|
|
REG_L a0, (10 * SZREG + MCONTEXT_GREGS)(t0)
|
105 |
|
|
REG_L a1, (11 * SZREG + MCONTEXT_GREGS)(t0)
|
106 |
|
|
REG_L a2, (12 * SZREG + MCONTEXT_GREGS)(t0)
|
107 |
|
|
REG_L a3, (13 * SZREG + MCONTEXT_GREGS)(t0)
|
108 |
|
|
REG_L a4, (14 * SZREG + MCONTEXT_GREGS)(t0)
|
109 |
|
|
REG_L a5, (15 * SZREG + MCONTEXT_GREGS)(t0)
|
110 |
|
|
REG_L a6, (16 * SZREG + MCONTEXT_GREGS)(t0)
|
111 |
|
|
REG_L a7, (17 * SZREG + MCONTEXT_GREGS)(t0)
|
112 |
|
|
REG_L s2, (18 * SZREG + MCONTEXT_GREGS)(t0)
|
113 |
|
|
REG_L s3, (19 * SZREG + MCONTEXT_GREGS)(t0)
|
114 |
|
|
REG_L s4, (20 * SZREG + MCONTEXT_GREGS)(t0)
|
115 |
|
|
REG_L s5, (21 * SZREG + MCONTEXT_GREGS)(t0)
|
116 |
|
|
REG_L s6, (22 * SZREG + MCONTEXT_GREGS)(t0)
|
117 |
|
|
REG_L s7, (23 * SZREG + MCONTEXT_GREGS)(t0)
|
118 |
|
|
REG_L s8, (24 * SZREG + MCONTEXT_GREGS)(t0)
|
119 |
|
|
REG_L s9, (25 * SZREG + MCONTEXT_GREGS)(t0)
|
120 |
|
|
REG_L s10,(26 * SZREG + MCONTEXT_GREGS)(t0)
|
121 |
|
|
REG_L s11,(27 * SZREG + MCONTEXT_GREGS)(t0)
|
122 |
|
|
|
123 |
|
|
jr t1
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
99: j __syscall_error
|
127 |
|
|
|
128 |
|
|
PSEUDO_END (__swapcontext)
|
129 |
|
|
|
130 |
|
|
weak_alias (__swapcontext, swapcontext)
|