19918665a45095ad135576f005c0e5307feb366a1Chris Dearman/* 29918665a45095ad135576f005c0e5307feb366a1Chris Dearman * Copyright (C) 2012 The Android Open Source Project 39918665a45095ad135576f005c0e5307feb366a1Chris Dearman * All rights reserved. 49918665a45095ad135576f005c0e5307feb366a1Chris Dearman * 59918665a45095ad135576f005c0e5307feb366a1Chris Dearman * Redistribution and use in source and binary forms, with or without 69918665a45095ad135576f005c0e5307feb366a1Chris Dearman * modification, are permitted provided that the following conditions 79918665a45095ad135576f005c0e5307feb366a1Chris Dearman * are met: 89918665a45095ad135576f005c0e5307feb366a1Chris Dearman * * Redistributions of source code must retain the above copyright 99918665a45095ad135576f005c0e5307feb366a1Chris Dearman * notice, this list of conditions and the following disclaimer. 109918665a45095ad135576f005c0e5307feb366a1Chris Dearman * * Redistributions in binary form must reproduce the above copyright 119918665a45095ad135576f005c0e5307feb366a1Chris Dearman * notice, this list of conditions and the following disclaimer in 129918665a45095ad135576f005c0e5307feb366a1Chris Dearman * the documentation and/or other materials provided with the 139918665a45095ad135576f005c0e5307feb366a1Chris Dearman * distribution. 149918665a45095ad135576f005c0e5307feb366a1Chris Dearman * 159918665a45095ad135576f005c0e5307feb366a1Chris Dearman * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 169918665a45095ad135576f005c0e5307feb366a1Chris Dearman * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 179918665a45095ad135576f005c0e5307feb366a1Chris Dearman * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 189918665a45095ad135576f005c0e5307feb366a1Chris Dearman * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 199918665a45095ad135576f005c0e5307feb366a1Chris Dearman * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 209918665a45095ad135576f005c0e5307feb366a1Chris Dearman * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 219918665a45095ad135576f005c0e5307feb366a1Chris Dearman * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 229918665a45095ad135576f005c0e5307feb366a1Chris Dearman * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 239918665a45095ad135576f005c0e5307feb366a1Chris Dearman * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 249918665a45095ad135576f005c0e5307feb366a1Chris Dearman * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 259918665a45095ad135576f005c0e5307feb366a1Chris Dearman * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 269918665a45095ad135576f005c0e5307feb366a1Chris Dearman * SUCH DAMAGE. 279918665a45095ad135576f005c0e5307feb366a1Chris Dearman */ 289918665a45095ad135576f005c0e5307feb366a1Chris Dearman 29851e68a2402fa414544e66650e09dfdaac813e51Elliott Hughes#include <private/bionic_asm.h> 309918665a45095ad135576f005c0e5307feb366a1Chris Dearman 319918665a45095ad135576f005c0e5307feb366a1Chris Dearman#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) 329918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define ELF_DYNSZ 8 339918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define ELF_DYN_TAG 0 349918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define ELF_DYN_VAL 4 359918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define GOTENT_SZ 4 369918665a45095ad135576f005c0e5307feb366a1Chris Dearman#else 379918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define ELF_DYNSZ 16 389918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define ELF_DYN_TAG 0 399918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define ELF_DYN_VAL 8 409918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define GOTENT_SZ 8 419918665a45095ad135576f005c0e5307feb366a1Chris Dearman#endif 429918665a45095ad135576f005c0e5307feb366a1Chris Dearman 439918665a45095ad135576f005c0e5307feb366a1Chris Dearman .text 449918665a45095ad135576f005c0e5307feb366a1Chris Dearman .align 4 459918665a45095ad135576f005c0e5307feb366a1Chris Dearman .type __start,@function 469918665a45095ad135576f005c0e5307feb366a1Chris Dearman 479918665a45095ad135576f005c0e5307feb366a1Chris Dearman .ent __start 489918665a45095ad135576f005c0e5307feb366a1Chris Dearman .globl __start 491a5db57d5a0f633a83f20e667a4698757a63413eDmitriy Ivanov .globl _start 509918665a45095ad135576f005c0e5307feb366a1Chris Dearman__start: 511a5db57d5a0f633a83f20e667a4698757a63413eDmitriy Ivanov_start: 529918665a45095ad135576f005c0e5307feb366a1Chris Dearman .set noreorder 539918665a45095ad135576f005c0e5307feb366a1Chris Dearman bal 1f 549918665a45095ad135576f005c0e5307feb366a1Chris Dearman nop 559918665a45095ad135576f005c0e5307feb366a1Chris Dearman1: 569918665a45095ad135576f005c0e5307feb366a1Chris Dearman#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) 579918665a45095ad135576f005c0e5307feb366a1Chris Dearman .cpload ra 589918665a45095ad135576f005c0e5307feb366a1Chris Dearman#else 599918665a45095ad135576f005c0e5307feb366a1Chris Dearman .cpsetup ra, $0, 1b 609918665a45095ad135576f005c0e5307feb366a1Chris Dearman#endif 619918665a45095ad135576f005c0e5307feb366a1Chris Dearman .set reorder 629918665a45095ad135576f005c0e5307feb366a1Chris Dearman 639918665a45095ad135576f005c0e5307feb366a1Chris Dearman /* Discover the load address */ 649918665a45095ad135576f005c0e5307feb366a1Chris Dearman LA t0, 1b 659918665a45095ad135576f005c0e5307feb366a1Chris Dearman PTR_SUBU t0, ra, t0 669918665a45095ad135576f005c0e5307feb366a1Chris Dearman 679918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define DT_PLTGOT 3 689918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define DT_MIPS_LOCAL_GOTNO 0x7000000a 699918665a45095ad135576f005c0e5307feb366a1Chris Dearman 709918665a45095ad135576f005c0e5307feb366a1Chris Dearman /* Search dynamic table for DT_MIPS_LOCAL_GOTNO and DT_PLTGOT values */ 719918665a45095ad135576f005c0e5307feb366a1Chris Dearman LA t1, _DYNAMIC 729918665a45095ad135576f005c0e5307feb366a1Chris Dearman PTR_ADDU t1, t0 739918665a45095ad135576f005c0e5307feb366a1Chris Dearman LI t3, DT_PLTGOT 749918665a45095ad135576f005c0e5307feb366a1Chris Dearman LI ta0, DT_MIPS_LOCAL_GOTNO 759918665a45095ad135576f005c0e5307feb366a1Chris Dearman0: 769918665a45095ad135576f005c0e5307feb366a1Chris Dearman REG_L t2, ELF_DYN_TAG(t1) 779918665a45095ad135576f005c0e5307feb366a1Chris Dearman beqz t2, .Lrelocate_local_got 789918665a45095ad135576f005c0e5307feb366a1Chris Dearman 799918665a45095ad135576f005c0e5307feb366a1Chris Dearman bne t2, t3, 1f /* DT_PLTGOT? */ 809918665a45095ad135576f005c0e5307feb366a1Chris Dearman REG_L s0, ELF_DYN_VAL(t1) 819918665a45095ad135576f005c0e5307feb366a1Chris Dearman PTR_ADDU s0, t0 829918665a45095ad135576f005c0e5307feb366a1Chris Dearman b 2f 839918665a45095ad135576f005c0e5307feb366a1Chris Dearman 849918665a45095ad135576f005c0e5307feb366a1Chris Dearman1: 859918665a45095ad135576f005c0e5307feb366a1Chris Dearman bne t2, ta0, 2f /* DT_MIPS_LOCAL_GOTNO? */ 869918665a45095ad135576f005c0e5307feb366a1Chris Dearman REG_L s1, ELF_DYN_VAL(t1) 879918665a45095ad135576f005c0e5307feb366a1Chris Dearman 889918665a45095ad135576f005c0e5307feb366a1Chris Dearman2: PTR_ADDU t1, ELF_DYNSZ 899918665a45095ad135576f005c0e5307feb366a1Chris Dearman b 0b 909918665a45095ad135576f005c0e5307feb366a1Chris Dearman 919918665a45095ad135576f005c0e5307feb366a1Chris Dearman.Lrelocate_local_got: 929918665a45095ad135576f005c0e5307feb366a1Chris Dearman /* 939918665a45095ad135576f005c0e5307feb366a1Chris Dearman * Relocate the local GOT entries 949918665a45095ad135576f005c0e5307feb366a1Chris Dearman * got[0] is address of lazy resolver function 959918665a45095ad135576f005c0e5307feb366a1Chris Dearman * got[1] may be used for a GNU extension 969918665a45095ad135576f005c0e5307feb366a1Chris Dearman */ 979918665a45095ad135576f005c0e5307feb366a1Chris Dearman 989918665a45095ad135576f005c0e5307feb366a1Chris Dearman PTR_ADDU s0, GOTENT_SZ 999918665a45095ad135576f005c0e5307feb366a1Chris Dearman SUBU s1, 1 1009918665a45095ad135576f005c0e5307feb366a1Chris Dearman PTR_L t1, (s0) 1019918665a45095ad135576f005c0e5307feb366a1Chris Dearman bgez t1, 9f 1029918665a45095ad135576f005c0e5307feb366a1Chris Dearman PTR_ADDU s0, GOTENT_SZ 1039918665a45095ad135576f005c0e5307feb366a1Chris Dearman SUBU s1, 1 1049918665a45095ad135576f005c0e5307feb366a1Chris Dearman b 9f 1059918665a45095ad135576f005c0e5307feb366a1Chris Dearman 1069918665a45095ad135576f005c0e5307feb366a1Chris Dearman1: PTR_L t1, (s0) 1079918665a45095ad135576f005c0e5307feb366a1Chris Dearman PTR_ADDU t1, t0 1089918665a45095ad135576f005c0e5307feb366a1Chris Dearman PTR_S t1, (s0) 1099918665a45095ad135576f005c0e5307feb366a1Chris Dearman PTR_ADDU s0, GOTENT_SZ 1109918665a45095ad135576f005c0e5307feb366a1Chris Dearman9: SUBU s1, 1 1119918665a45095ad135576f005c0e5307feb366a1Chris Dearman bgez s1, 1b 1129918665a45095ad135576f005c0e5307feb366a1Chris Dearman 1139918665a45095ad135576f005c0e5307feb366a1Chris Dearman /* call linker_init */ 1149918665a45095ad135576f005c0e5307feb366a1Chris Dearman move a0, sp 1159918665a45095ad135576f005c0e5307feb366a1Chris Dearman#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) 1169918665a45095ad135576f005c0e5307feb366a1Chris Dearman PTR_SUBU sp, 4*REGSZ /* space for arg saves in linker_init */ 1179918665a45095ad135576f005c0e5307feb366a1Chris Dearman#endif 1189918665a45095ad135576f005c0e5307feb366a1Chris Dearman jal __linker_init 1199918665a45095ad135576f005c0e5307feb366a1Chris Dearman#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) 1209918665a45095ad135576f005c0e5307feb366a1Chris Dearman PTR_ADDU sp, 4*REGSZ /* restore sp */ 1219918665a45095ad135576f005c0e5307feb366a1Chris Dearman#endif 1229918665a45095ad135576f005c0e5307feb366a1Chris Dearman move t9, v0 1239918665a45095ad135576f005c0e5307feb366a1Chris Dearman j t9 1249918665a45095ad135576f005c0e5307feb366a1Chris Dearman .end __start 125