1 /* $NetBSD: rtld_start.S,v 1.16 2004/02/18 23:04:49 enami Exp $ */
4 * Copyright 1996 Matt Thomas <matt@3am-software.com>
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.
31 #include <machine/asm.h>
34 * Note: we can call ourselves LEAF even though we use callee-saved
35 * registers because we're the root of the call graph.
37 LEAF_NOPROFILE(_rtld_start, 0)
45 br s2, 2f /* get our PC */
46 2: ldiq s3, 2b /* get where the linker thought we were */
48 subq s2, s3, a1 /* relocbase */
50 addq a1, t5, a0 /* &_DYNAMIC */
52 /* Squirrel away ps_strings. */
55 bsr ra, _rtld_relocate_nonplt_self
59 * Allocate space on the stack for the cleanup and obj_main
60 * entries that _rtld() will provide for us.
64 subq s2, s3, a1 /* relocbase */
66 CALL(_rtld) /* v0 = _rtld(sp, relocbase); */
68 ldq a1, 0(sp) /* cleanup */
69 ldq a2, 8(sp) /* obj_main */
70 lda sp, 16(sp) /* pop stack */
72 mov sp, a0 /* stack pointer */
73 mov s0, a3 /* ps_strings */
75 mov v0, pv /* set up PV for entry point */
77 jsr ra, (v0), 0 /* (*_start)(sp, cleanup, obj, ps_strings); */
84 #define RTLD_BIND_START_PROLOGUE \
85 /* at_reg already used by PLT code. */ \
89 * Allocate stack frame and preserve all registers that the \
90 * caller would have normally saved themselves. \
116 * Load our global pointer. Note, can't use pv, since it is \
117 * already used by the PLT code. \
122 #define RTLD_BIND_START_EPILOGUE \
123 /* Move the destination address into position. */ \
126 /* Restore program registers. */ \
151 * We've patched the PLT; sync the I-stream. \
155 /* Pop the stack frame and turn control to the destination. */ \
160 * Lazy binding entry point, called via PLT.
162 NESTED_NOPROFILE(_rtld_bind_start, 0, 168, ra, 0, 0)
164 RTLD_BIND_START_PROLOGUE
166 /* Set up the arguments for _rtld_bind. */
167 subq at_reg, pv, a1 /* calculate offset of reloc entry */
168 ldq a0, 8(pv) /* object structure */
169 subq a1, 20, a1 /* = (at - pv - 20) / 12 * 24 */
174 RTLD_BIND_START_EPILOGUE
176 END(_rtld_bind_start)
179 * Lazy binding entry point, called via PLT. This version is for the
180 * old PLT entry format.
182 NESTED_NOPROFILE(_rtld_bind_start_old, 0, 168, ra, 0, 0)
184 RTLD_BIND_START_PROLOGUE
186 /* Set up the arguments for _rtld_bind. */
187 ldq a0, 8(pv) /* object structure */
188 mov at_reg, a1 /* offset of reloc entry */
192 RTLD_BIND_START_EPILOGUE
194 END(_rtld_bind_start_old)