switchcontext.S revision 1.1 1 /* PowerPC support code for fibers and multithreading.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
19
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
24
25 #include "../common/threadasm.S"
26
27 /**
28 * Performs a context switch.
29 *
30 * r3 - old context pointer
31 * r4 - new context pointer
32 *
33 */
34 .text
35 .globl CSYM(_fiber_switchContext)
36 .type CSYM(_fiber_switchContext), @function
37 .align 2
38 CSYM(_fiber_switchContext):
39 .cfi_startproc
40 /* Save linkage area */
41 mflr 0
42 mfcr 5
43 stw 0, 8(1)
44 stw 5, 4(1)
45
46 /* Save GPRs */
47 stw 11, (-1 * 4)(1)
48 stw 13, (-2 * 4)(1)
49 stw 14, (-3 * 4)(1)
50 stw 15, (-4 * 4)(1)
51 stw 16, (-5 * 4)(1)
52 stw 17, (-6 * 4)(1)
53 stw 18, (-7 * 4)(1)
54 stw 19, (-8 * 4)(1)
55 stw 20, (-9 * 4)(1)
56 stw 21, (-10 * 4)(1)
57 stw 22, (-11 * 4)(1)
58 stw 23, (-12 * 4)(1)
59 stw 24, (-13 * 4)(1)
60 stw 25, (-14 * 4)(1)
61 stw 26, (-15 * 4)(1)
62 stw 27, (-16 * 4)(1)
63 stw 28, (-17 * 4)(1)
64 stw 29, (-18 * 4)(1)
65 stw 30, (-19 * 4)(1)
66 stwu 31, (-20 * 4)(1)
67
68 /* We update the stack pointer here, since we do not want the GC to
69 scan the floating point registers. */
70
71 /* Save FPRs */
72 stfd 14, (-1 * 8)(1)
73 stfd 15, (-2 * 8)(1)
74 stfd 16, (-3 * 8)(1)
75 stfd 17, (-4 * 8)(1)
76 stfd 18, (-5 * 8)(1)
77 stfd 19, (-6 * 8)(1)
78 stfd 20, (-7 * 8)(1)
79 stfd 21, (-8 * 8)(1)
80 stfd 22, (-9 * 8)(1)
81 stfd 23, (-10 * 8)(1)
82 stfd 24, (-11 * 8)(1)
83 stfd 25, (-12 * 8)(1)
84 stfd 26, (-13 * 8)(1)
85 stfd 27, (-14 * 8)(1)
86 stfd 28, (-15 * 8)(1)
87 stfd 29, (-16 * 8)(1)
88 stfd 30, (-17 * 8)(1)
89 stfd 31, (-18 * 8)(1)
90
91 /* Update the old stack pointer */
92 stw 1, 0(3)
93
94 /* Set new stack pointer */
95 addi 1, 4, 20 * 4
96
97 /* Restore linkage area */
98 lwz 0, 8(1)
99 lwz 5, 4(1)
100
101 /* Restore GPRs */
102 lwz 11, (-1 * 4)(1)
103 lwz 13, (-2 * 4)(1)
104 lwz 14, (-3 * 4)(1)
105 lwz 15, (-4 * 4)(1)
106 lwz 16, (-5 * 4)(1)
107 lwz 17, (-6 * 4)(1)
108 lwz 18, (-7 * 4)(1)
109 lwz 19, (-8 * 4)(1)
110 lwz 20, (-9 * 4)(1)
111 lwz 21, (-10 * 4)(1)
112 lwz 22, (-11 * 4)(1)
113 lwz 23, (-12 * 4)(1)
114 lwz 24, (-13 * 4)(1)
115 lwz 25, (-14 * 4)(1)
116 lwz 26, (-15 * 4)(1)
117 lwz 27, (-16 * 4)(1)
118 lwz 28, (-17 * 4)(1)
119 lwz 29, (-18 * 4)(1)
120 lwz 30, (-19 * 4)(1)
121 lwz 31, (-20 * 4)(1)
122
123 /* Restore FPRs */
124 lfd 14, (-1 * 8)(4)
125 lfd 15, (-2 * 8)(4)
126 lfd 16, (-3 * 8)(4)
127 lfd 17, (-4 * 8)(4)
128 lfd 18, (-5 * 8)(4)
129 lfd 19, (-6 * 8)(4)
130 lfd 20, (-7 * 8)(4)
131 lfd 21, (-8 * 8)(4)
132 lfd 22, (-9 * 8)(4)
133 lfd 23, (-10 * 8)(4)
134 lfd 24, (-11 * 8)(4)
135 lfd 25, (-12 * 8)(4)
136 lfd 26, (-13 * 8)(4)
137 lfd 27, (-14 * 8)(4)
138 lfd 28, (-15 * 8)(4)
139 lfd 29, (-16 * 8)(4)
140 lfd 30, (-17 * 8)(4)
141 lfd 31, (-18 * 8)(4)
142
143 /* Set condition and link register */
144 mtcr 5
145 mtlr 0
146
147 /* Return and switch context */
148 blr
149 .cfi_endproc
150 .size CSYM(_fiber_switchContext),.-CSYM(_fiber_switchContext)
151