xref: /illumos-gate/usr/src/lib/crt/i386/mach-crt1.S (revision 5d9d9091)
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 (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26#include <sys/asm_linkage.h>
27
28	.file	"mach-crt1.S"
29	.ident	""
30
31/* global entities defined elsewhere but used here */
32	.globl	_start_crt
33
34/*
35 * C language startup routine.
36 * Assume that exec code has cleared the direction flag in the TSS.
37 * Assume that %esp is set to the addr after the last word pushed.
38 * The stack contains (in order): argc, argv[],envp[],...
39 * Assume that all of the segment registers are initialized.
40 *
41 * Allocate a NULL return address and a NULL previous %ebp as if
42 * there was a genuine call to _start.
43 * debugger stack trace shows _start(argc,argv[0],argv[1],...,envp[0],...)
44 */
45ENTRY_NP(_start)
46	pushl	$0
47	pushl	$0
48	movl	%esp,%ebp		/* The first stack frame */
49
50	/*
51	 * The stack needs to be 16-byte aligned with a 4-byte bias.  See
52	 * comment in lib/libc/i386/gen/makectxt.c.
53	 *
54	 * Note: If you change it, you need to change it in the following
55	 * files as well:
56	 *
57	 *  - lib/libc/i386/threads/machdep.c
58	 *  - lib/libc/i386/gen/makectxt.c
59	 *  - lib/crt/i386/crti.s
60	 */
61	andl	$-16,%esp	/* make main() and exit() be called with */
62	subl	$4,%esp		/* a properly aligned stack pointer */
63	pushl	%edx		/* possible atexit handler */
64	leal	12(%ebp),%edx	/* argv */
65	movl	8(%ebp),%eax	/* argc */
66	pushl	%edx
67	pushl	%eax
68	call	_start_crt
69	hlt
70SET_SIZE(_start)
71
72#include "fsr.S"
73
74/*
75 * The following is here in case any object module compiled with cc -p
76 * was linked into this module.
77 */
78ENTRY_NP(_mcount)
79	.weak	_mcount
80	ret
81SET_SIZE(_mcount)
82