#include <ibcs/unistd.h>
#include <sysdeps.h>

	.text
	.align	ALIGN
#ifdef ELF_LIBRARY
	.globl SYMBOL_NAME(_waitpid)
	.type SYMBOL_NAME(_waitpid),@function
SYMBOL_NAME_LABEL(_waitpid)
	.weak waitpid
	waitpid = _waitpid
	.type SYMBOL_NAME(waitpid),@function
#else
	.globl SYMBOL_NAME(waitpid)
SYMBOL_NAME_LABEL(waitpid)
#endif

/*
 *  Entry to wait for the PID to terminate
 */

/*
 *  The waitpid function is denoted by having the ZF PF SF and OF
 *  flags set at the same time.
 */
	pushf
	orl	$0x8c4,(%esp)
	popf
/*
 *  Issue the waitpid function request
 */
	movl	$ __IBCS_waitpid , %eax	/* Fetch the function for wait	*/
	.byte	0x9a, 0, 0, 0, 0, 7, 0	/* Issue the request		*/
	cld				/* Reset normal status		*/
/*
 *  Update the error return should an error occur
 */
	jnc	LF(1)			/* If error did not occur, skip	*/
	STORE_NUMBER(%eax,ERRNO)
	mov	$-1,%eax		/* Change the result to error	*/
	ret
LL(1)
	pushl	%ebx
	movl	12(%esp),%ebx
	movl	%edx,(%ebx)		/* Store the child status */
	popl	%ebx
	ret				/* Leave			*/

