xref: /titanic_51/usr/src/lib/crt/amd64/mach-crt1.s (revision afe959e5fe5d27ed1cc47aef88fde468fe511e6a)
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 2007 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#include <sys/asm_linkage.h>
28
29	.file	"mach-crt1.s"
30
31	.global	_start_crt
32
33/*
34 *   The SVR4/amd64 ABI (pages 3-29) says that when the entry
35 *   point runs registers' %rbp, %rsp, %rdx values are specified
36 *   the following:
37 *
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.
42 *
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.
46 *
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)
54 *
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].
59 *
60 */
61
62ENTRY_NP(_start)
63/*
64 * Allocate a NULL return address and a NULL previous %rbp as if
65 * there was a genuine call to _start.
66 */
67	pushq	$0
68	pushq	$0
69	movq	%rsp,%rbp		/* The first stack frame */
70
71/*
72 * The stack now is
73 *
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)
81 */
82
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
89SET_SIZE(_start)
90
91/*
92 * The following is here in case any object module compiled with cc -p
93 *	was linked into this module.
94 */
95ENTRY_NP(_mcount)
96	.weak	_mcount
97	ret
98SET_SIZE(_mcount)
99