master
  1/* Copyright (C) 1995-2020 Free Software Foundation, Inc.
  2
  3   This file is part of the GNU C Library.
  4
  5   The GNU C Library is free software; you can redistribute it and/or
  6   modify it under the terms of the GNU Lesser General Public License as
  7   published by the Free Software Foundation; either version 2.1 of the
  8   License, or (at your option) any later version.
  9
 10   The GNU C Library is distributed in the hope that it will be useful,
 11   but WITHOUT ANY WARRANTY; without even the implied warranty of
 12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13   Lesser General Public License for more details.
 14
 15   You should have received a copy of the GNU Lesser General Public
 16   License along with the GNU C Library.  If not, see
 17   <https://www.gnu.org/licenses/>.  */
 18
 19#include <sysdep.h>
 20
 21/* This is the canonical entry point, usually the first thing in the text
 22   segment.
 23
 24   Note that the code in the .init section has already been run.
 25   This includes _init and _libc_init
 26
 27
 28   At this entry point, most registers' values are unspecified, except:
 29
 30   x0/w0	Contains a function pointer to be registered with `atexit'.
 31		This is how the dynamic linker arranges to have DT_FINI
 32		functions called for shared libraries that have been loaded
 33		before this code runs.
 34
 35   sp		The stack contains the arguments and environment:
 36		0(sp)			argc
 37		8(sp)			argv[0]
 38		...
 39		(8*argc)(sp)		NULL
 40		(8*(argc+1))(sp)	envp[0]
 41		...
 42					NULL
 43 */
 44
 45	.text
 46	.globl _start
 47	.type _start,#function
 48_start:
 49	/* Create an initial frame with 0 LR and FP */
 50	mov	x29, #0
 51	mov	x30, #0
 52
 53	/* Setup rtld_fini in argument register */
 54	mov	x5, x0
 55
 56	/* Load argc and a pointer to argv */
 57	ldr	x1, [sp, #0]
 58	add	x2, sp, 8
 59
 60	/* Setup stack limit in argument register */
 61	mov	x6, sp
 62
 63#ifdef PIC
 64# ifdef SHARED
 65        adrp    x0, :got:main
 66	ldr     x0, [x0, #:got_lo12:main]
 67
 68        adrp    x3, :got:__libc_csu_init
 69	ldr     x3, [x3, #:got_lo12:__libc_csu_init]
 70
 71        adrp    x4, :got:__libc_csu_fini
 72	ldr     x4, [x4, #:got_lo12:__libc_csu_fini]
 73# else
 74	adrp	x0, __wrap_main
 75	add	x0, x0, :lo12:__wrap_main
 76	adrp	x3, __libc_csu_init
 77	add	x3, x3, :lo12:__libc_csu_init
 78	adrp	x4, __libc_csu_fini
 79	add	x4, x4, :lo12:__libc_csu_fini
 80# endif
 81#else
 82	/* Set up the other arguments in registers */
 83	movz    x0, :abs_g3:main
 84	movk    x0, :abs_g2_nc:main
 85	movk    x0, :abs_g1_nc:main
 86	movk    x0, :abs_g0_nc:main
 87	movz    x3, :abs_g3:__libc_csu_init
 88	movk    x3, :abs_g2_nc:__libc_csu_init
 89	movk    x3, :abs_g1_nc:__libc_csu_init
 90	movk    x3, :abs_g0_nc:__libc_csu_init
 91	movz    x4, :abs_g3:__libc_csu_fini
 92	movk    x4, :abs_g2_nc:__libc_csu_fini
 93	movk    x4, :abs_g1_nc:__libc_csu_fini
 94	movk    x4, :abs_g0_nc:__libc_csu_fini
 95#endif
 96
 97	/* __libc_start_main (main, argc, argv, init, fini, rtld_fini,
 98			      stack_end) */
 99
100	/* Let the libc call main and exit with its return code.  */
101	bl	__libc_start_main
102
103	/* should never get here....*/
104	bl	abort
105
106#if defined PIC && !defined SHARED
107	/* When main is not defined in the executable but in a shared library
108	   then a wrapper is needed in crt1.o of the static-pie enabled libc,
109	   because crt1.o and rcrt1.o share code and the later must avoid the
110	   use of GOT relocations before __libc_start_main is called.  */
111__wrap_main:
112	b	main
113#endif
114
115	/* Define a symbol for the first piece of initialized data.  */
116	.data
117	.globl __data_start
118__data_start:
119	.long 0
120	.weak data_start
121	data_start = __data_start