#include <sysdep.h>
/*
 * These are various helper routines that are needed to run an ELF image.
 */

#ifndef NO_UNDERSCORE
#define RUN _linux_run
#define RESOLVE __dl_linux_resolve
#define EXIT __interpreter_exit
#define RESOLVER __dl_linux_resolver
#define INIT ___loader_bootstrap
#else
#define RUN linux_run
#define RESOLVE _dl_linux_resolve
#define RESOLVER _dl_linux_resolver
#define EXIT _interpreter_exit
#define INIT __loader_bootstrap
#endif

.text
.align ALIGN
#if 0
.globl RUN
	.type	RUN,@function
RUN:
#ifdef __PIC__
	call	.L16
.L14:
#endif
	addl $4,%esp    # take return address off stack so we can get args
	popl %ecx       # get the number of args
	popl %edx	# get the address if argv[1]
	movl %edx,%esp  # now sp points to argv[1]
	pushl %ecx	# and put the number of args back again.
#ifdef __PIC__
	movl EXIT@GOT(%ebx),%edx  # the elf crt0 calls atexit with this
	movl (%edx),%edx
	movl _elf_main@GOT(%ebx),%ebx   # the calling routine should have
			      #  stored the entry point here.
	jmp *%ebx
#else
	movl $EXIT,%edx  # the elf crt0 calls atexit with this
	jmp _elf_main
#endif


#ifdef __PIC__
.L16:
	popl	%ebx
	addl	$_GLOBAL_OFFSET_TABLE_+[.-.L16],%ebx
	jmp	.L14
#endif
.LFE1:
	.size RUN,.LFE1-RUN
#endif
	.align 16

.globl RESOLVE
	.type	RESOLVE,@function
RESOLVE:
#ifdef __PIC__
	pushl %ebx;
	call	.L26
.L24:
	movl RESOLVER@GOT(%ebx),%ebx
	call *%ebx
#else
	call RESOLVER
#endif
	popl %ebx
	addl $8,%esp
	jmp *%eax
#ifdef __PIC__
.L26:
	popl	%ebx
	addl	$_GLOBAL_OFFSET_TABLE_+[.-.L24],%ebx
	jmp	.L24
#endif
.LFE2:
	.size RESOLVE,.LFE2-RESOLVE
#if 0
.comm _elf_main,4
#endif
