Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / lib / crt / i386 / mach-crt1.s
blob1824d41ec37c609dd9939fc1a0f50e8e3a26444d
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 #include <sys/asm_linkage.h>
28 .file "mach-crt1.s"
30 /* global entities defined elsewhere but used here */
31 .globl _start_crt
34 * C language startup routine.
35 * Assume that exec code has cleared the direction flag in the TSS.
36 * Assume that %esp is set to the addr after the last word pushed.
37 * The stack contains (in order): argc, argv[],envp[],...
38 * Assume that all of the segment registers are initialized.
40 * Allocate a NULL return address and a NULL previous %ebp as if
41 * there was a genuine call to _start.
42 * debugger stack trace shows _start(argc,argv[0],argv[1],...,envp[0],...)
44 ENTRY_NP(_start)
45 pushl $0
46 pushl $0
47 movl %esp,%ebp /* The first stack frame */
50 * The stack needs to be 16-byte aligned with a 4-byte bias. See
51 * comment in lib/libc/i386/gen/makectxt.c.
53 * Note: If you change it, you need to change it in the following
54 * files as well:
56 * - lib/libc/i386/threads/machdep.c
57 * - lib/libc/i386/gen/makectxt.c
58 * - lib/crt/i386/crti.s
60 andl $-16,%esp /* make main() and exit() be called with */
61 subl $4,%esp /* a properly aligned stack pointer */
62 pushl %edx /* possible atexit handler */
63 leal 12(%ebp),%edx /* argv */
64 movl 8(%ebp),%eax /* argc */
65 pushl %edx
66 pushl %eax
67 call _start_crt
68 hlt
69 SET_SIZE(_start)
71 #include "fsr.s"
74 * The following is here in case any object module compiled with cc -p
75 * was linked into this module.
77 ENTRY_NP(_mcount)
78 .weak _mcount
79 ret
80 SET_SIZE(_mcount)