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