Skip to content

Commit e7588b7

Browse files
committed
Add s390x support
1 parent 32dc90b commit e7588b7

File tree

3 files changed

+266
-0
lines changed

3 files changed

+266
-0
lines changed

Zend/asm/jump_s390x_sysv_elf_gas.S

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/*******************************************************
2+
* ------------------------------------------------- *
3+
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
4+
* ------------------------------------------------- *
5+
* | 0 | 8 | 16 | 24 | *
6+
* ------------------------------------------------- *
7+
* | t.fctx | t.data | r2 | r6 | *
8+
* ------------------------------------------------- *
9+
* ------------------------------------------------- *
10+
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
11+
* ------------------------------------------------- *
12+
* | 32 | 40 | 48 | 56 | *
13+
* ------------------------------------------------- *
14+
* | r7 | r8 | r9 | r10 | *
15+
* ------------------------------------------------- *
16+
* ------------------------------------------------- *
17+
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
18+
* ------------------------------------------------- *
19+
* | 64 | 72 | 80 | 88 | *
20+
* ------------------------------------------------- *
21+
* | r11 | r12 | r13 | r14 | *
22+
* ------------------------------------------------- *
23+
* ------------------------------------------------- *
24+
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
25+
* ------------------------------------------------- *
26+
* | 96 | 104 | 112 | 120 | *
27+
* ------------------------------------------------- *
28+
* | f8 | f9 | f10 | f11 | *
29+
* ------------------------------------------------- *
30+
* ------------------------------------------------- *
31+
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
32+
* ------------------------------------------------- *
33+
* | 128 | 136 | 144 | 152 | *
34+
* ------------------------------------------------- *
35+
* | f12 | f13 | f14 | f15 | *
36+
* ------------------------------------------------- *
37+
* ------------------------------------------------- *
38+
* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
39+
* ------------------------------------------------- *
40+
* | 160 | 168 | 176 | | *
41+
* ------------------------------------------------- *
42+
* | fpc | pc | | | *
43+
* ------------------------------------------------- *
44+
*******************************************************/
45+
46+
.text
47+
.align 8
48+
.global jump_fcontext
49+
.type jump_fcontext, @function
50+
51+
#define ARG_OFFSET 0
52+
#define GR_OFFSET 16
53+
#define FP_OFFSET 96
54+
#define FPC_OFFSET 160
55+
#define PC_OFFSET 168
56+
#define CONTEXT_SIZE 176
57+
58+
#define REG_SAVE_AREA_SIZE 160
59+
60+
/*
61+
62+
typedef void* fcontext_t;
63+
64+
struct transfer_t {
65+
fcontext_t fctx;
66+
void * data;
67+
};
68+
69+
transfer_t jump_fcontext( fcontext_t const to,
70+
void * data);
71+
72+
Incoming args
73+
r2 - Hidden argument to the location where the return transfer_t needs to be returned
74+
r3 - Context we want to switch to
75+
r4 - Data pointer
76+
77+
*/
78+
79+
jump_fcontext:
80+
.machine "z10"
81+
/* Reserve stack space to store the current context. */
82+
aghi %r15,-CONTEXT_SIZE
83+
84+
/* Save the argument register holding the location of the return value. */
85+
stg %r2,GR_OFFSET(%r15)
86+
87+
/* Save the call-saved general purpose registers. */
88+
stmg %r6,%r14,GR_OFFSET+8(%r15)
89+
90+
/* Save call-saved floating point registers. */
91+
std %f8,FP_OFFSET(%r15)
92+
std %f9,FP_OFFSET+8(%r15)
93+
std %f10,FP_OFFSET+16(%r15)
94+
std %f11,FP_OFFSET+24(%r15)
95+
std %f12,FP_OFFSET+32(%r15)
96+
std %f13,FP_OFFSET+40(%r15)
97+
std %f14,FP_OFFSET+48(%r15)
98+
std %f15,FP_OFFSET+56(%r15)
99+
100+
/* Save the return address as current pc. */
101+
stg %r14,PC_OFFSET(%r15)
102+
103+
/* Save the floating point control register. */
104+
stfpc FPC_OFFSET(%r15)
105+
106+
/* Backup the stack pointer pointing to the old context-data into r1. */
107+
lgr %r1,%r15
108+
109+
/* Load the new context pointer as stack pointer. */
110+
lgr %r15,%r3
111+
112+
/* Restore the call-saved GPRs from the new context. */
113+
lmg %r6,%r14,GR_OFFSET+8(%r15)
114+
115+
/* Restore call-saved floating point registers. */
116+
ld %f8,FP_OFFSET(%r15)
117+
ld %f9,FP_OFFSET+8(%r15)
118+
ld %f10,FP_OFFSET+16(%r15)
119+
ld %f11,FP_OFFSET+24(%r15)
120+
ld %f12,FP_OFFSET+32(%r15)
121+
ld %f13,FP_OFFSET+40(%r15)
122+
ld %f14,FP_OFFSET+48(%r15)
123+
ld %f15,FP_OFFSET+56(%r15)
124+
125+
/* Load the floating point control register. */
126+
lfpc FPC_OFFSET(%r15)
127+
128+
/* Restore PC - the location where we will jump to at the end. */
129+
lg %r5,PC_OFFSET(%r15)
130+
131+
ltg %r2,GR_OFFSET(%r15)
132+
jnz use_return_slot
133+
134+
/* We restore a make_fcontext context. Use the function
135+
argument slot in the context we just saved and allocate the
136+
register save area for the target function. */
137+
la %r2,ARG_OFFSET(%r1)
138+
aghi %r15,-REG_SAVE_AREA_SIZE
139+
140+
use_return_slot:
141+
/* Save the two fields in transfer_t. When calling a
142+
make_fcontext function this becomes the function argument of
143+
the target function, otherwise it will be the return value of
144+
jump_fcontext. */
145+
stg %r1,0(%r2)
146+
stg %r4,8(%r2)
147+
148+
/* Free the restored context. */
149+
aghi %r15,CONTEXT_SIZE
150+
151+
/* Jump to the PC loaded from the new context. */
152+
br %r5
153+
154+
155+
.size jump_fcontext,.-jump_fcontext
156+
.section .note.GNU-stack,"",%progbits

