xref: /titanic_51/usr/src/lib/crt/amd64/mach-crt1.s (revision 3e0c804466b61d42dc6a3e1cb114c11681ef181a)
1*3e0c8044SRichard Lowe/*
2*3e0c8044SRichard Lowe * CDDL HEADER START
3*3e0c8044SRichard Lowe *
4*3e0c8044SRichard Lowe * The contents of this file are subject to the terms of the
5*3e0c8044SRichard Lowe * Common Development and Distribution License (the "License").
6*3e0c8044SRichard Lowe * You may not use this file except in compliance with the License.
7*3e0c8044SRichard Lowe *
8*3e0c8044SRichard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*3e0c8044SRichard Lowe * or http://www.opensolaris.org/os/licensing.
10*3e0c8044SRichard Lowe * See the License for the specific language governing permissions
11*3e0c8044SRichard Lowe * and limitations under the License.
12*3e0c8044SRichard Lowe *
13*3e0c8044SRichard Lowe * When distributing Covered Code, include this CDDL HEADER in each
14*3e0c8044SRichard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*3e0c8044SRichard Lowe * If applicable, add the following below this CDDL HEADER, with the
16*3e0c8044SRichard Lowe * fields enclosed by brackets "[]" replaced with your own identifying
17*3e0c8044SRichard Lowe * information: Portions Copyright [yyyy] [name of copyright owner]
18*3e0c8044SRichard Lowe *
19*3e0c8044SRichard Lowe * CDDL HEADER END
20*3e0c8044SRichard Lowe */
21*3e0c8044SRichard Lowe
22*3e0c8044SRichard Lowe/*
23*3e0c8044SRichard Lowe * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24*3e0c8044SRichard Lowe * Use is subject to license terms.
25*3e0c8044SRichard Lowe */
26*3e0c8044SRichard Lowe
27*3e0c8044SRichard Lowe#include <sys/asm_linkage.h>
28*3e0c8044SRichard Lowe
29*3e0c8044SRichard Lowe	.file	"mach-crt1.s"
30*3e0c8044SRichard Lowe
31*3e0c8044SRichard Lowe	.global	_start_crt
32*3e0c8044SRichard Lowe
33*3e0c8044SRichard Lowe/*
34*3e0c8044SRichard Lowe *   The SVR4/amd64 ABI (pages 3-29) says that when the entry
35*3e0c8044SRichard Lowe *   point runs registers' %rbp, %rsp, %rdx values are specified
36*3e0c8044SRichard Lowe *   the following:
37*3e0c8044SRichard Lowe *
38*3e0c8044SRichard Lowe *	%rbp The content of this register is unspecified at
39*3e0c8044SRichard Lowe *		process initialization time, but the user code should mark
40*3e0c8044SRichard Lowe *		the deepest stack frame by setting the frame pointer to zero.
41*3e0c8044SRichard Lowe *		No other frame's %ebp should have a zero value.
42*3e0c8044SRichard Lowe *
43*3e0c8044SRichard Lowe *	%rsp Performing its usual job, the stack pointer holds the address
44*3e0c8044SRichard Lowe *	of the bottom of the stack, which is guaranteed to be
45*3e0c8044SRichard Lowe *	quadword aligned.
46*3e0c8044SRichard Lowe *
47*3e0c8044SRichard Lowe *		The stack contains the arguments and environment:
48*3e0c8044SRichard Lowe *	  ...
49*3e0c8044SRichard Lowe *	  envp[0]		(16+(8*argc))(%rsp)
50*3e0c8044SRichard Lowe *	  NULL			(8+(8*argc))(%rsp)
51*3e0c8044SRichard Lowe *	  ...
52*3e0c8044SRichard Lowe *	  argv[0]		8(%rsp)
53*3e0c8044SRichard Lowe *	  argc			0(%rsp)
54*3e0c8044SRichard Lowe *
55*3e0c8044SRichard Lowe *	%rdx In a conforming program, this register contains a function
56*3e0c8044SRichard Lowe *		pointer that the application should register with atexit(BA_OS).
57*3e0c8044SRichard Lowe *		This function is used for shared object termination code
58*3e0c8044SRichard Lowe *		[see Dynamic Linking in Chapter 5 of the System V ABI].
59*3e0c8044SRichard Lowe *
60*3e0c8044SRichard Lowe */
61*3e0c8044SRichard Lowe
62*3e0c8044SRichard LoweENTRY_NP(_start)
63*3e0c8044SRichard Lowe/*
64*3e0c8044SRichard Lowe * Allocate a NULL return address and a NULL previous %rbp as if
65*3e0c8044SRichard Lowe * there was a genuine call to _start.
66*3e0c8044SRichard Lowe */
67*3e0c8044SRichard Lowe	pushq	$0
68*3e0c8044SRichard Lowe	pushq	$0
69*3e0c8044SRichard Lowe	movq	%rsp,%rbp		/* The first stack frame */
70*3e0c8044SRichard Lowe
71*3e0c8044SRichard Lowe/*
72*3e0c8044SRichard Lowe * The stack now is
73*3e0c8044SRichard Lowe *
74*3e0c8044SRichard Lowe *	  envp[0]		(32+(8*argc))(%rsp)	 - (A)
75*3e0c8044SRichard Lowe *	  NULL			(24+(8*argc))(%rsp)
76*3e0c8044SRichard Lowe *	  ...
77*3e0c8044SRichard Lowe *	  argv[0]		24(%rbp)		 - (B)
78*3e0c8044SRichard Lowe *	  argc			16(%rbp)
79*3e0c8044SRichard Lowe *	  0			8(%rbp)
80*3e0c8044SRichard Lowe *	  0			0(%rbp)
81*3e0c8044SRichard Lowe */
82*3e0c8044SRichard Lowe
83*3e0c8044SRichard Lowe	andq	$-16,%rsp		/* align the stack */
84*3e0c8044SRichard Lowe	movq	16(%rbp),%rdi		/* argc */
85*3e0c8044SRichard Lowe	leaq	24(%rbp),%rsi		/* argv */
86*3e0c8044SRichard Lowe	/* NB: rt_do_exit, if applicable, is already in %rdx */
87*3e0c8044SRichard Lowe	call	_start_crt
88*3e0c8044SRichard Lowe	hlt
89*3e0c8044SRichard LoweSET_SIZE(_start)
90*3e0c8044SRichard Lowe
91*3e0c8044SRichard Lowe/*
92*3e0c8044SRichard Lowe * The following is here in case any object module compiled with cc -p
93*3e0c8044SRichard Lowe *	was linked into this module.
94*3e0c8044SRichard Lowe */
95*3e0c8044SRichard LoweENTRY_NP(_mcount)
96*3e0c8044SRichard Lowe	.weak	_mcount
97*3e0c8044SRichard Lowe	ret
98*3e0c8044SRichard LoweSET_SIZE(_mcount)
99