head	1.9;
access;
symbols
	netbsd-11-0-RC5:1.9
	netbsd-11-0-RC4:1.9
	netbsd-11-0-RC3:1.9
	netbsd-11-0-RC2:1.9
	netbsd-11-0-RC1:1.9
	perseant-exfatfs-base-20250801:1.9
	netbsd-11:1.9.0.54
	netbsd-11-base:1.9
	netbsd-10-1-RELEASE:1.9
	perseant-exfatfs-base-20240630:1.9
	perseant-exfatfs:1.9.0.52
	perseant-exfatfs-base:1.9
	netbsd-8-3-RELEASE:1.9
	netbsd-9-4-RELEASE:1.9
	netbsd-10-0-RELEASE:1.9
	netbsd-10-0-RC6:1.9
	netbsd-10-0-RC5:1.9
	netbsd-10-0-RC4:1.9
	netbsd-10-0-RC3:1.9
	netbsd-10-0-RC2:1.9
	netbsd-10-0-RC1:1.9
	netbsd-10:1.9.0.50
	netbsd-10-base:1.9
	netbsd-9-3-RELEASE:1.9
	cjep_sun2x-base1:1.9
	cjep_sun2x:1.9.0.48
	cjep_sun2x-base:1.9
	cjep_staticlib_x-base1:1.9
	netbsd-9-2-RELEASE:1.9
	cjep_staticlib_x:1.9.0.46
	cjep_staticlib_x-base:1.9
	netbsd-9-1-RELEASE:1.9
	phil-wifi-20200421:1.9
	phil-wifi-20200411:1.9
	is-mlppp:1.9.0.44
	is-mlppp-base:1.9
	phil-wifi-20200406:1.9
	netbsd-8-2-RELEASE:1.9
	netbsd-9-0-RELEASE:1.9
	netbsd-9-0-RC2:1.9
	netbsd-9-0-RC1:1.9
	phil-wifi-20191119:1.9
	netbsd-9:1.9.0.42
	netbsd-9-base:1.9
	phil-wifi-20190609:1.9
	netbsd-8-1-RELEASE:1.9
	netbsd-8-1-RC1:1.9
	pgoyette-compat-merge-20190127:1.9
	pgoyette-compat-20190127:1.9
	pgoyette-compat-20190118:1.9
	pgoyette-compat-1226:1.9
	pgoyette-compat-1126:1.9
	pgoyette-compat-1020:1.9
	pgoyette-compat-0930:1.9
	pgoyette-compat-0906:1.9
	netbsd-7-2-RELEASE:1.9
	pgoyette-compat-0728:1.9
	netbsd-8-0-RELEASE:1.9
	phil-wifi:1.9.0.40
	phil-wifi-base:1.9
	pgoyette-compat-0625:1.9
	netbsd-8-0-RC2:1.9
	pgoyette-compat-0521:1.9
	pgoyette-compat-0502:1.9
	pgoyette-compat-0422:1.9
	netbsd-8-0-RC1:1.9
	pgoyette-compat-0415:1.9
	pgoyette-compat-0407:1.9
	pgoyette-compat-0330:1.9
	pgoyette-compat-0322:1.9
	pgoyette-compat-0315:1.9
	netbsd-7-1-2-RELEASE:1.9
	pgoyette-compat:1.9.0.38
	pgoyette-compat-base:1.9
	netbsd-7-1-1-RELEASE:1.9
	matt-nb8-mediatek:1.9.0.36
	matt-nb8-mediatek-base:1.9
	perseant-stdc-iso10646:1.9.0.34
	perseant-stdc-iso10646-base:1.9
	netbsd-8:1.9.0.32
	netbsd-8-base:1.9
	prg-localcount2-base3:1.9
	prg-localcount2-base2:1.9
	prg-localcount2-base1:1.9
	prg-localcount2:1.9.0.30
	prg-localcount2-base:1.9
	pgoyette-localcount-20170426:1.9
	bouyer-socketcan-base1:1.9
	pgoyette-localcount-20170320:1.9
	netbsd-7-1:1.9.0.28
	netbsd-7-1-RELEASE:1.9
	netbsd-7-1-RC2:1.9
	netbsd-7-nhusb-base-20170116:1.9
	bouyer-socketcan:1.9.0.26
	bouyer-socketcan-base:1.9
	pgoyette-localcount-20170107:1.9
	netbsd-7-1-RC1:1.9
	pgoyette-localcount-20161104:1.9
	netbsd-7-0-2-RELEASE:1.9
	localcount-20160914:1.9
	netbsd-7-nhusb:1.9.0.24
	netbsd-7-nhusb-base:1.9
	pgoyette-localcount-20160806:1.9
	pgoyette-localcount-20160726:1.9
	pgoyette-localcount:1.9.0.22
	pgoyette-localcount-base:1.9
	netbsd-7-0-1-RELEASE:1.9
	netbsd-7-0:1.9.0.20
	netbsd-7-0-RELEASE:1.9
	netbsd-7-0-RC3:1.9
	netbsd-7-0-RC2:1.9
	netbsd-7-0-RC1:1.9
	netbsd-5-2-3-RELEASE:1.6
	netbsd-5-1-5-RELEASE:1.6
	netbsd-6-0-6-RELEASE:1.9
	netbsd-6-1-5-RELEASE:1.9
	netbsd-7:1.9.0.18
	netbsd-7-base:1.9
	yamt-pagecache-base9:1.9
	yamt-pagecache-tag8:1.8.6.1
	netbsd-6-1-4-RELEASE:1.9
	netbsd-6-0-5-RELEASE:1.9
	tls-earlyentropy:1.9.0.16
	tls-earlyentropy-base:1.9
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.9
	riastradh-drm2-base3:1.9
	netbsd-6-1-3-RELEASE:1.9
	netbsd-6-0-4-RELEASE:1.9
	netbsd-5-2-2-RELEASE:1.6
	netbsd-5-1-4-RELEASE:1.6
	netbsd-6-1-2-RELEASE:1.9
	netbsd-6-0-3-RELEASE:1.9
	netbsd-5-2-1-RELEASE:1.6
	netbsd-5-1-3-RELEASE:1.6
	netbsd-6-1-1-RELEASE:1.9
	riastradh-drm2-base2:1.9
	riastradh-drm2-base1:1.9
	riastradh-drm2:1.9.0.10
	riastradh-drm2-base:1.9
	netbsd-6-1:1.9.0.14
	netbsd-6-0-2-RELEASE:1.9
	netbsd-6-1-RELEASE:1.9
	netbsd-6-1-RC4:1.9
	netbsd-6-1-RC3:1.9
	agc-symver:1.9.0.12
	agc-symver-base:1.9
	netbsd-6-1-RC2:1.9
	netbsd-6-1-RC1:1.9
	yamt-pagecache-base8:1.9
	netbsd-5-2:1.6.0.50
	netbsd-6-0-1-RELEASE:1.9
	yamt-pagecache-base7:1.9
	netbsd-5-2-RELEASE:1.6
	netbsd-5-2-RC1:1.6
	matt-nb6-plus-nbase:1.9
	yamt-pagecache-base6:1.9
	netbsd-6-0:1.9.0.8
	netbsd-6-0-RELEASE:1.9
	netbsd-6-0-RC2:1.9
	tls-maxphys:1.9.0.6
	tls-maxphys-base:1.9
	matt-nb6-plus:1.9.0.4
	matt-nb6-plus-base:1.9
	netbsd-6-0-RC1:1.9
	yamt-pagecache-base5:1.9
	yamt-pagecache-base4:1.9
	netbsd-6:1.9.0.2
	netbsd-6-base:1.9
	netbsd-5-1-2-RELEASE:1.6
	netbsd-5-1-1-RELEASE:1.6
	yamt-pagecache-base3:1.8
	yamt-pagecache-base2:1.8
	yamt-pagecache:1.8.0.6
	yamt-pagecache-base:1.8
	cherry-xenmp:1.8.0.4
	cherry-xenmp-base:1.8
	bouyer-quota2-nbase:1.8
	bouyer-quota2:1.8.0.2
	bouyer-quota2-base:1.8
	matt-mips64-premerge-20101231:1.8
	matt-nb5-mips64-premerge-20101231:1.6
	matt-nb5-pq3:1.6.0.48
	matt-nb5-pq3-base:1.6
	netbsd-5-1:1.6.0.46
	netbsd-5-1-RELEASE:1.6
	netbsd-5-1-RC4:1.6
	matt-nb5-mips64-k15:1.6
	netbsd-5-1-RC3:1.6
	netbsd-5-1-RC2:1.6
	netbsd-5-1-RC1:1.6
	netbsd-5-0-2-RELEASE:1.6
	matt-nb5-mips64-premerge-20091211:1.6
	matt-premerge-20091211:1.6
	matt-nb5-mips64-u2-k2-k4-k7-k8-k9:1.6
	matt-nb4-mips64-k7-u2a-k9b:1.6
	matt-nb5-mips64-u1-k1-k5:1.6
	matt-nb5-mips64:1.6.0.44
	netbsd-5-0-1-RELEASE:1.6
	jym-xensuspend-nbase:1.6
	netbsd-5-0:1.6.0.42
	netbsd-5-0-RELEASE:1.6
	netbsd-5-0-RC4:1.6
	netbsd-5-0-RC3:1.6
	netbsd-5-0-RC2:1.6
	jym-xensuspend:1.6.0.40
	jym-xensuspend-base:1.6
	netbsd-5-0-RC1:1.6
	netbsd-5:1.6.0.38
	netbsd-5-base:1.6
	matt-mips64-base2:1.6
	matt-mips64:1.6.0.36
	mjf-devfs2:1.6.0.34
	mjf-devfs2-base:1.6
	netbsd-4-0-1-RELEASE:1.6
	wrstuden-revivesa-base-3:1.6
	wrstuden-revivesa-base-2:1.6
	wrstuden-fixsa-newbase:1.6
	wrstuden-revivesa-base-1:1.6
	yamt-pf42-base4:1.6
	yamt-pf42-base3:1.6
	hpcarm-cleanup-nbase:1.6
	yamt-pf42-baseX:1.6
	yamt-pf42-base2:1.6
	wrstuden-revivesa:1.6.0.32
	wrstuden-revivesa-base:1.6
	yamt-pf42:1.6.0.30
	yamt-pf42-base:1.6
	keiichi-mipv6:1.6.0.28
	keiichi-mipv6-base:1.6
	matt-armv6-nbase:1.6
	matt-armv6-prevmlocking:1.6
	wrstuden-fixsa-base-1:1.6
	netbsd-4-0:1.6.0.26
	netbsd-4-0-RELEASE:1.6
	cube-autoconf:1.6.0.24
	cube-autoconf-base:1.6
	netbsd-4-0-RC5:1.6
	netbsd-4-0-RC4:1.6
	netbsd-4-0-RC3:1.6
	netbsd-4-0-RC2:1.6
	netbsd-4-0-RC1:1.6
	matt-armv6:1.6.0.22
	matt-armv6-base:1.6
	matt-mips64-base:1.6
	hpcarm-cleanup:1.6.0.20
	hpcarm-cleanup-base:1.6
	netbsd-3-1-1-RELEASE:1.6
	netbsd-3-0-3-RELEASE:1.6
	wrstuden-fixsa:1.6.0.18
	wrstuden-fixsa-base:1.6
	abandoned-netbsd-4-base:1.6
	abandoned-netbsd-4:1.6.0.12
	netbsd-3-1:1.6.0.14
	netbsd-3-1-RELEASE:1.6
	netbsd-3-0-2-RELEASE:1.6
	netbsd-3-1-RC4:1.6
	netbsd-3-1-RC3:1.6
	netbsd-3-1-RC2:1.6
	netbsd-3-1-RC1:1.6
	netbsd-4:1.6.0.16
	netbsd-4-base:1.6
	netbsd-3-0-1-RELEASE:1.6
	netbsd-3-0:1.6.0.10
	netbsd-3-0-RELEASE:1.6
	netbsd-3-0-RC6:1.6
	netbsd-3-0-RC5:1.6
	netbsd-3-0-RC4:1.6
	netbsd-3-0-RC3:1.6
	netbsd-3-0-RC2:1.6
	netbsd-3-0-RC1:1.6
	netbsd-2-0-3-RELEASE:1.6
	netbsd-2-1:1.6.0.8
	netbsd-2-1-RELEASE:1.6
	netbsd-2-1-RC6:1.6
	netbsd-2-1-RC5:1.6
	netbsd-2-1-RC4:1.6
	netbsd-2-1-RC3:1.6
	netbsd-2-1-RC2:1.6
	netbsd-2-1-RC1:1.6
	netbsd-2-0-2-RELEASE:1.6
	netbsd-3:1.6.0.6
	netbsd-3-base:1.6
	netbsd-2-0-1-RELEASE:1.6
	netbsd-2:1.6.0.4
	netbsd-2-base:1.6
	netbsd-2-0-RELEASE:1.6
	netbsd-2-0-RC5:1.6
	netbsd-2-0-RC4:1.6
	netbsd-2-0-RC3:1.6
	netbsd-2-0-RC2:1.6
	netbsd-2-0-RC1:1.6
	netbsd-2-0:1.6.0.2
	netbsd-2-0-base:1.6
	netbsd-1-6-PATCH002-RELEASE:1.3
	netbsd-1-6-PATCH002:1.3
	netbsd-1-6-PATCH002-RC4:1.3
	netbsd-1-6-PATCH002-RC3:1.3
	netbsd-1-6-PATCH002-RC2:1.3
	netbsd-1-6-PATCH002-RC1:1.3
	netbsd-1-6-PATCH001:1.3
	netbsd-1-6-PATCH001-RELEASE:1.3
	netbsd-1-6-PATCH001-RC3:1.3
	netbsd-1-6-PATCH001-RC2:1.3
	netbsd-1-6-PATCH001-RC1:1.3
	fvdl_fs64_base:1.5
	netbsd-1-6-RELEASE:1.3
	netbsd-1-6-RC3:1.3
	netbsd-1-6-RC2:1.3
	netbsd-1-6-RC1:1.3
	netbsd-1-6:1.3.0.2
	netbsd-1-6-base:1.3;
