ldasm.S revision 1.24
1/* $OpenBSD: ldasm.S,v 1.24 2016/08/28 06:15:32 guenther Exp $ */ 2 3/* 4 * Copyright (c) 2004 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 * 4) /* XXX */ 30#include <machine/asm.h> 31#include <sys/syscall.h> 32#include <SYS.h> 33 34ENTRY(_dl_start) 35 mov fp, sp 36 mov r5, sp 37 mov lr, r6 @ save lr 38 sub sp, sp, #4+4+DL_DATA_SIZE 39 add r7, sp, #4 @ dl_data 40 41 mov r0, fp @ original stack 42 mov r1, r7 @ dl_data 43 44 ldr r8, .L_GOT @ calculate address of GOT... 451: add r8, pc, r8 @ into r8 46 47 ldr r2, .L__DYNAMIC @ &_DYNAMIC 48 add r2, r2, r8 49 50 bl _dl_boot_bind 51 52 add r0, r5, #4 @ argv 53 ldr r1, [r5, #0x0] @ envp 54 add r1, r1, #2 55 add r1, fp, r1, lsl #2 56 ldr r2, [r7, #7*4] @ loff from dl_data 57 mov r3, r7 @ dl_data 58 bl _dl_boot 59 60 mov sp, fp 61 mov fp, #0 62 mov lr, r6 63 64 mov r1, r0 65 ldr r0, .L_dl_dtors 66 add r0, r0, r8 67 mov pc, r1 68.L_GOT: 69 .long _GLOBAL_OFFSET_TABLE_-(1b+8) 70.L__DYNAMIC: 71 .long _DYNAMIC(GOTOFF) 72.L_dl_dtors: 73 .long _dl_dtors(GOTOFF) 74 75 76ENTRY(_dl_bind_start) 77 /* 78 * ip is pointer to got entry for this relocation 79 * lr is pointer to pltgot[2], which is entry -1 of got plt reloc. 80 * return address is on stack 81 */ 82 stmdb sp!, {r0-r4,sl,fp} 83 84 sub r1, ip, lr /* r1 = 4 * (n + 1) */ 85 sub r1, r1, #4 /* r1 = 4 * n */ 86 mov r1, r1, lsr #2 /* r1 = n */ 87 88 ldr r0, [lr, #-4] 89 bl _dl_bind 90 mov ip, r0 91 ldmia sp!, {r0-r4,sl,fp,lr} 92 mov pc, ip 93 94 /* STUB */ 95 96 97/* ld.so SYSCALLS */ 98 99#define DL_SYSCALL(n) DL_SYSCALL2(n,n) 100#define DL_SYSCALL2(n,c) \ 101 .global __CONCAT(_dl_,n) ;\ 102 .type __CONCAT(_dl_,n)%function ;\ 103__CONCAT(_dl_,n): ;\ 104 SYSTRAP(c) ;\ 105 bcs .L_cerr ;\ 106 mov pc, lr 107 108 .section ".text" 109 .align 4 110DL_SYSCALL(close) 111 112 113 .global _dl_exit 114 .type _dl_exit%function 115_dl_exit: 116 SYSTRAP(exit) 117 1: 118 b 1b 119 120DL_SYSCALL(issetugid) 121DL_SYSCALL(getthrid) 122DL_SYSCALL2(_syscall,__syscall) 123DL_SYSCALL(munmap) 124DL_SYSCALL(mprotect) 125DL_SYSCALL(open) 126DL_SYSCALL(read) 127DL_SYSCALL(write) 128DL_SYSCALL(fstat) 129DL_SYSCALL(readlink) 130DL_SYSCALL(utrace) 131DL_SYSCALL(getentropy) 132DL_SYSCALL(sendsyslog) 133DL_SYSCALL(pledge) 134DL_SYSCALL2(getcwd,__getcwd) 135DL_SYSCALL(sysctl) 136DL_SYSCALL2(set_tcb,__set_tcb) 137 138DL_SYSCALL(getdents) 139 140.L_cerr: 141 rsb r0, r0, #0 /* r0 = -errno */ 142 mov pc, lr 143