head	1.17;
access;
symbols
	netbsd-11-0-RC5:1.17
	netbsd-11-0-RC4:1.17
	netbsd-11-0-RC3:1.17
	netbsd-11-0-RC2:1.17
	netbsd-11-0-RC1:1.17
	perseant-exfatfs-base-20250801:1.17
	netbsd-11:1.17.0.56
	netbsd-11-base:1.17
	netbsd-10-1-RELEASE:1.17
	perseant-exfatfs-base-20240630:1.17
	perseant-exfatfs:1.17.0.54
	perseant-exfatfs-base:1.17
	netbsd-8-3-RELEASE:1.17
	netbsd-9-4-RELEASE:1.17
	netbsd-10-0-RELEASE:1.17
	netbsd-10-0-RC6:1.17
	netbsd-10-0-RC5:1.17
	netbsd-10-0-RC4:1.17
	netbsd-10-0-RC3:1.17
	netbsd-10-0-RC2:1.17
	netbsd-10-0-RC1:1.17
	netbsd-10:1.17.0.52
	netbsd-10-base:1.17
	netbsd-9-3-RELEASE:1.17
	cjep_sun2x-base1:1.17
	cjep_sun2x:1.17.0.50
	cjep_sun2x-base:1.17
	cjep_staticlib_x-base1:1.17
	netbsd-9-2-RELEASE:1.17
	cjep_staticlib_x:1.17.0.48
	cjep_staticlib_x-base:1.17
	netbsd-9-1-RELEASE:1.17
	phil-wifi-20200421:1.17
	phil-wifi-20200411:1.17
	is-mlppp:1.17.0.46
	is-mlppp-base:1.17
	phil-wifi-20200406:1.17
	netbsd-8-2-RELEASE:1.17
	netbsd-9-0-RELEASE:1.17
	netbsd-9-0-RC2:1.17
	netbsd-9-0-RC1:1.17
	phil-wifi-20191119:1.17
	netbsd-9:1.17.0.44
	netbsd-9-base:1.17
	phil-wifi-20190609:1.17
	netbsd-8-1-RELEASE:1.17
	netbsd-8-1-RC1:1.17
	pgoyette-compat-merge-20190127:1.17
	pgoyette-compat-20190127:1.17
	pgoyette-compat-20190118:1.17
	pgoyette-compat-1226:1.17
	pgoyette-compat-1126:1.17
	pgoyette-compat-1020:1.17
	pgoyette-compat-0930:1.17
	pgoyette-compat-0906:1.17
	netbsd-7-2-RELEASE:1.17
	pgoyette-compat-0728:1.17
	netbsd-8-0-RELEASE:1.17
	phil-wifi:1.17.0.42
	phil-wifi-base:1.17
	pgoyette-compat-0625:1.17
	netbsd-8-0-RC2:1.17
	pgoyette-compat-0521:1.17
	pgoyette-compat-0502:1.17
	pgoyette-compat-0422:1.17
	netbsd-8-0-RC1:1.17
	pgoyette-compat-0415:1.17
	pgoyette-compat-0407:1.17
	pgoyette-compat-0330:1.17
	pgoyette-compat-0322:1.17
	pgoyette-compat-0315:1.17
	netbsd-7-1-2-RELEASE:1.17
	pgoyette-compat:1.17.0.40
	pgoyette-compat-base:1.17
	netbsd-7-1-1-RELEASE:1.17
	matt-nb8-mediatek:1.17.0.38
	matt-nb8-mediatek-base:1.17
	perseant-stdc-iso10646:1.17.0.36
	perseant-stdc-iso10646-base:1.17
	netbsd-8:1.17.0.34
	netbsd-8-base:1.17
	prg-localcount2-base3:1.17
	prg-localcount2-base2:1.17
	prg-localcount2-base1:1.17
	prg-localcount2:1.17.0.32
	prg-localcount2-base:1.17
	pgoyette-localcount-20170426:1.17
	bouyer-socketcan-base1:1.17
	pgoyette-localcount-20170320:1.17
	netbsd-7-1:1.17.0.30
	netbsd-7-1-RELEASE:1.17
	netbsd-7-1-RC2:1.17
	netbsd-7-nhusb-base-20170116:1.17
	bouyer-socketcan:1.17.0.28
	bouyer-socketcan-base:1.17
	pgoyette-localcount-20170107:1.17
	netbsd-7-1-RC1:1.17
	pgoyette-localcount-20161104:1.17
	netbsd-7-0-2-RELEASE:1.17
	localcount-20160914:1.17
	netbsd-7-nhusb:1.17.0.26
	netbsd-7-nhusb-base:1.17
	pgoyette-localcount-20160806:1.17
	pgoyette-localcount-20160726:1.17
	pgoyette-localcount:1.17.0.24
	pgoyette-localcount-base:1.17
	netbsd-7-0-1-RELEASE:1.17
	netbsd-7-0:1.17.0.22
	netbsd-7-0-RELEASE:1.17
	netbsd-7-0-RC3:1.17
	netbsd-7-0-RC2:1.17
	netbsd-7-0-RC1:1.17
	netbsd-5-2-3-RELEASE:1.13
	netbsd-5-1-5-RELEASE:1.13
	netbsd-6-0-6-RELEASE:1.17
	netbsd-6-1-5-RELEASE:1.17
	netbsd-7:1.17.0.20
	netbsd-7-base:1.17
	yamt-pagecache-base9:1.17
	yamt-pagecache-tag8:1.17
	netbsd-6-1-4-RELEASE:1.17
	netbsd-6-0-5-RELEASE:1.17
	tls-earlyentropy:1.17.0.18
	tls-earlyentropy-base:1.17
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.17
	riastradh-drm2-base3:1.17
	netbsd-6-1-3-RELEASE:1.17
	netbsd-6-0-4-RELEASE:1.17
	netbsd-5-2-2-RELEASE:1.13
	netbsd-5-1-4-RELEASE:1.13
	netbsd-6-1-2-RELEASE:1.17
	netbsd-6-0-3-RELEASE:1.17
	netbsd-5-2-1-RELEASE:1.13
	netbsd-5-1-3-RELEASE:1.13
	netbsd-6-1-1-RELEASE:1.17
	riastradh-drm2-base2:1.17
	riastradh-drm2-base1:1.17
	riastradh-drm2:1.17.0.12
	riastradh-drm2-base:1.17
	netbsd-6-1:1.17.0.16
	netbsd-6-0-2-RELEASE:1.17
	netbsd-6-1-RELEASE:1.17
	netbsd-6-1-RC4:1.17
	netbsd-6-1-RC3:1.17
	agc-symver:1.17.0.14
	agc-symver-base:1.17
	netbsd-6-1-RC2:1.17
	netbsd-6-1-RC1:1.17
	yamt-pagecache-base8:1.17
	netbsd-5-2:1.13.0.50
	netbsd-6-0-1-RELEASE:1.17
	yamt-pagecache-base7:1.17
	netbsd-5-2-RELEASE:1.13
	netbsd-5-2-RC1:1.13
	matt-nb6-plus-nbase:1.17
	yamt-pagecache-base6:1.17
	netbsd-6-0:1.17.0.10
	netbsd-6-0-RELEASE:1.17
	netbsd-6-0-RC2:1.17
	tls-maxphys:1.17.0.8
	tls-maxphys-base:1.17
	matt-nb6-plus:1.17.0.6
	matt-nb6-plus-base:1.17
	netbsd-6-0-RC1:1.17
	yamt-pagecache-base5:1.17
	yamt-pagecache-base4:1.17
	netbsd-6:1.17.0.4
	netbsd-6-base:1.17
	netbsd-5-1-2-RELEASE:1.13
	netbsd-5-1-1-RELEASE:1.13
	yamt-pagecache-base3:1.17
	yamt-pagecache-base2:1.17
	yamt-pagecache:1.17.0.2
	yamt-pagecache-base:1.17
	cherry-xenmp:1.16.0.2
	cherry-xenmp-base:1.16
	bouyer-quota2-nbase:1.16
	bouyer-quota2:1.14.0.2
	bouyer-quota2-base:1.15
	matt-mips64-premerge-20101231:1.13
	matt-nb5-mips64-premerge-20101231:1.13
	matt-nb5-pq3:1.13.0.48
	matt-nb5-pq3-base:1.13
	netbsd-5-1:1.13.0.46
	netbsd-5-1-RELEASE:1.13
	netbsd-5-1-RC4:1.13
	matt-nb5-mips64-k15:1.13
	netbsd-5-1-RC3:1.13
	netbsd-5-1-RC2:1.13
	netbsd-5-1-RC1:1.13
	netbsd-5-0-2-RELEASE:1.13
	matt-nb5-mips64-premerge-20091211:1.13
	matt-premerge-20091211:1.13
	matt-nb5-mips64-u2-k2-k4-k7-k8-k9:1.13
	matt-nb4-mips64-k7-u2a-k9b:1.13
	matt-nb5-mips64-u1-k1-k5:1.13
	matt-nb5-mips64:1.13.0.44
	netbsd-5-0-1-RELEASE:1.13
	jym-xensuspend-nbase:1.13
	netbsd-5-0:1.13.0.42
	netbsd-5-0-RELEASE:1.13
	netbsd-5-0-RC4:1.13
	netbsd-5-0-RC3:1.13
	netbsd-5-0-RC2:1.13
	jym-xensuspend:1.13.0.40
	jym-xensuspend-base:1.13
	netbsd-5-0-RC1:1.13
	netbsd-5:1.13.0.38
	netbsd-5-base:1.13
	matt-mips64-base2:1.13
	matt-mips64:1.13.0.36
	mjf-devfs2:1.13.0.34
	mjf-devfs2-base:1.13
	netbsd-4-0-1-RELEASE:1.13
	wrstuden-revivesa-base-3:1.13
	wrstuden-revivesa-base-2:1.13
	wrstuden-fixsa-newbase:1.13
	wrstuden-revivesa-base-1:1.13
	yamt-pf42-base4:1.13
	yamt-pf42-base3:1.13
	hpcarm-cleanup-nbase:1.13
	yamt-pf42-baseX:1.13
	yamt-pf42-base2:1.13
	wrstuden-revivesa:1.13.0.32
	wrstuden-revivesa-base:1.13
	yamt-pf42:1.13.0.30
	yamt-pf42-base:1.13
	keiichi-mipv6:1.13.0.28
	keiichi-mipv6-base:1.13
	matt-armv6-nbase:1.13
	matt-armv6-prevmlocking:1.13
	wrstuden-fixsa-base-1:1.13
	netbsd-4-0:1.13.0.26
	netbsd-4-0-RELEASE:1.13
	cube-autoconf:1.13.0.24
	cube-autoconf-base:1.13
	netbsd-4-0-RC5:1.13
	netbsd-4-0-RC4:1.13
	netbsd-4-0-RC3:1.13
	netbsd-4-0-RC2:1.13
	netbsd-4-0-RC1:1.13
	matt-armv6:1.13.0.22
	matt-armv6-base:1.13
	matt-mips64-base:1.13
	hpcarm-cleanup:1.13.0.20
	hpcarm-cleanup-base:1.13
	netbsd-3-1-1-RELEASE:1.13
	netbsd-3-0-3-RELEASE:1.13
	wrstuden-fixsa:1.13.0.18
	wrstuden-fixsa-base:1.13
	abandoned-netbsd-4-base:1.13
	abandoned-netbsd-4:1.13.0.12
	netbsd-3-1:1.13.0.14
	netbsd-3-1-RELEASE:1.13
	netbsd-3-0-2-RELEASE:1.13
	netbsd-3-1-RC4:1.13
	netbsd-3-1-RC3:1.13
	netbsd-3-1-RC2:1.13
	netbsd-3-1-RC1:1.13
	netbsd-4:1.13.0.16
	netbsd-4-base:1.13
	netbsd-3-0-1-RELEASE:1.13
	netbsd-3-0:1.13.0.10
	netbsd-3-0-RELEASE:1.13
	netbsd-3-0-RC6:1.13
	netbsd-3-0-RC5:1.13
	netbsd-3-0-RC4:1.13
	netbsd-3-0-RC3:1.13
	netbsd-3-0-RC2:1.13
	netbsd-3-0-RC1:1.13
	netbsd-2-0-3-RELEASE:1.13
	netbsd-2-1:1.13.0.8
	netbsd-2-1-RELEASE:1.13
	netbsd-2-1-RC6:1.13
	netbsd-2-1-RC5:1.13
	netbsd-2-1-RC4:1.13
	netbsd-2-1-RC3:1.13
	netbsd-2-1-RC2:1.13
	netbsd-2-1-RC1:1.13
	netbsd-2-0-2-RELEASE:1.13
	netbsd-3:1.13.0.6
	netbsd-3-base:1.13
	netbsd-2-0-1-RELEASE:1.13
	netbsd-2:1.13.0.4
	netbsd-2-base:1.13
	netbsd-2-0-RELEASE:1.13
	netbsd-2-0-RC5:1.13
	netbsd-2-0-RC4:1.13
	netbsd-2-0-RC3:1.13
	netbsd-2-0-RC2:1.13
	netbsd-2-0-RC1:1.13
	netbsd-2-0:1.13.0.2
	netbsd-2-0-base:1.13
	netbsd-1-6-PATCH002-RELEASE:1.4
	netbsd-1-6-PATCH002:1.4
	netbsd-1-6-PATCH002-RC4:1.4
	netbsd-1-6-PATCH002-RC3:1.4
	netbsd-1-6-PATCH002-RC2:1.4
	netbsd-1-6-PATCH002-RC1:1.4
	netbsd-1-6-PATCH001:1.4
	netbsd-1-6-PATCH001-RELEASE:1.4
	netbsd-1-6-PATCH001-RC3:1.4
	netbsd-1-6-PATCH001-RC2:1.4
	netbsd-1-6-PATCH001-RC1:1.4
	fvdl_fs64_base:1.13
	netbsd-1-6-RELEASE:1.4
	netbsd-1-6-RC3:1.4
	netbsd-1-6-RC2:1.4
	netbsd-1-6-RC1:1.4
	netbsd-1-6:1.4.0.2
	netbsd-1-6-base:1.4
	netbsd-1-5-PATCH003:1.3.8.1
	netbsd-1-5-PATCH002:1.3
	netbsd-1-5-PATCH001:1.3
	netbsd-1-5-RELEASE:1.3
	netbsd-1-5-BETA2:1.3
	netbsd-1-5-BETA:1.3
	netbsd-1-4-PATCH003:1.1
	netbsd-1-5-ALPHA2:1.3
	netbsd-1-5:1.3.0.8
	netbsd-1-5-base:1.3
	minoura-xpg4dl:1.3.0.6
	minoura-xpg4dl-base:1.3
	netbsd-1-4-PATCH002:1.1
	wrstuden-devbsize-19991221:1.3
	wrstuden-devbsize:1.3.0.4
	wrstuden-devbsize-base:1.3
	comdex-fall-1999:1.3.0.2
	comdex-fall-1999-base:1.3
	netbsd-1-4-PATCH001:1.1
	netbsd-1-4-RELEASE:1.1
	netbsd-1-4:1.1.0.2
	netbsd-1-4-base:1.1;
