| xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | /* Copyright (C) 1995-2016 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 |    <http://www.gnu.org/licenses/>.  */ | 
 | 18 |  | 
 | 19 | /* This is the canonical entry point, usually the first thing in the text | 
 | 20 |    segment. | 
 | 21 |  | 
 | 22 |    Note that the code in the .init section has already been run. | 
 | 23 |    This includes _init and _libc_init | 
 | 24 |  | 
 | 25 |  | 
 | 26 |    At this entry point, most registers' values are unspecified, except: | 
 | 27 |  | 
 | 28 |    x0		Contains a function pointer to be registered with `atexit'. | 
 | 29 | 		This is how the dynamic linker arranges to have DT_FINI | 
 | 30 | 		functions called for shared libraries that have been loaded | 
 | 31 | 		before this code runs. | 
 | 32 |  | 
 | 33 |    sp		The stack contains the arguments and environment: | 
 | 34 | 		0(sp)			argc | 
 | 35 | 		8(sp)			argv[0] | 
 | 36 | 		... | 
 | 37 | 		(8*argc)(sp)		NULL | 
 | 38 | 		(8*(argc+1))(sp)	envp[0] | 
 | 39 | 		... | 
 | 40 | 					NULL | 
 | 41 |  */ | 
 | 42 |  | 
 | 43 | 	.text | 
 | 44 | 	.globl _start | 
 | 45 | 	.type _start,#function | 
 | 46 | _start: | 
 | 47 | 	/* Create an initial frame with 0 LR and FP */ | 
 | 48 | 	mov	x29, #0 | 
 | 49 | 	mov	x30, #0 | 
 | 50 |  | 
 | 51 | 	/* Setup rtld_fini in argument register */ | 
 | 52 | 	mov	x5, x0 | 
 | 53 |  | 
 | 54 | 	/* Load argc and a pointer to argv */ | 
 | 55 | 	ldr	x1, [sp, #0] | 
 | 56 | 	add	x2, sp, #8 | 
 | 57 |  | 
 | 58 | 	/* Setup stack limit in argument register */ | 
 | 59 | 	mov	x6, sp | 
 | 60 |  | 
 | 61 | #ifdef SHARED | 
 | 62 |         adrp    x0, :got:main | 
 | 63 | 	ldr     x0, [x0, #:got_lo12:main] | 
 | 64 |  | 
 | 65 |         adrp    x3, :got:__libc_csu_init | 
 | 66 | 	ldr     x3, [x3, #:got_lo12:__libc_csu_init] | 
 | 67 |  | 
 | 68 |         adrp    x4, :got:__libc_csu_fini | 
 | 69 | 	ldr     x4, [x4, #:got_lo12:__libc_csu_fini] | 
 | 70 | #else | 
 | 71 | 	/* Set up the other arguments in registers */ | 
 | 72 | 	ldr	x0, =main | 
 | 73 | 	ldr	x3, =__libc_csu_init | 
 | 74 | 	ldr	x4, =__libc_csu_fini | 
 | 75 | #endif | 
 | 76 |  | 
 | 77 | 	/* __libc_start_main (main, argc, argv, init, fini, rtld_fini, | 
 | 78 | 			      stack_end) */ | 
 | 79 |  | 
 | 80 | 	/* Let the libc call main and exit with its return code.  */ | 
 | 81 | 	bl	__libc_start_main | 
 | 82 |  | 
 | 83 | 	/* should never get here....*/ | 
 | 84 | 	bl	abort | 
 | 85 |  | 
 | 86 | 	/* Define a symbol for the first piece of initialized data.  */ | 
 | 87 | 	.data | 
 | 88 | 	.globl __data_start | 
 | 89 | __data_start: | 
 | 90 | 	.long 0 | 
 | 91 | 	.weak data_start | 
 | 92 | 	data_start = __data_start |