Blame sysdeps/unix/sysv/linux/m68k/clone.S

Packit 6c4009
/* Copyright (C) 1996-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Andreas Schwab (schwab@issan.informatik.uni-dortmund.de)
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library.  If not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
/* clone() is even more special than fork() as it mucks with stacks
Packit 6c4009
   and invokes a function in the right context after its all over.  */
Packit 6c4009
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
#define _ERRNO_H	1
Packit 6c4009
#include <bits/errno.h>
Packit 6c4009
#include <tls.h>
Packit 6c4009
Packit 6c4009
/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
Packit 6c4009
	     void *parent_tidptr, void *tls, void *child_tidptr) */
Packit 6c4009
Packit 6c4009
        .text
Packit 6c4009
ENTRY (__clone)
Packit 6c4009
Packit 6c4009
	/* Sanity check arguments.  */
Packit 6c4009
	movel	#-EINVAL, %d0
Packit 6c4009
	movel	4(%sp), %a0		/* no NULL function pointers */
Packit 6c4009
	tstl	%a0
Packit 6c4009
	jeq	SYSCALL_ERROR_LABEL
Packit 6c4009
	movel	8(%sp), %a1		/* no NULL stack pointers */
Packit 6c4009
	tstl	%a1
Packit 6c4009
	jeq	SYSCALL_ERROR_LABEL
Packit 6c4009
Packit 6c4009
	/* Allocate space and copy the argument onto the new stack.  */
Packit 6c4009
	movel	16(%sp), -(%a1)
Packit 6c4009
Packit 6c4009
	/* Do the system call */
Packit 6c4009
	movel	12+0(%sp), %d1		/* get flags */
Packit 6c4009
	movel	%d3, -(%a1)             /* save %d3 and get parent_tidptr */
Packit 6c4009
	movel	%d3, -(%sp)
Packit 6c4009
	cfi_adjust_cfa_offset (4)
Packit 6c4009
	cfi_rel_offset (%d3, 0)
Packit 6c4009
	movel	20+4(%sp), %d3
Packit 6c4009
	movel	%d4, -(%a1)		/* save %d4 and get child_tidptr */
Packit 6c4009
	movel	%d4, -(%sp)
Packit 6c4009
	cfi_adjust_cfa_offset (4)
Packit 6c4009
	cfi_rel_offset (%d4, 0)
Packit 6c4009
	movel	28+8(%sp), %d4
Packit 6c4009
	movel	%d5, -(%a1)             /* save %d5 and get tls */
Packit 6c4009
	movel	%d5, -(%sp)
Packit 6c4009
	cfi_adjust_cfa_offset (4)
Packit 6c4009
	cfi_rel_offset (%d5, 0)
Packit 6c4009
	movel	24+12(%sp), %d5
Packit 6c4009
	/* save %d2 and get stack pointer */
Packit 6c4009
#ifdef __mcoldfire__
Packit 6c4009
	movel	%d2, -(%a1)
Packit 6c4009
	movel	%d2, -(%sp)
Packit 6c4009
	cfi_adjust_cfa_offset (4)
Packit 6c4009
	cfi_rel_offset (%d2, 0)
Packit 6c4009
	movel	%a1, %d2
Packit 6c4009
#else
Packit 6c4009
	exg	%d2, %a1		/* save %d2 and get stack pointer */
Packit 6c4009
	cfi_register (%d2, %a1)
Packit 6c4009
#endif
Packit 6c4009
	movel	#SYS_ify (clone), %d0
Packit 6c4009
Packit 6c4009
	/* End FDE now, because in the child the unwind info will be
Packit 6c4009
	   wrong.  */
Packit 6c4009
	cfi_endproc
Packit 6c4009
Packit 6c4009
	trap	#0
Packit 6c4009
#ifdef __mcoldfire__
Packit 6c4009
	movel	(%sp)+, %d2
Packit 6c4009
#else
Packit 6c4009
	exg	%d2, %a1		/* restore %d2 */
Packit 6c4009
#endif
Packit 6c4009
	movel	(%sp)+, %d5             /* restore %d5, %d4 and %d3 */
Packit 6c4009
	movel	(%sp)+, %d4
Packit 6c4009
	movel	(%sp)+, %d3
Packit 6c4009
Packit 6c4009
	tstl	%d0
Packit 6c4009
	jmi	SYSCALL_ERROR_LABEL
Packit 6c4009
	jeq	1f
Packit 6c4009
Packit 6c4009
	rts
Packit 6c4009
Packit 6c4009
1:
Packit 6c4009
	cfi_startproc
Packit 6c4009
	cfi_undefined (pc)	/* Mark end of stack */
Packit 6c4009
	subl	%fp, %fp	/* terminate the stack frame */
Packit 6c4009
	jsr	(%a0)
Packit 6c4009
	movel	%d0, %d1
Packit 6c4009
	movel	#SYS_ify (exit), %d0
Packit 6c4009
	trap	#0
Packit 6c4009
	cfi_endproc
Packit 6c4009
Packit 6c4009
	cfi_startproc
Packit 6c4009
PSEUDO_END (__clone)
Packit 6c4009
Packit 6c4009
libc_hidden_def (__clone)
Packit 6c4009
weak_alias (__clone, clone)