ldasm.S revision 1.5
1/* $OpenBSD: ldasm.S,v 1.5 2005/10/23 06:04:03 drahn 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 pc, r0 59 60 61ENTRY(_dl_bind_start) 62 /* 63 * ip is pointer to got entry for this relocation 64 * lr is pointer to pltgot[2], which is entry -1 of got plt reloc. 65 * return address is on stack 66 */ 67 stmdb sp!, {r0-r4,sl,fp} 68 69 sub r1, ip, lr /* r1 = 4 * (n + 1) */ 70 sub r1, r1, #4 /* r1 = 4 * n */ 71 mov r1, r1, lsr #2 /* r1 = n */ 72 73 ldr r0, [lr, #-4] 74 bl _dl_bind 75 mov ip, r0 76 ldmia sp!, {r0-r4,sl,fp,lr} 77 mov pc, ip 78 79 /* STUB */ 80 81 82/* ld.so SYSCALLS */ 83 84#define DL_SYSCALL(n) DL_SYSCALL2(n,n) 85#define DL_SYSCALL2(n,c) \ 86 .global __CONCAT(_dl_,n) ;\ 87 .type __CONCAT(_dl_,n)%function ;\ 88__CONCAT(_dl_,n): ;\ 89 SYSTRAP(c) ;\ 90 bcs .L_cerr ;\ 91 mov pc, lr 92 93 .section ".text" 94 .align 4 95DL_SYSCALL(close) 96 97 98 .global _dl_exit 99 .type _dl_exit%function 100_dl_exit: 101 SYSTRAP(exit) 102 1: 103 b 1b 104 105DL_SYSCALL(issetugid) 106DL_SYSCALL2(_syscall,__syscall) 107DL_SYSCALL(munmap) 108DL_SYSCALL(mprotect) 109DL_SYSCALL(open) 110DL_SYSCALL(read) 111DL_SYSCALL(write) 112DL_SYSCALL(stat) 113DL_SYSCALL(fstat) 114DL_SYSCALL(fcntl) 115DL_SYSCALL2(sysctl,__sysctl) 116 117DL_SYSCALL(getdirentries) 118 119 .global _dl_sigprocmask 120 .type _dl_sigprocmask%function 121_dl_sigprocmask: 122 teq r1, #0 123 moveq r0, #1 124 moveq r1, #0 125 ldrne r1, [r1] 126 SYSTRAP(sigprocmask) 127 bcs .L_cerr 128 teq r2, #0 129 strne r0, [r2] 130 mov r0, #0 131 mov pc, lr 132 133.L_cerr: 134 mov r0, #0 135 sub r0, r0, #1 136 mov pc, lr 137