locks; strict;
comment	@# @;


1.17
date	2011.09.26.01.52.22;	author mrg;	state Exp;
branches;
next	1.16;

1.16
date	2011.03.04.00.40.48;	author matt;	state Exp;
branches;
next	1.15;

1.15
date	2011.02.10.02.28.20;	author matt;	state Exp;
branches;
next	1.14;

1.14
date	2011.01.16.01.22.29;	author matt;	state Exp;
branches
	1.14.2.1;
next	1.13;

1.13
date	2002.12.04.01.19.37;	author thorpej;	state Exp;
branches;
next	1.12;

1.12
date	2002.10.31.20.23.25;	author matt;	state Exp;
branches;
next	1.11;

1.11
date	2002.10.05.11.59.06;	author mycroft;	state Exp;
branches;
next	1.10;

1.10
date	2002.09.25.07.27.53;	author mycroft;	state Exp;
branches;
next	1.9;

1.9
date	2002.09.12.17.18.40;	author mycroft;	state Exp;
branches;
next	1.8;

1.8
date	2002.09.12.17.07.26;	author mycroft;	state Exp;
branches;
next	1.7;

1.7
date	2002.09.11.21.14.08;	author mycroft;	state Exp;
branches;
next	1.6;

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

1.5
date	2002.09.10.02.24.51;	author mycroft;	state Exp;
branches;
next	1.4;

