Blame sysdeps/i386/start.S

Packit Service 82fcde
/* Startup code compliant to the ELF i386 ABI.
Packit Service 82fcde
   Copyright (C) 1995-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   In addition to the permissions in the GNU Lesser General Public
Packit Service 82fcde
   License, the Free Software Foundation gives you unlimited
Packit Service 82fcde
   permission to link the compiled version of this file with other
Packit Service 82fcde
   programs, and to distribute those programs without any restriction
Packit Service 82fcde
   coming from the use of this file. (The GNU Lesser General Public
Packit Service 82fcde
   License restrictions do apply in other respects; for example, they
Packit Service 82fcde
   cover modification of the file, and distribution when not linked
Packit Service 82fcde
   into another program.)
Packit Service 82fcde
Packit Service 82fcde
   Note that people who make modified versions of this file are not
Packit Service 82fcde
   obligated to grant this special exception for their modified
Packit Service 82fcde
   versions; it is their choice whether to do so. The GNU Lesser
Packit Service 82fcde
   General Public License gives permission to release a modified
Packit Service 82fcde
   version without this exception; this exception also makes it
Packit Service 82fcde
   possible to release a modified version which carries forward this
Packit Service 82fcde
   exception.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
/* This is the canonical entry point, usually the first thing in the text
Packit Service 82fcde
   segment.  The SVR4/i386 ABI (pages 3-31, 3-32) says that when the entry
Packit Service 82fcde
   point runs, most registers' values are unspecified, except for:
Packit Service 82fcde
Packit Service 82fcde
   %edx		Contains a function pointer to be registered with `atexit'.
Packit Service 82fcde
		This is how the dynamic linker arranges to have DT_FINI
Packit Service 82fcde
		functions called for shared libraries that have been loaded
Packit Service 82fcde
		before this code runs.
Packit Service 82fcde
Packit Service 82fcde
   %esp		The stack contains the arguments and environment:
Packit Service 82fcde
		0(%esp)			argc
Packit Service 82fcde
		4(%esp)			argv[0]
Packit Service 82fcde
		...
Packit Service 82fcde
		(4*argc)(%esp)		NULL
Packit Service 82fcde
		(4*(argc+1))(%esp)	envp[0]
Packit Service 82fcde
		...
Packit Service 82fcde
					NULL
Packit Service 82fcde
*/
Packit Service 82fcde
Packit Service 1c5418
	.text
Packit Service 1c5418
	.globl _start
Packit Service 1c5418
	.type _start,@function
Packit Service 1c5418
_start:
Packit Service 82fcde
	/* Clear the frame pointer.  The ABI suggests this be done, to mark
Packit Service 82fcde
	   the outermost frame obviously.  */
Packit Service 82fcde
	xorl %ebp, %ebp
Packit Service 82fcde
Packit Service 82fcde
	/* Extract the arguments as encoded on the stack and set up
Packit Service 82fcde
	   the arguments for `main': argc, argv.  envp will be determined
Packit Service 82fcde
	   later in __libc_start_main.  */
Packit Service 82fcde
	popl %esi		/* Pop the argument count.  */
Packit Service 82fcde
	movl %esp, %ecx		/* argv starts just at the current stack top.*/
Packit Service 82fcde
Packit Service 82fcde
	/* Before pushing the arguments align the stack to a 16-byte
Packit Service 82fcde
	(SSE needs 16-byte alignment) boundary to avoid penalties from
Packit Service 82fcde
	misaligned accesses.  Thanks to Edward Seidl <seidl@janed.com>
Packit Service 82fcde
	for pointing this out.  */
Packit Service 82fcde
	andl $0xfffffff0, %esp
Packit Service 82fcde
	pushl %eax		/* Push garbage because we allocate
Packit Service 82fcde
				   28 more bytes.  */
Packit Service 82fcde
Packit Service 82fcde
	/* Provide the highest stack address to the user code (for stacks
Packit Service 82fcde
	   which grow downwards).  */
Packit Service 82fcde
	pushl %esp
