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
|
/* PowerPC support code for fibers and multithreading.
Copyright (C) 2019 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"
/**
* Performs a context switch.
*
* r3 - old context pointer
* r4 - new context pointer
*
*/
.text
.globl CSYM(_fiber_switchContext)
.type CSYM(_fiber_switchContext), @function
.align 2
CSYM(_fiber_switchContext):
.cfi_startproc
/* Save linkage area */
mflr 0
mfcr 5
stw 0, 8(1)
stw 5, 4(1)
/* Save GPRs */
stw 11, (-1 * 4)(1)
stw 13, (-2 * 4)(1)
stw 14, (-3 * 4)(1)
stw 15, (-4 * 4)(1)
stw 16, (-5 * 4)(1)
stw 17, (-6 * 4)(1)
stw 18, (-7 * 4)(1)
stw 19, (-8 * 4)(1)
stw 20, (-9 * 4)(1)
stw 21, (-10 * 4)(1)
stw 22, (-11 * 4)(1)
stw 23, (-12 * 4)(1)
stw 24, (-13 * 4)(1)
stw 25, (-14 * 4)(1)
stw 26, (-15 * 4)(1)
stw 27, (-16 * 4)(1)
stw 28, (-17 * 4)(1)
stw 29, (-18 * 4)(1)
stw 30, (-19 * 4)(1)
stwu 31, (-20 * 4)(1)
/* We update the stack pointer here, since we do not want the GC to
scan the floating point registers. */
/* Save FPRs */
stfd 14, (-1 * 8)(1)
stfd 15, (-2 * 8)(1)
stfd 16, (-3 * 8)(1)
stfd 17, (-4 * 8)(1)
stfd 18, (-5 * 8)(1)
stfd 19, (-6 * 8)(1)
stfd 20, (-7 * 8)(1)
stfd 21, (-8 * 8)(1)
stfd 22, (-9 * 8)(1)
stfd 23, (-10 * 8)(1)
stfd 24, (-11 * 8)(1)
stfd 25, (-12 * 8)(1)
stfd 26, (-13 * 8)(1)
stfd 27, (-14 * 8)(1)
stfd 28, (-15 * 8)(1)
stfd 29, (-16 * 8)(1)
stfd 30, (-17 * 8)(1)
stfd 31, (-18 * 8)(1)
/* Update the old stack pointer */
stw 1, 0(3)
/* Set new stack pointer */
addi 1, 4, 20 * 4
/* Restore linkage area */
lwz 0, 8(1)
lwz 5, 4(1)
/* Restore GPRs */
lwz 11, (-1 * 4)(1)
lwz 13, (-2 * 4)(1)
lwz 14, (-3 * 4)(1)
lwz 15, (-4 * 4)(1)
lwz 16, (-5 * 4)(1)
lwz 17, (-6 * 4)(1)
lwz 18, (-7 * 4)(1)
lwz 19, (-8 * 4)(1)
lwz 20, (-9 * 4)(1)
lwz 21, (-10 * 4)(1)
lwz 22, (-11 * 4)(1)
lwz 23, (-12 * 4)(1)
lwz 24, (-13 * 4)(1)
lwz 25, (-14 * 4)(1)
lwz 26, (-15 * 4)(1)
lwz 27, (-16 * 4)(1)
lwz 28, (-17 * 4)(1)
lwz 29, (-18 * 4)(1)
lwz 30, (-19 * 4)(1)
lwz 31, (-20 * 4)(1)
/* Restore FPRs */
lfd 14, (-1 * 8)(4)
lfd 15, (-2 * 8)(4)
lfd 16, (-3 * 8)(4)
lfd 17, (-4 * 8)(4)
lfd 18, (-5 * 8)(4)
lfd 19, (-6 * 8)(4)
lfd 20, (-7 * 8)(4)
lfd 21, (-8 * 8)(4)
lfd 22, (-9 * 8)(4)
lfd 23, (-10 * 8)(4)
lfd 24, (-11 * 8)(4)
lfd 25, (-12 * 8)(4)
lfd 26, (-13 * 8)(4)
lfd 27, (-14 * 8)(4)
lfd 28, (-15 * 8)(4)
lfd 29, (-16 * 8)(4)
lfd 30, (-17 * 8)(4)
lfd 31, (-18 * 8)(4)
/* Set condition and link register */
mtcr 5
mtlr 0
/* Return and switch context */
blr
.cfi_endproc
.size CSYM(_fiber_switchContext),.-CSYM(_fiber_switchContext)
|