rtld_start.S revision 1.9.44.2 1 1.9.44.2 matt /* $NetBSD: rtld_start.S,v 1.9.44.2 2009/09/02 15:49:42 matt Exp $ */
2 1.1 mhitch
3 1.1 mhitch /*
4 1.1 mhitch * Copyright 1997 Michael L. Hitch <mhitch (at) montana.edu>
5 1.9 mycroft * Portions copyright 2002 Charles M. Hannum <root (at) ihack.net>
6 1.1 mhitch * All rights reserved.
7 1.1 mhitch *
8 1.1 mhitch * Redistribution and use in source and binary forms, with or without
9 1.1 mhitch * modification, are permitted provided that the following conditions
10 1.1 mhitch * are met:
11 1.1 mhitch * 1. Redistributions of source code must retain the above copyright
12 1.1 mhitch * notice, this list of conditions and the following disclaimer.
13 1.1 mhitch * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 mhitch * notice, this list of conditions and the following disclaimer in the
15 1.1 mhitch * documentation and/or other materials provided with the distribution.
16 1.1 mhitch * 3. The name of the author may not be used to endorse or promote products
17 1.1 mhitch * derived from this software without specific prior written permission.
18 1.1 mhitch *
19 1.1 mhitch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 1.1 mhitch * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 1.1 mhitch * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 1.1 mhitch * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 1.1 mhitch * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 1.1 mhitch * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 1.1 mhitch * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 1.1 mhitch * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 1.1 mhitch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 1.1 mhitch * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 1.1 mhitch */
30 1.1 mhitch
31 1.1 mhitch #include <mips/asm.h>
32 1.1 mhitch
33 1.5 mycroft .globl _C_LABEL(_rtld_relocate_nonplt_self)
34 1.5 mycroft .globl _C_LABEL(_rtld)
35 1.5 mycroft
36 1.1 mhitch LEAF(rtld_start)
37 1.1 mhitch .set noreorder
38 1.9.44.1 matt SETUP_GP
39 1.9.44.1 matt PTR_SUBU sp, 2*SZREG # adjust stack pointer
40 1.9.44.1 matt SETUP_GP64(s4, rtld_start)
41 1.9.44.1 matt SAVE_GP(s4)
42 1.9.44.1 matt # -> 0*SZREG(sp) for atexit
43 1.9.44.1 matt # -> 1*SZREG(sp) for obj_main
44 1.9.44.1 matt move s0, a0 # save stack pointer from a0
45 1.9.44.1 matt move s3, a3 # save ps_strings pointer
46 1.1 mhitch
47 1.9.44.1 matt PTR_LA a1, 1f
48 1.5 mycroft bal 1f
49 1.9.44.1 matt PTR_LA t9, _C_LABEL(_rtld_relocate_nonplt_self)
50 1.9.44.1 matt 1: PTR_SUBU a1, ra, a1 # relocbase
51 1.5 mycroft move s2,a1
52 1.9.44.1 matt PTR_LA a0,_DYNAMIC
53 1.9.44.1 matt PTR_ADDU t9, a1, t9
54 1.9.44.1 matt jalr t9 # _rtld_relocate_nonplt_self(dynp, relocabase)
55 1.9.44.1 matt PTR_ADDU a0, a1, a0 # &_DYNAMIC
56 1.5 mycroft
57 1.9.44.1 matt move a1, s2 # relocbase
58 1.9.44.1 matt move a0, sp # sp
59 1.5 mycroft jal _C_LABEL(_rtld) # v0 = _rtld(sp, relocbase)
60 1.5 mycroft nop
61 1.5 mycroft
62 1.9.44.1 matt PTR_L a1, 0*SZREG(sp) # our atexit function
63 1.9.44.1 matt PTR_L a2, 1*SZREG(sp) # obj_main entry
64 1.9.44.2 matt PTR_ADDU sp, 2*SZREG # readjust stack
65 1.9.44.1 matt move a0, s0 # stack pointer
66 1.9.44.1 matt move t9, v0
67 1.1 mhitch jr t9 # _start(sp, cleanup, obj);
68 1.9.44.1 matt move a3, s3 # restore ps_strings
69 1.1 mhitch
70 1.1 mhitch END(rtld_start)
71 1.1 mhitch
72 1.9.44.1 matt #define XCALLFRAME_SIZ (11*SZREG)
73 1.9.44.1 matt #define XCALLFRAME_RA (10*SZREG)
74 1.9.44.1 matt #define XCALLFRAME_GP (9*SZREG)
75 1.9.44.1 matt #define XCALLFRAME_S0 (8*SZREG)
76 1.9.44.1 matt #define XCALLFRAME_A3 (7*SZREG)
77 1.9.44.1 matt #define XCALLFRAME_A2 (6*SZREG)
78 1.9.44.1 matt #define XCALLFRAME_A1 (5*SZREG)
79 1.9.44.1 matt #define XCALLFRAME_A0 (4*SZREG)
80 1.9.44.1 matt #if defined(__mips_n32) || defined(__mips_n64)
81 1.9.44.1 matt #define XCALLFRAME_A7 (3*SZREG)
82 1.9.44.1 matt #define XCALLFRAME_A6 (2*SZREG)
83 1.9.44.1 matt #define XCALLFRAME_A5 (1*SZREG)
84 1.9.44.1 matt #define XCALLFRAME_A4 (0*SZREG)
85 1.9.44.1 matt #endif
86 1.9.44.1 matt
87 1.1 mhitch .globl _rtld_bind_start
88 1.1 mhitch .ent _rtld_bind_start
89 1.1 mhitch _rtld_bind_start:
90 1.9.44.1 matt #if defined(__mips_o32) || defined(__mips_o64)
91 1.9.44.1 matt move v1, gp # save old GP
92 1.9.44.1 matt PTR_ADDU t9, 8 # modify T9 to point at .cpload
93 1.9.44.1 matt #endif
94 1.9.44.1 matt SETUP_GP
95 1.9.44.1 matt PTR_SUBU sp, XCALLFRAME_SIZ # save arguments and sp value in stack
96 1.9.44.1 matt SETUP_GP64(XCALLFRAME_GP, _rtld_bind_start)
97 1.9.44.1 matt SAVE_GP(XCALLFRAME_GP)
98 1.9.44.1 matt #if defined(__mips_n32) || defined(__mips_n64)
99 1.9.44.1 matt REG_S a4, XCALLFRAME_A4(sp)
100 1.9.44.1 matt REG_S a5, XCALLFRAME_A5(sp)
101 1.9.44.1 matt REG_S a6, XCALLFRAME_A6(sp)
102 1.9.44.1 matt REG_S a7, XCALLFRAME_A7(sp)
103 1.9.44.1 matt #endif
104 1.9.44.1 matt REG_S a0, XCALLFRAME_A0(sp)
105 1.9.44.1 matt REG_S a1, XCALLFRAME_A1(sp)
106 1.9.44.1 matt REG_S a2, XCALLFRAME_A2(sp)
107 1.9.44.1 matt REG_S a3, XCALLFRAME_A3(sp)
108 1.9.44.1 matt REG_S $15, XCALLFRAME_RA(sp) # ra is in t7/t3
109 1.9.44.1 matt REG_S s0, XCALLFRAME_SP(sp)
110 1.9.44.1 matt move s0, sp
111 1.9.44.1 matt move a0, t8 # symbol index
112 1.9.44.1 matt move a1, $15 # old RA
113 1.9.44.1 matt move a2, v1 # old GP
114 1.9.44.1 matt move a3, ra # current RA
115 1.8 mycroft jal _C_LABEL(_rtld_bind)
116 1.9.44.1 matt nop
117 1.9.44.1 matt move sp, s0
118 1.9.44.1 matt REG_L ra, XCALLFRAME_RA(sp)
119 1.9.44.1 matt REG_L s0, XCALLFRAME_S0(sp)
120 1.9.44.1 matt REG_L a0, XCALLFRAME_A0(sp)
121 1.9.44.1 matt REG_L a1, XCALLFRAME_A1(sp)
122 1.9.44.1 matt REG_L a2, XCALLFRAME_A2(sp)
123 1.9.44.1 matt REG_L a3, XCALLFRAME_A3(sp)
124 1.9.44.1 matt #if defined(__mips_n32) || defined(__mips_n64)
125 1.9.44.1 matt REG_L a4, XCALLFRAME_A4(sp)
126 1.9.44.1 matt REG_L a5, XCALLFRAME_A5(sp)
127 1.9.44.1 matt REG_L a6, XCALLFRAME_A6(sp)
128 1.9.44.1 matt REG_L a7, XCALLFRAME_A7(sp)
129 1.9.44.1 matt #endif
130 1.9.44.1 matt RESTORE_GP64
131 1.9.44.1 matt PTR_ADDU sp, XCALLFRAME_SIZ
132 1.9.44.1 matt move t9, v0
133 1.1 mhitch jr t9
134 1.9.44.1 matt nop
135 1.9.44.1 matt END(_rtld_bind_start)
136