locks; strict;
comment	@# @;


1.9
date	2011.12.11.22.07.26;	author joerg;	state Exp;
branches;
next	1.8;

1.8
date	2010.12.05.00.56.07;	author joerg;	state Exp;
branches
	1.8.6.1;
next	1.7;

1.7
date	2010.12.03.22.48.25;	author joerg;	state Exp;
branches;
next	1.6;

1.6
date	2003.02.28.22.37.35;	author mycroft;	state Exp;
branches;
next	1.5;

1.5
date	2002.11.24.18.16.45;	author fvdl;	state Exp;
branches;
next	1.4;

1.4
date	2002.09.25.08.37.57;	author mycroft;	state Exp;
branches;
next	1.3;

1.3
date	2001.12.14.21.33.59;	author fvdl;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2001.06.20.17.58.16;	author fvdl;	state Exp;
branches;
next	1.1;

1.1
date	2001.06.19.01.11.44;	author fvdl;	state Exp;
branches;
next	;

1.8.6.1
date	2012.04.17.00.05.36;	author yamt;	state Exp;
branches;
next	;

1.3.2.1
date	2004.05.28.08.31.23;	author tron;	state Exp;
branches;
next	;


desc
@@


1.9
log
@Align in the stack before calling _rtld in the way the x86_64 ABI
specifies. This is necessary to ensure that init functions are always
called with the correct alignment, e.g. in case they use SSE
instructions.
@
text
@/*	$NetBSD: rtld_start.S,v 1.8 2010/12/05 00:56:07 joerg Exp $	*/

