/************************************************************************/
/* This file contains the BCC compiler helper functions */
/* Minix startup routines 
 * __crtso.o __head.o
 */
#asm
	.text	! This is common to all.
	.even
#endasm

/************************************************************************/
/* Function crtso */

#ifdef L___crtso
#asm

| This is the C run-time start-off routine.  It`s job is to take the
| arguments as put on the stack by EXEC, and to parse them and set them up the
| way _main expects them.

	.text
.extern _main, _exit
.globl crtso, _environ
.globl begtext, begdata, begbss
begtext:
crtso:
		sub	bp,bp	| clear for backtrace of core files
		mov	bx,sp
		mov	cx,(bx)
		add	bx,*2
		mov	ax,cx
		inc	ax
		shl	ax,#1
		add	ax,bx
		mov	_environ,ax	| save envp in environ
		push	ax	| push environ
		push	bx	| push argv
		push	cx	| push argc
		call	_main
		add	sp,*6
		push	ax	| push exit status
		call	_exit

.data
begdata:
		.zerow 8	| food for null pointer bugs
_environ:	.word 0
.bss
begbss:
#endasm
#endif

/************************************************************************/
/* Function head */

#ifdef L___head
#asm

.extern _main
.globl begtext, begdata, begbss
.globl crtso, _data_org, _exit
	.text
begtext:
crtso:
	j .0
	.zerow 13		| stack for inital IRET when common I&D
				| also padding to make INIT_SP same as
				| for separate I&D
.0:	mov sp,_stackpt
	call _main
.1:	jmp .1			| this will never be executed
_exit:	jmp _exit		| this will never be executed either
.data
begdata:
_data_org:			| fs needs to know where build stuffed table
.word 0xDADA			| magic number for build
.word 8				| CLICK_SHIFT to check - must match h/const.h
.word 0,0,0			| used by FS only for sizes of init
				| stack for separate I&D follows
.word 0,0,0			| for ip:ss:f pushed by debugger traps
.word 0,0,0			| for cs:ds:ret adr in save()
				| this was missing - a bug as late as V1.3c
				| for ds for new restart() as well
.word 0,0,0			| for ip:ss:f built by restart()
				| so INIT_SP in const.h must be 0x1C
.bss
begbss:
.extern _stackpt
#endasm
#endif

