blob: b782947d96a20b3174993c7cce0079b6166ca14a [file] [log] [blame]
Raghu Gandhamd7daacb2012-07-31 12:07:22 -07001/*
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 .align 4
31 .type __start,@function
32
33 .ent __start
34 .globl __start
35__start:
36 .set noreorder
37 bal 1f
38 nop
391: .cpload $31
40 .set reorder
41
42 /* Discover the load address */
43 la $t0, 1f
44 bal 1f
451: subu $t0, $ra, $t0
46
47#define DT_PLTGOT 3
48#define DT_MIPS_LOCAL_GOTNO 0x7000000a
49
50 /* Search dynamic table for DT_MIPS_LOCAL_GOTNO and DT_PLTGOT values */
51 la $t1, _DYNAMIC
52 addu $t1, $t0
53 li $t3, DT_PLTGOT
54 li $t4, DT_MIPS_LOCAL_GOTNO
550:
56 lw $t2, 0($t1)
57 beqz $t2, .Lrelocate_local_got
58
59 bne $t2, $t3, 1f /* DT_PLTGOT? */
60 lw $s0, 4($t1)
61 addu $s0, $t0
62 b 2f
63
641: bne $t2, $t4, 1f /* DT_MIPS_LOCAL_GOTNO? */
65 lw $s1, 4($t1)
66 b 2f
67
681:
692: addu $t1, 8
70 b 0b
71
72.Lrelocate_local_got:
73 /*
74 * Relocate the local GOT entries
75 * got[0] is address of lazy resolver function
76 * got[1] may be used for a GNU extension
77 */
78
79 addu $s0, 4
80 subu $s1, 1
81 lw $t1, ($s0)
82 bgez $t1, 9f
83 addu $s0, 4
84 subu $s1, 1
85 b 9f
86
871: lw $t1, ($s0)
88 addu $t1, $t0
89 sw $t1, ($s0)
90 addu $s0, 4
919: subu $s1, 1
92 bgez $s1, 1b
93
94 /* call linker_init */
95 move $a0, $sp
96 addiu $sp, -4*4 /* space for arg saves in linker_init */
97 la $t9, __linker_init
98 jalr $t9
99 move $t9, $v0
100 addu $sp, 4*4 /* restore sp */
101 j $t9
102 .end __start
103
104 .section .ctors, "wa"
105 .globl __CTOR_LIST__
106__CTOR_LIST__:
107 .long -1