Skip to content

Commit 0766ac6

Browse files
qiangxuhuidevnexen
authored andcommitted
loongarch64 support for fibers
Add loongarch64 assembly files from Boost, needed for fibers support, and hook up loongarch64 fibers support during configure. Close phpGH-13914
1 parent ae5220a commit 0766ac6

File tree

4 files changed

+196
-0
lines changed

4 files changed

+196
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ PHP NEWS
1818
. Implement GH-13609 (Dump wrapped object in WeakReference class). (nielsdos)
1919
. Added sparc64 arch assembly support for zend fiber. (Claudio Jeker)
2020
. Fixed GH-13581 no space available for TLS on NetBSD. (Paul Ripke)
21+
. Added fiber Sys-V loongarch64 support. (qiangxuhui)
2122

2223
- Curl:
2324
. Deprecated the CURLOPT_BINARYTRANSFER constant. (divinity76)
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*******************************************************
2+
* *
3+
* ------------------------------------------------- *
4+
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
5+
* ------------------------------------------------- *
6+
* | 0 | 8 | 16 | 24 | *
7+
* ------------------------------------------------- *
8+
* | FS0 | FS1 | FS2 | FS3 | *
9+
* ------------------------------------------------- *
10+
* ------------------------------------------------- *
11+
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
12+
* ------------------------------------------------- *
13+
* | 32 | 40 | 48 | 56 | *
14+
* ------------------------------------------------- *
15+
* | FS4 | FS5 | FS6 | FS7 | *
16+
* ------------------------------------------------- *
17+
* ------------------------------------------------- *
18+
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
19+
* ------------------------------------------------- *
20+
* | 64 | 72 | 80 | 88 | *
21+
* ------------------------------------------------- *
22+
* | S0 | S1 | S2 | S3 | *
23+
* ------------------------------------------------- *
24+
* ------------------------------------------------- *
25+
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
26+
* ------------------------------------------------- *
27+
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
28+
* ------------------------------------------------- *
29+
* | S4 | S5 | S6 | S7 | *
30+
* ------------------------------------------------- *
31+
* ------------------------------------------------- *
32+
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
33+
* ------------------------------------------------- *
34+
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
35+
* ------------------------------------------------- *
36+
* | S8 | FP | RA | PC | *
37+
* ------------------------------------------------- *
38+
* *
39+
* *****************************************************/
40+
41+
.file "jump_loongarch64_sysv_elf_gas.S"
42+
.text
43+
.globl jump_fcontext
44+
.align 2
45+
.type jump_fcontext,@function
46+
jump_fcontext:
47+
# reserve space on stack
48+
addi.d $sp, $sp, -160
49+
50+
# save fs0 - fs7
51+
fst.d $fs0, $sp, 0
52+
fst.d $fs1, $sp, 8
53+
fst.d $fs2, $sp, 16
54+
fst.d $fs3, $sp, 24
55+
fst.d $fs4, $sp, 32
56+
fst.d $fs5, $sp, 40
57+
fst.d $fs6, $sp, 48
58+
fst.d $fs7, $sp, 56
59+
60+
# save s0 - s8, fp, ra
61+
st.d $s0, $sp, 64
62+
st.d $s1, $sp, 72
63+
st.d $s2, $sp, 80
64+
st.d $s3, $sp, 88
65+
st.d $s4, $sp, 96
66+
st.d $s5, $sp, 104
67+
st.d $s6, $sp, 112
68+
st.d $s7, $sp, 120
69+
st.d $s8, $sp, 128
70+
st.d $fp, $sp, 136
71+
st.d $ra, $sp, 144
72+
73+
# save RA as PC
74+
st.d $ra, $sp, 152
75+
76+
# store SP (pointing to context-data) in A2
77+
move $a2, $sp
78+
79+
# restore SP (pointing to context-data) from A0
80+
move $sp, $a0
81+
82+
# load fs0 - fs7
83+
fld.d $fs0, $sp, 0
84+
fld.d $fs1, $sp, 8
85+
fld.d $fs2, $sp, 16
86+
fld.d $fs3, $sp, 24
87+
fld.d $fs4, $sp, 32
88+
fld.d $fs5, $sp, 40
89+
fld.d $fs6, $sp, 48
90+
fld.d $fs7, $sp, 56
91+
92+
#load s0 - s7
93+
ld.d $s0, $sp, 64
94+
ld.d $s1, $sp, 72
95+
ld.d $s2, $sp, 80
96+
ld.d $s3, $sp, 88
97+
ld.d $s4, $sp, 96
98+
ld.d $s5, $sp, 104
99+
ld.d $s6, $sp, 112
100+
ld.d $s7, $sp, 120
101+
ld.d $s8, $sp, 128
102+
ld.d $fp, $sp, 136
103+
ld.d $ra, $sp, 144
104+
105+
# return transfer_t from jump
106+
# pass transfer_t as first arg in context function
107+
# a0 == FCTX, a1 == DATA
108+
move $a0, $a2
109+
110+
# load PC
111+
ld.d $a2, $sp, 152
112+
113+
# restore stack
114+
addi.d $sp, $sp, 160
115+
116+
# jump to context
117+
jr $a2
118+
.size jump_fcontext, .-jump_fcontext
119+
120+
/* Mark that we don't need executable stack. */
121+
.section .note.GNU-stack,"",%progbits
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*******************************************************
2+
* *
3+
* ------------------------------------------------- *
4+
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
5+
* ------------------------------------------------- *
6+
* | 0 | 8 | 16 | 24 | *
7+
* ------------------------------------------------- *
8+
* | FS0 | FS1 | FS2 | FS3 | *
9+
* ------------------------------------------------- *
10+
* ------------------------------------------------- *
11+
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
12+
* ------------------------------------------------- *
13+
* | 32 | 40 | 48 | 56 | *
14+
* ------------------------------------------------- *
15+
* | FS4 | FS5 | FS6 | FS7 | *
16+
* ------------------------------------------------- *
17+
* ------------------------------------------------- *
18+
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
19+
* ------------------------------------------------- *
20+
* | 64 | 72 | 80 | 88 | *
21+
* ------------------------------------------------- *
22+
* | S0 | S1 | S2 | S3 | *
23+
* ------------------------------------------------- *
24+
* ------------------------------------------------- *
25+
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
26+
* ------------------------------------------------- *
27+
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
28+
* ------------------------------------------------- *
29+
* | S4 | S5 | S6 | S7 | *
30+
* ------------------------------------------------- *
31+
* ------------------------------------------------- *
32+
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
33+
* ------------------------------------------------- *
34+
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
35+
* ------------------------------------------------- *
36+
* | S8 | FP | RA | PC | *
37+
* ------------------------------------------------- *
38+
* *
39+
* *****************************************************/
40+
41+
.file "make_loongarch64_sysv_elf_gas.S"
42+
.text
43+
.globl make_fcontext
44+
.align 2
45+
.type make_fcontext,@function
46+
make_fcontext:
47+
# shift address in A0 to lower 16 byte boundary
48+
bstrins.d $a0, $zero, 3, 0
49+
50+
# reserve space for context-data on context-stack
51+
addi.d $a0, $a0, -160
52+
53+
# third arg of make_fcontext() == address of context-function
54+
st.d $a2, $a0, 152
55+
56+
# save address of finish as return-address for context-function
57+
# will be entered after context-function returns
58+
la.local $a4, finish
59+
st.d $a4, $a0, 144
60+
61+
# return pointer to context-data
62+
jr $ra
63+
64+
finish:
65+
# exit code is zero
66+
li.d $a0, 0
67+
# call _exit(0)
68+
b %plt(_exit)
69+
70+
.size make_fcontext, .-make_fcontext
71+
/* Mark that we don't need executable stack. */
72+
.section .note.GNU-stack,"",%progbits

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,7 @@ AS_CASE([$host_cpu],
12531253
[riscv64*], [fiber_cpu="riscv64"],
12541254
[sparc64], [fiber_cpu="sparc64"],
12551255
[s390x*], [fiber_cpu="s390x"],
1256+
[loongarch64*], [fiber_cpu="loongarch64"],
12561257
[mips64*], [fiber_cpu="mips64"],
12571258
[mips*], [fiber_cpu="mips32"],
12581259
[fiber_cpu="unknown"]
@@ -1275,6 +1276,7 @@ AS_CASE([$fiber_cpu],
12751276
[riscv64], [fiber_asm_file_prefix="riscv64_sysv"],
12761277
[sparc64], [fiber_asm_file_prefix="sparc64_sysv"],
12771278
[s390x], [fiber_asm_file_prefix="s390x_sysv"],
1279+
[loongarch64], [fiber_asm_file_prefix="loongarch64_sysv"],
12781280
[mips64], [fiber_asm_file_prefix="mips64_n64"],
12791281
[mips32], [fiber_asm_file_prefix="mips32_o32"],
12801282
[fiber_asm_file_prefix="unknown"]

0 commit comments

Comments
 (0)