update from main archive 961016
[glibc.git] / sysdeps / unix / sysv / linux / m68k / clone.S
blob4dcd90e96cb35c856752baa004570e1af6f3146d
1 /* Copyright (C) 1996 Free Software Foundation, Inc.
2    Contributed by Andreas Schwab (schwab@issan.informatik.uni-dortmund.de)
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB.  If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA.  */
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 <errnos.h>
26 /* int clone (int (*fn) (), void *child_stack, int flags, int nargs, ...) */
28         .text
29 ENTRY (__clone)
30         CALL_MCOUNT
32         /* Sanity check arguments.  */
33         movel   #-EINVAL, %d0
34         movel   4(%sp), %a0             /* no NULL function pointers */
35         tstl    %a0
36         jeq     syscall_error
37         movel   8(%sp), %a1             /* no NULL stack pointers */
38         tstl    %a1
39         jeq     syscall_error
40         movel   16(%sp), %d1            /* no negative argument counts */
41         jmi     syscall_error
43         /* Allocate space on the new stack and copy args over */
44         movel   %d1, %d0
45         negl    %d0
46         lea     (%a1,%d0.l*4), %a1
47         jeq     2f
48 1:      movel   16(%sp,%d1.l*4), -4(%a1,%d1.l*4)
49         subql   #1, %d1
50         jne     1b
53         /* Do the system call */
54         exg     %d2, %a1                /* save %d2 and get stack pointer */
55         movel   12(%sp), %d1            /* get flags */
56         movel   #SYS_ify (clone), %d0
57         trap    #0
58         exg     %d2, %a1                /* restore %d2 */
60         tstl    %d0
61         jmi     syscall_error
62         jeq     thread_start
64         rts
66         SYSCALL_ERROR_HANDLER
68 thread_start:
69         subl    %fp, %fp        /* terminate the stack frame */
70         jsr     (%a0)
71         movel   %d0, -(%sp)
72 #ifdef PIC
73         bsrl    _exit@PLTPC
74 #else
75         jbsr    _exit
76 #endif
77 PSEUDO_END (__clone)
79 weak_alias (__clone, clone)