]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/nios2/clone.S
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / nios2 / clone.S
1 /*
2  * libc/sysdeps/linux/nios2/clone.S -- `clone' syscall for linux/nios2
3  *
4  *  Copyright (C) 2004  Microtronix Datacom Ltd
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License.  See the file COPYING.LIB in the main
8  * directory of this archive for more details.
9  * 
10  * Written by Wentao Xu <wentao@microtronix.com>
11  */
12
13 #define _ERRNO_H
14 #include <bits/errno.h>
15 #include <sys/syscall.h>
16
17 #ifdef __NR_clone
18 /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
19
20 .text
21 .global clone
22 .type   clone,%function
23 .align 4
24 clone:
25         addi    sp,sp,-8
26         mov     r8,r4
27         stw     ra,4(sp)
28         stw     r16,0(sp)
29
30         mov     r4,r6
31         movi    r2,-EINVAL
32         
33         /* sanity check */
34         beq     r8,zero,CLONE_ERROR_LABEL
35         beq     r5,zero,CLONE_ERROR_LABEL
36         
37         /* system call */
38         movi    r2,TRAP_ID_SYSCALL
39         movi    r3,__NR_clone
40         trap
41         
42         /* child call the function */
43         mov     r4,r7
44         bne     r2,zero,CLONE_ERROR_LABEL
45         callr   r8
46         
47         /* exit if it returns */
48         mov     r4,r2
49         movi    r3,__NR_exit
50         trap
51         
52 CLONE_ERROR_LABEL: 
53         movi    r3,-4096
54         sub     r16,zero,r2
55         bgeu    r3,r2,CLONE_OK
56         
57         /* store errno */
58         call    __errno_location
59         stw     r16,0(r2)
60         movi    r2,-1
61
62 CLONE_OK:
63         ldw     ra,4(sp)
64         ldw     r16,0(sp)
65         addi    sp,sp,8
66         ret
67
68 .size clone,.-clone
69
70 #endif