#
# (c) Rainer Schnitker 1995,1996
#

# define L_FLAG_DLL	 1
# define L_FLAGS	52

.data
	__win32_app:
	.long	1

.text

# The arguments and the environment are passed on the stack:
#
#	 (high end of stack)
#	 environment and argument strings; use envp[] and argv[] for accessing
#	 argv[], NULL terminated
# ESP->  envp[], NULL terminated


# CAUTION do not use registers ebp, esi, edi, ebx

#ifdef EMX_SYS_LIB
	.globl __dos_init
__dos_init:
#else
	.globl	_RSXNT_Init
_RSXNT_Init:
#endif
	finit

	popl	%edx			# return address
	popl	%eax			# _data line

	pushl	%edx
	pushl	%eax
	call	_init_process_test_fork
	movl	%eax, %ecx
	popl	%eax
	popl	%edx

	orl	%ecx, %ecx
	jz	1f
	movl	%ecx, %esp
	pushl	%esp
	call	_init_process_fork
	popl	%eax
	popa
	popf
	ret

	1:
	pushl	%edx
	pushl	%eax
        call    _init_rte
	popl	%eax
	popl	%edx

	testl	$1, 52(%eax)
        jne     return_to_app           # called by dll startup code


					# block:    <- ebp
	movl	%esp, %ecx		# -1 space
	subl	$24 ,%esp		# -2 envc
	movl	%esp, %eax		# -3 argc
					# -4 env
					# -5 argv
					# -6 esp    <- ebx
	pushl	%ecx
	pushl	%edx
	pushl	%eax
	call	_get_argv_env
	popl	%eax
	popl	%edx
	popl	%ecx

	subl	-4(%ecx),%esp
	movl	%esp,-24(%ecx)

	pushl	%edx
	pushl	%eax
	call	_cpy_argv_env
	popl	%eax
	popl	%edx

return_to_app:
	jmp	%edx
	ret

	.align	2, 0x90
#ifdef EMX_SYS_LIB
	.globl __dos_syscall
__dos_syscall:
	jmp __dos_syscall

	call	_force_reloc_call

#else
	.globl	_RSXNT_Call
_RSXNT_Call:
	pushf
	pusha
	pushl	%esp
	call	_sys_call
	popl	%eax
	popa
	popf
	ret
#endif

