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 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 #include <sys/asm_linkage.h>
  27 
  28         .file   "mach-crt1.s"
  29 
  30 /* global entities defined elsewhere but used here */
  31         .globl  _start_crt
  32 
  33 /*
  34  * C language startup routine.
  35  * Assume that exec code has cleared the direction flag in the TSS.
  36  * Assume that %esp is set to the addr after the last word pushed.
  37  * The stack contains (in order): argc, argv[],envp[],...
  38  * Assume that all of the segment registers are initialized.
  39  *
  40  * Allocate a NULL return address and a NULL previous %ebp as if
  41  * there was a genuine call to _start.
  42  * debugger stack trace shows _start(argc,argv[0],argv[1],...,envp[0],...)
  43  */
  44 ENTRY_NP(_start)
  45         pushl   $0
  46         pushl   $0
  47         movl    %esp,%ebp               /* The first stack frame */
  48 
  49         /*
  50          * The stack needs to be 16-byte aligned with a 4-byte bias.  See
  51          * comment in lib/libc/i386/gen/makectxt.c.
  52          *
  53          * Note: If you change it, you need to change it in the following
  54          * files as well:
  55          *
  56          *  - lib/libc/i386/threads/machdep.c
  57          *  - lib/libc/i386/gen/makectxt.c
  58          *  - lib/crt/i86/crti.s
  59          */
  60         andl    $-16,%esp       /* make main() and exit() be called with */
  61         subl    $4,%esp         /* a properly aligned stack pointer */
  62         pushl   %edx            /* possible atexit handler */
  63         leal    12(%ebp),%edx   /* argv */
  64         movl    8(%ebp),%eax    /* argc */
  65         pushl   %edx
  66         pushl   %eax
  67         call    _start_crt
  68         hlt
  69 SET_SIZE(_start)
  70 
  71 #include "fsr.s"
  72 
  73 /*
  74  * The following is here in case any object module compiled with cc -p
  75  * was linked into this module.
  76  */
  77 ENTRY_NP(_mcount)
  78         .weak   _mcount
  79         ret
  80 SET_SIZE(_mcount)