]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/nios2/clone.S
4a951de86518ccb9a1aa167e5e2b121a8886af00
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / nios2 / clone.S
1 /* clone() implementation for Nios II.
2 Copyright (C) 2008-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Andrew Jenner <andrew@codesourcery.com>, 2008.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the 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 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser 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 <tcb-offsets.h>
27
28 /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
29 void *parent_tidptr, void *tls, void *child_tidptr) */
30
31 .text
32 ENTRY(__clone)
33 /* Sanity check arguments. */
34 movi r2, EINVAL
35 /* No NULL function pointers. */
36 beq r4, zero, SYSCALL_ERROR_LABEL
37 /* No NULL stack pointers. */
38 beq r5, zero, SYSCALL_ERROR_LABEL
39
40 subi r5, r5, 8 /* Reserve argument save space. */
41 stw r4, 4(r5) /* Save function pointer. */
42 stw r7, 0(r5) /* Save argument pointer. */
43
44 /* Load arguments. */
45 mov r4, r6
46 ldw r6, 0(sp)
47 ldw r7, 8(sp)
48 ldw r8, 4(sp)
49
50 /* Do the system call. */
51 movi r2, SYS_ify (clone)
52
53 /* End FDE now, because in the child the unwind info will be
54 wrong. */
55 cfi_endproc
56 trap
57
58 /* Check for errors. */
59 bne r7, zero, SYSCALL_ERROR_LABEL
60 /* See if we're on the newly created thread. */
61 beq r2, zero, thread_start
62 /* Successful return from the parent */
63 ret
64
65 thread_start:
66 cfi_startproc
67 cfi_undefined (ra)
68
69 ldw r5, 4(sp) /* Function pointer. */
70 ldw r4, 0(sp) /* Argument pointer. */
71 addi sp, sp, 8
72
73 /* Call the user's function. */
74 callr r5
75
76 /* exit with the result. */
77 movi r2, SYS_ify (exit)
78 trap
79 cfi_endproc
80
81 cfi_startproc
82 PSEUDO_END (__clone)
83 libc_hidden_def (__clone)
84 weak_alias (__clone, clone)