| 1 |
/* MIPS support code for fibers and multithreading. |
| 2 |
Copyright (C) 2019-2025 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 |
#if _MIPS_SIM == _ABIO32 |
| 28 |
|
| 29 |
/** |
| 30 |
* Performs a context switch. |
| 31 |
* |
| 32 |
* $a0 - void** - ptr to old stack pointer |
| 33 |
* $a1 - void* - new stack pointer |
| 34 |
* |
| 35 |
*/ |
| 36 |
.text |
| 37 |
.globl fiber_switchContext |
| 38 |
.align 2 |
| 39 |
.ent fiber_switchContext,0 |
| 40 |
fiber_switchContext: |
| 41 |
.cfi_startproc |
| 42 |
addiu $sp, $sp, -(10 * 4) |
| 43 |
|
| 44 |
// fp regs and return address are stored below the stack |
| 45 |
// because we don't want the GC to scan them. |
| 46 |
|
| 47 |
#ifdef __mips_hard_float |
| 48 |
#define ALIGN8(val) (val + (-val & 7)) |
| 49 |
#define BELOW (ALIGN8(6 * 8 + 4)) |
| 50 |
s.d $f20, (0 * 8 - BELOW)($sp) |
| 51 |
s.d $f22, (1 * 8 - BELOW)($sp) |
| 52 |
s.d $f24, (2 * 8 - BELOW)($sp) |
| 53 |
s.d $f26, (3 * 8 - BELOW)($sp) |
| 54 |
s.d $f28, (4 * 8 - BELOW)($sp) |
| 55 |
s.d $f30, (5 * 8 - BELOW)($sp) |
| 56 |
#endif |
| 57 |
sw $ra, -4($sp) |
| 58 |
|
| 59 |
sw $s0, (0 * 4)($sp) |
| 60 |
sw $s1, (1 * 4)($sp) |
| 61 |
sw $s2, (2 * 4)($sp) |
| 62 |
sw $s3, (3 * 4)($sp) |
| 63 |
sw $s4, (4 * 4)($sp) |
| 64 |
sw $s5, (5 * 4)($sp) |
| 65 |
sw $s6, (6 * 4)($sp) |
| 66 |
sw $s7, (7 * 4)($sp) |
| 67 |
sw $s8, (8 * 4)($sp) |
| 68 |
sw $gp, (9 * 4)($sp) |
| 69 |
|
| 70 |
// swap stack pointer |
| 71 |
sw $sp, 0($a0) |
| 72 |
move $sp, $a1 |
| 73 |
|
| 74 |
#ifdef __mips_hard_float |
| 75 |
l.d $f20, (0 * 8 - BELOW)($sp) |
| 76 |
l.d $f22, (1 * 8 - BELOW)($sp) |
| 77 |
l.d $f24, (2 * 8 - BELOW)($sp) |
| 78 |
l.d $f26, (3 * 8 - BELOW)($sp) |
| 79 |
l.d $f28, (4 * 8 - BELOW)($sp) |
| 80 |
l.d $f30, (5 * 8 - BELOW)($sp) |
| 81 |
#endif |
| 82 |
lw $ra, -4($sp) |
| 83 |
|
| 84 |
lw $s0, (0 * 4)($sp) |
| 85 |
lw $s1, (1 * 4)($sp) |
| 86 |
lw $s2, (2 * 4)($sp) |
| 87 |
lw $s3, (3 * 4)($sp) |
| 88 |
lw $s4, (4 * 4)($sp) |
| 89 |
lw $s5, (5 * 4)($sp) |
| 90 |
lw $s6, (6 * 4)($sp) |
| 91 |
lw $s7, (7 * 4)($sp) |
| 92 |
lw $s8, (8 * 4)($sp) |
| 93 |
lw $gp, (9 * 4)($sp) |
| 94 |
|
| 95 |
addiu $sp, $sp, (10 * 4) |
| 96 |
|
| 97 |
jr $ra // return |
| 98 |
.cfi_endproc |
| 99 |
.end fiber_switchContext |
| 100 |
.size fiber_switchContext,.-fiber_switchContext |
| 101 |
|
| 102 |
#endif /* _MIPS_SIM == _ABIO32 */ |
| 103 |
|
| 104 |
#if defined(__mips64) && _MIPS_SIM == _ABI64 |
| 105 |
/************************************************************************************ |
| 106 |
* MIPS 64 ASM BITS |
| 107 |
* $a0 - void** - ptr to old stack pointer |
| 108 |
* $a1 - void* - new stack pointer |
| 109 |
* |
| 110 |
*/ |
| 111 |
.text |
| 112 |
.globl fiber_switchContext |
| 113 |
.align 2 |
| 114 |
.ent fiber_switchContext,0 |
| 115 |
fiber_switchContext: |
| 116 |
.cfi_startproc |
| 117 |
daddiu $sp, $sp, -(10 * 8) |
| 118 |
|
| 119 |
// fp regs and return address are stored below the stack |
| 120 |
// because we don't want the GC to scan them. |
| 121 |
|
| 122 |
#ifdef __mips_hard_float |
| 123 |
#define BELOW (8 * 8 + 8) |
| 124 |
s.d $f24, (0 * 8 - BELOW)($sp) |
| 125 |
s.d $f25, (1 * 8 - BELOW)($sp) |
| 126 |
s.d $f26, (2 * 8 - BELOW)($sp) |
| 127 |
s.d $f27, (3 * 8 - BELOW)($sp) |
| 128 |
s.d $f28, (4 * 8 - BELOW)($sp) |
| 129 |
s.d $f29, (5 * 8 - BELOW)($sp) |
| 130 |
s.d $f30, (6 * 8 - BELOW)($sp) |
| 131 |
s.d $f31, (7 * 8 - BELOW)($sp) |
| 132 |
#endif |
| 133 |
sd $ra, -8($sp) |
| 134 |
|
| 135 |
sd $s0, (0 * 8)($sp) |
| 136 |
sd $s1, (1 * 8)($sp) |
| 137 |
sd $s2, (2 * 8)($sp) |
| 138 |
sd $s3, (3 * 8)($sp) |
| 139 |
sd $s4, (4 * 8)($sp) |
| 140 |
sd $s5, (5 * 8)($sp) |
| 141 |
sd $s6, (6 * 8)($sp) |
| 142 |
sd $s7, (7 * 8)($sp) |
| 143 |
sd $gp, (8 * 8)($sp) |
| 144 |
sd $fp, (9 * 8)($sp) |
| 145 |
|
| 146 |
// swap stack pointer |
| 147 |
sd $sp, 0($a0) |
| 148 |
move $sp, $a1 |
| 149 |
|
| 150 |
#ifdef __mips_hard_float |
| 151 |
l.d $f24, (0 * 8 - BELOW)($sp) |
| 152 |
l.d $f25, (1 * 8 - BELOW)($sp) |
| 153 |
l.d $f26, (2 * 8 - BELOW)($sp) |
| 154 |
l.d $f27, (3 * 8 - BELOW)($sp) |
| 155 |
l.d $f28, (4 * 8 - BELOW)($sp) |
| 156 |
l.d $f29, (5 * 8 - BELOW)($sp) |
| 157 |
l.d $f30, (6 * 8 - BELOW)($sp) |
| 158 |
l.d $f31, (7 * 8 - BELOW)($sp) |
| 159 |
#endif |
| 160 |
ld $ra, -8($sp) |
| 161 |
|
| 162 |
ld $s0, (0 * 8)($sp) |
| 163 |
ld $s1, (1 * 8)($sp) |
| 164 |
ld $s2, (2 * 8)($sp) |
| 165 |
ld $s3, (3 * 8)($sp) |
| 166 |
ld $s4, (4 * 8)($sp) |
| 167 |
ld $s5, (5 * 8)($sp) |
| 168 |
ld $s6, (6 * 8)($sp) |
| 169 |
ld $s7, (7 * 8)($sp) |
| 170 |
ld $gp, (8 * 8)($sp) |
| 171 |
ld $fp, (9 * 8)($sp) |
| 172 |
|
| 173 |
daddiu $sp, $sp, (10 * 8) |
| 174 |
|
| 175 |
jr $ra // return |
| 176 |
.cfi_endproc |
| 177 |
.end fiber_switchContext |
| 178 |
.size fiber_switchContext,.-fiber_switchContext |
| 179 |
|
| 180 |
#endif /* defined(__mips64) && _MIPS_SIM == _ABI64 */ |