dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / crt / amd64 / mach-crt1.s
blobab8ff28b5cdf0ed46c732c7e5aece974dba4715c
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 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include <sys/asm_linkage.h>
29 .file "mach-crt1.s"
31 .global _start_crt
34 * The SVR4/i386 ABI (pages 3-29) says that when the entry
35 * point runs registers' %rbp, %rsp, %rdx values are specified
36 * the following:
38 * %rbp The content of this register is unspecified at
39 * process initialization time, but the user code should mark
40 * the deepest stack frame by setting the frame pointer to zero.
41 * No other frame's %ebp should have a zero value.
43 * %rsp Performing its usual job, the stack pointer holds the address
44 * of the bottom of the stack, which is guaranteed to be
45 * quadword aligned.
47 * The stack contains the arguments and environment:
48 * ...
49 * envp[0] (16+(8*argc))(%rsp)
50 * NULL (8+(8*argc))(%rsp)
51 * ...
52 * argv[0] 8(%rsp)
53 * argc 0(%rsp)
55 * %rdx In a conforming program, this register contains a function
56 * pointer that the application should register with atexit(BA_OS).
57 * This function is used for shared object termination code
58 * [see Dynamic Linking in Chapter 5 of the System V ABI].
62 ENTRY_NP(_start)
64 * Allocate a NULL return address and a NULL previous %rbp as if
65 * there was a genuine call to _start.
67 pushq $0
68 pushq $0
69 movq %rsp,%rbp /* The first stack frame */
72 * The stack now is
74 * envp[0] (32+(8*argc))(%rsp) - (A)
75 * NULL (24+(8*argc))(%rsp)
76 * ...
77 * argv[0] 24(%rbp) - (B)
78 * argc 16(%rbp)
79 * 0 8(%rbp)
80 * 0 0(%rbp)
83 andq $-16,%rsp /* align the stack */
84 movq 16(%rbp),%rdi /* argc */
85 leaq 24(%rbp),%rsi /* argv */
86 /* NB: rt_do_exit, if applicable, is already in %rdx */
87 call _start_crt
88 hlt
89 SET_SIZE(_start)
92 * The following is here in case any object module compiled with cc -p
93 * was linked into this module.
95 ENTRY_NP(_mcount)
96 .weak _mcount
97 ret
98 SET_SIZE(_mcount)