blob: 60169b40f655341d1f89d4280ee0e99db03c0f52 [file] [log] [blame]
Chris Dearman99186652014-02-06 20:36:51 -08001/*
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
Elliott Hughes851e68a2014-02-19 16:53:20 -080029#include <private/bionic_asm.h>
Chris Dearman99186652014-02-06 20:36:51 -080030
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
Dimitry Ivanove6ee9602016-10-27 02:32:47 -070044 .balign 16
Chris Dearman99186652014-02-06 20:36:51 -080045 .type __start,@function
46
47 .ent __start
48 .globl __start
Dmitriy Ivanov1a5db572014-07-28 17:53:29 -070049 .globl _start
Chris Dearman99186652014-02-06 20:36:51 -080050__start:
Dmitriy Ivanov1a5db572014-07-28 17:53:29 -070051_start:
Chris Dearman99186652014-02-06 20:36:51 -080052 .set noreorder
53 bal 1f
54 nop
551:
56#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
Elliott Hughesab413c52017-10-13 13:22:24 -070057 .cpload $ra
Chris Dearman99186652014-02-06 20:36:51 -080058#else
Elliott Hughesab413c52017-10-13 13:22:24 -070059 .cpsetup $ra, $0, 1b
Chris Dearman99186652014-02-06 20:36:51 -080060#endif
61 .set reorder
62
63 /* Discover the load address */
Elliott Hughesab413c52017-10-13 13:22:24 -070064 LA $t0, 1b
65 PTR_SUBU $t0, $ra, $t0
Chris Dearman99186652014-02-06 20:36:51 -080066
67#define DT_PLTGOT 3
68#define DT_MIPS_LOCAL_GOTNO 0x7000000a
69
70 /* Search dynamic table for DT_MIPS_LOCAL_GOTNO and DT_PLTGOT values */
Elliott Hughesab413c52017-10-13 13:22:24 -070071 LA $t1, _DYNAMIC
72 PTR_ADDU $t1, $t0
73 LI $t3, DT_PLTGOT
74 LI $ta0, DT_MIPS_LOCAL_GOTNO
Chris Dearman99186652014-02-06 20:36:51 -0800750:
Elliott Hughesab413c52017-10-13 13:22:24 -070076 REG_L $t2, ELF_DYN_TAG($t1)
77 beqz $t2, .Lrelocate_local_got
Chris Dearman99186652014-02-06 20:36:51 -080078
Elliott Hughesab413c52017-10-13 13:22:24 -070079 bne $t2, $t3, 1f /* DT_PLTGOT? */
80 REG_L $s0, ELF_DYN_VAL($t1)
81 PTR_ADDU $s0, $t0
Chris Dearman99186652014-02-06 20:36:51 -080082 b 2f
83
841:
Elliott Hughesab413c52017-10-13 13:22:24 -070085 bne $t2, $ta0, 2f /* DT_MIPS_LOCAL_GOTNO? */
86 REG_L $s1, ELF_DYN_VAL($t1)
Chris Dearman99186652014-02-06 20:36:51 -080087
Elliott Hughesab413c52017-10-13 13:22:24 -0700882: PTR_ADDU $t1, ELF_DYNSZ
Chris Dearman99186652014-02-06 20:36:51 -080089 b 0b
90
91.Lrelocate_local_got:
92 /*
93 * Relocate the local GOT entries
94 * got[0] is address of lazy resolver function
95 * got[1] may be used for a GNU extension
96 */
97
Elliott Hughesab413c52017-10-13 13:22:24 -070098 PTR_ADDU $s0, GOTENT_SZ
99 SUBU $s1, 1
100 PTR_L $t1, ($s0)
101 bgez $t1, 9f
102 PTR_ADDU $s0, GOTENT_SZ
103 SUBU $s1, 1
Chris Dearman99186652014-02-06 20:36:51 -0800104 b 9f
105
Elliott Hughesab413c52017-10-13 13:22:24 -07001061: PTR_L $t1, ($s0)
107 PTR_ADDU $t1, $t0
108 PTR_S $t1, ($s0)
109 PTR_ADDU $s0, GOTENT_SZ
1109: SUBU $s1, 1
111 bgez $s1, 1b
Chris Dearman99186652014-02-06 20:36:51 -0800112
113 /* call linker_init */
Elliott Hughesab413c52017-10-13 13:22:24 -0700114 move $a0, $sp
Chris Dearman99186652014-02-06 20:36:51 -0800115#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
Elliott Hughesab413c52017-10-13 13:22:24 -0700116 PTR_SUBU $sp, 4*REGSZ /* space for arg saves in linker_init */
Chris Dearman99186652014-02-06 20:36:51 -0800117#endif
118 jal __linker_init
119#if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32)
Elliott Hughesab413c52017-10-13 13:22:24 -0700120 PTR_ADDU $sp, 4*REGSZ /* restore sp */
Chris Dearman99186652014-02-06 20:36:51 -0800121#endif
Elliott Hughesab413c52017-10-13 13:22:24 -0700122 move $t9, $v0
123 j $t9
Chris Dearman99186652014-02-06 20:36:51 -0800124 .end __start