1.4
date	2001.09.26.04.06.43;	author mycroft;	state Exp;
branches
	1.4.2.1;
next	1.3;

1.3
date	99.05.21.08.00.11;	author tsubai;	state Exp;
branches
	1.3.8.1;
next	1.2;

1.2
date	99.04.18.19.40.07;	author ws;	state Exp;
branches;
next	1.1;

1.1
date	98.11.24.11.34.31;	author tsubai;	state Exp;
branches;
next	;

1.14.2.1
date	2011.02.17.11.59.24;	author bouyer;	state Exp;
branches;
next	1.14.2.2;

1.14.2.2
date	2011.03.05.15.09.24;	author bouyer;	state Exp;
branches;
next	;

1.4.2.1
date	2004.05.28.08.31.22;	author tron;	state Exp;
branches;
next	;

1.3.8.1
date	2001.12.09.17.23.30;	author he;	state Exp;
branches;
next	;


desc
@@


1.17
log
@match END() with a relevant ENTRY*().  gas 2.21 complains about the
non-constant-ness of the symbol otherwise.
@
text
@/*	$NetBSD: rtld_start.S,v 1.16 2011/03/04 00:40:48 matt Exp $	*/

/*-
 * Copyright (C) 1998	Tsubai Masanari
 * Portions copyright 2002 Charles M. Hannum <root@@ihack.net>
 * All rights reserved.
 *
 * 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. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 THE AUTHOR 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>

	.globl	_rtld_start
	.globl	_rtld

	.text

_rtld_start:
	stwu	%r1,-48(%r1)
	stw	%r3,12(%r1)		# argc
	stw	%r4,16(%r1)		# argv
	stw	%r5,20(%r1)		# envp
/*	stw	%r6,24(%r1)		# obj		(always 0) */
/*	stw	%r7,28(%r1)		# cleanup	(always 0) */
	stw	%r8,32(%r1)		# ps_strings

	bcl	20,31,1f
