1/* $MirOS: src/libexec/ld.so/sparc/ldasm.S,v 1.2 2008/10/16 14:20:32 tg Exp $ */ 2/* $OpenBSD: ldasm.S,v 1.15 2006/05/03 16:10:52 drahn Exp $ */ 3 4/* 5 * Copyright (c) 2001 Jason L. Wright (jason@thought.net) 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 26 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30/*- 31 * Copyright (c) 2000 Eduardo Horvath. 32 * Copyright (c) 1999 The NetBSD Foundation, Inc. 33 * All rights reserved. 34 * 35 * This code is derived from software contributed to The NetBSD Foundation 36 * by Christos Zoulas and Paul Kranenburg. 37 * 38 * Redistribution and use in source and binary forms, with or without 39 * modification, are permitted provided that the following conditions 40 * are met: 41 * 1. Redistributions of source code must retain the above copyright 42 * notice, this list of conditions and the following disclaimer. 43 * 2. Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in the 45 * documentation and/or other materials provided with the distribution. 46 * 3. All advertising materials mentioning features or use of this software 47 * must display the following acknowledgement: 48 * This product includes software developed by the NetBSD 49 * Foundation, Inc. and its contributors. 50 * 4. Neither the name of The NetBSD Foundation nor the names of its 51 * contributors may be used to endorse or promote products derived 52 * from this software without specific prior written permission. 53 * 54 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 55 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 56 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 57 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 58 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 59 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 60 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 61 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 62 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 63 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 64 * POSSIBILITY OF SUCH DAMAGE. 65 */ 66 67#include <sys/syscall.h> 68#include <machine/trap.h> 69#include <machine/asm.h> 70 71#define DL_DATA_SIZE (16*4) 72#define ARGC (16*4) 73 74 .section ".text" 75 .align 4 76 .global _dl_start 77 .type _dl_start,@function 78_dl_start: 79 sub %g0, %g0, %fp ! clear frame 80 mov %g1, %l1 ! save ps_strings 81 sub %sp, DL_DATA_SIZE, %sp ! make room for dl_data 82 add %sp, ARGC, %l3 83 84 add %l3, DL_DATA_SIZE, %o0 85 mov %o0, %l0 86 87 /* 88 * need to figure out where _DYNAMIC is located newer binutils 89 * does not fill in GOT to read _DYNAMIC before relocation. 90 */ 91 call 0f 92 nop 93 call _DYNAMIC+8 ! not executed (no delay needed) 940: ld [%o7+8], %o2 ! load stub call instruction 95 sll %o2, 2, %o2 ! extract PC offset 96 sra %o2, 0, %o2 ! sign-extend 97 98 add %o2, %o7, %o2 ! real &_DYNAMIC 99 100 call _dl_boot_bind ! _dl_boot_bind(sp,dl_data,dynamicp) 101 mov %l3, %o1 102 103 call __guard_setup 104 nop 105 106 mov %l3, %o3 107 ld [%l0], %l3 ! argc = *sp 108 sll %l3, 2, %l3 ! argc *= sizeof(long) 109 add %l0, 4, %o0 ! argv = [sp + argc] 110 add %l0, 8, %o1 ! envp = sp + 8 + 111 add %o1, %l3, %o1 ! + argc 112 113 add %o3, (7*4), %l2 114 ld [%l2], %o2 ! loff = dl_data[AUX_base]; 115 116 call _dl_boot ! _dl_boot(argv,envp,loff,dl_data) 117 nop 118 119 add %sp, DL_DATA_SIZE, %sp ! restore stack 120 121 jmp %o0 122 mov %l1, %g1 ! restore ps_strings 123 124 125 .section ".text" 126 .align 4 127 .global _dl_bind_start 128 .type _dl_bind_start,@function 129_dl_bind_start: # (obj, reloff) 130 save %sp, -96, %sp /* setup standard stack frame */ 131 ld [%i7 + 8], %o0 /* obj id is in second PLT slot */ 132 srl %g1, 10, %o1 /* offset is in high 22 bits */ 133 call _dl_bind /* Call _rtld_bind(obj, offset) */ 134 sub %o1, 12*4, %o1 /* first 4 `pltrel' entries missing! */ 135 136 mov %o0, %g1 /* return value == function address */ 137 restore /* get rid of our context */ 138 jmp %g1 /* and the jmpslot context, then go. */ 139 restore 140 141 .section ".text" 142 .align 4 143 .global _dl_close 144 .type _dl_close,@function 145_dl_close: 146 mov SYS_close | SYSCALL_G2RFLAG, %g1 ! call sys_close 147 add %o7, 8, %g2 ! just return on success 148 t ST_SYSCALL ! off to wonderland 149 retl 150 sub %g0, %o0, %o0 ! error: result = -errno 151 152 153 .section ".text" 154 .align 4 155 .global _dl_exit 156 .type _dl_exit,@function 157_dl_exit: 158 mov SYS_exit | SYSCALL_G2RFLAG, %g1 ! call sys_exit 159 add %o7, 8, %g2 ! just return on success 160 t ST_SYSCALL ! off to wonderland 161 retl 162 sub %g0, %o0, %o0 ! error: result = -errno 163 164 165 .section ".text" 166 .align 4 167 .global _dl_issetugid 168 .type _dl_issetugid,@function 169_dl_issetugid: 170 mov SYS_issetugid | SYSCALL_G2RFLAG, %g1 ! call sys_issetugid 171 add %o7, 8, %g2 ! just return on success 172 t ST_SYSCALL ! off to wonderland 173 retl 174 sub %g0, %o0, %o0 ! error: result = -errno 175 176 177 .section ".text" 178 .align 4 179 .global _dl__syscall 180 .type _dl__syscall,@function 181_dl__syscall: 182 mov SYS___syscall | SYSCALL_G2RFLAG, %g1 ! call sys_syscall 183 add %o7, 8, %g2 ! just return on success 184 t ST_SYSCALL ! off to wonderland 185 retl 186 sub %g0, %o0, %o0 ! error: result = -errno 187 188 189 .section ".text" 190 .align 4 191 .global _dl_munmap 192 .type _dl_munmap,@function 193_dl_munmap: 194 mov SYS_munmap | SYSCALL_G2RFLAG, %g1 ! calling sys_munmap 195 add %o7, 8, %g2 ! just return on success 196 t ST_SYSCALL ! off to wonderland 197 retl 198 sub %g0, %o0, %o0 ! error: result = -errno 199 200 201 .section ".text" 202 .align 4 203 .global _dl_mprotect 204 .type _dl_mprotect,@function 205_dl_mprotect: 206 mov SYS_mprotect | SYSCALL_G2RFLAG, %g1 ! calling sys_mprotect 207 add %o7, 8, %g2 ! just return on success 208 t ST_SYSCALL ! off to wonderland 209 retl 210 sub %g0, %o0, %o0 ! error: result = -errno 211 212 213 .section ".text" 214 .align 4 215 .global _dl_open 216 .type _dl_open,@function 217_dl_open: 218 mov SYS_open | SYSCALL_G2RFLAG, %g1 ! calling sys_open 219 add %o7, 8, %g2 ! just return on success 220 t ST_SYSCALL ! off to wonderland 221 retl 222 sub %g0, %o0, %o0 ! error: result = -errno 223 224 225 .section ".text" 226 .align 4 227 .global _dl_read 228 .type _dl_read,@function 229_dl_read: 230 mov SYS_read | SYSCALL_G2RFLAG, %g1 ! calling sys_read 231 add %o7, 8, %g2 ! just return on success 232 t ST_SYSCALL ! off to wonderland 233 retl 234 sub %g0, %o0, %o0 ! error: result = -errno 235 236 237 .section ".text" 238 .align 4 239 .global _dl_write 240 .type _dl_write,@function 241_dl_write: 242 mov SYS_write | SYSCALL_G2RFLAG, %g1 ! calling sys_write 243 add %o7, 8, %g2 ! just return on success 244 t ST_SYSCALL ! off to wonderland 245 retl 246 sub %g0, %o0, %o0 ! error: result = -errno 247 248 249 .section ".text" 250 .align 4 251 .global _dl_stat 252 .type _dl_stat,@function 253_dl_stat: 254 mov SYS_stat | SYSCALL_G2RFLAG, %g1 ! call sys_stat 255 add %o7, 8, %g2 ! just return on success 256 t ST_SYSCALL ! off to wonderland 257 retl 258 sub %g0, %o0, %o0 ! error: result = -errno 259 260 261 .section ".text" 262 .align 4 263 .globl _dl_fstat 264 .type _dl_fstat,@function 265_dl_fstat: 266 mov SYS_fstat | SYSCALL_G2RFLAG, %g1 ! call sys_fstat 267 add %o7, 8, %g2 ! just return on success 268 t ST_SYSCALL ! off to wonderland 269 retl 270 sub %g0, %o0, %o0 ! error: result = -errno 271 272 273 .section ".text" 274 .align 4 275 .globl _dl_fcntl 276 .type _dl_fcntl,@function 277_dl_fcntl: 278 mov SYS_fcntl | SYSCALL_G2RFLAG, %g1 ! call sys_fcntl 279 add %o7, 8, %g2 ! just return on success 280 t ST_SYSCALL ! off to wonderland 281 retl 282 sub %g0, %o0, %o0 ! error: result = -errno 283 284 285 .section ".text" 286 .align 4 287 .globl _dl_getdirentries 288 .type _dl_getdirentries,@function 289_dl_getdirentries: 290 mov SYS_getdirentries | SYSCALL_G2RFLAG, %g1 ! call sys_getdirentries 291 add %o7, 8, %g2 ! just return on success 292 t ST_SYSCALL ! off to wonderland 293 retl 294 sub %g0, %o0, %o0 ! error: result = -errno 295 296 297 .section ".text" 298 .align 4 299 .globl _dl_sysctl 300 .type _dl_sysctl,@function 301_dl_sysctl: 302 mov SYS___sysctl | SYSCALL_G2RFLAG, %g1 ! call sys___sysctl 303 add %o7, 8, %g2 ! just return on success 304 t ST_SYSCALL ! off to wonderland 305 retl 306 sub %g0, %o0, %o0 ! error: result = -errno 307 308 309 /* _dl_sigprocmask does not support NULL new mask */ 310 .section ".text" 311 .align 4 312 .globl _dl_sigprocmask 313 .type _dl_sigprocmask,@function 314_dl_sigprocmask: 315 ld [%o1], %o1 316 mov SYS_sigprocmask, %g1 ! call sys___sigprocmask 317 t ST_SYSCALL ! off to wonderland 318 319 cmp %o2, 0 320 bne,a 1f 321 st %o0, [%o2] 3221: 323 retl 324 clr %o0 325 326 327 .section ".text" 328 .align 4 329 .global _dl_gettimeofday 330 .type _dl_gettimeofday,@function 331_dl_gettimeofday: 332 mov SYS_gettimeofday | SYSCALL_G2RFLAG, %g1 ! calling sys_gettimeofday 333 add %o7, 8, %g2 ! just return on success 334 t ST_SYSCALL ! off to wonderland 335 retl 336 sub %g0, %o0, %o0 ! error: result = -errno 337 338/* 339 * V8 sparc .{,u}{mul,div,rem} replacements. 340 * We try to mimic them 100%. Full 64 bit sources or outputs, and 341 * these routines are required to update the condition codes. 342 */ 343.globl _C_LABEL(_mulreplace), _C_LABEL(_mulreplace_end) 344_C_LABEL(_mulreplace): 345 smulcc %o0, %o1, %o0 346 retl 347 rd %y, %o1 348_C_LABEL(_mulreplace_end): 349 350.globl _C_LABEL(_umulreplace), _C_LABEL(_umulreplace_end) 351_C_LABEL(_umulreplace): 352 umulcc %o0, %o1, %o0 353 retl 354 rd %y, %o1 355_C_LABEL(_umulreplace_end): 356 357.globl _C_LABEL(_divreplace), _C_LABEL(_divreplace_end) 358_C_LABEL(_divreplace): 359 sra %o0, 31, %g1 360 wr %g1, 0, %y 361 nop 362 nop 363 nop 364 retl 365 sdivcc %o0, %o1, %o0 366_C_LABEL(_divreplace_end): 367 368.globl _C_LABEL(_udivreplace), _C_LABEL(_udivreplace_end) 369_C_LABEL(_udivreplace): 370 wr %g0, 0, %y 371 nop 372 nop 373 nop 374 retl 375 udivcc %o0, %o1, %o0 376_C_LABEL(_udivreplace_end): 377 378.globl _C_LABEL(_remreplace), _C_LABEL(_remreplace_end) 379_C_LABEL(_remreplace): 380 sra %o0, 31, %g1 381 wr %g1, 0, %y 382 nop 383 nop 384 nop 385 sdiv %o0, %o1, %o2 386 smul %o1, %o2, %o2 387 retl 388 subcc %o0, %o2, %o0 389_C_LABEL(_remreplace_end): 390 391.globl _C_LABEL(_uremreplace), _C_LABEL(_uremreplace_end) 392_C_LABEL(_uremreplace): 393 wr %g0, 0, %y 394 nop 395 nop 396 nop 397 udiv %o0, %o1, %o2 398 umul %o1, %o2, %o2 399 retl 400 subcc %o0, %o2, %o0 401_C_LABEL(_uremreplace_end): 402