1 /* $NetBSD: rtld_start.S,v 1.9 2002/10/05 11:59:05 mycroft Exp $ */
5 * Copyright 1997 Michael L. Hitch <mhitch@montana.edu>
6 * Portions copyright 2002 Charles M. Hannum <root@ihack.net>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <machine/asm.h>
34 .globl _C_LABEL(_rtld_relocate_nonplt_self)
35 .globl _C_LABEL(_rtld)
42 addu sp, sp, -16 /* adjust stack pointer */
44 .cprestore 0 /* -> 0(sp) for gp */
45 /* -> 4(sp) for atexit */
46 /* -> 8(sp) for obj_main */
47 move s0,a0 /* save stack pointer from a0 */
48 move s1,a3 /* save ps_strings pointer */
53 1: subu a1, ra, a1 /* relocbase */
54 la t9,_C_LABEL(_rtld_relocate_nonplt_self)
59 addu a0, a1, a0 /* &_DYNAMIC */
62 move a0, s0 /* stack pointer */
63 addu a1, sp, 4 /* &exit_proc */
64 addu a2, sp, 8 /* &objp */
65 addu sp, sp, -16 /* arguments slot */
66 jal _C_LABEL(_rtld) /* v0 = _rtld(sp, exit_proc, objp) */
70 move a0, s0 /* arguments pointer */
71 move a3, s1 /* arguments pointer */
72 lw a1, 4(sp) /* our atexit function */
73 lw a2, 8(sp) /* obj_main entry */
74 addu sp, sp, 16 /* readjust stack */
76 move a2,s1 /* restore ps_strings */
77 jr t9 /* _start(ap, cleanup, obj, ps_strings); */
82 .globl _rtld_bind_start
85 /* ABI conventions for stubs:
86 * t8 contains symbol index
87 * t7 contains return address
89 .frame sp, 0, ra /* satisfy compiler */
91 move v1,gp /* save old GP */
92 add t9,8 /* modify T9 to point at .cpload */
94 subu sp,48 /* save arguments and sp value */
103 move a0,v1 /* old GP */
104 subu a0,a0,0x7ff0 /* The offset of $gp from the */
105 /* beginning of the .got section: */
106 /* $gp = .got + 0x7ff0, so */
107 /* .got = $gp - 0x7ff0 */
108 /* Simple math as you can see. */
110 lw a0,4(a0) /* object = pltgot[1] & 0x7fffffff */
112 move a1,t8 /* symbol index */
114 jal _C_LABEL(_mips_rtld_bind)
127 .end _rtld_bind_start