xref: /titanic_50/usr/src/lib/libc/i386/crt/_rtboot.s (revision 15d9d0b528387242011cdcc6190c9e598cfe3a07)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27	.ident	"%Z%%M%	%I%	%E% SMI"
28
29	.file	"%M%"
30
31/ bootstrap routine for run-time linker
32/ we get control from exec which has loaded our text and
33/ data into the process' address space and created the process
34/ stack
35/
36/ on entry, the process stack looks like this:
37/
38/			# <- %esp
39/_______________________#  high addresses
40/	strings		#
41/_______________________#
42/	0 word		#
43/_______________________#
44/	Auxiliary	#
45/	entries		#
46/	...		#
47/	(size varies)	#
48/_______________________#
49/	0 word		#
50/_______________________#
51/	Environment	#
52/	pointers	#
53/	...		#
54/	(one word each)	#
55/_______________________#
56/	0 word		#
57/_______________________#
58/	Argument	# low addresses
59/	pointers	#
60/	Argc words	#
61/_______________________#
62/	argc		#
63/_______________________# <- %ebp
64
65#include <SYS.h>
66
67	.set	EB_NULL,0
68	.set	EB_DYNAMIC,1
69	.set	EB_LDSO_BASE,2
70	.set	EB_ARGV,3
71	.set	EB_ENVP,4
72	.set	EB_AUXV,5
73	.set	EB_DEVZERO,6
74	.set	EB_PAGESIZE,7
75	.set	EB_MAX,8
76	.set	EB_MAX_SIZE32,64
77
78	.text
79	.globl	__rtboot
80	.globl	__rtld
81	.type	__rtboot,@function
82	.align	4
83__rtboot:
84	movl	%esp,%ebp
85	subl	$EB_MAX_SIZE32,%esp	/ make room for a max sized boot vector
86	movl	%esp,%esi		/ use esi as a pointer to &eb[0]
87	movl	$EB_ARGV,0(%esi)	/ set up tag for argv
88	leal	4(%ebp),%eax		/ get address of argv
89	movl	%eax,4(%esi)		/ put after tag
90	movl	$EB_ENVP,8(%esi)	/ set up tag for envp
91	movl	(%ebp),%eax		/ get # of args
92	addl	$2,%eax			/ one for the zero & one for argc
93	leal	(%ebp,%eax,4),%edi	/ now points past args & @ envp
94	movl	%edi,12(%esi)		/ set envp
95	addl	$-4,%edi		/ start loop at &env[-1]
96.L00:	addl	$4,%edi			/ next
97	cmpl	$0,(%edi)		/ search for 0 at end of env
98	jne	.L00
99	addl	$4,%edi			/ advance past 0
100	movl	$EB_AUXV,16(%esi)	/ set up tag for auxv
101	movl	%edi,20(%esi)		/ point to auxv
102	movl	$EB_NULL,24(%esi)	/ set up NULL tag
103	call	.L01		/ only way to get IP into a register
104.L01:	popl	%ebx		/ pop the IP we just "pushed"
105	leal	s.EMPTY - .L01(%ebx),%eax
106	pushl	%eax
107	leal	s.ZERO - .L01(%ebx),%eax
108	pushl	%eax
109	leal	s.LDSO - .L01(%ebx),%eax
110	pushl	%eax
111	movl	%esp,%edi	/ save pointer to strings
112	leal	f.MUNMAP - .L01(%ebx),%eax
113	pushl	%eax
114	leal	f.CLOSE - .L01(%ebx),%eax
115	pushl	%eax
116	leal	f.SYSCONFIG - .L01(%ebx),%eax
117	pushl	%eax
118	leal	f.FSTAT - .L01(%ebx),%eax
119	pushl	%eax
120	leal	f.MMAP - .L01(%ebx),%eax
121	pushl	%eax
122	leal	f.OPEN - .L01(%ebx),%eax
123	pushl	%eax
124	leal	f.PANIC - .L01(%ebx),%eax
125	pushl	%eax
126	movl	%esp,%ecx	/ save pointer to functions
127
128	pushl	%ecx		/ address of functions
129	pushl	%edi		/ address of strings
130	pushl	%esi		/ &eb[0]
131	call	__rtld		/ __rtld(&eb[0], strings, funcs)
132	movl	%esi,%esp	/ restore the stack (but leaving boot vector)
133	jmp	*%eax 		/ transfer control to ld.so.1
134	.size	__rtboot,.-__rtboot
135
136	.align	4
137s.LDSO:		.string	"/usr/lib/ld.so.1"
138s.ZERO:		.string	"/dev/zero"
139s.EMPTY:	.string	"(null)"
140s.ERROR:	.string	": no (or bad) /usr/lib/ld.so.1\n"
141l.ERROR:
142
143	.align	4
144f.PANIC:
145	movl	%esp,%ebp
146/ Add using of argument string
147	pushl	$l.ERROR - s.ERROR
148	call	.L02
149.L02:	popl	%ebx
150	leal	s.ERROR - .L02(%ebx),%eax
151	pushl	%eax
152	pushl	$2
153	call	f.WRITE
154	jmp	f.EXIT
155/ Not reached
156
157f.OPEN:
158	movl	$SYS_open,%eax
159	jmp	__syscall
160f.MMAP:
161	movl	$SYS_mmap,%eax
162	jmp	__syscall
163f.MUNMAP:
164	movl	$SYS_munmap,%eax
165	jmp	__syscall
166f.READ:
167	movl	$SYS_read,%eax
168	jmp	__syscall
169f.WRITE:
170	movl	$SYS_write,%eax
171	jmp	__syscall
172f.LSEEK:
173	movl	$SYS_lseek,%eax
174	jmp	__syscall
175f.CLOSE:
176	movl	$SYS_close,%eax
177	jmp	__syscall
178f.FSTAT:
179	movl	$SYS_fxstat,%eax	/ NEEDSWORK: temp kludge for G6
180	jmp	__syscall
181f.SYSCONFIG:
182	movl	$SYS_sysconfig,%eax
183	jmp	__syscall
184f.EXIT:
185	movl	$SYS_exit,%eax
186/	jmp	__syscall
187__syscall:
188	int	$T_SYSCALLINT
189	jc	__err_exit
190	ret
191__err_exit:
192	movl	$-1,%eax
193	ret
194