xref: /minix3/libexec/ld.elf_so/arch/m68k/rtld_start.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc/*	$NetBSD: rtld_start.S,v 1.11 2014/03/18 18:20:38 riastradh Exp $	*/
2e83f7ba2SBen Gras
3e83f7ba2SBen Gras/*-
4e83f7ba2SBen Gras * Copyright (c) 1999, 2002, 2003 The NetBSD Foundation, Inc.
5e83f7ba2SBen Gras * All rights reserved.
6e83f7ba2SBen Gras *
7e83f7ba2SBen Gras * This code is derived from software contributed to The NetBSD Foundation
8e83f7ba2SBen Gras * by Klaus Klein and by Charles M. Hannum.
9e83f7ba2SBen Gras *
10e83f7ba2SBen Gras * Redistribution and use in source and binary forms, with or without
11e83f7ba2SBen Gras * modification, are permitted provided that the following conditions
12e83f7ba2SBen Gras * are met:
13e83f7ba2SBen Gras * 1. Redistributions of source code must retain the above copyright
14e83f7ba2SBen Gras *    notice, this list of conditions and the following disclaimer.
15e83f7ba2SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
16e83f7ba2SBen Gras *    notice, this list of conditions and the following disclaimer in the
17e83f7ba2SBen Gras *    documentation and/or other materials provided with the distribution.
18e83f7ba2SBen Gras *
19e83f7ba2SBen Gras * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20e83f7ba2SBen Gras * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21e83f7ba2SBen Gras * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22e83f7ba2SBen Gras * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23e83f7ba2SBen Gras * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24e83f7ba2SBen Gras * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25e83f7ba2SBen Gras * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26e83f7ba2SBen Gras * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27e83f7ba2SBen Gras * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28e83f7ba2SBen Gras * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29e83f7ba2SBen Gras * POSSIBILITY OF SUCH DAMAGE.
30e83f7ba2SBen Gras */
31e83f7ba2SBen Gras
32e83f7ba2SBen Gras#include <machine/asm.h>
33e83f7ba2SBen Gras
34e83f7ba2SBen Gras	.text
35e83f7ba2SBen Gras	.align	4
36e83f7ba2SBen Gras	.globl	.rtld_start
37e83f7ba2SBen Gras	.type	.rtld_start,@function
38e83f7ba2SBen Gras.rtld_start:
39e83f7ba2SBen Gras	subql	#8,%sp			| storage for obj and cleanup
40e83f7ba2SBen Gras
4184d9c625SLionel Sambuc	GOT_SETUP(%a0)
4284d9c625SLionel Sambuc	LEA_LCL(_DYNAMIC,%a1)
4384d9c625SLionel Sambuc
44e83f7ba2SBen Gras	movel	%a1,%a5
45e83f7ba2SBen Gras	subl	(%a0),%a5
46e83f7ba2SBen Gras
47e83f7ba2SBen Gras	movel	%a5,-(%sp)		| relocbase
48e83f7ba2SBen Gras	movel	%a1,-(%sp)		| &_DYNAMIC
49e83f7ba2SBen Gras	jbsr	_rtld_relocate_nonplt_self@PLTPC
50e83f7ba2SBen Gras	addql	#8,%sp			| pop arguments
51e83f7ba2SBen Gras
52e83f7ba2SBen Gras	movel	%a5,-(%sp)		| relocbase
53e83f7ba2SBen Gras	pea	4(%sp)			| sp
54e83f7ba2SBen Gras	jbsr	_rtld@PLTPC		| entry = _rtld(sp, relocbase)
55e83f7ba2SBen Gras	addql	#8,%sp			| pop arguments
56e83f7ba2SBen Gras
57e83f7ba2SBen Gras	moveal	(%sp)+,%a1		| cleanup
58e83f7ba2SBen Gras	moveal	(%sp)+,%a0		| obj
59e83f7ba2SBen Gras	moveal	%d0,%a3
60e83f7ba2SBen Gras	jmp	(%a3)			| Go for it!
61e83f7ba2SBen Gras	.size	.rtld_start,.-.rtld_start
62e83f7ba2SBen Gras
63e83f7ba2SBen Gras	.align	4
64e83f7ba2SBen Gras	.globl	_rtld_bind_start
65e83f7ba2SBen Gras	.type	_rtld_bind_start,@function
66e83f7ba2SBen Gras_rtld_bind_start:
6784d9c625SLionel Sambuc	INTERRUPT_SAVEREG
68e83f7ba2SBen Gras	movel	20(%sp),-(%sp)		| push reloff
69e83f7ba2SBen Gras	movel	(16+4)(%sp),-(%sp)	| push obj
70e83f7ba2SBen Gras	jbsr	_rtld_bind@PLTPC	| %a0 = _rtld_bind(obj, reloff)
71e83f7ba2SBen Gras	addql	#8,%sp			| pop args
72e83f7ba2SBen Gras#ifdef __SVR4_ABI__
73e83f7ba2SBen Gras	movel	%a0,(16+4)(%sp)		| write fake `return' address over obj
74e83f7ba2SBen Gras#else
75e83f7ba2SBen Gras	movel	%d0,(16+4)(%sp)		| write fake `return' address over obj
76e83f7ba2SBen Gras#endif
7784d9c625SLionel Sambuc	INTERRUPT_RESTOREREG		| restore caller-saved registers
78e83f7ba2SBen Gras	addql	#4,%sp			| skip reloff
79e83f7ba2SBen Gras	rts				| `return' right into function
80e83f7ba2SBen Gras	.size	_rtld_bind_start,.-_rtld_bind_start
81