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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
/* MIPS support code for fibers and multithreading.
Copyright (C) 2019-2026 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#include "../common/threadasm.S"
#if _MIPS_SIM == _ABIO32
/**
* Performs a context switch.
*
* $a0 - void** - ptr to old stack pointer
* $a1 - void* - new stack pointer
*
*/
.text
.globl fiber_switchContext
.align 2
.ent fiber_switchContext,0
fiber_switchContext:
.cfi_startproc
addiu $sp, $sp, -(10 * 4)
// fp regs and return address are stored below the stack
// because we don't want the GC to scan them.
#ifdef __mips_hard_float
#define ALIGN8(val) (val + (-val & 7))
#define BELOW (ALIGN8(6 * 8 + 4))
s.d $f20, (0 * 8 - BELOW)($sp)
s.d $f22, (1 * 8 - BELOW)($sp)
s.d $f24, (2 * 8 - BELOW)($sp)
s.d $f26, (3 * 8 - BELOW)($sp)
s.d $f28, (4 * 8 - BELOW)($sp)
s.d $f30, (5 * 8 - BELOW)($sp)
#endif
sw $ra, -4($sp)
sw $s0, (0 * 4)($sp)
sw $s1, (1 * 4)($sp)
sw $s2, (2 * 4)($sp)
sw $s3, (3 * 4)($sp)
sw $s4, (4 * 4)($sp)
sw $s5, (5 * 4)($sp)
sw $s6, (6 * 4)($sp)
sw $s7, (7 * 4)($sp)
sw $s8, (8 * 4)($sp)
sw $gp, (9 * 4)($sp)
// swap stack pointer
sw $sp, 0($a0)
move $sp, $a1
#ifdef __mips_hard_float
l.d $f20, (0 * 8 - BELOW)($sp)
l.d $f22, (1 * 8 - BELOW)($sp)
l.d $f24, (2 * 8 - BELOW)($sp)
l.d $f26, (3 * 8 - BELOW)($sp)
l.d $f28, (4 * 8 - BELOW)($sp)
l.d $f30, (5 * 8 - BELOW)($sp)
#endif
lw $ra, -4($sp)
lw $s0, (0 * 4)($sp)
lw $s1, (1 * 4)($sp)
lw $s2, (2 * 4)($sp)
lw $s3, (3 * 4)($sp)
lw $s4, (4 * 4)($sp)
lw $s5, (5 * 4)($sp)
lw $s6, (6 * 4)($sp)
lw $s7, (7 * 4)($sp)
lw $s8, (8 * 4)($sp)
lw $gp, (9 * 4)($sp)
addiu $sp, $sp, (10 * 4)
jr $ra // return
.cfi_endproc
.end fiber_switchContext
.size fiber_switchContext,.-fiber_switchContext
#endif /* _MIPS_SIM == _ABIO32 */
#if defined(__mips64) && _MIPS_SIM == _ABI64
/************************************************************************************
* MIPS 64 ASM BITS
* $a0 - void** - ptr to old stack pointer
* $a1 - void* - new stack pointer
*
*/
.text
.globl fiber_switchContext
.align 2
.ent fiber_switchContext,0
fiber_switchContext:
.cfi_startproc
daddiu $sp, $sp, -(10 * 8)
// fp regs and return address are stored below the stack
// because we don't want the GC to scan them.
#ifdef __mips_hard_float
#define BELOW (8 * 8 + 8)
s.d $f24, (0 * 8 - BELOW)($sp)
s.d $f25, (1 * 8 - BELOW)($sp)
s.d $f26, (2 * 8 - BELOW)($sp)
s.d $f27, (3 * 8 - BELOW)($sp)
s.d $f28, (4 * 8 - BELOW)($sp)
s.d $f29, (5 * 8 - BELOW)($sp)
s.d $f30, (6 * 8 - BELOW)($sp)
s.d $f31, (7 * 8 - BELOW)($sp)
#endif
sd $ra, -8($sp)
sd $s0, (0 * 8)($sp)
sd $s1, (1 * 8)($sp)
sd $s2, (2 * 8)($sp)
sd $s3, (3 * 8)($sp)
sd $s4, (4 * 8)($sp)
sd $s5, (5 * 8)($sp)
sd $s6, (6 * 8)($sp)
sd $s7, (7 * 8)($sp)
sd $gp, (8 * 8)($sp)
sd $fp, (9 * 8)($sp)
// swap stack pointer
sd $sp, 0($a0)
move $sp, $a1
#ifdef __mips_hard_float
l.d $f24, (0 * 8 - BELOW)($sp)
l.d $f25, (1 * 8 - BELOW)($sp)
l.d $f26, (2 * 8 - BELOW)($sp)
l.d $f27, (3 * 8 - BELOW)($sp)
l.d $f28, (4 * 8 - BELOW)($sp)
l.d $f29, (5 * 8 - BELOW)($sp)
l.d $f30, (6 * 8 - BELOW)($sp)
l.d $f31, (7 * 8 - BELOW)($sp)
#endif
ld $ra, -8($sp)
ld $s0, (0 * 8)($sp)
ld $s1, (1 * 8)($sp)
ld $s2, (2 * 8)($sp)
ld $s3, (3 * 8)($sp)
ld $s4, (4 * 8)($sp)
ld $s5, (5 * 8)($sp)
ld $s6, (6 * 8)($sp)
ld $s7, (7 * 8)($sp)
ld $gp, (8 * 8)($sp)
ld $fp, (9 * 8)($sp)
daddiu $sp, $sp, (10 * 8)
jr $ra // return
.cfi_endproc
.end fiber_switchContext
.size fiber_switchContext,.-fiber_switchContext
#endif /* defined(__mips64) && _MIPS_SIM == _ABI64 */
|