1 /* $NetBSD: rtld_start.S,v 1.5 2006/10/16 13:53:09 skrll Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <machine/asm.h>
33 #define _LOCORE /* XXX fredette we MUST get rid of this */
34 #include <machine/frame.h>
37 .import _GLOBAL_OFFSET_TABLE_
39 ENTRY($rtld_start,HPPA_FRAME_SIZE)
41 /* Start stack calling convention. */
44 stw,ma %r1, HPPA_FRAME_SIZE(%sp)
47 * Save our single argument, the ps_strings pointer.
48 * We'll need this twice later: once to call _rtld,
49 * and again to transfer to the program's entry point.
51 stw %arg0, HPPA_FRAME_ARG(0)(%r3)
54 * We can't move to C until we relocate at least the
55 * Global Offset Table. Even finding the GOT is tricky
56 * without inadvertently causing the linker to make
57 * relocations for this part of the text segment.
62 L$lpc1: addil L'_DYNAMIC - ($PIC_pcrel$0 - 8), %r19
63 ldo R'_DYNAMIC - ($PIC_pcrel$0 - 12)(%r1),%arg0
66 * Load the absolute address of the beginning of the
67 * GOT into %r19, the shared library linkage table
68 * register, leaving it ready-to-use by the dynamic
71 addil L'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 16), %r19
72 ldo R'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 20)(%r1),%r19
75 * The linker sets the first entry in the GOT to the
76 * unrelocated address of _DYNAMIC. Subtract this
77 * from the absolute address of _DYNAMIC to get our
81 sub %arg0, %arg1, %arg1 ; %arg1 = relocbase
82 bl _rtld_relocate_nonplt_self, %rp
83 copy %arg1, %r4 ; save for later
86 * Recover the ps_strings pointer, and take out the
89 ldw HPPA_FRAME_ARG(0)(%r3), %arg0 ; ps_strings
90 ldw 0(%arg0), %arg0 ; ps_argvstr member first in struct
93 * ps_argvstr - 4 would get us a pointer to argc,
94 * comparable to the initial stack pointer on
95 * architectures where the stack grows down.
96 * Subtracting an additional eight creates the
97 * storage for obj and cleanup that _rtld needs.
100 stw %arg0, HPPA_FRAME_ARG(1)(%r3)
102 /* Call _rtld, copying relocbase into arg1. */
104 copy %r4, %arg1 ; %arg1 = relocbase
106 /* Prepare the arguments for the entry point. */
107 ldw HPPA_FRAME_ARG(1)(%r3), %r1
108 ldw HPPA_FRAME_ARG(0)(%r3), %arg0 ; ps_strings
109 ldw 0(%r1), %arg1 ; cleanup
110 ldw 4(%r1), %arg2 ; obj
112 /* End stack calling convention. */
113 ldo HPPA_FRAME_SIZE(%r3), %sp
114 ldw,mb -HPPA_FRAME_SIZE(%sp), %r3
122 * This does our setup for an object's GOT. %arg0 is the
123 * Obj_Entry * for the object, and %arg1 is its GOT pointer.
125 LEAF_ENTRY(__rtld_setup_hppa_pltgot)
128 * The second entry of the GOT is reserved for
129 * the dynamic linker. We put the Obj_Entry *
130 * for the object in there.
135 * Fill the fixup_func and fixup_ltp members of
136 * the PLT stub. This stub is inserted by the
137 * linker immediately before the GOT. We use
138 * this stub to enter our binder.
143 L$lpc2: addil L'_rtld_bind_start - ($PIC_pcrel$0 - 8), %arg0
144 ldo R'_rtld_bind_start - ($PIC_pcrel$0 - 12)(%r1),%arg0
149 EXIT(__rtld_hppa_setup_pltgot)
152 * In order to support lazy binding, this implementation of
153 * _rtld_bind_start is very closely tied to the shared-library
154 * call stub and the PLT stub, both inserted by the linker.
156 ENTRY(_rtld_bind_start,HPPA_FRAME_SIZE)
158 /* Start stack calling convention. */
162 stw,ma %r1, HPPA_FRAME_SIZE(%sp)
165 * We have to save all calling convention registers
166 * that are set by the caller, because we have to
167 * restore them before transferring to the bound
168 * function. Note that this includes %ret0 and %ret1,
169 * because they can have meaning on entry to a function.
171 stw %rp, HPPA_FRAME_CRP(%r3)
172 stw %arg0, HPPA_FRAME_ARG(0)(%r3)
173 stw %arg1, HPPA_FRAME_ARG(1)(%r3)
174 stw %arg2, HPPA_FRAME_ARG(2)(%r3)
175 stw %arg3, HPPA_FRAME_ARG(3)(%r3)
176 /* 0(%r3) is filled with the saved %r3 above */
181 * The linker PLT stub loads %r20 with (GOT - 8) for
182 * the object that needs binding done. The second entry
183 * of the GOT is reserved for the dynamic linker's use,
184 * and we previously stashed the object's Obj_Entry *
190 * The linker shared-library call stub loads %r19 from
191 * the shared linkage member of the PLT entry. We
192 * previously stashed the reloff of the relocation there.
197 * The linker PLT stub loads %r21 with the fixup_ltp
198 * word in itself. We previously stashed our %r19
205 * Our hppa version of _rtld_bind returns to us the
206 * address of the PLT entry that it fixed up. Load
207 * the function address and shared linkage for the
208 * newly bound function.
213 /* Restore registers saved above. */
214 ldw HPPA_FRAME_CRP(%r3), %rp
215 ldw HPPA_FRAME_ARG(0)(%r3), %arg0
216 ldw HPPA_FRAME_ARG(1)(%r3), %arg1
217 ldw HPPA_FRAME_ARG(2)(%r3), %arg2
218 ldw HPPA_FRAME_ARG(3)(%r3), %arg3
222 /* End stack calling convention. */
223 ldo HPPA_FRAME_SIZE(%r3), %sp
224 ldw,mb -HPPA_FRAME_SIZE(%sp), %r3
226 /* Transfer to the function. */
229 EXIT(_rtld_bind_start)