OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / h8300 / clone.S
1 /* Adapted from glibc */
2 /* Copyright (C) 1996, 1997 Free Software Foundation, Inc. */
3
4 /* clone is even more special than fork as it mucks with stacks
5    and invokes a function in the right context after its all over.  */
6
7 #define _ERRNO_H
8 #include <bits/errno.h>
9 #include <sys/syscall.h>
10
11 /* int _clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
12
13 #ifdef __H8300H__
14         .h8300h
15 #endif
16 #ifdef __H8300S__
17         .h8300s
18 #endif
19
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
29
30         /* Allocate space and copy the argument onto the new stack.  */
31         mov.l   @(4:16,sp),er3
32         mov.l   er3,@-er1
33
34         /* Do the system call */
35         mov.l   er0,er3                 /* er3 = child entry */
36         mov.l   er1,er0
37         mov.l   er2,er1                 /* er1 = flags */
38         mov.l   er0,er2                 /* er2 = child sp */
39         mov.l   #__NR_clone,r0
40         trapa   #0
41         mov.l   er0,er0
42         bmi     __syscall_error
43         beq     thread_start
44
45         rts
46
47 __syscall_error:
48         neg.l   er0
49         mov.l   er0,@-sp
50 #if !defined(__PIC__)
51         jsr     @__errno_location
52 #else
53         mov.l   @(__errno_location@GOTOFF,er5),er1
54         jsr     @er1
55 #endif
56         mov.l   @sp,er1
57         mov.l   er1,@er0
58         sub.l   er0,er0
59         dec.l   #1,er0
60
61         rts
62
63 thread_start:
64         mov.l   @sp+,er0                /* restore args */
65         jsr     @er3
66         mov.l   er0,er1
67         mov.l   #__NR_exit,er0
68         trapa   #0