xref: /netbsd-src/libexec/ld.elf_so/arch/sparc/rtld_start.S (revision ce099b40997c43048fb78bd578195f81d2456523)
1*ce099b40Smartin/*	$NetBSD: rtld_start.S,v 1.16 2008/04/28 20:23:03 martin Exp $	*/
262926e7eSchristos
362926e7eSchristos/*-
433131cb2Smycroft * Copyright (c) 1999, 2002, 2003 The NetBSD Foundation, Inc.
562926e7eSchristos * All rights reserved.
662926e7eSchristos *
762926e7eSchristos * This code is derived from software contributed to The NetBSD Foundation
8ebf50cdfSmycroft * by Christos Zoulas, Paul Kranenburg, and by Charles M. Hannum.
962926e7eSchristos *
1062926e7eSchristos * Redistribution and use in source and binary forms, with or without
1162926e7eSchristos * modification, are permitted provided that the following conditions
1262926e7eSchristos * are met:
1362926e7eSchristos * 1. Redistributions of source code must retain the above copyright
1462926e7eSchristos *    notice, this list of conditions and the following disclaimer.
1562926e7eSchristos * 2. Redistributions in binary form must reproduce the above copyright
1662926e7eSchristos *    notice, this list of conditions and the following disclaimer in the
1762926e7eSchristos *    documentation and/or other materials provided with the distribution.
1862926e7eSchristos *
1962926e7eSchristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2062926e7eSchristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2162926e7eSchristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2262926e7eSchristos * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2362926e7eSchristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2462926e7eSchristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2562926e7eSchristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2662926e7eSchristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2762926e7eSchristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2862926e7eSchristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2962926e7eSchristos * POSSIBILITY OF SUCH DAMAGE.
3062926e7eSchristos */
3162926e7eSchristos
3262926e7eSchristos#include <machine/asm.h>
3362926e7eSchristos
34801d8e5bSpk	.section	".text"
3577aa6b2aSchristos	.align	4
36801d8e5bSpk	.global	_rtld_start
3762926e7eSchristos	.type	_rtld_start,@function
3862926e7eSchristos_rtld_start:
3977aa6b2aSchristos	mov	0, %fp			/* Erect a fence post for ourselves */
4077aa6b2aSchristos	mov	%g1, %l1		/* save ps_strings */
41f1c792d6Smycroft	sub	%sp, 32+8, %sp		/* room for return args and save area */
4262926e7eSchristos
43c127ff08Smycroft	sethi	%hi(_GLOBAL_OFFSET_TABLE_-4), %l7
44eea1001aSmycroft	call	0f
45c127ff08Smycroft	 add	%l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7
46eea1001aSmycroft	call	_DYNAMIC+8
47eea1001aSmycroft0:	add	%l7, %o7, %l7		/* real &_GLOBAL_OFFSET_TABLE_ */
48eea1001aSmycroft	ld	[%o7+8], %o0		/* load stub call instruction */
49eea1001aSmycroft	ld	[%l7], %l0		/* base-relative &_DYNAMIC */
50eea1001aSmycroft	sll	%o0, 2, %o0		/* extract PC offset */
51c127ff08Smycroft
52eea1001aSmycroft	add	%o0, %o7, %o0		/* real &_DYNAMIC */
53eea1001aSmycroft	sub	%o0, %l0, %l0		/* relocbase */
545ee0e5e1Smycroft	call	_rtld_relocate_nonplt_self
55eea1001aSmycroft	 mov	%l0, %o1		/* relocbase */
565ee0e5e1Smycroft
57eea1001aSmycroft	mov	%l0, %o1		/* relocbase */
58801d8e5bSpk	call	_rtld
59f1c792d6Smycroft	 add	%sp, 96, %o0		/* &argc - 8 */
6062926e7eSchristos
61f1c792d6Smycroft	ld	[%sp + 96], %g3	/* arg: cleanup */
62f1c792d6Smycroft	ld	[%sp + 96 + 4], %g2	/* arg: obj */
63f1c792d6Smycroft	add	%sp, 32+8, %sp		/* restore stack pointer */
6462926e7eSchristos
65801d8e5bSpk	jmp	%o0
6677aa6b2aSchristos	 mov	%l1, %g1		/* restore ps_strings */
67801d8e5bSpk
68801d8e5bSpk
69801d8e5bSpk	.section	".text"
7062926e7eSchristos	.align	4
71801d8e5bSpk	.global	_rtld_bind_start
7262926e7eSchristos	.type	_rtld_bind_start,@function
7362926e7eSchristos_rtld_bind_start:	# (obj, reloff)
749e31b448Smycroft	ld	[%o7 + 8], %o0		/* obj id is in second PLT slot */
7577aa6b2aSchristos	srl	%g1, 10, %o1		/* offset is in high 22 bits */
7677aa6b2aSchristos	call	_rtld_bind		/* Call _rtld_bind(obj, offset) */
7777aa6b2aSchristos	 sub	%o1, 12*4, %o1		/* first 4 `pltrel' entries missing! */
78801d8e5bSpk
799e31b448Smycroft	jmp	%o0			/* return value == function address */
8077aa6b2aSchristos	 restore
81801d8e5bSpk
82