Zend/asm/make_s390x_sysv_elf_gas.S

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*******************************************************
2+
* ------------------------------------------------- *
3+
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
4+
* ------------------------------------------------- *
5+
* | 0 | 8 | 16 | 24 | *
6+
* ------------------------------------------------- *
7+
* | t.fctx | t.data | r2 | r6 | *
8+
* ------------------------------------------------- *
9+
* ------------------------------------------------- *
10+
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
11+
* ------------------------------------------------- *
12+
* | 32 | 40 | 48 | 56 | *
13+
* ------------------------------------------------- *
14+
* | r7 | r8 | r9 | r10 | *
15+
* ------------------------------------------------- *
16+
* ------------------------------------------------- *
17+
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
18+
* ------------------------------------------------- *
19+
* | 64 | 72 | 80 | 88 | *
20+
* ------------------------------------------------- *
21+
* | r11 | r12 | r13 | r14 | *
22+
* ------------------------------------------------- *
23+
* ------------------------------------------------- *
24+
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
25+
* ------------------------------------------------- *
26+
* | 96 | 104 | 112 | 120 | *
27+
* ------------------------------------------------- *
28+
* | f8 | f9 | f10 | f11 | *
29+
* ------------------------------------------------- *
30+
* ------------------------------------------------- *
31+
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
32+
* ------------------------------------------------- *
33+
* | 128 | 136 | 144 | 152 | *
34+
* ------------------------------------------------- *
35+
* | f12 | f13 | f14 | f15 | *
36+
* ------------------------------------------------- *
37+
* ------------------------------------------------- *
38+
* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
39+
* ------------------------------------------------- *
40+
* | 160 | 168 | 176 | | *
41+
* ------------------------------------------------- *
42+
* | fpc | pc | | | *
43+
* ------------------------------------------------- *
44+
*******************************************************/
45+
46+
.text
47+
.align 8
48+
.global make_fcontext
49+
.type make_fcontext, @function
50+
51+
#define ARG_OFFSET 0
52+
#define GR_OFFSET 16
53+
#define R14_OFFSET 88
54+
#define FP_OFFSET 96
55+
#define FPC_OFFSET 160
56+
#define PC_OFFSET 168
57+
#define CONTEXT_SIZE 176
58+
59+
/*
60+
61+
fcontext_t make_fcontext( void * sp, std::size_t size, void (* fn)( transfer_t) );
62+
63+
Create and return a context below SP to call FN.
64+
65+
Incoming args
66+
r2 - The stack location where to create the context
67+
r3 - The size of the context
68+
r4 - The address of the context function
69+
70+
*/
71+
72+
make_fcontext:
73+
.machine "z10"
74+
/* Align the stack to an 8 byte boundary. */
75+
nill %r2,0xfff0
76+
77+
/* Allocate stack space for the context. */
78+
aghi %r2,-CONTEXT_SIZE
79+
80+
/* Set the r2 save slot to zero. This indicates jump_fcontext
81+
that this is a special context. */
82+
mvghi GR_OFFSET(%r2),0
83+
84+
/* Save the floating point control register. */
85+
stfpc FPC_OFFSET(%r2)
86+
87+
/* Store the address of the target function as new pc. */
88+
stg %r4,PC_OFFSET(%r2)
89+
90+
/* Store a pointer to the finish routine as r14. If a function
91+
called via context routines just returns that value will be
92+
loaded and used as return address. Hence the program will
93+
just exit. */
94+
larl %r1,finish
95+
stg %r1,R14_OFFSET(%r2)
96+
97+
/* Return as usual with the new context returned in r2. */
98+
br %r14
99+
100+
finish:
101+
/* In finish tasks, you load the exit code and exit the
102+
make_fcontext This is called when the context-function is
103+
entirely executed. */
104+
lghi %r2,0
105+
brasl %r14,_exit@PLT
106+
107+
.size make_fcontext,.-make_fcontext
108+
.section .note.GNU-stack,"",%progbits

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@ AS_CASE([$host_cpu],
11911191
[arm*], [fiber_cpu="arm32"],
11921192
[ppc64*], [fiber_cpu="ppc64"],
11931193
[powerpc*], [fiber_cpu="ppc32"],
1194+
[s390x*], [fiber_cpu="s390x"],
11941195
[mips64*], [fiber_cpu="mips64"],
11951196
[mips*], [fiber_cpu="mips32"],
11961197
[fiber_cpu="unknown"]
@@ -1208,6 +1209,7 @@ AS_CASE([$fiber_cpu],
12081209
[arm32], [fiber_asm_file_prefix="arm_aapcs"],
12091210
[ppc64], [fiber_asm_file_prefix="ppc64_sysv"],
12101211
[ppc32], [fiber_asm_file_prefix="ppc_sysv"],
1212+
[s390x], [fiber_asm_file_prefix="s390x_sysv"],
12111213
[mips64], [fiber_asm_file_prefix="mips64_n64"],
12121214
[mips32], [fiber_asm_file_prefix="mips32_o32"],
12131215
[fiber_asm_file_prefix="unknown"]

0 commit comments

Comments
 (0)