	.file	"crt0.s"
/*
 * $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 *
 */

/*	Copyright (c) 1984 AT&T	*/
/*	All Rights Reserved	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any	*/
/*	actual or intended publication of such source code.	*/

	.ident	"@(#)$Header: crt0.s 1.7 90/03/19 $"

/* C runtime startoff */

/*
 *	C language startup routine
 *	Assume exec code cleared direction flag
 *	Assume that %esp is set to the addr after the last word pushed.
 *	The stack contains (in order): argc, argv[], envp[], ...
 */

#include "sys.s"

	.text
	.globl	_start
	.align	4
_start:
	/* 
	 * Allocate a NULL return address and a NULL previous %ebp as if
	 * there was a genuine call to _start so debuggers stack trace ok.
	 */
	subl	$8,%esp			/* space for NULL pc and %ebp */
	movl	%esp,%ebp		/* first stack frame begins here */

	/*
	 * The location of the envp array is found by adding the
	 * size of the argv array to the start of the argv array.
	 *
	 * environ is placed on stack for later use by main.
	 * It will be ignored by ppinit, but placing it there now
	 * saves later pushes of argv and argc.
	 */
	movl	8(%ebp),%eax		/* argc */
	leal	16(%ebp,%eax,4),%edx	/* envp */
	movl	%edx,environ		/* copy to environ */
	pushl	%edx			/* _ppinit(...,...,envp) */
	leal	12(%ebp),%edx		/* argv */
	pushl	%edx			/* _ppinit(...,argv) */
	pushl	%eax			/* _ppinit(argc,argv) */
	call	_ppinit			/* _ppinit(argc,argv) */

	/*
	 * All arguments from ppinit remain on stack and will be
	 * passed on to main.
	 */

	call    _init_locale            /* call _init_locale() */
	call	main			/* call main(...) */
	addl	$12,%esp		/* clear stack */
	pushl	%eax			/* push exit argument */
	call	exit			/* and call exit */
	xorl	R1,R1			/* return zero */
	SVC(1,exit)			/* in case user defines own exit() */
	hlt

	/*
	 * In case some object modules were compiled "-p", we 
	 * define a dummy _mcount routine.
	 */
	.globl	_mcount
_mcount:
	ret

	.data
	.globl	environ
	.align	4
environ:
	.long	0

#ifdef	COPYRIGHT
#include "copyright"
#endif	/* COPYRIGHT */
