1 /* $NetBSD: rtld_start.S,v 1.10 2009/12/14 00:41:19 matt Exp $ */
4 * Copyright 1997 Michael L. Hitch <mhitch@montana.edu>
5 * Portions copyright 2002 Charles M. Hannum <root@ihack.net>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
33 .globl _C_LABEL(_rtld_relocate_nonplt_self)
34 .globl _C_LABEL(_rtld)
36 #define PTR_SIZE (1<<PTR_SCALESHIFT)
39 .frame sp, 4*PTR_SIZE, ra
40 .mask 0x10090000,-PTR_SIZE
43 PTR_SUBU sp, 4*PTR_SIZE # adjust stack pointer
44 SETUP_GP64(s4, rtld_start)
46 # -> 1*PTR_SIZE(sp) for atexit
47 # -> 2*PTR_SIZE(sp) for obj_main
48 move s0, a0 # save stack pointer from a0
49 move s3, a3 # save ps_strings pointer
53 PTR_LA t0, _C_LABEL(_rtld_relocate_nonplt_self)
54 1: PTR_SUBU a1, ra, a1 # relocbase
55 move s2, a1 # save for _rtld
58 jalr t9 # _rtld_relocate_nonplt_self(dynp, relocabase)
59 PTR_ADDU a0, a1, a0 # &_DYNAMIC
61 move a1, s2 # relocbase
62 PTR_ADDU a0, sp, 2*PTR_SIZE # sp
63 jal _C_LABEL(_rtld) # v0 = _rtld(sp, relocbase)
66 PTR_L a1, 2*PTR_SIZE(sp) # our atexit function
67 PTR_L a2, 3*PTR_SIZE(sp) # obj_main entry
68 PTR_ADDU sp, 4*PTR_SIZE # readjust stack
69 move a0, s0 # stack pointer
71 jr t9 # _start(sp, cleanup, obj);
72 move a3, s3 # restore ps_strings
76 #define XCALLFRAME_SIZ (12*SZREG)
77 #define XCALLFRAME_RA (10*SZREG)
78 #define XCALLFRAME_GP (9*SZREG)
79 #define XCALLFRAME_S0 (8*SZREG)
80 #define XCALLFRAME_A3 (7*SZREG)
81 #define XCALLFRAME_A2 (6*SZREG)
82 #define XCALLFRAME_A1 (5*SZREG)
83 #define XCALLFRAME_A0 (4*SZREG)
84 #if defined(__mips_n32) || defined(__mips_n64)
85 #define XCALLFRAME_A7 (3*SZREG)
86 #define XCALLFRAME_A6 (2*SZREG)
87 #define XCALLFRAME_A5 (1*SZREG)
88 #define XCALLFRAME_A4 (0*SZREG)
91 .globl _rtld_bind_start
94 .frame sp, XCALLFRAME_SIZ, $15
95 move v1, gp # save old GP
96 #if defined(__mips_o32) || defined(__mips_o64)
97 PTR_ADDU t9, 8 # modify T9 to point at .cpload
100 PTR_SUBU sp, XCALLFRAME_SIZ # save arguments and sp value in stack
101 SETUP_GP64(XCALLFRAME_GP, _rtld_bind_start)
102 SAVE_GP(XCALLFRAME_GP)
103 #if defined(__mips_n32) || defined(__mips_n64)
104 REG_S a4, XCALLFRAME_A4(sp)
105 REG_S a5, XCALLFRAME_A5(sp)
106 REG_S a6, XCALLFRAME_A6(sp)
107 REG_S a7, XCALLFRAME_A7(sp)
109 REG_S a0, XCALLFRAME_A0(sp)
110 REG_S a1, XCALLFRAME_A1(sp)
111 REG_S a2, XCALLFRAME_A2(sp)
112 REG_S a3, XCALLFRAME_A3(sp)
113 REG_S $15, XCALLFRAME_RA(sp) # ra is in t7/t3
114 REG_S s0, XCALLFRAME_S0(sp)
116 move a0, t8 # symbol index
117 move a1, $15 # old RA
119 move a3, ra # current RA
120 jal _C_LABEL(_rtld_bind)
123 REG_L ra, XCALLFRAME_RA(sp)
124 REG_L s0, XCALLFRAME_S0(sp)
125 REG_L a0, XCALLFRAME_A0(sp)
126 REG_L a1, XCALLFRAME_A1(sp)
127 REG_L a2, XCALLFRAME_A2(sp)
128 REG_L a3, XCALLFRAME_A3(sp)
129 #if defined(__mips_n32) || defined(__mips_n64)
130 REG_L a4, XCALLFRAME_A4(sp)
131 REG_L a5, XCALLFRAME_A5(sp)
132 REG_L a6, XCALLFRAME_A6(sp)
133 REG_L a7, XCALLFRAME_A7(sp)
136 PTR_ADDU sp, XCALLFRAME_SIZ
140 END(_rtld_bind_start)