rtld_start.S revision 1.5
11.5Sfvdl/*	$NetBSD: rtld_start.S,v 1.5 2002/11/24 18:16:45 fvdl Exp $	*/
21.3Sfvdl
31.3Sfvdl/*
41.3Sfvdl * Copyright (c) 2001 Wasabi Systems, Inc.
51.3Sfvdl * All rights reserved.
61.3Sfvdl *
71.3Sfvdl * Written by Frank van der Linden for Wasabi Systems, Inc.
81.3Sfvdl *
91.3Sfvdl * Redistribution and use in source and binary forms, with or without
101.3Sfvdl * modification, are permitted provided that the following conditions
111.3Sfvdl * are met:
121.3Sfvdl * 1. Redistributions of source code must retain the above copyright
131.3Sfvdl *    notice, this list of conditions and the following disclaimer.
141.3Sfvdl * 2. Redistributions in binary form must reproduce the above copyright
151.3Sfvdl *    notice, this list of conditions and the following disclaimer in the
161.3Sfvdl *    documentation and/or other materials provided with the distribution.
171.3Sfvdl * 3. All advertising materials mentioning features or use of this software
181.3Sfvdl *    must display the following acknowledgement:
191.3Sfvdl *      This product includes software developed for the NetBSD Project by
201.3Sfvdl *      Wasabi Systems, Inc.
211.3Sfvdl * 4. The name of Wasabi Systems, Inc. may not be used to endorse
221.3Sfvdl *    or promote products derived from this software without specific prior
231.3Sfvdl *    written permission.
241.3Sfvdl *
251.3Sfvdl * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
261.3Sfvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
271.3Sfvdl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
281.3Sfvdl * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
291.3Sfvdl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301.3Sfvdl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311.3Sfvdl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
321.3Sfvdl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
331.3Sfvdl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
341.3Sfvdl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
351.3Sfvdl * POSSIBILITY OF SUCH DAMAGE.
361.3Sfvdl */
371.1Sfvdl
381.1Sfvdl#include <machine/asm.h>
391.1Sfvdl
401.1Sfvdl	.text
411.1Sfvdl	.align	16
421.1Sfvdl	.globl	.rtld_start
431.1Sfvdl	.type	.rtld_start,@function
441.1Sfvdl.rtld_start:
451.1Sfvdl	subq	$16,%rsp		# make room of obj_main and exit proc
461.5Sfvdl	movq	%rsp,%r12		# stack pointer arg to _rtld
471.1Sfvdl	pushq	%rbx			# save ps_strings
481.1Sfvdl
491.5Sfvdl	leaq	_GLOBAL_OFFSET_TABLE_(%rip),%rbx
501.5Sfvdl	movq	_GLOBAL_OFFSET_TABLE_@GOTPCREL(%rip),%rdx
511.5Sfvdl	subq	%rdx,%rbx		# %rbx = relocbase
521.5Sfvdl
531.5Sfvdl	movq	_DYNAMIC@GOTPCREL(%rip),%rdi
541.5Sfvdl	addq	%rbx,%rdi
551.5Sfvdl	movq	%rbx,%rsi
561.5Sfvdl	call	_rtld_relocate_nonplt_self@PLT
571.5Sfvdl
581.5Sfvdl	movq	%r12,%rdi
591.5Sfvdl	movq	%rbx,%rsi
601.5Sfvdl
611.5Sfvdl	call	_rtld@PLT		# _rtld(sp, relocbase)
621.1Sfvdl
631.1Sfvdl	popq	%rbx			# %rbx = ps_strings
641.1Sfvdl	popq	%rdx			# %rdx = cleanup
651.1Sfvdl	popq	%rcx			# %rcx = obj_main
661.1Sfvdl	jmp	*%rax
671.1Sfvdl
681.1Sfvdl	.align	4
691.1Sfvdl	.globl	_rtld_bind_start
701.1Sfvdl	.type	_rtld_bind_start,@function
711.1Sfvdl_rtld_bind_start:	# (obj, reloff)
721.1Sfvdl	pushfq				# save caller-saved registers
731.1Sfvdl	pushq	%rax
741.1Sfvdl	pushq	%rcx
751.1Sfvdl	pushq	%rdx
761.1Sfvdl	pushq	%rsi
771.1Sfvdl	pushq	%rdi
781.1Sfvdl	pushq	%r8
791.1Sfvdl	pushq	%r9
801.1Sfvdl	pushq	%r10
811.1Sfvdl	pushq	%r11
821.1Sfvdl
831.2Sfvdl	movq	80(%rsp),%rdi
841.2Sfvdl	movq	88(%rsp),%rsi
851.2Sfvdl
861.1Sfvdl	call	_rtld_bind@PLT		# call the binder
871.2Sfvdl	movq	%rax,88(%rsp)		# store function in obj
881.1Sfvdl
891.1Sfvdl	popq	%r11
901.1Sfvdl	popq	%r10
911.1Sfvdl	popq	%r9
921.1Sfvdl	popq	%r8
931.1Sfvdl	popq	%rdi
941.1Sfvdl	popq	%rsi
951.1Sfvdl	popq	%rdx
961.1Sfvdl	popq	%rcx
971.1Sfvdl	popq	%rax
981.1Sfvdl	popfq
991.2Sfvdl
1001.2Sfvdl	leaq	8(%rsp),%rsp
1011.1Sfvdl
1021.1Sfvdl	ret
103