rtld_start.S revision 1.11
11.11Sriastrad/*	$NetBSD: rtld_start.S,v 1.11 2014/03/18 18:20:38 riastradh Exp $	*/
21.1Skleink
31.1Skleink/*-
41.8Smycroft * Copyright (c) 1999, 2002, 2003 The NetBSD Foundation, Inc.
51.1Skleink * All rights reserved.
61.1Skleink *
71.1Skleink * This code is derived from software contributed to The NetBSD Foundation
81.6Smycroft * by Klaus Klein and by Charles M. Hannum.
91.1Skleink *
101.1Skleink * Redistribution and use in source and binary forms, with or without
111.1Skleink * modification, are permitted provided that the following conditions
121.1Skleink * are met:
131.1Skleink * 1. Redistributions of source code must retain the above copyright
141.1Skleink *    notice, this list of conditions and the following disclaimer.
151.1Skleink * 2. Redistributions in binary form must reproduce the above copyright
161.1Skleink *    notice, this list of conditions and the following disclaimer in the
171.1Skleink *    documentation and/or other materials provided with the distribution.
181.1Skleink *
191.1Skleink * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Skleink * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Skleink * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Skleink * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Skleink * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Skleink * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Skleink * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Skleink * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Skleink * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Skleink * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Skleink * POSSIBILITY OF SUCH DAMAGE.
301.1Skleink */
311.1Skleink
321.1Skleink#include <machine/asm.h>
331.1Skleink
341.1Skleink	.text
351.2Skleink	.align	4
361.1Skleink	.globl	.rtld_start
371.1Skleink	.type	.rtld_start,@function
381.1Skleink.rtld_start:
391.1Skleink	subql	#8,%sp			| storage for obj and cleanup
401.4Smycroft
411.10Smatt	GOT_SETUP(%a0)
421.10Smatt	LEA_LCL(_DYNAMIC,%a1)
431.10Smatt
441.7Smycroft	movel	%a1,%a5
451.7Smycroft	subl	(%a0),%a5
461.5Smycroft
471.5Smycroft	movel	%a5,-(%sp)		| relocbase
481.7Smycroft	movel	%a1,-(%sp)		| &_DYNAMIC
491.4Smycroft	jbsr	_rtld_relocate_nonplt_self@PLTPC
501.4Smycroft	addql	#8,%sp			| pop arguments
511.4Smycroft
521.5Smycroft	movel	%a5,-(%sp)		| relocbase
531.5Smycroft	pea	4(%sp)			| sp
541.5Smycroft	jbsr	_rtld@PLTPC		| entry = _rtld(sp, relocbase)
551.5Smycroft	addql	#8,%sp			| pop arguments
561.4Smycroft
571.1Skleink	moveal	(%sp)+,%a1		| cleanup
581.1Skleink	moveal	(%sp)+,%a0		| obj
591.1Skleink	moveal	%d0,%a3
601.1Skleink	jmp	(%a3)			| Go for it!
611.1Skleink	.size	.rtld_start,.-.rtld_start
621.1Skleink
631.2Skleink	.align	4
641.1Skleink	.globl	_rtld_bind_start
651.1Skleink	.type	_rtld_bind_start,@function
661.1Skleink_rtld_bind_start:
671.10Smatt	INTERRUPT_SAVEREG
681.1Skleink	movel	20(%sp),-(%sp)		| push reloff
691.1Skleink	movel	(16+4)(%sp),-(%sp)	| push obj
701.1Skleink	jbsr	_rtld_bind@PLTPC	| %a0 = _rtld_bind(obj, reloff)
711.1Skleink	addql	#8,%sp			| pop args
721.3Sitohy#ifdef __SVR4_ABI__
731.1Skleink	movel	%a0,(16+4)(%sp)		| write fake `return' address over obj
741.3Sitohy#else
751.3Sitohy	movel	%d0,(16+4)(%sp)		| write fake `return' address over obj
761.3Sitohy#endif
771.10Smatt	INTERRUPT_RESTOREREG		| restore caller-saved registers
781.1Skleink	addql	#4,%sp			| skip reloff
791.1Skleink	rts				| `return' right into function
801.1Skleink	.size	_rtld_bind_start,.-_rtld_bind_start
81