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    .text
30    .balign   16
31    .type    __start,@function
32
33    .ent    __start
34    .globl    __start
35    .globl    _start
36__start:
37_start:
38    .set    noreorder
39    bal    1f
40    nop
411:  .cpload    $31
42    .set    reorder
43
44    /* Discover the load address */
45    la    $t0, 1f
46    bal    1f
471:  subu    $t0, $ra, $t0
48
49#define DT_PLTGOT 3
50#define DT_MIPS_LOCAL_GOTNO 0x7000000a
51
52    /* Search dynamic table for DT_MIPS_LOCAL_GOTNO and DT_PLTGOT values */
53    la    $t1, _DYNAMIC
54    addu    $t1, $t0
55    li    $t3, DT_PLTGOT
56    li    $t4, DT_MIPS_LOCAL_GOTNO
570:
58    lw    $t2, 0($t1)
59    beqz    $t2, .Lrelocate_local_got
60
61    bne    $t2, $t3, 1f    /* DT_PLTGOT? */
62    lw    $s0, 4($t1)
63    addu    $s0, $t0
64    b    2f
65
661:  bne    $t2, $t4, 1f    /* DT_MIPS_LOCAL_GOTNO? */
67    lw    $s1, 4($t1)
68    b    2f
69
701:
712:  addu    $t1, 8
72    b    0b
73
74.Lrelocate_local_got:
75    /*
76     * Relocate the local GOT entries
77     * got[0] is address of lazy resolver function
78     * got[1] may be used for a GNU extension
79     */
80
81    addu    $s0, 4
82    subu    $s1, 1
83    lw    $t1, ($s0)
84    bgez    $t1, 9f
85    addu    $s0, 4
86    subu    $s1, 1
87    b    9f
88
891:  lw    $t1, ($s0)
90    addu    $t1, $t0
91    sw    $t1, ($s0)
92    addu    $s0, 4
939:  subu    $s1, 1
94    bgez    $s1, 1b
95
96    /* call linker_init */
97    move    $a0, $sp
98    addiu    $sp, -4*4        /* space for arg saves in linker_init */
99    la    $t9, __linker_init
100    jalr    $t9
101    move    $t9, $v0
102    addu    $sp, 4*4        /* restore sp */
103    j    $t9
104    .end    __start
105