Add Changelog ...
[jlayton/glibc.git] / sysdeps / unix / sysv / linux / am33 / clone.S
1 /* Copyright 2001 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Alexandre Oliva <aoliva@redhat.com>.
4    Based on ../i386/clone.S.
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Library General Public License as
8    published by the Free Software Foundation; either version 2 of the
9    License, or (at your option) any later version.
10
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Library General Public License for more details.
15
16    You should have received a copy of the GNU Library General Public
17    License along with the GNU C Library.  If not, see
18    <http://www.gnu.org/licenses/>.  */
19
20 /* clone() is even more special than fork() as it mucks with stacks
21    and invokes a function in the right context after its all over.  */
22
23 #include <sysdep.h>
24 #define _ERRNO_H        1
25 #include <bits/errno.h>
26 #include <asm-syntax.h>
27 #include <bp-sym.h>
28
29 /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
30
31         .text
32 ENTRY (BP_SYM (__clone))
33         /* Sanity check arguments.  */
34         cmp     0,d0    /* no NULL function pointers */
35         beq     L(error_inval)
36         cmp     0,d1    /* no NULL stack pointers */
37         beq     L(error_inval)
38
39         /* Allocate room for a function call in the new stack, and
40            store fn and arg in it.  They will be read back in
41            thread_start.  */
42         mov     d1,a0
43         sub     12,a0
44         mov     d0,(a0)
45         mov     (16,sp),d1
46         mov     d1,(4,a0)
47
48         /* Do the system call */
49         mov     a0,d1
50         mov     (12,sp),a0
51         mov     SYS_ify(clone),d0
52         syscall 0
53
54         cmp     0,d0
55         beq     thread_start
56         blt     L(to_SYSCALL_ERROR_LABEL)
57
58 L(pseudo_end):
59         ret
60
61 L(error_inval):
62         mov     -EINVAL,d0
63 L(to_SYSCALL_ERROR_LABEL):
64         jmp     SYSCALL_ERROR_LABEL
65
66 thread_start:
67         mov     0,a3    /* terminate the stack frame */
68         mov     (4,sp),d0
69         mov     (sp),a0
70         calls   (a0)
71 #ifdef PIC
72 L(here):
73         mov     pc,a2
74         add     _GLOBAL_OFFSET_TABLE_-(L(here) - .),a2
75 #endif
76         call    JUMPTARGET (_exit),[],0
77
78 PSEUDO_END (BP_SYM (__clone))
79
80 weak_alias (BP_SYM (__clone), BP_SYM (clone))