blob: e7bc3eec0503e125f646427f36366bcd1122dfdd [file] [log] [blame]
Elliott Hughesbdff26d2013-02-11 17:08:16 -08001#include <machine/asm.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08002#include <sys/linux-syscalls.h>
3
Elliott Hughes5e3fc432013-02-11 16:36:48 -08004// int __pthread_clone(int (*fn)(void*), void* tls, int flags, void* arg);
Elliott Hughesbdff26d2013-02-11 17:08:16 -08005ENTRY(__pthread_clone)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08006 pushl %ebx
7 pushl %ecx
8 movl 16(%esp), %ecx
Jack Rencb082042012-03-21 17:48:13 +08009
10 # save tls
11 movl %ecx, %ebx
12 # 16-byte alignment on child stack
13 andl $~15, %ecx
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080014
15 # insert arguments onto the child stack
16 movl 12(%esp), %eax
Jack Rencb082042012-03-21 17:48:13 +080017 movl %eax, -16(%ecx)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080018 movl 24(%esp), %eax
Jack Rencb082042012-03-21 17:48:13 +080019 movl %eax, -12(%ecx)
20 movl %ebx, -8(%ecx)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080021
Jack Rene480fc82011-09-21 12:44:11 +020022 subl $16, %ecx
Jack Rencb082042012-03-21 17:48:13 +080023 movl 20(%esp), %ebx
Elliott Hughesb6032512013-02-12 23:02:33 -080024
25 # make system call
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080026 movl $__NR_clone, %eax
27 int $0x80
Elliott Hughesb6032512013-02-12 23:02:33 -080028
29 cmpl $0, %eax
30 je pc_child
31 jg pc_parent
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080032
Jin Wei22d366c2012-08-08 15:15:16 +080033 # an error occurred, set errno and return -1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080034 negl %eax
Elliott Hughesb6032512013-02-12 23:02:33 -080035 pushl %eax
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080036 call __set_errno
Elliott Hughesb6032512013-02-12 23:02:33 -080037 addl $4, %esp
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080038 orl $-1, %eax
Elliott Hughesb6032512013-02-12 23:02:33 -080039 jmp pc_return
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080040
Elliott Hughesb6032512013-02-12 23:02:33 -080041pc_child:
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080042 # we're in the child thread now, call __thread_entry
43 # with the appropriate arguments on the child stack
44 # we already placed most of them
Jack Rencb082042012-03-21 17:48:13 +080045 call __thread_entry
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080046 hlt
47
Elliott Hughesb6032512013-02-12 23:02:33 -080048pc_parent:
49 # we're the parent; nothing to do.
50pc_return:
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080051 popl %ecx
52 popl %ebx
53 ret
Elliott Hughesbdff26d2013-02-11 17:08:16 -080054END(__pthread_clone)
David 'Digit' Turner97cf7f32010-01-22 18:59:05 -080055
Jin Wei22d366c2012-08-08 15:15:16 +080056
57/*
58 * int __bionic_clone(unsigned long clone_flags,
59 * void* newsp,
60 * int *parent_tidptr,
61 * void *new_tls,
62 * int *child_tidptr,
63 * int (*fn)(void *),
64 * void *arg);
Bruce Beare16984422010-06-25 09:02:10 -070065 */
Elliott Hughesbdff26d2013-02-11 17:08:16 -080066ENTRY(__bionic_clone)
Jin Wei22d366c2012-08-08 15:15:16 +080067 pushl %ebx
68 pushl %esi
69 pushl %edi
70
71 # insert arguments onto the child stack
72 movl 20(%esp), %ecx
73 andl $~15, %ecx
74 movl 36(%esp), %eax
75 movl %eax, -16(%ecx)
76 movl 40(%esp), %eax
77 movl %eax, -12(%ecx)
78
79 subl $16, %ecx
80 movl 16(%esp), %ebx
81 movl 24(%esp), %edx
82 movl 32(%esp), %esi
83 movl 28(%esp), %edi
Elliott Hughesb6032512013-02-12 23:02:33 -080084
85 # make system call
Jin Wei22d366c2012-08-08 15:15:16 +080086 movl $__NR_clone, %eax
87 int $0x80
Elliott Hughesb6032512013-02-12 23:02:33 -080088
89 cmpl $0, %eax
90 je bc_child
91 jg bc_parent
Jin Wei22d366c2012-08-08 15:15:16 +080092
93 # an error occurred, set errno and return -1
94 negl %eax
Elliott Hughesb6032512013-02-12 23:02:33 -080095 pushl %eax
Jin Wei22d366c2012-08-08 15:15:16 +080096 call __set_errno
Elliott Hughesb6032512013-02-12 23:02:33 -080097 addl $4, %esp
Jin Wei22d366c2012-08-08 15:15:16 +080098 orl $-1, %eax
Elliott Hughesb6032512013-02-12 23:02:33 -080099 jmp bc_return
Jin Wei22d366c2012-08-08 15:15:16 +0800100
Elliott Hughesb6032512013-02-12 23:02:33 -0800101bc_child:
Jin Wei22d366c2012-08-08 15:15:16 +0800102 # we're in the child now, call __bionic_clone_entry
103 # with the appropriate arguments on the child stack
104 # we already placed most of them
105 call __bionic_clone_entry
106 hlt
107
Elliott Hughesb6032512013-02-12 23:02:33 -0800108bc_parent:
109 # we're the parent; nothing to do.
110bc_return:
Jin Wei22d366c2012-08-08 15:15:16 +0800111 popl %edi
112 popl %esi
113 popl %ebx
114 ret
Elliott Hughesbdff26d2013-02-11 17:08:16 -0800115END(__bionic_clone)