/*
 * Copyright (c) 2001 Wasabi Systems, Inc.
 * All rights reserved.
 *
 * Written by Frank van der Linden for Wasabi Systems, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed for the NetBSD Project by
 *      Wasabi Systems, Inc.
 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
 *    or promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <machine/asm.h>

	.text
	.align	16
	.globl	.rtld_start
	.hidden	.rtld_start
	.type	.rtld_start,@@function
.rtld_start:
	subq	$16,%rsp		# make room of obj_main and exit proc
	movq	%rsp,%r12		# stack pointer arg to _rtld
	pushq	%rbx			# save ps_strings

	andq	$~15,%rsp		# align rsp, to be restored from r12

	leaq	_GLOBAL_OFFSET_TABLE_(%rip),%rax
	leaq	_DYNAMIC(%rip),%rdi	# &_DYNAMIC
	movq	%rdi,%rbx
	subq	(%rax),%rbx		# relocbase

	movq	%rbx,%rsi
	call	_rtld_relocate_nonplt_self

	movq	%r12,%rdi
	movq	%rbx,%rsi
	call	_rtld			# _rtld(sp, relocbase)

	leaq	-8(%r12),%rsp		# restore saved rsp, including %rbx
	popq	%rbx			# %rbx = ps_strings
	popq	%rdx			# %rdx = cleanup
	popq	%rcx			# %rcx = obj_main
	jmp	*%rax

	.align	4
	.globl	_rtld_bind_start
	.hidden	_rtld_bind_start
	.type	_rtld_bind_start,@@function
_rtld_bind_start:	# (obj, reloff)
	# This function is called with a misaligned stack from the PLT
	# due to the additional argument pushed.
	# At this point %rsp % 16 == 8.
	pushfq				# save caller-saved registers
	pushq	%rax
	pushq	%rcx
	pushq	%rdx
	pushq	%rsi
	pushq	%rdi
	pushq	%r8
	pushq	%r9
	pushq	%r10
	pushq	%r11

	movq	80(%rsp),%rdi
	movq	88(%rsp),%rsi

	call	_rtld_bind		# call the binder
	movq	%rax,88(%rsp)		# store function in obj

	popq	%r11
	popq	%r10
	popq	%r9
	popq	%r8
	popq	%rdi
	popq	%rsi
	popq	%rdx
	popq	%rcx
	popq	%rax
	popfq

	leaq	8(%rsp),%rsp

	ret
@


1.8
log
@Build ld.elf_so with -fvisibility=hidden. Exploit this for i386/x86_64
to simplify the assembler code.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.7 2010/12/03 22:48:25 joerg Exp $	*/
d50 2
d64 1
@


