xref: /onnv-gate/usr/src/cmd/sgs/rtld/sparc/boot.s (revision 4832:afa9dda73346)
10Sstevel@tonic-gate/*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*4832Srie * Common Development and Distribution License (the "License").
6*4832Srie * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*4832Srie
220Sstevel@tonic-gate/*
230Sstevel@tonic-gate *	Copyright (c) 1988 AT&T
240Sstevel@tonic-gate *	  All Rights Reserved
250Sstevel@tonic-gate *
26*4832Srie * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27*4832Srie * Use is subject to license terms.
280Sstevel@tonic-gate */
290Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate
310Sstevel@tonic-gate/*
320Sstevel@tonic-gate * Bootstrap routine for ld.so.  Control arrives here either directly from
330Sstevel@tonic-gate * exec() upon invocation of a dynamically linked program specifying ld.so
340Sstevel@tonic-gate * as its interpreter, or from the "a.out compatibility ld.so".  Entry
350Sstevel@tonic-gate * vector at "_rt_boot" used to discriminate between the two.
360Sstevel@tonic-gate *
370Sstevel@tonic-gate * On entry, the stack appears as:
380Sstevel@tonic-gate *
390Sstevel@tonic-gate *	!_______________________!  high addresses
400Sstevel@tonic-gate *	!			!
410Sstevel@tonic-gate *	!	Information	!
420Sstevel@tonic-gate *	!	Block		!
430Sstevel@tonic-gate *	!	(size varies)	!
440Sstevel@tonic-gate *	!_______________________!
450Sstevel@tonic-gate *	!	0 word		!
460Sstevel@tonic-gate *	!_______________________!
470Sstevel@tonic-gate *	!	Auxiliary	!
480Sstevel@tonic-gate *	!	vector		!
490Sstevel@tonic-gate *	!	2 word entries	!
500Sstevel@tonic-gate *	!			!
510Sstevel@tonic-gate *	!_______________________!
520Sstevel@tonic-gate *	!	0 word		!
530Sstevel@tonic-gate *	!_______________________!
540Sstevel@tonic-gate *	!	Environment	!
550Sstevel@tonic-gate *	!	pointers	!
560Sstevel@tonic-gate *	!	...		!
570Sstevel@tonic-gate *	!	(one word each)	!
580Sstevel@tonic-gate *	!_______________________!
590Sstevel@tonic-gate *	!	0 word		!
600Sstevel@tonic-gate *	!_______________________!
610Sstevel@tonic-gate *	!	Argument	! low addresses
620Sstevel@tonic-gate *	!	pointers	!
630Sstevel@tonic-gate *	!	Argc words	!
640Sstevel@tonic-gate *	!_______________________!
650Sstevel@tonic-gate *	!			!
660Sstevel@tonic-gate *	!	Argc		!
67*4832Srie *	!_______________________! <- %sp + 64
680Sstevel@tonic-gate *	!			!
690Sstevel@tonic-gate *	!   Window save area	!
700Sstevel@tonic-gate *	!_______________________! <- %sp
710Sstevel@tonic-gate *
720Sstevel@tonic-gate * In the case of being invoked from the a.out compatibility ld.so, the stack
730Sstevel@tonic-gate * has the appearance above but also several frames pushed by the compatibility
740Sstevel@tonic-gate * routine.  An "elf_boot" structure is available in %o1 on entry, which
750Sstevel@tonic-gate * has been "pre-evaluated" to hold much of the information needed from the
760Sstevel@tonic-gate * original stack frame -- we pass this directly into the main portion of the
770Sstevel@tonic-gate * ld.so bootstrap.
780Sstevel@tonic-gate */
790Sstevel@tonic-gate
800Sstevel@tonic-gate#if	defined(lint)
810Sstevel@tonic-gate
820Sstevel@tonic-gateextern	unsigned long	_setup();
830Sstevel@tonic-gateextern	void		atexit_fini();
840Sstevel@tonic-gate
850Sstevel@tonic-gatevoid
860Sstevel@tonic-gatemain()
870Sstevel@tonic-gate{
880Sstevel@tonic-gate	(void) _setup();
890Sstevel@tonic-gate	atexit_fini();
900Sstevel@tonic-gate}
910Sstevel@tonic-gate
920Sstevel@tonic-gate#else
930Sstevel@tonic-gate
940Sstevel@tonic-gate#include <sys/asm_linkage.h>
950Sstevel@tonic-gate#include <sys/param.h>
960Sstevel@tonic-gate#include <link.h>
970Sstevel@tonic-gate
980Sstevel@tonic-gate	.file	"boot.s"
990Sstevel@tonic-gate	.seg	".text"
1000Sstevel@tonic-gate	.global	_rt_boot, _setup, atexit_fini
1010Sstevel@tonic-gate	.type	_rt_boot, #function
1020Sstevel@tonic-gate	.align	4
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate! Entry vector
1050Sstevel@tonic-gate!	+0: normal start
1060Sstevel@tonic-gate!	+4: compatibility start
1070Sstevel@tonic-gate!	+8: alias start (frame exists)
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate_rt_boot:
1100Sstevel@tonic-gate	ba,a	_elf_start
1110Sstevel@tonic-gate	ba,a	_aout_start
1120Sstevel@tonic-gate	ba,a	_alias_start
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate! Start up routines -- the aout_start will have a pointer in %o0 that we'll
1150Sstevel@tonic-gate! want to save -- the elf can be zeroed.
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate_elf_start:
1180Sstevel@tonic-gate	clr	%o0			! 0 in %o0 == ELF
1190Sstevel@tonic-gate_aout_start:				! (falls through)
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate! Create a stack frame, perform PIC set up.  If we're a "normal" start, we have
1220Sstevel@tonic-gate! to determine a bunch of things from our "environment" and construct an ELF
1230Sstevel@tonic-gate! boot attribute value vector.  Otherwise, it's already been done and we can
1240Sstevel@tonic-gate! skip it.
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate	save	%sp, -SA(MINFRAME + (EB_MAX * 8)), %sp
1270Sstevel@tonic-gate_alias_start:
1280Sstevel@tonic-gate1:					! PIC prologue
1290Sstevel@tonic-gate	call	2f
1300Sstevel@tonic-gate	sethi	%hi(_GLOBAL_OFFSET_TABLE_ + (. - 1b)), %l7
1310Sstevel@tonic-gate2:
1320Sstevel@tonic-gate	or	%l7, %lo(_GLOBAL_OFFSET_TABLE_ + (. - 1b)), %l7
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate! If %i0 (was %o0) is non-zero, we're in compatibility and we can
1350Sstevel@tonic-gate! skip construction of the ELF boot attribute vector.
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate	addcc	%i0, %g0, %o0		! set condition codes
1380Sstevel@tonic-gate	bne	1f			! if non-zero, skip setup
1390Sstevel@tonic-gate	add	%l7, %o7, %l7		! finish PIC prologue
1400Sstevel@tonic-gate
1410Sstevel@tonic-gate! %fp points to the root of our ELF bootstrap vector, use it to construct
1420Sstevel@tonic-gate! the vector and send it to _setup.
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate	add	%sp, SA(MINFRAME), %o0	! &eb[0] == %sp + frame size
1450Sstevel@tonic-gate	set	EB_ARGV, %l0		! code for this entry
1460Sstevel@tonic-gate	st	%l0, [%o0]		!   store it
1470Sstevel@tonic-gate	add	%fp, 68, %l0		! argument vector is at %fp+68
1480Sstevel@tonic-gate	st	%l0, [%o0 + 4]		!   store that
1490Sstevel@tonic-gate	ld	[%fp + 64], %l1		! get argument count
1500Sstevel@tonic-gate	inc	%l1			! account for last element of 0
1510Sstevel@tonic-gate	sll	%l1, 2, %l1		! multiply by 4
1520Sstevel@tonic-gate	add	%l0, %l1, %l0		!   and get address of first env ptr
1530Sstevel@tonic-gate	st	%l0, [%o0 + 12]		! store it in the vector
1540Sstevel@tonic-gate	set	EB_ENVP, %l1		! code for environment base
1550Sstevel@tonic-gate	st	%l1, [%o0 + 8]		!   store it
1560Sstevel@tonic-gate	set	EB_AUXV, %l1		! get code for auxiliary vector
1570Sstevel@tonic-gate	st	%l1, [%o0 + 16]		!   store it
1580Sstevel@tonic-gate2:
1590Sstevel@tonic-gate	ld	[%l0], %l1		! get an entry
1600Sstevel@tonic-gate	tst	%l1			! are we at a "0" entry in environment?
1610Sstevel@tonic-gate	bne	2b			!   no, go back and look again
1620Sstevel@tonic-gate	add	%l0, 4, %l0		!	incrementing pointer in delay
1630Sstevel@tonic-gate	st	%l0, [%o0 + 20]		! store aux vector pointer
1640Sstevel@tonic-gate	set	EB_NULL, %l0		! set up for the last pointer
1650Sstevel@tonic-gate	st	%l0, [%o0 + 24]		!   and store it
1660Sstevel@tonic-gate
1670Sstevel@tonic-gate! Call _setup.  Two arguments, the ELF bootstrap vector and our (unrelocated)
1680Sstevel@tonic-gate! _DYNAMIC address.  The _DYNAMIC address is located in entry 0 of the GOT
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate1:
1710Sstevel@tonic-gate	mov	%g0, %g2		! clear globals
1720Sstevel@tonic-gate	mov	%g0, %g3
1730Sstevel@tonic-gate	call	_setup			! call it
1740Sstevel@tonic-gate	ld	[%l7], %o1		! 2nd parameter
1750Sstevel@tonic-gate
1760Sstevel@tonic-gate! On return, give callee the exit function in %g1, and either jump to the
1770Sstevel@tonic-gate! target program (normal), or if return value of _setup is "0" we have
1780Sstevel@tonic-gate! to return to the compatibility bootstrap.  In either case, clear out
1790Sstevel@tonic-gate! reserved globals.
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate	ld	[%l7 + atexit_fini], %g1! get function address
1820Sstevel@tonic-gate	restore	%o0, %g0, %l1		! release frame
1830Sstevel@tonic-gate	tst	%l1			! compatibility return?
1840Sstevel@tonic-gate	be	1f			! yes,
1850Sstevel@tonic-gate	mov	%g0, %g4		!   but clear one last global in delay
1860Sstevel@tonic-gate	jmpl	%l1, %g0		! call main program
1870Sstevel@tonic-gate	nop
1880Sstevel@tonic-gate1:
1890Sstevel@tonic-gate	retl				! compatibility return
1900Sstevel@tonic-gate	nop
1910Sstevel@tonic-gate
1920Sstevel@tonic-gate	.size	_rt_boot, . - _rt_boot
1930Sstevel@tonic-gate#endif
194