1/* Startup code for elf64-sparc 2 Copyright (C) 1997-2017 Free Software Foundation, Inc. 3 Contributed by Richard Henderson <richard@gnu.ai.mit.edu>, 1997. 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 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 In addition to the permissions in the GNU Lesser General Public 11 License, the Free Software Foundation gives you unlimited 12 permission to link the compiled version of this file with other 13 programs, and to distribute those programs without any restriction 14 coming from the use of this file. (The GNU Lesser General Public 15 License restrictions do apply in other respects; for example, they 16 cover modification of the file, and distribution when not linked 17 into another program.) 18 19 Note that people who make modified versions of this file are not 20 obligated to grant this special exception for their modified 21 versions; it is their choice whether to do so. The GNU Lesser 22 General Public License gives permission to release a modified 23 version without this exception; this exception also makes it 24 possible to release a modified version which carries forward this 25 exception. 26 27 The GNU C Library is distributed in the hope that it will be useful, 28 but WITHOUT ANY WARRANTY; without even the implied warranty of 29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 30 Lesser General Public License for more details. 31 32 You should have received a copy of the GNU Lesser General Public 33 License along with the GNU C Library; if not, see 34 <http://www.gnu.org/licenses/>. */ 35 36#include <features.h> 37#include <sysdep.h> 38 39.text 40.align 4 41.global _start 42.type _start,%function 43#if defined(__UCLIBC_CTOR_DTOR__) 44.type _init,%function 45.type _fini,%function 46#else 47.weak _init 48.weak _fini 49#endif 50.type __uClibc_main,%function 51/* Stick in a dummy reference to main(), so that if an application 52 * is linking when the main() function is in a static library (.a) 53 * we can be sure that main() actually gets linked in */ 54.global main 55.type main,%function 56 57#ifdef __PIC__ 58.LLGETPC0: 59 retl 60 add %o7, %l7, %l7 61#endif 62 63_start: 64#ifdef __PIC__ 65 sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7 66 call .LLGETPC0 67 add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7 68#endif 69 70 /* Terminate the stack frame, and reserve space for functions to 71 * drop their arguments. */ 72 mov %g0, %fp 73 sub %sp, 6*8, %sp 74 75 /* Extract the arguments and environment as encoded on the stack. The 76 argument info starts after one register window (16 words) past the SP, 77 plus the bias we added, plus the magic v9 STACK_BIAS. */ 78 ldx [%sp+STACK_BIAS+22*8], %o1 /* %o1 = argc */ 79 add %sp, STACK_BIAS+23*8, %o2 /* %o2 = argv */ 80 81 /* Load the addresses of the user entry points. */ 82 sethi %hi(main), %o0 83 sethi %hi(_init), %o3 84 sethi %hi(_fini), %o4 85 or %o0, %lo(main), %o0 86 or %o3, %lo(_init), %o3 87 or %o4, %lo(_fini), %o4 88#ifdef __PIC__ 89 /* Need a little more magic when building PIC to get addr of main */ 90 LD [%l7 + %o0], %o0 91 LD [%l7 + %o3], %o3 92 LD [%l7 + %o4], %o4 93#endif 94 95 /* When starting a binary via the dynamic linker, %g1 contains the 96 * address of the shared library termination function, which will be 97 * registered with atexit(). If we are statically linked, this will 98 * be NULL. */ 99 mov %g1, %o5 100 101 /* Let libc do the rest of the initialization, and call main. */ 102 call __uClibc_main 103 nop 104 105 /* Die very horribly if exit returns. */ 106 unimp 107 108.size _start,.-_start 109 110/* Define a symbol for the first piece of initialized data. */ 111.data 112.global __data_start 113__data_start: 114.long 0 115.weak data_start 116 data_start = __data_start 117