1.8.6.1
log
@sync with head
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.8 2010/12/05 00:56:07 joerg Exp $	*/
a49 2
	andq	$~15,%rsp		# align rsp, to be restored from r12

a61 1
	leaq	-8(%r12),%rsp		# restore saved rsp, including %rbx
@


1.7
log
@Add comment about the unusual stack alignment in .rtld_bind_start.
@
text
@d1 1
a1 1
/*	$NetBSD: src/libexec/ld.elf_so/arch/x86_64/rtld_start.S,v 1.6 2003-02-28 22:37:35 mycroft Exp $	*/
d43 1
d56 1
a56 1
	call	_rtld_relocate_nonplt_self@@PLT
d60 1
a60 1
	call	_rtld@@PLT		# _rtld(sp, relocbase)
d69 1
d89 1
a89 1
	call	_rtld_bind@@PLT		# call the binder
@


1.6
log
@Eliminate GOT usage in rtld_start() on this platform, too.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.5 2002/11/24 18:16:45 fvdl Exp $	*/
d70 3
@


1.5
log
@Implement self-relocation as is required now.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.4 2002/09/25 08:37:57 mycroft Exp $	*/
d49 4
a52 3
	leaq	_GLOBAL_OFFSET_TABLE_(%rip),%rbx
	movq	_GLOBAL_OFFSET_TABLE_@@GOTPCREL(%rip),%rdx
	subq	%rdx,%rbx		# %rbx = relocbase
