Skip to content

Commit 7ff53ad

Browse files
committed
rename spaen stdlib call to clone_wrapper
1 parent 58ea4ac commit 7ff53ad

6 files changed

Lines changed: 106 additions & 22 deletions

File tree

BE/CodeGenA32/isel_tab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,8 @@ def InitMiscBra():
10671067

10681068
Pattern(o.TRAP, [], [InsTmpl("ud2", [])])
10691069

1070-
# not any change in the stack behavior of the code below needs to be reflected
1071-
# in the spawn() code in StdLib/syscall.a32.asm
1070+
# note: any change in the stack behavior of the code below needs to be reflected
1071+
# in the clone_wrapper() code in StdLib/syscall.a32.asm
10721072
Pattern(o.SYSCALL, [o.DK.INVALID, o.DK.U32],
10731073
[ # push r7 on stack twice for 8 byte alignment
10741074
InsTmpl("str_imm_sub_pre", [arm.REG.sp, 4, arm.REG.r7]),

BE/StdLib/syscall.a32.asm

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
.fun a32_syscall_clone SIGNATURE [S32] = [U32 A32 A32 A32 A32]
223223
.fun a32_thread_function SIGNATURE [] = [U32]
224224

225-
.fun spawn NORMAL [S32] = [C32 A32 A32 U32 U32]
225+
.fun clone_wrapper NORMAL [S32] = [C32 A32 A32 U32 U32]
226226
.bbl entry
227227
poparg proc:C32
228228
poparg new_stack:A32
@@ -270,6 +270,52 @@
270270
ret
271271

272272

273+
.fun a32_syscall_clone3 SIGNATURE [S32] = [A32 U32]
274+
275+
.fun clone3_wrapper NORMAL [S32] = [C32 U32 A32 U32]
276+
.bbl entry
277+
poparg proc:C32
278+
poparg user_arg:U32
279+
poparg param:A32
280+
poparg param_size:U32
281+
# make space on stack
282+
ld stk:U32 param 20
283+
ld stk_size:U32 param 24
284+
sub stk_size stk_size 8 # make space for two parameters (preserves 16 byte alignment)
285+
add stk stk stk_size
286+
# We need to save this to the new stack as there is not guarantee
287+
# that these values will end up in (preserved) registers. (see below)
288+
bitcast sp:A32 stk
289+
st sp 4 proc
290+
st sp 0 user_arg
291+
st param 24 stk_size
292+
#
293+
pusharg param_size
294+
pusharg param
295+
syscall a32_syscall_clone3 435:U16
296+
poparg res:S32
297+
beq res 0 child
298+
pusharg res
299+
ret
300+
301+
.bbl child
302+
# Why do we have to save the user_arg temporarily onto the new stack?
303+
# If user_arg ends up in register we might get lucky because the register
304+
# are presumably preserved when we reach here.
305+
# But if user_arg is spilled onto the old stack it is not clear if we can see it
306+
# at this point.
307+
getsp sp
308+
lea sp sp -8 # compensate for the syscall poping 16 bytes off the stack
309+
# needs to be adjusted when the syscall expansion changes
310+
ld user_arg sp 0
311+
ld proc sp 4
312+
pusharg user_arg
313+
jsr proc a32_thread_function
314+
pusharg 0:S32
315+
syscall a32_syscall_exit 1:U8
316+
trap # unreachable
317+
pusharg 0:S32
318+
ret
273319

274320
.fun socket NORMAL [S32] = [U32 U32 U32]
275321
.bbl entry

BE/StdLib/syscall.a64.asm

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
.fun a64_syscall_clone SIGNATURE [S32] = [U64 A64 A64 A64 A64]
223223
.fun a64_thread_function SIGNATURE [] = [U64]
224224

225-
.fun spawn NORMAL [S32] = [C64 A64 A64 U64 U64]
225+
.fun clone_wrapper NORMAL [S32] = [C64 A64 A64 U64 U64]
226226
.bbl entry
227227
poparg proc:C64
228228
poparg new_stack:A64
@@ -267,6 +267,52 @@
267267
pusharg 0:S32
268268
ret
269269

270+
.fun a64_syscall_clone3 SIGNATURE [S32] = [A64 U64]
271+
272+
.fun clone3_wrapper NORMAL [S32] = [C64 U64 A64 U64]
273+
.bbl entry
274+
poparg proc:C64
275+
poparg user_arg:U64
276+
poparg param:A64
277+
poparg param_size:U64
278+
# make space on stack
279+
ld stk:U64 param 40
280+
ld stk_size:U64 param 48
281+
sub stk_size stk_size 16 # make space for two parameters (preserves 16 byte alignment)
282+
add stk stk stk_size
283+
# We need to save this to the new stack as there is not guarantee
284+
# that these values will end up in (preserved) registers. (see below)
285+
bitcast sp:A64 stk
286+
st sp 8 proc
287+
st sp 0 user_arg
288+
st param 48 stk_size
289+
#
290+
pusharg param_size
291+
pusharg param
292+
syscall a64_syscall_clone3 435:U16
293+
poparg res:S32
294+
beq res 0 child
295+
pusharg res
296+
ret
297+
298+
.bbl child
299+
# Why do we have to save the user_arg temporarily onto the new stack?
300+
# If user_arg ends up in register we might get lucky because the register
301+
# are presumably preserved when we reach here.
302+
# But if user_arg is spilled onto the old stack it is not clear if we can see it
303+
# at this point.
304+
getsp sp
305+
lea sp sp -16 # compensate for the syscall poping 16 bytes off the stack
306+
# needs to be adjusted when the syscall expansion changes
307+
ld user_arg sp 0
308+
ld proc sp 8
309+
pusharg user_arg
310+
jsr proc a64_thread_function
311+
pusharg 0:S32
312+
syscall a64_syscall_exit 60:U8
313+
trap # unreachable
314+
pusharg 0:S32
315+
ret
270316

271317
.fun socket NORMAL [S32] = [U32 U32 U32]
272318
.bbl entry

BE/StdLib/syscall.x64.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
.fun x64_thread_function SIGNATURE [] = [U64]
225225

226226

227-
.fun spawn NORMAL [S32] = [C64 A64 A64 U64 U64]
227+
.fun clone_wrapper NORMAL [S32] = [C64 A64 A64 U64 U64]
228228
.bbl entry
229229
poparg proc:C64
230230
poparg new_stack:A64

BE/TestData/threads.32.asm

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
cas.mem prev_val:U32 old_val new_val gSUM 0
4545
#bsr yield
4646
#poparg res:S32
47-
bne prev_val old_val cas_loop
47+
bne prev_val old_val cas_loop
4848

4949
bne i 0 loop
5050
ret
@@ -67,7 +67,7 @@
6767
pusharg 0:A32 # tls
6868
pusharg stk
6969
pusharg proc
70-
bsr spawn
70+
bsr clone_wrapper
7171
poparg x:S32
7272

7373
bne i 0 loop
@@ -76,7 +76,7 @@
7676
bsr print_s_ln
7777

7878
# bsr short_sleep
79-
79+
8080
mov i = 100
8181
.bbl loop2
8282
sub i i 1
@@ -87,18 +87,14 @@
8787
pusharg siginfo
8888
pusharg 0:S32
8989
pusharg 0:S32 # P_ALL
90-
bsr waitid
90+
bsr waitid
9191
poparg x
9292
bne i 0 loop2
93-
93+
9494
ld.mem sum:U32 gSUM 0
9595
conv iarg:U32 sum
9696
pusharg iarg
9797
bsr print_x_ln
9898

9999
pusharg 0:S32
100100
ret
101-
102-
103-
104-

BE/TestData/threads.64.asm

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
cas.mem prev_val:U64 old_val new_val gSUM 0
4545
#bsr yield
4646
#poparg res:S32
47-
bne prev_val old_val cas_loop
47+
bne prev_val old_val cas_loop
4848

4949
bne i 0 loop
5050
ret
@@ -67,14 +67,14 @@
6767
pusharg 0:A64 # tls
6868
pusharg stk
6969
pusharg proc
70-
bsr spawn
70+
bsr clone_wrapper
7171
poparg x:S32
7272

7373
bne i 0 loop
7474
lea msg:A64 gWORKER_SPAWNED_MSG 0
7575
pusharg msg
7676
bsr print_s_ln
77-
77+
7878
# bsr short_sleep
7979

8080
mov i = 100
@@ -87,7 +87,7 @@
8787
pusharg siginfo
8888
pusharg 0:S32
8989
pusharg 0:S32 # P_ALL
90-
bsr waitid
90+
bsr waitid
9191
poparg x
9292
bne i 0 loop2
9393

@@ -99,7 +99,3 @@
9999

100100
pusharg 0:S32
101101
ret
102-
103-
104-
105-

0 commit comments

Comments
 (0)