1/* $OpenBSD: ldasm.S,v 1.8 2019/05/10 13:29:21 guenther Exp $ */ 2 3/* 4 * Copyright (c) 2016 Dale Rahn 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 */ 28 29#define DL_DATA_SIZE (16 * 8) /* XXX */ 30#include <machine/asm.h> 31#include <sys/syscall.h> 32 33 .section .boot.text,"ax",@progbits 34 _ALIGN_TEXT 35 .globl _dl_start 36 .type _dl_start,#function 37_dl_start: 38 mov x29, sp 39 // need to worry about alignment, I think not? 40 mov x19, sp 41 sub sp, sp, #8+8+DL_DATA_SIZE // dl_data size 42 add x20, sp, #4 // dl_data 43 mov x21, lr // save old lr 44 45 mov x0, x29 // original stack 46 mov x1, x20 // dl_data 47 48 adrp x2, _DYNAMIC /* &_DYNAMIC */ 49 add x2, x2, #:lo12:_DYNAMIC 50 51 bl _dl_boot_bind 52 53 add x0, x29, #8 // argv 54 ldr x1, [x29] // load argc 55 add x1, x0, x1, lsl #3 // envp = argv + argc * 8 56 add x1, x1, #8 // + 8 57 ldr x2, [x20, #7*8] // loff from dl_data 58 mov x3, x20 // dl_data 59 bl _dl_boot 60 61 mov sp, x29 // move stack back 62 mov x29, xzr // clear frame back pointer 63 mov lr, xzr 64 65 adrp x8, :got:_dl_dtors 66 ldr x2, [x8, :got_lo12:_dl_dtors] 67 68 br x0 69END(_dl_start) 70 71ENTRY(_dl_bind_start) 72 /* 73 * x16 is pointer to pltgot[2] 74 * x17 is available as scratch register 75 * return address and pointer to pltgot entry for this 76 * relocation are on the stack 77 */ 78 mov x17, sp 79 80 // save parameter/result registers 81 stp x0, x1, [sp, #-16]! 82 stp x2, x3, [sp, #-16]! 83 stp x4, x5, [sp, #-16]! 84 stp x6, x7, [sp, #-16]! 85 stp x8, xzr, [sp, #-16]! 86 87 /* 88 * no need to save v0-v9 as ld.so is compiled with 89 * -march=armv8-a+nofp+nosimd and therefore doesn't touch the 90 * SIMD and Floating-Point registers 91 */ 92 93 ldr x0, [x16, #-8] // object 94 ldr x2, [x17] 95 sub x1, x2, x16 96 sub x1, x1, #8 97 lsr x1, x1, #3 // relidx 98 bl _dl_bind 99 mov x17, x0 100 101 // restore parameter/result registers 102 ldp x8, xzr, [sp], #16 103 ldp x6, x7, [sp], #16 104 ldp x4, x5, [sp], #16 105 ldp x2, x3, [sp], #16 106 ldp x0, x1, [sp], #16 107 108 // restore LR saved by PLT stub 109 ldp xzr, x30, [sp], #16 110 br x17 111END(_dl_bind_start) 112 113ENTRY(_rtld_tlsdesc) 114 RETGUARD_SETUP(_rtld_tlsdesc, x15) 115 ldr x0, [x0, #8] 116 RETGUARD_CHECK(_rtld_tlsdesc, x15) 117 ret 118END(_rtld_tlsdesc) 119