2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/*
2N/A * This crt1.o module is provided as the bare minimum required to build a
2N/A * 64-bit progile executable with gcc -pg. It is installed in /usr/lib/amd64
2N/A * where it will be picked up by gcc, along with crti.o and crtn.o
2N/A */
2N/A
2N/A .ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A .file "gcrt1.s"
2N/A
2N/A .globl _start
2N/A .globl _etext
2N/A
2N/A/* global entities defined elsewhere but used here */
2N/A .globl main
2N/A .globl __fpstart
2N/A .globl _init
2N/A .globl _fini
2N/A .globl exit
2N/A .globl _exit
2N/A .globl monstartup
2N/A .weak _mcleanup
2N/A .weak _DYNAMIC
2N/A
2N/A .section .data
2N/A
2N/A .weak environ
2N/A .set environ,_environ
2N/A .globl _environ
2N/A .type _environ,@object
2N/A .size _environ,8
2N/A .align 8
2N/A_environ:
2N/A .8byte 0x0
2N/A
2N/A .globl ___Argv
2N/A .type ___Argv,@object
2N/A .size ___Argv,8
2N/A .align 8
2N/A___Argv:
2N/A .8byte 0x0
2N/A
2N/A .section .text
2N/A .align 8
2N/A
2N/A/*
2N/A * The SVR4/i386 ABI (pages 3-29) says that when the entry
2N/A * point runs registers' %rbp, %rsp, %rdx values are specified
2N/A * the following:
2N/A *
2N/A * %rbp The content of this register is unspecified at
2N/A * process initialization time, but the user code should mark
2N/A * the deepest stack frame by setting the frame pointer to zero.
2N/A * No other frame's %ebp should have a zero value.
2N/A *
2N/A * %rsp Performing its usual job, the stack pointer holds the address
2N/A * of the bottom of the stack, which is guaranteed to be
2N/A * quadword aligned.
2N/A *
2N/A * The stack contains the arguments and environment:
2N/A * ...
2N/A * envp[0] (16+(8*argc))(%rsp)
2N/A * NULL (8+(8*argc))(%rsp)
2N/A * ...
2N/A * argv[0] 8(%rsp)
2N/A * argc 0(%rsp)
2N/A *
2N/A * %rdx In a conforming program, this register contains a function
2N/A * pointer that the application should register with atexit(BA_OS).
2N/A * This function is used for shared object termination code
2N/A * [see Dynamic Linking in Chapter 5 of the System V ABI].
2N/A *
2N/A */
2N/A
2N/A .type _start,@function
2N/A_start:
2N/A/*
2N/A * Allocate a NULL return address and a NULL previous %rbp as if
2N/A * there was a genuine call to _start.
2N/A */
2N/A pushq $0
2N/A pushq $0
2N/A movq %rsp,%rbp /* The first stack frame */
2N/A
2N/A/*
2N/A * The stack now is
2N/A *
2N/A * envp[0] (32+(8*argc))(%rsp) - (A)
2N/A * NULL (24+(8*argc))(%rsp)
2N/A * ...
2N/A * argv[0] 24(%rbp) - (B)
2N/A * argc 16(%rbp)
2N/A * 0 8(%rbp)
2N/A * 0 0(%rbp)
2N/A */
2N/A
2N/A/*
2N/A * Check to see if there is an _mcleanup() function linked in, and if so,
2N/A * register it with atexit() as the last thing to be run by exit().
2N/A */
2N/A movq %rdx,%r12 /* save rt_do_exit for later atexit */
2N/A
2N/A movq $_mcleanup,%rdi
2N/A testq %rdi,%rdi
2N/A jz 1f
2N/A call atexit
2N/A1:
2N/A
2N/A movq $_DYNAMIC,%rax
2N/A testq %rax,%rax
2N/A jz 1f
2N/A movq %r12,%rdi /* register rt_do_exit */
2N/A call atexit
2N/A1:
2N/A
2N/A movq $_fini,%rdi
2N/A call atexit
2N/A
2N/A/* start profiling */
2N/A pushq %rbp
2N/A movq %rsp,%rbp
2N/A movq $_start,%rdi
2N/A movq $_etext,%rsi
2N/A call monstartup
2N/A popq %rbp
2N/A
2N/A/*
2N/A * Calculate the location of the envp array by adding the size of
2N/A * the argv array to the start of the argv array.
2N/A */
2N/A movq 16(%rbp),%rax /* argc */
2N/A movq _environ, %rcx
2N/A testq %rcx, %rcx /* check if _environ==0 */
2N/A jne 1f
2N/A leaq 32(%rbp,%rax,8),%rcx /* (A) */
2N/A movq %rcx,_environ /* copy to _environ */
2N/A1:
2N/A
2N/A/*
2N/A * Force stack alignment - below here there must have been an even
2N/A * number of un-popped pushq instructions whenever a call is reached
2N/A */
2N/A andq $-16,%rsp
2N/A pushq %rdx
2N/A leaq 24(%rbp),%rdx /* argv (B) */
2N/A movq %rdx,___Argv
2N/A pushq %rcx
2N/A pushq %rdx
2N/A pushq %rax
2N/A call __fpstart
2N/A call _init
2N/A popq %rdi
2N/A popq %rsi
2N/A popq %rdx
2N/A popq %rcx
2N/A call main /* main(argc,argv,envp) */
2N/A pushq %rax
2N/A pushq %rax
2N/A movq %rax,%rdi /* and call exit */
2N/A call exit
2N/A popq %rdi
2N/A popq %rdi
2N/A call _exit /* if user redefined exit, call _exit */
2N/A hlt
2N/A .size _start, .-_start