1/* $OpenBSD: ldasm.S,v 1.15 2014/07/14 03:54:51 deraadt Exp $ */ 2 3/* 4 * Copyright (c) 2004 Michael Shalayeff 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 26 * THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/syscall.h> 30#include <machine/asm.h> 31#define _LOCORE 32#include <machine/frame.h> 33#include <machine/vmparam.h> 34#undef _LOCORE 35 36ENTRY(_dl_start,32) 37 copy r3, r1 38 copy sp, r3 39 stwm r1, HPPA_FRAME_SIZE+16*4(sp) 40 41 stw %arg0, HPPA_FRAME_ARG(0)(r3) /* ps_strings */ 42 43#define ADDR(s,r) \ 44 bl 4, t1 !\ 45 depi 0, 31, 2, t1 /* kill pl bits */ !\ 46 b s /* cold brunch -- never done */ !\ 47 ldw 0(t1), t2 /* cat(w,w1,w2{10},w2{0..9}) << 2 */ !\ 48 extru t2, 28, 10, t3 /* w2{0..9} */ !\ 49 extru t2, 26, 16, r /* w1 */ !\ 50 dep t3, 31, 11, r !\ 51 extru,= t2, 31, 1, r0 /* w */ !\ 52 depi 1, 15, 1, r !\ 53 extru,= t2, 29, 1, r0 /* w2{10} */ !\ 54 depi 1, 21, 1, r !\ 55 sh2add r, t1, r /* plus the base */ !\ 56 addi 8, r, r /* bl target is -8 */ 57 58 ADDR(_GLOBAL_OFFSET_TABLE_, r19) 59 ADDR(_DYNAMIC, arg2) 60 stw arg2, HPPA_FRAME_ARG(1)(r3) 61 62 /* make sure to get a fault until it's set proper */ 63 ldi -1, %dp 64 65 ldw 0(arg0), arg0 66 ldo 4(r3), arg1 /* dl_data */ 67 bl _dl_boot_bind, rp 68 ldo -4(arg0), arg0 69 70 ldw HPPA_FRAME_ARG(1)(r3), arg1 /* &_DYNAMIC */ 71 ldw HPPA_FRAME_ARG(0)(r3), arg3 /* ps_strings */ 72 ldw 0(r19), arg2 73 sub arg1, arg2, arg2 /* loff */ 74 75 ldw 0(arg3), arg0 /* argv */ 76 ldw 8(arg3), arg1 /* envp */ 77 78 bl _dl_boot, rp 79 ldo 4(r3), arg3 /* dl_data */ 80 81 ldw HPPA_FRAME_ARG(0)(r3), arg0 /* ps_strings */ 82 ADDR(_hppa_dl_dtors_plabel, arg1) 83 ldw 0(arg1), arg1 /* cleanup */ 84 85 ldo HPPA_FRAME_SIZE(r3), sp 86 copy r0, rp 87 bv r0(ret0) 88 ldwm -HPPA_FRAME_SIZE(sp), r3 89EXIT(_dl_start) 90 91/* 92 * void _hppa_dl_dtors(void); 93 */ 94ENTRY(_hppa_dl_dtors,0) 95 ADDR(_GLOBAL_OFFSET_TABLE_, r19) 96 b _dl_dtors 97 nop 98EXIT(_hppa_dl_dtors) 99 100 .section .data 101 .align 4 102_hppa_dl_dtors_plabel: 103 .word P%_hppa_dl_dtors 104 .previous 105 106LEAF_ENTRY(_hppa_dl_set_dp) 107 bv r0(rp) 108 copy arg0, r27 109EXIT(_hppa_dl_set_dp) 110 111/* 112 * This is a magic branch instruction that is used by GCC's 113 * __canonicalize_funcptr_for_compare() function to fixup relocations 114 * in order to do function pointer comparisons. 115 */ 116 bl _dl_bind, rp 117 118ENTRY(_dl_bind_start,32) 119 copy r3, r1 120 copy sp, r3 121 stwm r1, HPPA_FRAME_SIZE(sp) 122 123 stw rp, HPPA_FRAME_CRP(r3) 124 stw arg0, HPPA_FRAME_ARG(0)(r3) 125 stw arg1, HPPA_FRAME_ARG(1)(r3) 126 stw arg2, HPPA_FRAME_ARG(2)(r3) 127 stw arg3, HPPA_FRAME_ARG(3)(r3) 128 stw t1, 4(r3) 129 stw ret0, 8(r3) 130 stw ret1, 12(r3) 131 132 ldw 12(r20), arg0 133 copy r19, arg1 134 135 bl _dl_bind, rp 136 copy r21, r19 137 138 copy ret0, r21 /* &func */ 139 copy ret1, r19 /* sl */ 140 141 ldw HPPA_FRAME_ARG(0)(r3), arg0 142 ldw HPPA_FRAME_ARG(1)(r3), arg1 143 ldw HPPA_FRAME_ARG(2)(r3), arg2 144 ldw HPPA_FRAME_ARG(3)(r3), arg3 145 ldw 4(r3), t1 146 ldw 8(r3), ret0 147 ldw 12(r3), ret1 148 149 ldw HPPA_FRAME_CRP(r3), rp 150 ldo HPPA_FRAME_SIZE(r3), sp 151 bv r0(r21) 152 ldwm -HPPA_FRAME_SIZE(sp), r3 153EXIT(_dl_bind_start) 154 155#define SYSCALL(x) !\ 156 stw rp, HPPA_FRAME_ERP(sr0,sp) !\ 157 ldil L%SYSCALLGATE, r1 !\ 158 ble 4(sr7, r1) !\ 159 ldi __CONCAT(SYS_,x), t1 !\ 160 comb,<> r0, t1, _dl_sysexit !\ 161 ldw HPPA_FRAME_ERP(sr0,sp), rp 162 163_dl_sysexit 164 bv r0(rp) 165 sub r0, ret0, ret0 166 167ENTRY(_dl_close,0) 168 SYSCALL(close) 169 bv r0(rp) 170 nop 171EXIT(_dl_close) 172 173ENTRY(_dl_exit,0) 174 SYSCALL(exit) 175 bv r0(rp) 176 nop 177EXIT(_dl_exit) 178 179ENTRY(_dl_issetugid,0) 180 SYSCALL(issetugid) 181 bv r0(rp) 182 nop 183EXIT(_dl_issetugid) 184 185ENTRY(_dl__syscall,0) 186 SYSCALL(__syscall) 187 bv r0(rp) 188 nop 189EXIT(_dl__syscall) 190 191ENTRY(_dl_munmap,0) 192 SYSCALL(munmap) 193 bv r0(rp) 194 nop 195EXIT(_dl_munmap) 196 197ENTRY(_dl_mprotect,0) 198 SYSCALL(mprotect) 199 bv r0(rp) 200 nop 201EXIT(_dl_mprotect) 202 203ENTRY(_dl_open,0) 204 SYSCALL(open) 205 bv r0(rp) 206 nop 207EXIT(_dl_open) 208 209ENTRY(_dl_read,0) 210 SYSCALL(read) 211 bv r0(rp) 212 nop 213EXIT(_dl_read) 214 215ENTRY(_dl_write,0) 216 SYSCALL(write) 217 bv r0(rp) 218 nop 219EXIT(_dl_write) 220 221ENTRY(_dl_fstat,0) 222 SYSCALL(fstat) 223 bv r0(rp) 224 nop 225EXIT(_dl_fstat) 226 227ENTRY(_dl_sysctl,0) 228 SYSCALL(__sysctl) 229 bv r0(rp) 230 nop 231EXIT(_dl_issetugid) 232 233ENTRY(_dl_getdents,0) 234 SYSCALL(getdents) 235 bv r0(rp) 236 nop 237EXIT(_dl_getdents) 238 239ENTRY(_dl_gettimeofday,0) 240 SYSCALL(gettimeofday) 241 bv r0(rp) 242 nop 243EXIT(_dl_gettimeofday) 244 245ENTRY(_dl_readlink,0) 246 SYSCALL(readlink) 247 bv r0(rp) 248 nop 249EXIT(_dl_readlink) 250 251ENTRY(_dl_lstat,0) 252 SYSCALL(lstat) 253 bv r0(rp) 254 nop 255EXIT(_dl_lstat) 256 257ENTRY(_dl_getcwd,0) 258 SYSCALL(__getcwd) 259 bv r0(rp) 260 nop 261EXIT(_dl_getcwd) 262 263ENTRY(_dl_utrace,0) 264 SYSCALL(utrace) 265 bv r0(rp) 266 nop 267EXIT(_dl_utrace) 268 269ENTRY(_dl_getentropy,0) 270 SYSCALL(getentropy) 271 bv r0(rp) 272 nop 273EXIT(_dl_getentropy) 274 275ENTRY(_dl_sendsyslog,0) 276 SYSCALL(sendsyslog) 277 bv r0(rp) 278 nop 279EXIT(_dl_sendsyslog) 280 281ENTRY(_dl_sigprocmask,0) 282 stw arg2, HPPA_FRAME_ARG(2)(sp) 283 284 comb,<>,n r0, arg1, _dl_sigprocmask$nblock 285 286 b _dl_sigprocmask$call 287 ldi 1, arg0 288 289_dl_sigprocmask$nblock 290 ldw 0(arg1), arg1 291 stw arg1, HPPA_FRAME_ARG(1)(sp) 292 293_dl_sigprocmask$call 294 SYSCALL(sigprocmask) 295 296 ldw HPPA_FRAME_ARG(2)(sp), arg2 297 add,= r0, arg2, r0 298 stw ret0, 0(arg2) 299 bv r0(rp) 300 copy r0, ret0 301EXIT(_dl_sigprocmask) 302 303 .end 304