xref: /titanic_50/usr/src/lib/libc/i386/crt/_rtboot.s (revision 8fd04b8338ed5093ec2d1e668fa620b7de44c177)
17c478bd9Sstevel@tonic-gate/*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
59a70fc3bSMark J. Nelson * Common Development and Distribution License (the "License").
69a70fc3bSMark J. Nelson * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
21*8fd04b83SRoger A. Faulkner
227c478bd9Sstevel@tonic-gate/*
23*8fd04b83SRoger A. Faulkner * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
279a70fc3bSMark J. Nelson	.file	"_rtboot.s"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate/ bootstrap routine for run-time linker
307c478bd9Sstevel@tonic-gate/ we get control from exec which has loaded our text and
317c478bd9Sstevel@tonic-gate/ data into the process' address space and created the process
327c478bd9Sstevel@tonic-gate/ stack
337c478bd9Sstevel@tonic-gate/
347c478bd9Sstevel@tonic-gate/ on entry, the process stack looks like this:
357c478bd9Sstevel@tonic-gate/
367c478bd9Sstevel@tonic-gate/			# <- %esp
377c478bd9Sstevel@tonic-gate/_______________________#  high addresses
387c478bd9Sstevel@tonic-gate/	strings		#
397c478bd9Sstevel@tonic-gate/_______________________#
407c478bd9Sstevel@tonic-gate/	0 word		#
417c478bd9Sstevel@tonic-gate/_______________________#
427c478bd9Sstevel@tonic-gate/	Auxiliary	#
437c478bd9Sstevel@tonic-gate/	entries		#
447c478bd9Sstevel@tonic-gate/	...		#
457c478bd9Sstevel@tonic-gate/	(size varies)	#
467c478bd9Sstevel@tonic-gate/_______________________#
477c478bd9Sstevel@tonic-gate/	0 word		#
487c478bd9Sstevel@tonic-gate/_______________________#
497c478bd9Sstevel@tonic-gate/	Environment	#
507c478bd9Sstevel@tonic-gate/	pointers	#
517c478bd9Sstevel@tonic-gate/	...		#
527c478bd9Sstevel@tonic-gate/	(one word each)	#
537c478bd9Sstevel@tonic-gate/_______________________#
547c478bd9Sstevel@tonic-gate/	0 word		#
557c478bd9Sstevel@tonic-gate/_______________________#
567c478bd9Sstevel@tonic-gate/	Argument	# low addresses
577c478bd9Sstevel@tonic-gate/	pointers	#
587c478bd9Sstevel@tonic-gate/	Argc words	#
597c478bd9Sstevel@tonic-gate/_______________________#
607c478bd9Sstevel@tonic-gate/	argc		#
617c478bd9Sstevel@tonic-gate/_______________________# <- %ebp
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate#include <SYS.h>
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate	.set	EB_NULL,0
667c478bd9Sstevel@tonic-gate	.set	EB_DYNAMIC,1
677c478bd9Sstevel@tonic-gate	.set	EB_LDSO_BASE,2
687c478bd9Sstevel@tonic-gate	.set	EB_ARGV,3
697c478bd9Sstevel@tonic-gate	.set	EB_ENVP,4
707c478bd9Sstevel@tonic-gate	.set	EB_AUXV,5
717c478bd9Sstevel@tonic-gate	.set	EB_DEVZERO,6
727c478bd9Sstevel@tonic-gate	.set	EB_PAGESIZE,7
737c478bd9Sstevel@tonic-gate	.set	EB_MAX,8
747c478bd9Sstevel@tonic-gate	.set	EB_MAX_SIZE32,64
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate	.text
777c478bd9Sstevel@tonic-gate	.globl	__rtboot
787c478bd9Sstevel@tonic-gate	.globl	__rtld
797c478bd9Sstevel@tonic-gate	.type	__rtboot,@function
807c478bd9Sstevel@tonic-gate	.align	4
817c478bd9Sstevel@tonic-gate__rtboot:
827c478bd9Sstevel@tonic-gate	movl	%esp,%ebp
837c478bd9Sstevel@tonic-gate	subl	$EB_MAX_SIZE32,%esp	/ make room for a max sized boot vector
847c478bd9Sstevel@tonic-gate	movl	%esp,%esi		/ use esi as a pointer to &eb[0]
857c478bd9Sstevel@tonic-gate	movl	$EB_ARGV,0(%esi)	/ set up tag for argv
867c478bd9Sstevel@tonic-gate	leal	4(%ebp),%eax		/ get address of argv
877c478bd9Sstevel@tonic-gate	movl	%eax,4(%esi)		/ put after tag
887c478bd9Sstevel@tonic-gate	movl	$EB_ENVP,8(%esi)	/ set up tag for envp
897c478bd9Sstevel@tonic-gate	movl	(%ebp),%eax		/ get # of args
907c478bd9Sstevel@tonic-gate	addl	$2,%eax			/ one for the zero & one for argc
917c478bd9Sstevel@tonic-gate	leal	(%ebp,%eax,4),%edi	/ now points past args & @ envp
927c478bd9Sstevel@tonic-gate	movl	%edi,12(%esi)		/ set envp
937c478bd9Sstevel@tonic-gate	addl	$-4,%edi		/ start loop at &env[-1]
947c478bd9Sstevel@tonic-gate.L00:	addl	$4,%edi			/ next
957c478bd9Sstevel@tonic-gate	cmpl	$0,(%edi)		/ search for 0 at end of env
967c478bd9Sstevel@tonic-gate	jne	.L00
977c478bd9Sstevel@tonic-gate	addl	$4,%edi			/ advance past 0
987c478bd9Sstevel@tonic-gate	movl	$EB_AUXV,16(%esi)	/ set up tag for auxv
997c478bd9Sstevel@tonic-gate	movl	%edi,20(%esi)		/ point to auxv
1007c478bd9Sstevel@tonic-gate	movl	$EB_NULL,24(%esi)	/ set up NULL tag
1017c478bd9Sstevel@tonic-gate	call	.L01		/ only way to get IP into a register
1027c478bd9Sstevel@tonic-gate.L01:	popl	%ebx		/ pop the IP we just "pushed"
1037c478bd9Sstevel@tonic-gate	leal	s.EMPTY - .L01(%ebx),%eax
1047c478bd9Sstevel@tonic-gate	pushl	%eax
1057c478bd9Sstevel@tonic-gate	leal	s.ZERO - .L01(%ebx),%eax
1067c478bd9Sstevel@tonic-gate	pushl	%eax
1077c478bd9Sstevel@tonic-gate	leal	s.LDSO - .L01(%ebx),%eax
1087c478bd9Sstevel@tonic-gate	pushl	%eax
1097c478bd9Sstevel@tonic-gate	movl	%esp,%edi	/ save pointer to strings
1107c478bd9Sstevel@tonic-gate	leal	f.MUNMAP - .L01(%ebx),%eax
1117c478bd9Sstevel@tonic-gate	pushl	%eax
1127c478bd9Sstevel@tonic-gate	leal	f.CLOSE - .L01(%ebx),%eax
1137c478bd9Sstevel@tonic-gate	pushl	%eax
1147c478bd9Sstevel@tonic-gate	leal	f.SYSCONFIG - .L01(%ebx),%eax
1157c478bd9Sstevel@tonic-gate	pushl	%eax
116*8fd04b83SRoger A. Faulkner	leal	f.FSTATAT - .L01(%ebx),%eax
1177c478bd9Sstevel@tonic-gate	pushl	%eax
1187c478bd9Sstevel@tonic-gate	leal	f.MMAP - .L01(%ebx),%eax
1197c478bd9Sstevel@tonic-gate	pushl	%eax
120*8fd04b83SRoger A. Faulkner	leal	f.OPENAT - .L01(%ebx),%eax
1217c478bd9Sstevel@tonic-gate	pushl	%eax
1227c478bd9Sstevel@tonic-gate	leal	f.PANIC - .L01(%ebx),%eax
1237c478bd9Sstevel@tonic-gate	pushl	%eax
1247c478bd9Sstevel@tonic-gate	movl	%esp,%ecx	/ save pointer to functions
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate	pushl	%ecx		/ address of functions
1277c478bd9Sstevel@tonic-gate	pushl	%edi		/ address of strings
1287c478bd9Sstevel@tonic-gate	pushl	%esi		/ &eb[0]
1297c478bd9Sstevel@tonic-gate	call	__rtld		/ __rtld(&eb[0], strings, funcs)
1307c478bd9Sstevel@tonic-gate	movl	%esi,%esp	/ restore the stack (but leaving boot vector)
1317c478bd9Sstevel@tonic-gate	jmp	*%eax 		/ transfer control to ld.so.1
1327c478bd9Sstevel@tonic-gate	.size	__rtboot,.-__rtboot
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate	.align	4
1357c478bd9Sstevel@tonic-gates.LDSO:		.string	"/usr/lib/ld.so.1"
1367c478bd9Sstevel@tonic-gates.ZERO:		.string	"/dev/zero"
1377c478bd9Sstevel@tonic-gates.EMPTY:	.string	"(null)"
1387c478bd9Sstevel@tonic-gates.ERROR:	.string	": no (or bad) /usr/lib/ld.so.1\n"
1397c478bd9Sstevel@tonic-gatel.ERROR:
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate	.align	4
1427c478bd9Sstevel@tonic-gatef.PANIC:
1437c478bd9Sstevel@tonic-gate	movl	%esp,%ebp
1447c478bd9Sstevel@tonic-gate/ Add using of argument string
1457c478bd9Sstevel@tonic-gate	pushl	$l.ERROR - s.ERROR
1467c478bd9Sstevel@tonic-gate	call	.L02
1477c478bd9Sstevel@tonic-gate.L02:	popl	%ebx
1487c478bd9Sstevel@tonic-gate	leal	s.ERROR - .L02(%ebx),%eax
1497c478bd9Sstevel@tonic-gate	pushl	%eax
1507c478bd9Sstevel@tonic-gate	pushl	$2
1517c478bd9Sstevel@tonic-gate	call	f.WRITE
1527c478bd9Sstevel@tonic-gate	jmp	f.EXIT
1537c478bd9Sstevel@tonic-gate/ Not reached
1547c478bd9Sstevel@tonic-gate
155*8fd04b83SRoger A. Faulknerf.OPENAT:
156*8fd04b83SRoger A. Faulkner	movl	$SYS_openat,%eax
1577c478bd9Sstevel@tonic-gate	jmp	__syscall
1587c478bd9Sstevel@tonic-gatef.MMAP:
1597c478bd9Sstevel@tonic-gate	movl	$SYS_mmap,%eax
1607c478bd9Sstevel@tonic-gate	jmp	__syscall
1617c478bd9Sstevel@tonic-gatef.MUNMAP:
1627c478bd9Sstevel@tonic-gate	movl	$SYS_munmap,%eax
1637c478bd9Sstevel@tonic-gate	jmp	__syscall
1647c478bd9Sstevel@tonic-gatef.READ:
1657c478bd9Sstevel@tonic-gate	movl	$SYS_read,%eax
1667c478bd9Sstevel@tonic-gate	jmp	__syscall
1677c478bd9Sstevel@tonic-gatef.WRITE:
1687c478bd9Sstevel@tonic-gate	movl	$SYS_write,%eax
1697c478bd9Sstevel@tonic-gate	jmp	__syscall
1707c478bd9Sstevel@tonic-gatef.LSEEK:
1717c478bd9Sstevel@tonic-gate	movl	$SYS_lseek,%eax
1727c478bd9Sstevel@tonic-gate	jmp	__syscall
1737c478bd9Sstevel@tonic-gatef.CLOSE:
1747c478bd9Sstevel@tonic-gate	movl	$SYS_close,%eax
1757c478bd9Sstevel@tonic-gate	jmp	__syscall
176*8fd04b83SRoger A. Faulknerf.FSTATAT:
177*8fd04b83SRoger A. Faulkner	movl	$SYS_fstatat,%eax
1787c478bd9Sstevel@tonic-gate	jmp	__syscall
1797c478bd9Sstevel@tonic-gatef.SYSCONFIG:
1807c478bd9Sstevel@tonic-gate	movl	$SYS_sysconfig,%eax
1817c478bd9Sstevel@tonic-gate	jmp	__syscall
1827c478bd9Sstevel@tonic-gatef.EXIT:
1837c478bd9Sstevel@tonic-gate	movl	$SYS_exit,%eax
1847c478bd9Sstevel@tonic-gate/	jmp	__syscall
1857c478bd9Sstevel@tonic-gate__syscall:
1867c478bd9Sstevel@tonic-gate	int	$T_SYSCALLINT
1877c478bd9Sstevel@tonic-gate	jc	__err_exit
1887c478bd9Sstevel@tonic-gate	ret
1897c478bd9Sstevel@tonic-gate__err_exit:
1907c478bd9Sstevel@tonic-gate	movl	$-1,%eax
1917c478bd9Sstevel@tonic-gate	ret
192