fix glob descent into . and .. with GLOB_PERIOD
[musl] / src / thread / powerpc / 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 # SYS_clone = 120
14 # SYS_exit = 1
15
16 # store non-volatile regs r30, r31 on stack in order to put our
17 # start func and its arg there
18 stwu 30, -16(1)
19 stw 31, 4(1)
20
21 # save r3 (func) into r30, and r6(arg) into r31
22 mr 30, 3
23 mr 31, 6
24
25 # create initial stack frame for new thread
26 clrrwi 4, 4, 4
27 li 0, 0
28 stwu 0, -16(4)
29
30 #move c into first arg
31 mr 3, 5
32 #mr 4, 4
33 mr 5, 7
34 mr 6, 8
35 mr 7, 9
36
37 # move syscall number into r0    
38 li 0, 120
39
40 sc
41
42 # check for syscall error
43 bns+ 1f # jump to label 1 if no summary overflow.
44 #else
45 neg 3, 3 #negate the result (errno)
46 1:
47 # compare sc result with 0
48 cmpwi cr7, 3, 0
49
50 # if not 0, jump to end
51 bne cr7, 2f
52
53 #else: we're the child
54 #call funcptr: move arg (d) into r3
55 mr 3, 31
56 #move r30 (funcptr) into CTR reg
57 mtctr 30
58 # call CTR reg
59 bctrl
60 # mov SYS_exit into r0 (the exit param is already in r3)
61 li 0, 1
62 sc
63
64 2:
65
66 # restore stack
67 lwz 30, 0(1)
68 lwz 31, 4(1)
69 addi 1, 1, 16
70
71 blr
72