rtld_start.S revision 1.6 1 /* $NetBSD: rtld_start.S,v 1.6 2006/01/11 22:24:34 uwe Exp $ */
2
3 /*-
4 * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Marcus Comstedt.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <machine/asm.h>
40
41 .text
42 .align 2
43 .globl .rtld_start
44 .type .rtld_start,@function
45
46 .rtld_start:
47 mova 2f,r0
48 mov.l @r0,r2
49 add r0,r2 /* GOT */
50 mov.l @(4,r0),r4 /* _DYNAMIC@GOTOFF */
51 add r2,r4 /* _DYNAMIC */
52 mov.l @(12,r0),r1 /* _rtld_relocate_nonplt_self offset */
53 mov.l @(8,r0),r0 /* _DYNAMIC@GOT */
54 mov r4,r5
55 mov.l @(r0,r2),r0 /* where linker thinks _DYNAMIC is */
56 sub r0,r5 /* compute relocation base */
57 bsrf r1 /* _rtld_relocate_nonplt_self(dynp, relocbase) */
58 mov.l r5,@-r15 /* save relocbase */
59
60 4:
61 mov.l @r15+,r5 /* restore relocbase */
62 add #-8,r15 /* room for values returned by _rtld */
63 mov r15,r4
64 mov.l 1f,r0
65 bsrf r0 /* _rtld(sp, relocbase) */
66 mov.l r9,@-r15 /* save ps_strings */
67 3:
68 mov.l @r15+,r9 /* restore ps_strings */
69
70 mov.l @r15+,r7 /* from _rtld: exit procedure */
71 mov.l @r15+,r8 /* from _rtld: main object */
72
73 mov.l @r15,r4 /* restore argc */
74
75 mov r15,r5 /* restore argv */
76 add #4,r5
77
78 mov r4,r6 /* restore envp */
79 shll2 r6
80 add r15,r6
81 jmp @r0 /* entry point returned by _rtld */
82 add #8,r6
83 .align 2
84 1: .long _rtld-3b
85 2: .long _GLOBAL_OFFSET_TABLE_
86 .long _DYNAMIC@GOTOFF
87 .long _DYNAMIC@GOT
88 .long _rtld_relocate_nonplt_self-4b
89 .size .rtld_start,.-.rtld_start
90
91 .align 2
92 .globl _rtld_bind_start
93 .type _rtld_bind_start,@function
94 _rtld_bind_start: /* r0 = obj, r1 = reloff */
95 mov.l r2,@-r15 /* save registers */
96 mov.l r3,@-r15
97 mov.l r4,@-r15
98 mov.l r5,@-r15
99 mov.l r6,@-r15
100 mov.l r7,@-r15
101 sts.l mach,@-r15
102 sts.l macl,@-r15
103 sts.l pr,@-r15
104
105 mov r0,r4 /* copy of obj */
106 mov.l 2f,r0
107 bsrf r0 /* call the binder */
108 mov r1,r5 /* copy of reloff */
109 4:
110 lds.l @r15+,pr /* restore registers */
111 lds.l @r15+,macl
112 lds.l @r15+,mach
113 mov.l @r15+,r7
114 mov.l @r15+,r6
115 mov.l @r15+,r5
116 mov.l @r15+,r4
117 mov.l @r15+,r3
118 jmp @r0
119 mov.l @r15+,r2
120 .align 2
121 2: .long _rtld_bind-4b
122 .size _rtld_bind_start,.-_rtld_bind_start
123
124 .end
125