xref: /titanic_44/usr/src/cmd/sgs/rtld/i386/boot.s (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate/*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate/*
23*7c478bd9Sstevel@tonic-gate *	Copyright (c) 1988 AT&T
24*7c478bd9Sstevel@tonic-gate *	  All Rights Reserved
25*7c478bd9Sstevel@tonic-gate *
26*7c478bd9Sstevel@tonic-gate *
27*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
29*7c478bd9Sstevel@tonic-gate */
30*7c478bd9Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate/*
33*7c478bd9Sstevel@tonic-gate * Bootstrap routine for run-time linker.
34*7c478bd9Sstevel@tonic-gate * We get control from exec which has loaded our text and
35*7c478bd9Sstevel@tonic-gate * data into the process' address space and created the process
36*7c478bd9Sstevel@tonic-gate * stack.
37*7c478bd9Sstevel@tonic-gate *
38*7c478bd9Sstevel@tonic-gate * On entry, the process stack looks like this:
39*7c478bd9Sstevel@tonic-gate *
40*7c478bd9Sstevel@tonic-gate *	#			# <- %esp
41*7c478bd9Sstevel@tonic-gate *	#_______________________#  high addresses
42*7c478bd9Sstevel@tonic-gate *	#	strings		#
43*7c478bd9Sstevel@tonic-gate *	#_______________________#
44*7c478bd9Sstevel@tonic-gate *	#	0 word		#
45*7c478bd9Sstevel@tonic-gate *	#_______________________#
46*7c478bd9Sstevel@tonic-gate *	#	Auxiliary	#
47*7c478bd9Sstevel@tonic-gate *	#	entries		#
48*7c478bd9Sstevel@tonic-gate *	#	...		#
49*7c478bd9Sstevel@tonic-gate *	#	(size varies)	#
50*7c478bd9Sstevel@tonic-gate *	#_______________________#
51*7c478bd9Sstevel@tonic-gate *	#	0 word		#
52*7c478bd9Sstevel@tonic-gate *	#_______________________#
53*7c478bd9Sstevel@tonic-gate *	#	Environment	#
54*7c478bd9Sstevel@tonic-gate *	#	pointers	#
55*7c478bd9Sstevel@tonic-gate *	#	...		#
56*7c478bd9Sstevel@tonic-gate *	#	(one word each)	#
57*7c478bd9Sstevel@tonic-gate *	#_______________________#
58*7c478bd9Sstevel@tonic-gate *	#	0 word		#
59*7c478bd9Sstevel@tonic-gate *	#_______________________#
60*7c478bd9Sstevel@tonic-gate *	#	Argument	# low addresses
61*7c478bd9Sstevel@tonic-gate *	#	pointers	#
62*7c478bd9Sstevel@tonic-gate *	#	Argc words	#
63*7c478bd9Sstevel@tonic-gate *	#_______________________#
64*7c478bd9Sstevel@tonic-gate *	#	argc		#
65*7c478bd9Sstevel@tonic-gate *	#_______________________# <- %ebp
66*7c478bd9Sstevel@tonic-gate *
67*7c478bd9Sstevel@tonic-gate *
68*7c478bd9Sstevel@tonic-gate * We must calculate the address at which ld.so was loaded,
69*7c478bd9Sstevel@tonic-gate * find the addr of the dynamic section of ld.so, of argv[0], and  of
70*7c478bd9Sstevel@tonic-gate * the process' environment pointers - and pass the thing to _setup
71*7c478bd9Sstevel@tonic-gate * to handle.  We then call _rtld - on return we jump to the entry
72*7c478bd9Sstevel@tonic-gate * point for the a.out.
73*7c478bd9Sstevel@tonic-gate */
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate#if	defined(lint)
76*7c478bd9Sstevel@tonic-gate
77*7c478bd9Sstevel@tonic-gateextern	unsigned long	_setup();
78*7c478bd9Sstevel@tonic-gateextern	void		atexit_fini();
79*7c478bd9Sstevel@tonic-gatevoid
80*7c478bd9Sstevel@tonic-gatemain()
81*7c478bd9Sstevel@tonic-gate{
82*7c478bd9Sstevel@tonic-gate	(void) _setup();
83*7c478bd9Sstevel@tonic-gate	atexit_fini();
84*7c478bd9Sstevel@tonic-gate}
85*7c478bd9Sstevel@tonic-gate
86*7c478bd9Sstevel@tonic-gate#else
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate#include	<link.h>
89*7c478bd9Sstevel@tonic-gate
90*7c478bd9Sstevel@tonic-gate	.file	"boot.s"
91*7c478bd9Sstevel@tonic-gate	.text
92*7c478bd9Sstevel@tonic-gate	.globl	_rt_boot
93*7c478bd9Sstevel@tonic-gate	.globl	_setup
94*7c478bd9Sstevel@tonic-gate	.globl	_GLOBAL_OFFSET_TABLE_
95*7c478bd9Sstevel@tonic-gate	.type	_rt_boot,@function
96*7c478bd9Sstevel@tonic-gate	.align	4
97*7c478bd9Sstevel@tonic-gate
98*7c478bd9Sstevel@tonic-gate_rt_alias:
99*7c478bd9Sstevel@tonic-gate	jmp	.get_ip			/ in case we were invoked from libc.so
100*7c478bd9Sstevel@tonic-gate_rt_boot:
101*7c478bd9Sstevel@tonic-gate	movl	%esp,%ebp		/ save for referencing args
102*7c478bd9Sstevel@tonic-gate	subl	$EB_MAX_SIZE32,%esp	/ make room for a max sized boot vector
103*7c478bd9Sstevel@tonic-gate	movl	%esp,%esi		/ use esi as a pointer to &eb[0]
104*7c478bd9Sstevel@tonic-gate	movl	$EB_ARGV,0(%esi)	/ set up tag for argv
105*7c478bd9Sstevel@tonic-gate	leal	4(%ebp),%eax		/ get address of argv
106*7c478bd9Sstevel@tonic-gate	movl	%eax,4(%esi)		/ put after tag
107*7c478bd9Sstevel@tonic-gate	movl	$EB_ENVP,8(%esi)	/ set up tag for envp
108*7c478bd9Sstevel@tonic-gate	movl	(%ebp),%eax		/ get # of args
109*7c478bd9Sstevel@tonic-gate	addl	$2,%eax			/ one for the zero & one for argc
110*7c478bd9Sstevel@tonic-gate	leal	(%ebp,%eax,4),%edi	/ now points past args & @ envp
111*7c478bd9Sstevel@tonic-gate	movl	%edi,12(%esi)		/ set envp
112*7c478bd9Sstevel@tonic-gate.L0:	addl	$4,%edi			/ next
113*7c478bd9Sstevel@tonic-gate	cmpl	$0,-4(%edi)		/ search for 0 at end of env
114*7c478bd9Sstevel@tonic-gate	jne	.L0
115*7c478bd9Sstevel@tonic-gate	movl	$EB_AUXV,16(%esi)	/ set up tag for auxv
116*7c478bd9Sstevel@tonic-gate	movl	%edi,20(%esi)		/ point to auxv
117*7c478bd9Sstevel@tonic-gate	movl	$EB_NULL,24(%esi)	/ set up NULL tag
118*7c478bd9Sstevel@tonic-gate.get_ip:
119*7c478bd9Sstevel@tonic-gate	call	.L1			/ only way to get IP into a register
120*7c478bd9Sstevel@tonic-gate.L1:
121*7c478bd9Sstevel@tonic-gate	popl	%ebx			/ pop the IP we just "pushed"
122*7c478bd9Sstevel@tonic-gate	addl	$_GLOBAL_OFFSET_TABLE_+[.-.L1],%ebx
123*7c478bd9Sstevel@tonic-gate	pushl	(%ebx)			/ address of dynamic structure
124*7c478bd9Sstevel@tonic-gate	pushl	%esi			/ push &eb[0]
125*7c478bd9Sstevel@tonic-gate
126*7c478bd9Sstevel@tonic-gate	call	_setup@PLT		/ _setup(&eb[0], _DYNAMIC)
127*7c478bd9Sstevel@tonic-gate	movl	%ebp,%esp		/ release stack frame
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate	movl	atexit_fini@GOT(%ebx), %edx
130*7c478bd9Sstevel@tonic-gate	jmp	*%eax 			/ transfer control to a.out
131*7c478bd9Sstevel@tonic-gate	.size	_rt_boot,.-_rt_boot
132*7c478bd9Sstevel@tonic-gate
133*7c478bd9Sstevel@tonic-gate#endif
134