Packit Service 82fcde
Packit Service 82fcde
	pushl %edx		/* Push address of the shared library
Packit Service 82fcde
				   termination function.  */
Packit Service 82fcde
Packit Service 82fcde
#ifdef PIC
Packit Service 82fcde
	/* Load PIC register.  */
Packit Service 82fcde
	call 1f
Packit Service 82fcde
	addl $_GLOBAL_OFFSET_TABLE_, %ebx
Packit Service 82fcde
Packit Service 82fcde
	/* Push address of our own entry points to .fini and .init.  */
Packit Service 82fcde
	leal __libc_csu_fini@GOTOFF(%ebx), %eax
Packit Service 82fcde
	pushl %eax
Packit Service 82fcde
	leal __libc_csu_init@GOTOFF(%ebx), %eax
Packit Service 82fcde
	pushl %eax
Packit Service 82fcde
Packit Service 82fcde
	pushl %ecx		/* Push second argument: argv.  */
Packit Service 82fcde
	pushl %esi		/* Push first argument: argc.  */
Packit Service 82fcde
Packit Service 82fcde
# ifdef SHARED
Packit Service 82fcde
	pushl main@GOT(%ebx)
Packit Service 82fcde
# else
Packit Service 82fcde
	/* Avoid relocation in static PIE since _start is called before
Packit Service 82fcde
	   it is relocated.  Don't use "leal main@GOTOFF(%ebx), %eax"
Packit Service 82fcde
	   since main may be in a shared object.  Linker will convert
Packit Service 82fcde
	   "movl main@GOT(%ebx), %eax" to "leal main@GOTOFF(%ebx), %eax"
Packit Service 82fcde
	   if main is defined locally.  */
Packit Service 82fcde
	movl main@GOT(%ebx), %eax
Packit Service 82fcde
	pushl %eax
Packit Service 82fcde
# endif
Packit Service 82fcde
Packit Service 82fcde
	/* Call the user's main function, and exit with its value.
Packit Service 82fcde
	   But let the libc call main.    */
Packit Service 82fcde
	call __libc_start_main@PLT
Packit Service 82fcde
#else
Packit Service 82fcde
	/* Push address of our own entry points to .fini and .init.  */
Packit Service 82fcde
	pushl $__libc_csu_fini
Packit Service 82fcde
	pushl $__libc_csu_init
Packit Service 82fcde
Packit Service 82fcde
	pushl %ecx		/* Push second argument: argv.  */
Packit Service 82fcde
	pushl %esi		/* Push first argument: argc.  */
Packit Service 82fcde
Packit Service 82fcde
	pushl $main
Packit Service 82fcde
Packit Service 82fcde
	/* Call the user's main function, and exit with its value.
Packit Service 82fcde
	   But let the libc call main.    */
Packit Service 82fcde
	call __libc_start_main
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
	hlt			/* Crash if somehow `exit' does return.  */
Packit Service 82fcde
Packit Service 82fcde
#ifdef PIC
Packit Service 82fcde
1:	movl	(%esp), %ebx
Packit Service 82fcde
	ret
Packit Service 82fcde
#endif
Packit Service 82fcde
Packit Service 82fcde
/* To fulfill the System V/i386 ABI we need this symbol.  Yuck, it's so
Packit Service 82fcde
   meaningless since we don't support machines < 80386.  */
Packit Service 82fcde
	.section .rodata
Packit Service 82fcde
	.globl _fp_hw
Packit Service 82fcde
_fp_hw:	.long 3
Packit Service 82fcde
	.size _fp_hw, 4
Packit Service 82fcde
	.type _fp_hw,@object
Packit Service 82fcde
Packit Service 82fcde
/* Define a symbol for the first piece of initialized data.  */
Packit Service 82fcde
	.data
Packit Service 82fcde
	.globl __data_start
Packit Service 82fcde
__data_start:
Packit Service 82fcde
	.long 0
Packit Service 82fcde
	.weak data_start
Packit Service 82fcde
	data_start = __data_start