Blame sysdeps/aarch64/start.S

Packit 6c4009
/* Copyright (C) 1995-2018 Free Software Foundation, Inc.
Packit 6c4009
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public License as
Packit 6c4009
   published by the Free Software Foundation; either version 2.1 of the
Packit 6c4009
   License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library.  If not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
Packit 6c4009
/* This is the canonical entry point, usually the first thing in the text
Packit 6c4009
   segment.
Packit 6c4009
Packit 6c4009
   Note that the code in the .init section has already been run.
Packit 6c4009
   This includes _init and _libc_init
Packit 6c4009
Packit 6c4009
Packit 6c4009
   At this entry point, most registers' values are unspecified, except:
Packit 6c4009
Packit 6c4009
   x0/w0	Contains a function pointer to be registered with `atexit'.
Packit 6c4009
		This is how the dynamic linker arranges to have DT_FINI
Packit 6c4009
		functions called for shared libraries that have been loaded
Packit 6c4009
		before this code runs.
Packit 6c4009
Packit 6c4009
   sp		The stack contains the arguments and environment:
Packit 6c4009
		0(sp)			argc
Packit 6c4009
		8(sp)			argv[0]
Packit 6c4009
		...
Packit 6c4009
		(8*argc)(sp)		NULL
Packit 6c4009
		(8*(argc+1))(sp)	envp[0]
Packit 6c4009
		...
Packit 6c4009
					NULL
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
	.text
Packit 6c4009
	.globl _start
Packit 6c4009
	.type _start,#function
Packit 6c4009
_start:
Packit 6c4009
	/* Create an initial frame with 0 LR and FP */
Packit 6c4009
	mov	x29, #0
Packit 6c4009
	mov	x30, #0
Packit 6c4009
Packit 6c4009
	/* Setup rtld_fini in argument register */
Packit 6c4009
	mov	x5, x0
Packit 6c4009
Packit 6c4009
	/* Load argc and a pointer to argv */
Packit 6c4009
	ldr	PTR_REG (1), [sp, #0]
Packit 6c4009
	add	x2, sp, #PTR_SIZE
Packit 6c4009
Packit 6c4009
	/* Setup stack limit in argument register */
Packit 6c4009
	mov	x6, sp
Packit 6c4009
Packit 6c4009
#ifdef PIC
Packit 6c4009
# ifdef SHARED
Packit 6c4009
        adrp    x0, :got:main
Packit 6c4009
	ldr     PTR_REG (0), [x0, #:got_lo12:main]
Packit 6c4009
Packit 6c4009
        adrp    x3, :got:__libc_csu_init
Packit 6c4009
	ldr     PTR_REG (3), [x3, #:got_lo12:__libc_csu_init]
Packit 6c4009
Packit 6c4009
        adrp    x4, :got:__libc_csu_fini
Packit 6c4009
	ldr     PTR_REG (4), [x4, #:got_lo12:__libc_csu_fini]
Packit 6c4009
# else
Packit 6c4009
	adrp	x0, __wrap_main
Packit 6c4009
	add	x0, x0, :lo12:__wrap_main
Packit 6c4009
	adrp	x3, __libc_csu_init
Packit 6c4009
	add	x3, x3, :lo12:__libc_csu_init
Packit 6c4009
	adrp	x4, __libc_csu_fini
Packit 6c4009
	add	x4, x4, :lo12:__libc_csu_fini
Packit 6c4009
# endif
Packit 6c4009
#else
Packit 6c4009
	/* Set up the other arguments in registers */
Packit 6c4009
	MOVL (0, main)
Packit 6c4009
	MOVL (3, __libc_csu_init)
Packit 6c4009
	MOVL (4, __libc_csu_fini)
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
	/* __libc_start_main (main, argc, argv, init, fini, rtld_fini,
Packit 6c4009
			      stack_end) */
Packit 6c4009
Packit 6c4009
	/* Let the libc call main and exit with its return code.  */
Packit 6c4009
	bl	__libc_start_main
Packit 6c4009
Packit 6c4009
	/* should never get here....*/
Packit 6c4009
	bl	abort
Packit 6c4009
Packit 6c4009
#if defined PIC && !defined SHARED
Packit 6c4009
	/* When main is not defined in the executable but in a shared library
Packit 6c4009
	   then a wrapper is needed in crt1.o of the static-pie enabled libc,
Packit 6c4009
	   because crt1.o and rcrt1.o share code and the later must avoid the
Packit 6c4009
	   use of GOT relocations before __libc_start_main is called.  */
Packit 6c4009
__wrap_main:
Packit 6c4009
	b	main
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
	/* Define a symbol for the first piece of initialized data.  */
Packit 6c4009
	.data
Packit 6c4009
	.globl __data_start
Packit 6c4009
__data_start:
Packit 6c4009
	.long 0
Packit 6c4009
	.weak data_start
Packit 6c4009
	data_start = __data_start