adjust fopencookie structure tag for ABI-compat
[musl] / src / thread / powerpc64 / clone.s
1 .text
2 .global __clone
3 .type __clone, %function
4 __clone:
5         # int clone(fn, stack, flags, arg, ptid, tls, ctid)
6         #            a  b       c     d     e    f    g
7         #            3  4       5     6     7    8    9
8         # pseudo C code:
9         # tid = syscall(SYS_clone,c,b,e,f,g);
10         # if (!tid) syscall(SYS_exit, a(d));
11         # return tid;
12
13         # create initial stack frame for new thread
14         clrrdi 4, 4, 4
15         li     0, 0
16         stdu   0,-32(4)
17
18         # save fn and arg to child stack
19         std    3,  8(4)
20         std    6, 16(4)
21
22         # shuffle args into correct registers and call SYS_clone
23         mr    3, 5
24         #mr   4, 4
25         mr    5, 7
26         mr    6, 8
27         mr    7, 9
28         li    0, 120  # SYS_clone = 120
29         sc
30
31         # if error, negate return (errno)
32         bns+  1f
33         neg   3, 3
34
35 1:      # if we're the parent, return
36         cmpwi cr7, 3, 0
37         bnelr cr7
38
39         # we're the child. call fn(arg)
40         ld     3, 16(1)
41         ld    12,  8(1)
42         mtctr 12
43         bctrl
44
45         # call SYS_exit. exit code is already in r3 from fn return value
46         li    0, 1    # SYS_exit = 1
47         sc