1/* $NetBSD: rtld_start.S,v 1.9 2002/10/05 11:59:05 mycroft Exp $ */ 2 3/* 4 * Copyright 1997 Michael L. Hitch <mhitch@montana.edu> 5 * Portions copyright 2002 Charles M. Hannum <root@ihack.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 * 3. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#include <mips/asm.h> 32 33.globl _C_LABEL(_rtld_relocate_nonplt_self) 34.globl _C_LABEL(_rtld) 35 36LEAF(rtld_start) 37 .set noreorder 38 39 .cpload t9 40 addu sp, sp, -12 # adjust stack pointer 41 .cprestore 0 # -> 0(sp) for gp 42 # -> 4(sp) for atexit 43 # -> 8(sp) for obj_main 44 move s0,a0 # save stack pointer from a0 45 move s1,a3 # save ps_strings pointer 46 47 la a1, 1f 48 bal 1f 49 la t9,_C_LABEL(_rtld_relocate_nonplt_self) 501: subu a1, ra, a1 # relocbase 51 move s2,a1 52 la a0,_DYNAMIC 53 addu t9, a1, t9 54 jalr t9 55 addu a0, a1, a0 # &_DYNAMIC 56 57 move a1,s2 # relocbase 58 addu a0, sp, 4 # sp 59 jal _C_LABEL(_rtld) # v0 = _rtld(sp, relocbase) 60 nop 61 62 lw a1, 4(sp) # our atexit function 63 lw a2, 8(sp) # obj_main entry 64 addu sp, sp,12 # readjust stack 65 move a0,s0 # stack pointer 66 move t9,v0 67 jr t9 # _start(sp, cleanup, obj); 68 move a3,s1 # restore ps_strings 69 70END(rtld_start) 71 72 .globl _rtld_bind_start 73 .ent _rtld_bind_start 74_rtld_bind_start: 75 76 move v1,gp # save old GP 77 add t9,8 # modify T9 to point at .cpload 78 .cpload t9 79 subu sp,44 # save arguments and sp value in stack 80 .cprestore 36 81 sw t7,40(sp) 82 sw a0,16(sp) 83 sw a1,20(sp) 84 sw a2,24(sp) 85 sw a3,28(sp) 86 sw s0,32(sp) 87 move s0,sp 88 move a0,t8 # symbol index 89 move a1,t7 # old RA 90 move a2,v1 # old GP 91 move a3,ra # current RA 92 jal _C_LABEL(_rtld_bind) 93 nop 94 move sp,s0 95 lw ra,40(sp) 96 lw a0,16(sp) 97 lw a1,20(sp) 98 lw a2,24(sp) 99 lw a3,28(sp) 100 lw s0,32(sp) 101 addu sp,44 102 move t9,v0 103 jr t9 104 nop 105 .end _rtld_bind_start 106