1:	mflr	%r30
	mr	%r3,%r30		# save for _DYNAMIC
	addis	%r30,%r30,_GLOBAL_OFFSET_TABLE_-1b@@ha
	addi	%r30,%r30,_GLOBAL_OFFSET_TABLE_-1b@@l
	addis	%r3,%r3,_DYNAMIC-1b@@ha	# get _DYNAMIC actual address
	addi	%r3,%r3,_DYNAMIC-1b@@l
	lwz	%r28,0(%r30)		# get base-relative &_DYNAMIC
	sub	%r28,%r3,%r28		# r28 = relocbase
	mr	%r4,%r28		# r4 = relocbase
	bl	_rtld_relocate_nonplt_self

	lwz	%r3,16(%r1)
	addi	%r3,%r3,-12		# sp = &argv[-3]	/* XXX */
	mr	%r4,%r28		# r4 = relocbase
	bl	_rtld			# _start = _rtld(sp, relocbase)
	mtlr	%r3

	lwz	%r3,12(%r1)		# argc
	lwz	%r4,16(%r1)		# argv
	lwz	%r5,20(%r1)		# envp
	lwz	%r6,-8(%r4)		# obj = sp[1] (== argv[-2])
	lwz	%r7,-12(%r4)		# cleanup = sp[0] (== argv[-3])
	lwz	%r8,32(%r1)		# ps_strings

	addi	%r1,%r1,48
	blrl		# _start(argc, argv, envp, obj, cleanup, ps_strings)

	li	%r0,1			# _exit()
	sc

