xref: /minix3/libexec/ld.elf_so/arch/i386/rtld_start.S (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*e83f7ba2SBen Gras/*	$NetBSD: rtld_start.S,v 1.11 2010/12/05 00:56:07 joerg Exp $	*/
2*e83f7ba2SBen Gras
3*e83f7ba2SBen Gras/*-
4*e83f7ba2SBen Gras * Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
5*e83f7ba2SBen Gras * All rights reserved.
6*e83f7ba2SBen Gras *
7*e83f7ba2SBen Gras * This code is derived from software contributed to The NetBSD Foundation
8*e83f7ba2SBen Gras * by Christos Zoulas and by Charles M. Hannum.
9*e83f7ba2SBen Gras *
10*e83f7ba2SBen Gras * Redistribution and use in source and binary forms, with or without
11*e83f7ba2SBen Gras * modification, are permitted provided that the following conditions
12*e83f7ba2SBen Gras * are met:
13*e83f7ba2SBen Gras * 1. Redistributions of source code must retain the above copyright
14*e83f7ba2SBen Gras *    notice, this list of conditions and the following disclaimer.
15*e83f7ba2SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
16*e83f7ba2SBen Gras *    notice, this list of conditions and the following disclaimer in the
17*e83f7ba2SBen Gras *    documentation and/or other materials provided with the distribution.
18*e83f7ba2SBen Gras *
19*e83f7ba2SBen Gras * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*e83f7ba2SBen Gras * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*e83f7ba2SBen Gras * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*e83f7ba2SBen Gras * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*e83f7ba2SBen Gras * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*e83f7ba2SBen Gras * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*e83f7ba2SBen Gras * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*e83f7ba2SBen Gras * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*e83f7ba2SBen Gras * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*e83f7ba2SBen Gras * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*e83f7ba2SBen Gras * POSSIBILITY OF SUCH DAMAGE.
30*e83f7ba2SBen Gras */
31*e83f7ba2SBen Gras
32*e83f7ba2SBen Gras#include <machine/asm.h>
33*e83f7ba2SBen Gras
34*e83f7ba2SBen Gras	.text
35*e83f7ba2SBen Gras	.align	4
36*e83f7ba2SBen Gras	.globl	.rtld_start
37*e83f7ba2SBen Gras	.hidden	.rtld_start
38*e83f7ba2SBen Gras	.type	.rtld_start,@function
39*e83f7ba2SBen Gras.rtld_start:
40*e83f7ba2SBen Gras	subl	$8,%esp			# make room of obj_main and exit proc
41*e83f7ba2SBen Gras	pushl	%ebx			# save ps_strings
42*e83f7ba2SBen Gras
43*e83f7ba2SBen Gras	call	1f
44*e83f7ba2SBen Gras1:
45*e83f7ba2SBen Gras	popl	%edx
46*e83f7ba2SBen Gras	leal	_DYNAMIC-1b(%edx),%ecx	# &_DYNAMIC
47*e83f7ba2SBen Gras	movl	%ecx,%ebx
48*e83f7ba2SBen Gras	subl	_GLOBAL_OFFSET_TABLE_-1b(%edx),%ebx
49*e83f7ba2SBen Gras
50*e83f7ba2SBen Gras	pushl	%ebx			# relocbase
51*e83f7ba2SBen Gras	pushl	%ecx			# &_DYNAMIC
52*e83f7ba2SBen Gras	call	_rtld_relocate_nonplt_self
53*e83f7ba2SBen Gras
54*e83f7ba2SBen Gras	leal	12(%esp),%eax		# &cleanup
55*e83f7ba2SBen Gras	pushl	%ebx			# relocbase
56*e83f7ba2SBen Gras	pushl	%eax			# sp
57*e83f7ba2SBen Gras	call	_rtld			# _rtld(sp, relocbase)
58*e83f7ba2SBen Gras
59*e83f7ba2SBen Gras	addl	$16,%esp		# pop args
60*e83f7ba2SBen Gras
61*e83f7ba2SBen Gras	popl	%ebx			# %ebx = ps_strings
62*e83f7ba2SBen Gras	popl	%edx			# %edx = cleanup
63*e83f7ba2SBen Gras	popl	%ecx			# %ecx = obj_main
64*e83f7ba2SBen Gras	jmp	*%eax
65*e83f7ba2SBen Gras
66*e83f7ba2SBen Gras	.align	4
67*e83f7ba2SBen Gras	.globl	_rtld_bind_start
68*e83f7ba2SBen Gras	.hidden	_rtld_bind_start
69*e83f7ba2SBen Gras	.type	_rtld_bind_start,@function
70*e83f7ba2SBen Gras_rtld_bind_start:	# (obj, reloff)
71*e83f7ba2SBen Gras	pushf				# save registers
72*e83f7ba2SBen Gras	pushl	%eax
73*e83f7ba2SBen Gras	pushl	%ecx
74*e83f7ba2SBen Gras	pushl	%edx
75*e83f7ba2SBen Gras
76*e83f7ba2SBen Gras	pushl	20(%esp)		# Copy of reloff
77*e83f7ba2SBen Gras	pushl	20(%esp)		# Copy of obj
78*e83f7ba2SBen Gras	call	_rtld_bind		# Call the binder
79*e83f7ba2SBen Gras	addl	$8,%esp			# pop binder args
80*e83f7ba2SBen Gras	movl	%eax,20(%esp)		# Store function to be called in obj
81*e83f7ba2SBen Gras
82*e83f7ba2SBen Gras	popl	%edx
83*e83f7ba2SBen Gras	popl	%ecx
84*e83f7ba2SBen Gras	popl	%eax
85*e83f7ba2SBen Gras	popf
86*e83f7ba2SBen Gras
87*e83f7ba2SBen Gras	leal	4(%esp),%esp		# Discard reloff, do not change eflags
88*e83f7ba2SBen Gras	ret
89