1 /* $NetBSD: rtld_start.S,v 1.5 2001/08/14 22:17:48 eeh Exp $ */
4 * Copyright (c) 2001 Jake Burkholder.
5 * Copyright (c) 2000 Eduardo Horvath.
6 * Copyright (c) 1999 The NetBSD Foundation, Inc.
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Christos Zoulas and Paul Kranenburg.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
43 #include <machine/asm.h>
47 * On startup the stack should contain 16 extended word register save
48 * area, followed by the arg count, etc.
57 add %sp, SPOFF + CCFSZ + 0x0, %o1
59 add %sp, SPOFF + CCFSZ + 0x8, %o2
61 ldx [%sp + SPOFF + CCFSZ + 0x0], %o1
62 ldx [%sp + SPOFF + CCFSZ + 0x8], %o2
71 * Find the address of _DYNAMIC by disassembling a call instruction to it.
72 * Binutils may not fill in the GOT as expected on other architectures.
76 ENTRY(rtld_dynamic_addr)
81 1: lduw [%o7 + 8], %o0
86 END(rtld_dynamic_addr)
89 * We have two separate entry points to the runtime linker.
90 * I'm implementing this following the SPARC v9 ABI spec.
92 * _rtld_bind_start_0(x, y) is called from .PLT0, and is used for
93 * PLT entries above 32768.
95 * _rtld_bind_start_1(x, y) is called from .PLT1, and is used for
96 * PLT entries below 32768.
98 * The first two entries of PLT2 contain the xword object pointer.
100 * These routines are called with two longword arguments,
101 * x and y. To calculate the address of the entry,
102 * _rtld_bind_start_1(x, y) does:
106 * and _rtld_bind_start_0(x, y) should do, according to the SCD:
108 * i = x - y - 1048596;
109 * n = 32768 + (i/5120)*160 + (i%5120)/24;
111 * Note that the number of 1048596 from above is incorrect; rather,
112 * we need to use HIPLTOFFS as defined below.
114 * Neither routine needs to issue a save since it's already been
115 * done in the PLT entry.
118 #define NPLTLOSLOTS 32768
121 * - 16 to compensate for the difference of the positions of the jumps that
122 * generate the arguments in .PLT0 and the high plt entry.
124 #define HIPLTOFFS (NPLTLOSLOTS * PLTSLOTSZ - 16)
126 ENTRY(_rtld_bind_start_0)
127 sethi %hi(HIPLTOFFS), %l1
128 or %l1, %lo(HIPLTOFFS), %l1
129 sub %o0, %o1, %l0 /* x - y */
130 sub %l0, %l1, %l0 /* i = x - y - HIPLTOFFS */
132 sdivx %l0, %l7, %l1 /* Calculate i / 5120 */
134 sub %l0, %l3, %l2 /* And i % 5120 */
135 mulx %l1, 160, %l5 /* (i / 5120) * 160 */
136 sdivx %l2, 24, %l4 /* (i % 5120) / 24 */
137 sethi %hi(NPLTLOSLOTS), %l6
138 add %l4, %l5, %l4 /* (i / 5120) * 160 + (i % 5120) / 24 */
139 add %l4, %l6, %l4 /* + NPLTLOSLOTS */
140 sub %l4, 4, %l4 /* XXX: 4 entries are reserved */
142 sllx %l4, 1, %l5 /* Each element is an Elf_Rela which */
143 add %l5, %l4, %l4 /* is 3 longwords or 24 bytes. */
144 sllx %l4, 3, %l4 /* So multiply by 24. */
146 ldx [%o1 + (10*4)], %o0 /* Load object pointer from PLT2 */
148 call _rtld_bind /* Call _rtld_bind(obj, offset) */
151 jmp %o0 /* return value == function address */
152 restore /* Dump our stack frame */
153 END(_rtld_bind_start_0)
155 ENTRY(_rtld_bind_start_1)
156 srax %o0, 15, %o2 /* %o0 is the index to our PLT slot */
157 sub %o2, 4, %o2 /* XXX: 4 entries are reserved */
159 sllx %o2, 1, %o3 /* Each element is an Elf_Rela which */
160 add %o3, %o2, %o2 /* is 3 longwords or 24 bytes. */
161 sllx %o2, 3, %o2 /* So multiply by 24. */
163 ldx [%o1 + 8], %o0 /* The object pointer is at [%o1 + 8] */
165 call _rtld_bind /* Call _rtld_bind(obj, offset) */
168 jmp %o0 /* return value == function address */
169 restore /* Dump our stack frame */
170 END(_rtld_bind_start_1)