Port musl to x86-64. One giant commit!
[musl] / src / thread / x86_64 / clone.s
1 /* Copyright 2011 Nicholas J. Kain, licensed GNU LGPL 2.1 or later */
2 .text
3 .global __uniclone
4 .type   __uniclone,%function
5 /* rdi = child_stack, rsi = start, rdx = pthread_struct */
6 __uniclone:
7         subq    $16,%rdi        /* grow child_stack */
8         mov     %rsi,8(%rdi)    /* push start onto child_stack as return ptr */
9         mov     %rdx,0(%rdi)    /* push pthread_struct onto child_stack */
10         mov     %rdx,%r8        /* r8 = tls */
11         mov     %rdi,%rsi       /* rsi = child_stack */
12         leaq    40(%rdx),%r10   /* r10 = child_id */
13         movl    $56,%eax        /* clone syscall number */
14         movl    $0x7d0f00,%edi  /* rdi = flags */
15         mov     %r10,%rdx       /* rdx = parent_id */
16         syscall                 /* clone(flags, child_stack, parent_id,
17                                  *       child_id, tls) */
18         test    %rax,%rax
19         jnz     1f              /* if we're in the parent -> goto 1f */
20         pop     %rdi            /* restore pthread_struct from child stack */
21 1:      ret
22 .size __uniclone,.-__uniclone