Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <machine/asm.h> |
| 30 | |
| 31 | #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) |
| 32 | #define ELF_DYNSZ 8 |
| 33 | #define ELF_DYN_TAG 0 |
| 34 | #define ELF_DYN_VAL 4 |
| 35 | #define GOTENT_SZ 4 |
| 36 | #else |
| 37 | #define ELF_DYNSZ 16 |
| 38 | #define ELF_DYN_TAG 0 |
| 39 | #define ELF_DYN_VAL 8 |
| 40 | #define GOTENT_SZ 8 |
| 41 | #endif |
| 42 | |
| 43 | .text |
| 44 | .align 4 |
| 45 | .type __start,@function |
| 46 | |
| 47 | .ent __start |
| 48 | .globl __start |
| 49 | __start: |
| 50 | .set noreorder |
| 51 | bal 1f |
| 52 | nop |
| 53 | 1: |
| 54 | #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) |
| 55 | .cpload ra |
| 56 | #else |
| 57 | .cpsetup ra, $0, 1b |
| 58 | #endif |
| 59 | .set reorder |
| 60 | |
| 61 | /* Discover the load address */ |
| 62 | LA t0, 1b |
| 63 | PTR_SUBU t0, ra, t0 |
| 64 | |
| 65 | #define DT_PLTGOT 3 |
| 66 | #define DT_MIPS_LOCAL_GOTNO 0x7000000a |
| 67 | |
| 68 | /* Search dynamic table for DT_MIPS_LOCAL_GOTNO and DT_PLTGOT values */ |
| 69 | LA t1, _DYNAMIC |
| 70 | PTR_ADDU t1, t0 |
| 71 | LI t3, DT_PLTGOT |
| 72 | LI ta0, DT_MIPS_LOCAL_GOTNO |
| 73 | 0: |
| 74 | REG_L t2, ELF_DYN_TAG(t1) |
| 75 | beqz t2, .Lrelocate_local_got |
| 76 | |
| 77 | bne t2, t3, 1f /* DT_PLTGOT? */ |
| 78 | REG_L s0, ELF_DYN_VAL(t1) |
| 79 | PTR_ADDU s0, t0 |
| 80 | b 2f |
| 81 | |
| 82 | 1: |
| 83 | bne t2, ta0, 2f /* DT_MIPS_LOCAL_GOTNO? */ |
| 84 | REG_L s1, ELF_DYN_VAL(t1) |
| 85 | |
| 86 | 2: PTR_ADDU t1, ELF_DYNSZ |
| 87 | b 0b |
| 88 | |
| 89 | .Lrelocate_local_got: |
| 90 | /* |
| 91 | * Relocate the local GOT entries |
| 92 | * got[0] is address of lazy resolver function |
| 93 | * got[1] may be used for a GNU extension |
| 94 | */ |
| 95 | |
| 96 | PTR_ADDU s0, GOTENT_SZ |
| 97 | SUBU s1, 1 |
| 98 | PTR_L t1, (s0) |
| 99 | bgez t1, 9f |
| 100 | PTR_ADDU s0, GOTENT_SZ |
| 101 | SUBU s1, 1 |
| 102 | b 9f |
| 103 | |
| 104 | 1: PTR_L t1, (s0) |
| 105 | PTR_ADDU t1, t0 |
| 106 | PTR_S t1, (s0) |
| 107 | PTR_ADDU s0, GOTENT_SZ |
| 108 | 9: SUBU s1, 1 |
| 109 | bgez s1, 1b |
| 110 | |
| 111 | /* call linker_init */ |
| 112 | move a0, sp |
| 113 | #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) |
| 114 | PTR_SUBU sp, 4*REGSZ /* space for arg saves in linker_init */ |
| 115 | #endif |
| 116 | jal __linker_init |
| 117 | #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) |
| 118 | PTR_ADDU sp, 4*REGSZ /* restore sp */ |
| 119 | #endif |
| 120 | move t9, v0 |
| 121 | j t9 |
| 122 | .end __start |
| 123 | |
| 124 | /* FIXME:Is this still needed? */ |
| 125 | .section .ctors, "wa" |
| 126 | .globl __CTOR_LIST__ |
| 127 | __CTOR_LIST__: |
| 128 | .long -1 |