END(_rtld_start)

	.globl	_rtld_bind

/*
 * secure-plt expects %r11 to be the offset to the rela entry.
 * bss-plt expects %r11 to be index of the rela entry.
 * So for bss-plt, we multiply the index by 12 to get the offset.
 */
ENTRY_NOPROFILE(_rtld_bind_secureplt_start)
	stwu	%r1,-160(%r1)
	stw	%r0,20(%r1)

	/*
	 * Instead of division which is costly we will use multiplicative
	 * inverse.  a / n = ((a * inv(n)) >> 32)
	 * where inv(n) = (0x100000000 + n - 1) / n
	 */
	mr	%r0,%r11
	lis	%r11,0x15555556@@h	# load multiplicative inverse of 12
	ori	%r11,%r11,0x15555556@@l
	mulhwu	%r11,%r11,%r0		# get high half of multiplication

	b	1f
ENTRY_NOPROFILE(_rtld_bind_bssplt_start)
	stwu	%r1,-160(%r1)

	stw	%r0,20(%r1)
1:
	mflr	%r0
	stw	%r0,16(%r1)		# save lr
	mfcr	%r0
	stw	%r0,12(%r1)		# save cr
	stmw	%r3,24(%r1)		# save r3-r31

	mr	%r3,%r12		# obj
	mr	%r4,%r11		# reloff
	bl	_rtld_bind		# _rtld_bind(obj, reloff)
	mtctr	%r3

	lmw	%r3,24(%r1)		# load r3-r31
	lwz	%r0,12(%r1)		# restore cr
	mtcr	%r0
	lwz	%r0,16(%r1)		# restore lr
	mtlr	%r0
	lwz	%r0,20(%r1)

	addi	%r1,%r1,160
	bctr
END(_rtld_bind_secureplt_start)

	.globl	_rtld_powerpc_pltcall
	.globl	_rtld_powerpc_pltresolve

_rtld_powerpc_pltcall:
	slwi	%r11,%r11,2
	addis	%r11,%r11,0		# addis	11,11,jmptab@@ha
	lwz	%r11,0(%r11)		# lwz	11,jmptab@@l(11)
	mtctr	%r11
	bctr

_rtld_powerpc_pltresolve:
	lis	%r12,0			# lis	12,_rtld_bind_bssplt_start@@ha
	addi	%r12,%r12,0		# addi	12,12,_rtld_bind_bssplt_start@@l
	mtctr	%r12
	lis	%r12,0			# lis	12,obj@@ha
	addi	%r12,%r12,0		# addi	12,12,obj@@l
	bctr
@


1.16
log
@Don't rely on >32bit math.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.15 2011/02/10 02:28:20 matt Exp $	*/
d127 1
a127 1
END(_rtld_bind_start)
@


