Update copyright notices with scripts/update-copyrights
[glibc.git] / ports / sysdeps / unix / sysv / linux / microblaze / clone.S
blobc11213c2bd2e3537d88322db46fd617fe175d5fe
1 /* Copyright (C) 1996-2014 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <http://www.gnu.org/licenses/>.  */
19 /* clone() is even more special than fork() as it mucks with stacks
20    and invokes a function in the right context after its all over.  */
22 #include <sysdep.h>
23 #define _ERRNO_H        1
24 #include <bits/errno.h>
26 /* int clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg,
27               pid_t *ptid, struct user_desc *tls, pid_t *ctid);
29    INCOMING: r5 (fn), r6 (child_stack), r7 (flags), r8 (arg), r9 (ptid)
30              r10 (tls), 28 (r1) ctid
32    OUTGOING:
34    linux: arch/microblaze/entry.S: sys_clone expects
35           r5 (flags)  r6 (child stack) r7 (stack_size) r8 (ptid)r9 (ctid)
36           r10 (tls)
39         .text
40 ENTRY (__clone)
41         addik   r3,r0,-EINVAL
42         beqi    r5,SYSCALL_ERROR_LABEL  ; // Invalid func
43         beqi    r6,SYSCALL_ERROR_LABEL  ; // Invalid stack
44         addik   r6,r6,-8
45         swi     r5,r6,0                 ; // Push fn onto child's stack
46         swi     r8,r6,4                 ; // Push arg for child
47         addk    r5,r0,r7                ; // flags for clone() syscall
48         addk    r7,r0,r0
49         addk    r8,r0,r9                ; // parent tid ptr
50         lwi     r9,r1,28                ; // child tid ptr
51         addik   r12,r0,SYS_ify(clone)
52         brki    r14,8
53         addk    r0,r0,r0
54         addik   r4,r0,-4095
55         cmpu    r4,r4,r3
56         bgei    r4,SYSCALL_ERROR_LABEL
57         beqi    r3,L(thread_start)
58         rtsd    r15,8
59         nop
61 L(thread_start):
62         lwi     r12,r1,0                ; // fn
63         lwi     r5,r1,4                 ; // arg
64         brald   r15,r12
65         nop
66         addk    r5,r0,r3
67         addik   r12,r0,SYS_ify(exit)
68         brki    r14,8
69         nop
70 PSEUDO_END(__clone)
72 weak_alias (__clone,clone)