rtld_start.S revision 280903
1/*- 2 * Copyright (c) 2014 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Andrew Turner under 6 * sponsorship from the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <machine/asm.h> 31__FBSDID("$FreeBSD: head/libexec/rtld-elf/aarch64/rtld_start.S 280903 2015-03-31 09:51:19Z andrew $"); 32 33ENTRY(.rtld_start) 34 mov x19, x0 /* Put ps_strings in a callee-saved register */ 35 mov x20, sp /* And the stack pointer */ 36 37 sub x8, x20, #16 /* Make room for obj_main & exit proc */ 38 mov sp, x8 /* Update the stack pointer */ 39 40 mov x0, x20 /* Pass the stack we were given to _rtld */ 41 mov x1, sp /* exit_proc */ 42 add x2, x1, #8 /* obj_main */ 43 bl _rtld /* Call the loader */ 44 mov x8, x0 /* Backup the entry point */ 45 46 ldr x2, [sp] /* Load cleanup */ 47 ldr x1, [sp, #8] /* Load obj_main */ 48 mov x0, x19 /* Restore ps_strings */ 49 mov sp, x20 /* Restore the stack pointer */ 50 br x8 /* Jump to the entry point */ 51END(.rtld_start) 52 53/* 54 * sp + 0 = &GOT[x + 3] 55 * sp + 8 = RA 56 * x16 = &GOT[2] 57 * x17 = &_rtld_bind_start 58 */ 59ENTRY(_rtld_bind_start) 60 mov x17, sp 61 62 /* Save the arguments */ 63 stp x0, x1, [sp, #-16]! 64 stp x2, x3, [sp, #-16]! 65 stp x4, x5, [sp, #-16]! 66 stp x6, x7, [sp, #-16]! 67 68 /* Calculate reloff */ 69 ldr x2, [x17, #0] /* Get the address of the entry */ 70 sub x1, x2, x16 /* Find its offset */ 71 sub x1, x1, #8 /* Adjust for x16 not being at offset 0 */ 72 /* Each rela item has 3 entriesso we need reloff = 3 * index */ 73 lsl x3, x1, #1 /* x3 = 2 * offset */ 74 add x1, x1, x3 /* x1 = x3 + offset = 3 * offset */ 75 76 /* Load obj */ 77 ldr x0, [x16, #-8] 78 79 /* Call into rtld */ 80 bl _rtld_bind 81 82 /* Restore the registers saved by the plt code */ 83 ldp xzr, x30, [sp, #(4 * 16)] 84 85 /* Backup the address to branch to */ 86 mov x16, x0 87 88 /* restore the arguments */ 89 ldp x6, x7, [sp], #16 90 ldp x4, x5, [sp], #16 91 ldp x2, x3, [sp], #16 92 ldp x0, x1, [sp], #16 93 /* And the part of the stack the plt entry handled */ 94 add sp, sp, #16 95 96 /* Call into the correct function */ 97 br x16 98END(_rtld_bind_start) 99 100/* 101 * uint64_t _rtld_tlsdesc(struct tlsdesc *); 102 * 103 * struct tlsdesc { 104 * uint64_t ptr; 105 * uint64_t data; 106 * }; 107 * 108 * Returns the data. 109 */ 110ENTRY(_rtld_tlsdesc) 111 ldr x0, [x0, #8] 112 RET 113END(_rtld_tlsdesc) 114