1.15
log
@Fix problem with bss-plt objects which a reloc index, not offset.
(secure-plt uses an offset (index*sizeof(rela), bss-plt uses an index)
secure-plt will now take the offset and divide by 12 for an index.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.14 2011/01/16 01:22:29 matt Exp $	*/
d97 2
a98 2
	lis	%r11,0x10000000b/12@@h	# load multiplicative inverse of 12
	ori	%r11,%r11,0x10000000b/12@@l
@


1.14
log
@Add secure-plt support for powerpc to ld.elf_so.  As part of this, we have to
stop calling into the GOT/_DYNAMIC since they are no longer executable.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.13 2002/12/04 01:19:37 thorpej Exp $	*/
d87 15
a102 4
	slwi	%r11,%r11,2
	add	%r0,%r11,%r11
	add	%r11,%r11,%r0
ENTRY_NOPROFILE(_rtld_bind_secureplt_start)
d106 1
@


1.14.2.1
log
@Sync with HEAD
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.15 2011/02/10 02:28:20 matt Exp $	*/
d87 4
a92 15
	stw	%r0,20(%r1)

	/*
	 * Instead of division which is costly we will use multiplicative
	 * inverse.  a / n = ((a * inv(n)) >> 32)
	 * where inv(n) = (0x100000000 + n - 1) / n
	 */
	mr	%r0,%r11
	lis	%r11,0x10000000b/12@@h	# load multiplicative inverse of 12
	ori	%r11,%r11,0x10000000b/12@@l
	mulhwu	%r11,%r11,%r0		# get high half of multiplication

	b	1f
ENTRY_NOPROFILE(_rtld_bind_bssplt_start)
	stwu	%r1,-160(%r1)
a94 1
1:
@


1.14.2.2
log
@Sync with HEAD
@
text
@d1 1
a1 1
/*	$NetBSD$	*/
d97 2
a98 2
	lis	%r11,0x15555556@@h	# load multiplicative inverse of 12
	ori	%r11,%r11,0x15555556@@l
@


1.13
log
@Bintuils-current initializes the GOT entries to 0 (instead of the
base-relative offsets that were placed there previously), so we
must use a different mechanism to compute our reloc base.

Patch from Charles Hannum.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.12 2002/10/31 20:23:25 matt Exp $	*/
d47 9
a55 11
	bl	_GLOBAL_OFFSET_TABLE_-4@@local
	mflr	%r31			# r31 = (real) GOT
	lwz	%r28,0(%r31)		# base-relative &_DYNAMIC

	bl	0f			# lr = next instruction
	b	_DYNAMIC@@local
0:	mflr	%r30
	lwz	%r29,0(%r30)		# load instruction contents
	rlwinm	%r29,%r29,0,6,29	# extract PC offset
	add	%r3,%r29,%r30		# r3 = &_DYNAMIC
	sub	%r28,%r3,%r28
d57 1
a57 1
	bl	_rtld_relocate_nonplt_self@@plt
d62 1
a62 1
	bl	_rtld@@plt		# _start = _rtld(sp, relocbase)
d78 1
a79 1
	.globl	_rtld_bind_start
d82 10
a91 1
_rtld_bind_start:
d103 1
a103 1
	bl	_rtld_bind@@plt		# _rtld_bind(obj, reloff)
d115 1
d128 2
a129 2
	lis	%r12,0			# lis	12,_rtld_bind_start@@ha
	addi	%r12,%r12,0		# addi	12,12,_rtld_bind_start@@l
@


1.12
log
@Convert to register prefixes.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.11 2002/10/05 11:59:06 mycroft Exp $	*/
d47 1
a47 1
	bl	_GLOBAL_OFFSET_TABLE_@@local-4
d49 1
a49 3
	lwz	%r30,_GLOBAL_OFFSET_TABLE_@@got(31)
					# the linker thought GOT were ...
	lwz	%r3,_DYNAMIC@@got(%r31)
d51 8
a58 2
	subf	%r4,%r30,%r31		# r4 = relocbase
	add	%r3,%r3,%r4		# r3 = &_DYNAMIC
a60 1
	subf	4,30,31			# r4 = relocbase
d63 1
@


1.11
log
@Minor cleanup.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.10 2002/09/25 07:27:53 mycroft Exp $	*/
d39 7
a45 7
	stwu	1,-48(1)
	stw	3,12(1)			# argc
	stw	4,16(1)			# argv
	stw	5,20(1)			# envp
/*	stw	6,24(1)			# obj		(always 0) */
/*	stw	7,28(1)			# cleanup	(always 0) */
	stw	8,32(1)			# ps_strings
d48 2
a49 2
	mflr	31			# r31 = (real) GOT
	lwz	30,_GLOBAL_OFFSET_TABLE_@@got(31)
d51 1
a51 1
	lwz	3,_DYNAMIC@@got(31)
d53 2
a54 2
	subf	4,30,31			# r4 = relocbase
	add	3,3,4			# r3 = &_DYNAMIC
d58 2
a59 2
	lwz	3,16(1)
	addi	3,3,-12			# sp = &argv[-3]	/* XXX */
d61 1
a61 1
	mtlr	3
d63 6
a68 6
	lwz	3,12(1)			# argc
	lwz	4,16(1)			# argv
	lwz	5,20(1)			# envp
	lwz	6,-8(4)			# obj = sp[1] (== argv[-2])
	lwz	7,-12(4)		# cleanup = sp[0] (== argv[-3])
	lwz	8,32(1)			# ps_strings
d70 1
a70 1
	addi	1,1,48
d73 1
a73 1
	li	0,1			# _exit()
d81 1
a81 1
	stwu	1,-160(1)
d83 6
a88 6
	stw	0,20(1)
	mflr	0
	stw	0,16(1)			# save lr
	mfcr	0
	stw	0,12(1)			# save cr
	stmw	3,24(1)			# save r3-r31
d90 2
a91 2
	mr	3,12			# obj
	mr	4,11			# reloff
d93 1
a93 1
	mtctr	3
d95 6
a100 6
	lmw	3,24(1)			# load r3-r31
	lwz	0,12(1)			# restore cr
	mtcr	0
	lwz	0,16(1)			# restore lr
	mtlr	0
	lwz	0,20(1)
d102 1
a102 1
	addi	1,1,160
d109 4
a112 4
	slwi	11,11,2
	addis	11,11,0			# addis	11,11,jmptab@@ha
	lwz	11,0(11)		# lwz	11,jmptab@@l(11)
	mtctr	11
d116 5
a120 5
	lis	12,0			# lis	12,_rtld_bind_start@@ha
	addi	12,12,0			# addi	12,12,_rtld_bind_start@@l
	mtctr	12
	lis	12,0			# lis	12,obj@@ha
	addi	12,12,0			# addi	12,12,obj@@l
@


1.10
log
@Push the _rtld_bind() interface into MD code -- it's just a trivial wrapper
anyway.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.9 2002/09/12 17:18:40 mycroft Exp $	*/
d5 1
a5 1
 * Portions copyright 2002 Charles M. Hannum.
@


1.9
log
@Update comments.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.8 2002/09/12 17:07:26 mycroft Exp $	*/
d78 1
a78 1
	.globl	_rtld_bind_powerpc
d92 1
a92 1
	bl	_rtld_bind_powerpc@@plt	# _rtld_bind(obj, reloff)
@


1.8
log
@Pass the calculated relocation offset down to _rtld().
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.7 2002/09/11 21:14:08 mycroft Exp $	*/
d5 1
@


1.7
log
@Implement _rtld_relocate_nonplt_self() here.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.6 2002/09/10 02:52:33 mycroft Exp $	*/
d47 2
a48 2
	mflr	11			# r11 = (real) GOT
	lwz	10,_GLOBAL_OFFSET_TABLE_@@got(11)
d50 3
a52 2
	lwz	3,_DYNAMIC@@got(11)
	subf	4,10,11			# r4 = relocbase
d56 4
a59 4
	lwz	4,16(1)
	addi	3,4,-12			# sp = &argv[-3]	/* XXX */

	bl	_rtld@@plt		# _start = _rtld(sp)
@


1.6
log
@Remove unneeded cruft from _rtld_start.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.5 2002/09/10 02:24:51 mycroft Exp $	*/
d50 4
a53 11
	subf	9,10,11			# r9 = displacement

	lwz	8,_GOT_END_@@got(11)
	add	8,8,9			# add the displacement

1:	lwz	3,0(11)
	add	3,3,9			# add the displacement
	stw	3,0(11)
	addi	11,11,4			# r11++
	cmplw	0,11,8			# done?
	blt	1b
@


1.5
log
@Shorten the startup sequence by a few instructions.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.4 2001/09/26 04:06:43 mycroft Exp $	*/
a47 7
	subi	3,11,4			# r3 = _GLOBAL_OFFSET_TABLE_-4

	dcbst	0,3			# sync i-cache with d-cache
	sync
	icbi	0,3
	isync

d59 1
a59 1
	cmpl	0,11,8			# done?
@


1.4
log
@In the `I can't believe it's been broken all this time' department:
_rtld_bind_start must save and restore the condition codes.  Varargs functions
(like, say, printf()) depend on the state of cr1 to determine whether they need
to store floating point registers in the save area.  Without this, the first
call to any particular varargs function will fail if floating point values were
passed.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.3 1999/05/21 08:00:11 tsubai Exp $	*/
d46 3
a48 6
	bl	1f
	.long	_GLOBAL_OFFSET_TABLE_-.-4
1:
	mflr	3
	lwz	4,0(3)
	add	3,3,4			# r3 = _GLOBAL_OFFSET_TABLE_ - 4
a54 1
	addi	11,3,4			# r11 = (real) GOT
@


1.4.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.13 2002/12/04 01:19:37 thorpej Exp $	*/
a4 1
 * Portions copyright 2002 Charles M. Hannum <root@@ihack.net>
d38 47
a84 34
	stwu	%r1,-48(%r1)
	stw	%r3,12(%r1)		# argc
	stw	%r4,16(%r1)		# argv
	stw	%r5,20(%r1)		# envp
/*	stw	%r6,24(%r1)		# obj		(always 0) */
/*	stw	%r7,28(%r1)		# cleanup	(always 0) */
	stw	%r8,32(%r1)		# ps_strings

	bl	_GLOBAL_OFFSET_TABLE_-4@@local
	mflr	%r31			# r31 = (real) GOT
	lwz	%r28,0(%r31)		# base-relative &_DYNAMIC

	bl	0f			# lr = next instruction
	b	_DYNAMIC@@local
0:	mflr	%r30
	lwz	%r29,0(%r30)		# load instruction contents
	rlwinm	%r29,%r29,0,6,29	# extract PC offset
	add	%r3,%r29,%r30		# r3 = &_DYNAMIC
	sub	%r28,%r3,%r28
	mr	%r4,%r28		# r4 = relocbase
	bl	_rtld_relocate_nonplt_self@@plt

	lwz	%r3,16(%r1)
	addi	%r3,%r3,-12		# sp = &argv[-3]	/* XXX */
	mr	%r4,%r28		# r4 = relocbase
	bl	_rtld@@plt		# _start = _rtld(sp, relocbase)
	mtlr	%r3

	lwz	%r3,12(%r1)		# argc
	lwz	%r4,16(%r1)		# argv
	lwz	%r5,20(%r1)		# envp
	lwz	%r6,-8(%r4)		# obj = sp[1] (== argv[-2])
	lwz	%r7,-12(%r4)		# cleanup = sp[0] (== argv[-3])
	lwz	%r8,32(%r1)		# ps_strings
d86 1
a86 1
	addi	%r1,%r1,48
d89 1
a89 1
	li	%r0,1			# _exit()
d94 1
a94 1
	.globl	_rtld_bind
d97 1
a97 1
	stwu	%r1,-160(%r1)
d99 18
a116 18
	stw	%r0,20(%r1)
	mflr	%r0
	stw	%r0,16(%r1)		# save lr
	mfcr	%r0
	stw	%r0,12(%r1)		# save cr
	stmw	%r3,24(%r1)		# save r3-r31

	mr	%r3,%r12		# obj
	mr	%r4,%r11		# reloff
	bl	_rtld_bind@@plt		# _rtld_bind(obj, reloff)
	mtctr	%r3

	lmw	%r3,24(%r1)		# load r3-r31
	lwz	%r0,12(%r1)		# restore cr
	mtcr	%r0
	lwz	%r0,16(%r1)		# restore lr
	mtlr	%r0
	lwz	%r0,20(%r1)
d118 1
a118 1
	addi	%r1,%r1,160
d125 4
a128 4
	slwi	%r11,%r11,2
	addis	%r11,%r11,0		# addis	11,11,jmptab@@ha
	lwz	%r11,0(%r11)		# lwz	11,jmptab@@l(11)
	mtctr	%r11
d132 5
a136 5
	lis	%r12,0			# lis	12,_rtld_bind_start@@ha
	addi	%r12,%r12,0		# addi	12,12,_rtld_bind_start@@l
	mtctr	%r12
	lis	%r12,0			# lis	12,obj@@ha
	addi	%r12,%r12,0		# addi	12,12,obj@@l
@


1.3
log
@syncicache is needed...
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.2 1999/04/18 19:40:07 ws Exp $	*/
d98 1
d102 2
d111 3
d117 1
a117 1
	lmw	3,24(1)			# load r3-r31
@


1.3.8.1
log
@Pull up revision 1.4 (requested by skrll):
  Add init/fini section support in crtbegin and crtend, and introduce
  support for DWARF2 exception handling.  Fixes PR#12865, PR#13488,
  PR#13489, and PR#13491.  Also fix ld.elf_so to deal appropriately.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.3 1999/05/21 08:00:11 tsubai Exp $	*/
a97 1

a100 2
	mfcr	0
	stw	0,12(1)			# save cr
a107 3
	lmw	3,24(1)			# load r3-r31
	lwz	0,12(1)			# restore cr
	mtcr	0
d111 1
a111 1

@


1.2
log
@Add code to use the kernel provided page size.
Enable this on the powerpc only for now.
@
text
@d1 1
a1 1
/*	$NetBSD: rtld_start.S,v 1.1 1998/11/24 11:34:31 tsubai Exp $	*/
d52 5
@


1.1
log
@Add powerpc support.
@
text
@d1 1
a1 1
/*	$NetBSD:$	*/
a51 5

	dcbst	0,3			# sync i-cache with d-cache
	sync
	icbi	0,3
	isync
@

