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 .ident "" 31 32 .global _start_crt 33 34/* 35 * The SVR4/amd64 ABI (pages 3-29) says that when the entry 36 * point runs registers' %rbp, %rsp, %rdx values are specified 37 * the following: 38 * 39 * %rbp The content of this register is unspecified at 40 * process initialization time, but the user code should mark 41 * the deepest stack frame by setting the frame pointer to zero. 42 * No other frame's %ebp should have a zero value. 43 * 44 * %rsp Performing its usual job, the stack pointer holds the address 45 * of the bottom of the stack, which is guaranteed to be 46 * quadword aligned. 47 * 48 * The stack contains the arguments and environment: 49 * ... 50 * envp[0] (16+(8*argc))(%rsp) 51 * NULL (8+(8*argc))(%rsp) 52 * ... 53 * argv[0] 8(%rsp) 54 * argc 0(%rsp) 55 * 56 * %rdx In a conforming program, this register contains a function 57 * pointer that the application should register with atexit(BA_OS). 58 * This function is used for shared object termination code 59 * [see Dynamic Linking in Chapter 5 of the System V ABI]. 60 * 61 */ 62 63ENTRY_NP(_start) 64/* 65 * Allocate a NULL return address and a NULL previous %rbp as if 66 * there was a genuine call to _start. 67 */ 68 pushq $0 69 pushq $0 70 movq %rsp,%rbp /* The first stack frame */ 71 72/* 73 * The stack now is 74 * 75 * envp[0] (32+(8*argc))(%rsp) - (A) 76 * NULL (24+(8*argc))(%rsp) 77 * ... 78 * argv[0] 24(%rbp) - (B) 79 * argc 16(%rbp) 80 * 0 8(%rbp) 81 * 0 0(%rbp) 82 */ 83 84 andq $-16,%rsp /* align the stack */ 85 movq 16(%rbp),%rdi /* argc */ 86 leaq 24(%rbp),%rsi /* argv */ 87 /* NB: rt_do_exit, if applicable, is already in %rdx */ 88 call _start_crt 89 hlt 90SET_SIZE(_start) 91 92/* 93 * The following is here in case any object module compiled with cc -p 94 * was linked into this module. 95 */ 96ENTRY_NP(_mcount) 97 .weak _mcount 98 ret 99SET_SIZE(_mcount) 100