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