1/* $OpenBSD: ldasm.S,v 1.12 2013/12/25 15:01:39 miod 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 bl _dl_boot_bind 45 46 add r0, r5, #4 @ argv 47 ldr r1, [r5, #0x0] @ envp 48 add r1, r1, #2 49 add r1, fp, r1, lsl #2 50 ldr r2, [r7, #7*4] @ loff from dl_data 51 mov r3, r7 @ dl_data 52 bl _dl_boot 53 54 mov sp, fp 55 mov fp, #0 56 mov lr, r6 57 58 mov r1, r0 59 ldr r2, .L_GOT 601: 61 add r2, pc, r2 62 ldr r0, .L_dl_dtors 63 add r0, r0, r2 64 mov pc, r1 65.L_GOT: 66 .long _GLOBAL_OFFSET_TABLE_-(1b+8) 67.L_dl_dtors: 68 .long _dl_dtors(GOTOFF) 69 70 71ENTRY(_dl_bind_start) 72 /* 73 * ip is pointer to got entry for this relocation 74 * lr is pointer to pltgot[2], which is entry -1 of got plt reloc. 75 * return address is on stack 76 */ 77 stmdb sp!, {r0-r4,sl,fp} 78 79 sub r1, ip, lr /* r1 = 4 * (n + 1) */ 80 sub r1, r1, #4 /* r1 = 4 * n */ 81 mov r1, r1, lsr #2 /* r1 = n */ 82 83 ldr r0, [lr, #-4] 84 bl _dl_bind 85 mov ip, r0 86 ldmia sp!, {r0-r4,sl,fp,lr} 87 mov pc, ip 88 89 /* STUB */ 90 91 92/* ld.so SYSCALLS */ 93 94#define DL_SYSCALL(n) DL_SYSCALL2(n,n) 95#define DL_SYSCALL2(n,c) \ 96 .global __CONCAT(_dl_,n) ;\ 97 .type __CONCAT(_dl_,n)%function ;\ 98__CONCAT(_dl_,n): ;\ 99 SYSTRAP(c) ;\ 100 bcs .L_cerr ;\ 101 mov pc, lr 102 103 .section ".text" 104 .align 4 105DL_SYSCALL(close) 106 107 108 .global _dl_exit 109 .type _dl_exit%function 110_dl_exit: 111 SYSTRAP(exit) 112 1: 113 b 1b 114 115DL_SYSCALL(issetugid) 116DL_SYSCALL2(_syscall,__syscall) 117DL_SYSCALL(munmap) 118DL_SYSCALL(mprotect) 119DL_SYSCALL(open) 120DL_SYSCALL(read) 121DL_SYSCALL(write) 122DL_SYSCALL(fstat) 123DL_SYSCALL(fcntl) 124DL_SYSCALL(gettimeofday) 125DL_SYSCALL(readlink) 126DL_SYSCALL(lstat) 127DL_SYSCALL(utrace) 128DL_SYSCALL2(getcwd,__getcwd) 129DL_SYSCALL2(sysctl,__sysctl) 130 131DL_SYSCALL(getdents) 132 133 .global _dl_sigprocmask 134 .type _dl_sigprocmask%function 135_dl_sigprocmask: 136 teq r1, #0 137 moveq r0, #1 138 moveq r1, #0 139 ldrne r1, [r1] 140 SYSTRAP(sigprocmask) 141 bcs .L_cerr 142 teq r2, #0 143 strne r0, [r2] 144 mov r0, #0 145 mov pc, lr 146 147.L_cerr: 148 mov r0, #0 149 sub r0, r0, #1 150 mov pc, lr 151