1/* Copyright (C) 1991, 1992 Free Software Foundation, Inc. 2 3This file is part of the GNU C Library. 4 5The GNU C Library is free software; you can redistribute it and/or 6modify it under the terms of the GNU Library General Public License as 7published by the Free Software Foundation; either version 2 of the 8License, or (at your option) any later version. 9 10The GNU C Library is distributed in the hope that it will be useful, 11but WITHOUT ANY WARRANTY; without even the implied warranty of 12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13Library General Public License for more details. 14 15You should have received a copy of the GNU Library General Public 16License along with the GNU C Library; see the file COPYING.LIB. If 17not, see <http://www.gnu.org/licenses/>. */ 18 19 20/* When we enter this piece of code, the user stack looks like this: 21* argc argument counter (integer) 22* argv[0] program name (pointer) 23* argv[1...N] program args (pointers) 24* NULL 25* env[0...N] environment variables (pointers) 26* NULL 27 28* When we are done here, we want 29* R0=argc 30* R1=*argv[0] 31* R2=*envp[0] 32*/ 33 34#include <features.h> 35 36#undef USE_GOT 37#if defined (__UCLIBC_FORMAT_SHARED_FLAT__) || defined (__UCLIBC_FORMAT_FLAT_SEP_DATA__) 38#define USE_GOT 39#endif 40 41#if !(defined L_Scrt1 && defined __UCLIBC_FORMAT_SHARED_FLAT__) 42 43.text 44.align 2 45.global __start; 46.type __start,STT_FUNC; 47.weak __init; 48.weak __fini; 49.global ___uClibc_main; 50.type ___uClibc_main,STT_FUNC; 51 52/* Stick in a dummy reference to main(), so that if an application 53 * is linking when the main() function is in a static library (.a) 54 * we can be sure that main() actually gets linked in */ 55 56.type _main,STT_FUNC; 57 58__start: 59 60#if defined(__BFIN_FDPIC__) && !defined(L_Scrt1) 61 /* P0 contains a pointer to the program's load map. */ 62 call .Lcall; 63.Lcall: 64 R4 = RETS; 65 SP += -12; 66 R0.L = .Lcall; 67 R0.H = .Lcall; 68 R1.L = __ROFIXUP_LIST__; 69 R1.H = __ROFIXUP_LIST__; 70 R2.L = __ROFIXUP_END__; 71 R2.H = __ROFIXUP_END__; 72 R1 = R1 - R0; 73 R1 = R1 + R4; 74 R2 = R2 - R0; 75 R2 = R2 + R4; 76 R0 = P0; 77 CALL ___self_reloc; 78 SP += 12; 79 P3 = R0; 80#endif 81 82/* clear the frame pointer and the L registers. */ 83 FP = 0; 84 L0 = 0; 85 L1 = 0; 86 L2 = 0; 87 L3 = 0; 88 89#ifdef __ID_SHARED_LIB__ 90 /* We know we have a local copy, so we can avoid the GOT. */ 91 CALL ___shared_flat_add_library; 92#endif 93/* Load register R1 (argc) from the stack to its final resting place */ 94 P0 = SP; 95 R1 = [P0++]; 96 97/* Copy argv pointer into R2 -- which its final resting place */ 98 R2 = P0; 99 100 SP += -28; 101 102#ifndef __BFIN_FDPIC__ 103 R7 = 0; 104#endif 105 /* Pass highest stack pointer to the app. */ 106 [SP + 24] = P2; 107 /* Store the pointer to ld.so's fini that we got in P1. */ 108 [SP + 20] = R7; 109 110/* Ok, now run uClibc's main() -- shouldn't return */ 111#if (defined L_crt1 || defined L_Scrt1) && defined __UCLIBC_CTOR_DTOR__ 112 113#ifdef __BFIN_FDPIC__ 114 R3 = [P3 + __init@FUNCDESC_GOT17M4]; 115#elif defined USE_GOT 116 R3 = [P5 + ___shared_flat_init@GOT]; 117#else 118 R3.H = __init; 119 R3.L = __init; 120#endif 121 [SP+12] = R3; 122 123 124#ifdef __BFIN_FDPIC__ 125 R3 = [P3 + __fini@FUNCDESC_GOT17M4]; 126#elif defined USE_GOT 127 R3 = [P5 + ___shared_flat_fini@GOT]; 128#else 129 R3.H = __fini; 130 R3.L = __fini; 131#endif 132 [SP+16] = R3; 133#else /* no ctor/dtor handling */ 134 R3 = 0; 135 [SP + 12] = R3; 136 [SP + 16] = R3; 137#endif 138 139#ifdef __BFIN_FDPIC__ 140 R0 = [P3 + _main@FUNCDESC_GOT17M4]; 141#elif defined USE_GOT 142 R0 = [P5 + _main@GOT]; 143#else 144 R0.H = _main; 145 R0.L = _main; 146#endif 147#ifdef USE_GOT 148 P0 = [P5 + ___uClibc_main@GOT]; 149 jump (P0) 150#else 151 jump.l ___uClibc_main; 152#endif 153 154#else 155 .text 156 .global lib_main 157 .hidden lib_main 158 .type lib_main,@function 159lib_main: 160 RETS = [SP++]; 161 /* We know we have a local copy, so we can avoid the GOT. */ 162 JUMP.L ___shared_flat_add_library; 163 164 .hidden _current_shared_library_p5_offset_ 165#endif 166 167.section .note.GNU-stack,"",%progbits 168