| 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 |  | 
| Elliott Hughes | 851e68a | 2014-02-19 16:53:20 -0800 | [diff] [blame] | 29 | #include <private/bionic_asm.h> | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 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 | 
| Dimitry Ivanov | e6ee960 | 2016-10-27 02:32:47 -0700 | [diff] [blame] | 44 |     .balign	16 | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 45 |     .type	__start,@function | 
 | 46 |  | 
 | 47 |     .ent	__start | 
 | 48 |     .globl	__start | 
| Dmitriy Ivanov | 1a5db57 | 2014-07-28 17:53:29 -0700 | [diff] [blame] | 49 |     .globl	_start | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 50 | __start: | 
| Dmitriy Ivanov | 1a5db57 | 2014-07-28 17:53:29 -0700 | [diff] [blame] | 51 | _start: | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 52 |     .set	noreorder | 
 | 53 |     bal		1f | 
 | 54 |      nop | 
 | 55 | 1: | 
 | 56 | #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) | 
| Elliott Hughes | ab413c5 | 2017-10-13 13:22:24 -0700 | [diff] [blame] | 57 |     .cpload	$ra | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 58 | #else | 
| Elliott Hughes | ab413c5 | 2017-10-13 13:22:24 -0700 | [diff] [blame] | 59 |     .cpsetup	$ra, $0, 1b | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 60 | #endif | 
 | 61 |     .set	reorder | 
 | 62 |  | 
 | 63 |     /* Discover the load address */ | 
| Elliott Hughes | ab413c5 | 2017-10-13 13:22:24 -0700 | [diff] [blame] | 64 |     LA		$t0, 1b | 
 | 65 |     PTR_SUBU	$t0, $ra, $t0 | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 66 |  | 
 | 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 Hughes | ab413c5 | 2017-10-13 13:22:24 -0700 | [diff] [blame] | 71 |     LA		$t1, _DYNAMIC | 
 | 72 |     PTR_ADDU	$t1, $t0 | 
 | 73 |     LI		$t3, DT_PLTGOT | 
 | 74 |     LI		$ta0, DT_MIPS_LOCAL_GOTNO | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 75 | 0: | 
| Elliott Hughes | ab413c5 | 2017-10-13 13:22:24 -0700 | [diff] [blame] | 76 |     REG_L	$t2, ELF_DYN_TAG($t1) | 
 | 77 |     beqz	$t2, .Lrelocate_local_got | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 78 |  | 
| Elliott Hughes | ab413c5 | 2017-10-13 13:22:24 -0700 | [diff] [blame] | 79 |     bne		$t2, $t3, 1f	/* DT_PLTGOT? */ | 
 | 80 |     REG_L	$s0, ELF_DYN_VAL($t1) | 
 | 81 |     PTR_ADDU	$s0, $t0 | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 82 |     b		2f | 
 | 83 |  | 
 | 84 | 1: | 
| Elliott Hughes | ab413c5 | 2017-10-13 13:22:24 -0700 | [diff] [blame] | 85 |     bne		$t2, $ta0, 2f    /* DT_MIPS_LOCAL_GOTNO? */ | 
 | 86 |     REG_L	$s1, ELF_DYN_VAL($t1) | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 87 |  | 
| Elliott Hughes | ab413c5 | 2017-10-13 13:22:24 -0700 | [diff] [blame] | 88 | 2:  PTR_ADDU    $t1, ELF_DYNSZ | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 89 |     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 Hughes | ab413c5 | 2017-10-13 13:22:24 -0700 | [diff] [blame] | 98 |     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 Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 104 |     b		9f | 
 | 105 |  | 
| Elliott Hughes | ab413c5 | 2017-10-13 13:22:24 -0700 | [diff] [blame] | 106 | 1:  PTR_L	$t1, ($s0) | 
 | 107 |     PTR_ADDU	$t1, $t0 | 
 | 108 |     PTR_S	$t1, ($s0) | 
 | 109 |     PTR_ADDU	$s0, GOTENT_SZ | 
 | 110 | 9:  SUBU	$s1, 1 | 
 | 111 |     bgez	$s1, 1b | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 112 |  | 
 | 113 |     /* call linker_init */ | 
| Elliott Hughes | ab413c5 | 2017-10-13 13:22:24 -0700 | [diff] [blame] | 114 |     move	$a0, $sp | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 115 | #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) | 
| Elliott Hughes | ab413c5 | 2017-10-13 13:22:24 -0700 | [diff] [blame] | 116 |     PTR_SUBU	$sp, 4*REGSZ       /* space for arg saves in linker_init */ | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 117 | #endif | 
 | 118 |     jal		__linker_init | 
 | 119 | #if (_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABI32) | 
| Elliott Hughes | ab413c5 | 2017-10-13 13:22:24 -0700 | [diff] [blame] | 120 |     PTR_ADDU	$sp, 4*REGSZ        /* restore sp */ | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 121 | #endif | 
| Elliott Hughes | ab413c5 | 2017-10-13 13:22:24 -0700 | [diff] [blame] | 122 |     move	$t9, $v0 | 
 | 123 |     j		$t9 | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 124 |     .end    __start |