arc: clone: Simplify CLONE_THREAD detection
[uclibc-ng.git] / libc / sysdeps / linux / h8300 / clone.S
bloba00eba4cb3bc76760c1e938b114b76ac9e91933d
1 /* Copyright 2015 Yoshinori Sato <ysato@users.sourceforge.jp> */
3 /* clone is even more special than fork as it mucks with stacks
4    and invokes a function in the right context after its all over.  */
6 #define _ERRNO_H
7 #include <bits/errno.h>
8 #include <sys/syscall.h>
10 /* int _clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg
11                 void *parent_tidptr, void *tls, void *child_tidptr)  */
13 #ifdef __H8300H__
14         .h8300h
15 #endif
16 #ifdef __H8300S__
17         .h8300s
18 #endif
20 .text
21 .globl  clone
22 clone:
23         /* Sanity check arguments.  */
24         mov.l   #-EINVAL,er3
25         mov.l   er0,er0                 /* no NULL function pointers */
26         beq     __syscall_error
27         mov.l   er1,er1                 /* no NULL stack pointers */
28         beq     __syscall_error
30         /* Allocate space and copy the argument onto the new stack.  */
31         mov.l   @(4:16,sp),er3
32         mov.l   er3,@-er1
34         /* setup argument */
35         mov.l   er0,er3                 /* er3 = child entry */
36         sub.l   #20,sp
37         mov.l   er2,@sp                 /* flags */
38         mov.l   er1,@(4,sp)             /* new sp */
39         mov.l   sp,er1
40         mov.l   @(20+8,sp),er0
41         mov.l   er0,@er1                /* parent tid */
42         adds    #4,er1
43         mov.l   @(20+16,sp),er0
44         mov.l   er0,@er1                /* child tid */
45         adds    #4,er1
46         mov.l   @(20+12,sp),er0
47         mov.l   er0,@er1                /* tls */
48         /* do the system call */
49         mov.l   sp,er1
50         mov.l   #__NR_clone,er0
51         trapa   #0
52         add.l   #20,sp
53         mov.l   er0,er0
54         bmi     __syscall_error
55         beq     thread_start
57         rts
59 __syscall_error:
60         neg.l   er0
61         mov.l   er0,@-sp
62 #if !defined(__PIC__)
63         jsr     @__errno_location
64 #else
65         mov.l   @(__errno_location@GOTOFF,er5),er1
66         jsr     @er1
67 #endif
68         mov.l   @sp,er1
69         mov.l   er1,@er0
70         sub.l   er0,er0
71         dec.l   #1,er0
73         rts
75 thread_start:
76         mov.l   @sp+,er0                /* restore args */
77         jsr     @er3
78         mov.l   er0,er1
79         mov.l   #__NR_exit,er0
80         trapa   #0
82         .end