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