1/*	$NetBSD: rtld_start.S,v 1.6 2002/09/12 17:18:39 mycroft Exp $	*/
2
3/*-
4 * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Klaus Klein and by Charles M. Hannum.
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	4
43	.globl	.rtld_start
44	.type	.rtld_start,@function
45.rtld_start:
46	subql	#8,%sp			| storage for obj and cleanup
47
48	lea	(%pc,_GLOBAL_OFFSET_TABLE_@GOTPC),%a5
49	movel	_GLOBAL_OFFSET_TABLE_@GOT.w(%a5),%d0
50	movel	_DYNAMIC@GOT.w(%a5),%d1
51	subl	%d0,%a5
52
53	movel	%a5,-(%sp)		| relocbase
54	addl	%a5,%d1
55	movel	%d1,-(%sp)		| &_DYNAMIC
56	jbsr	_rtld_relocate_nonplt_self@PLTPC
57	addql	#8,%sp			| pop arguments
58
59	movel	%a5,-(%sp)		| relocbase
60	pea	4(%sp)			| sp
61	jbsr	_rtld@PLTPC		| entry = _rtld(sp, relocbase)
62	addql	#8,%sp			| pop arguments
63
64	moveal	(%sp)+,%a1		| cleanup
65	moveal	(%sp)+,%a0		| obj
66	moveal	%d0,%a3
67	jmp	(%a3)			| Go for it!
68	.size	.rtld_start,.-.rtld_start
69
70	.align	4
71	.globl	_rtld_bind_start
72	.type	_rtld_bind_start,@function
73_rtld_bind_start:
74	moveml	%d0-%d1/%a0-%a1,-(%sp)	| preserve caller-saved registers
75	movel	20(%sp),-(%sp)		| push reloff
76	movel	(16+4)(%sp),-(%sp)	| push obj
77	jbsr	_rtld_bind@PLTPC	| %a0 = _rtld_bind(obj, reloff)
78	addql	#8,%sp			| pop args
79#ifdef __SVR4_ABI__
80	movel	%a0,(16+4)(%sp)		| write fake `return' address over obj
81#else
82	movel	%d0,(16+4)(%sp)		| write fake `return' address over obj
83#endif
84	moveml	(%sp)+,%d0-%d1/%a0-%a1	| restore caller-saved registers
85	addql	#4,%sp			| skip reloff
86	rts				| `return' right into function
87	.size	_rtld_bind_start,.-_rtld_bind_start
88