a53 2
	movq	_DYNAMIC@@GOTPCREL(%rip),%rdi
	addq	%rbx,%rdi
a58 1

@


1.4
log
@Partly fix this port -- still needs a self-reloc function.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.3 2001/12/14 21:33:59 fvdl Exp $	*/
d46 1
a46 1
	movq	%rsp,%rdi		# stack pointer arg to _rtld
d49 13
a61 1
	call	_rtld@@PLT		# _rtld(sp)
@


1.3
log
@Add missing copyright notice.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.2 2001/06/20 17:58:16 fvdl Exp $	*/
a72 4
	movq	%rsi,%r11		# multiply by sizeof (Elf64_Rela) (24)
	shlq	$3,%r11
	shlq	$4,%rsi			# 16 * index + 8 * index = 24 * index
	addq	%r11,%rsi
@


1.3.2.1
log
@Apply patch (request by skrll in ticket #1702):
Bring "ld.elf_so" (mostly) in sync with NetBSD-current:
- MI and MD (e.g. under NetBSD-alpha) performance improvements
- RTLD_SELF, RTLD_NEXT, RTLD_DEFAULT support
- much better structured code
- closes PR bin/25464
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.6 2003/02/28 22:37:35 mycroft Exp $	*/
d46 1
a46 1
	movq	%rsp,%r12		# stack pointer arg to _rtld
d49 1
a49 11
	leaq	_GLOBAL_OFFSET_TABLE_(%rip),%rax
	leaq	_DYNAMIC(%rip),%rdi	# &_DYNAMIC
	movq	%rdi,%rbx
	subq	(%rax),%rbx		# relocbase

	movq	%rbx,%rsi
	call	_rtld_relocate_nonplt_self@@PLT

	movq	%r12,%rdi
	movq	%rbx,%rsi
	call	_rtld@@PLT		# _rtld(sp, relocbase)
d73 4
@


1.2
log
@Get stack layout right.
@
text
@d1 36
a36 1
/*	$NetBSD: rtld_start.S,v 1.1 2001/06/19 01:11:44 fvdl Exp $	*/
@


1.1
log
@Preliminary x86-64 support. Not fully functional yet (toolchain bugs).
@
text
@d1 1
a1 1
/*	$NetBSD$	*/
d36 7
d44 1
a44 1
	movq	%rax,80(%rsp)		# store function in return address
d56 2
@

