1*7c478bd9Sstevel@tonic-gate/* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate/* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate/* 28*7c478bd9Sstevel@tonic-gate * This crt1.o module is provided as the bare minimum required to build 29*7c478bd9Sstevel@tonic-gate * a 32-bit executable with gcc. It is installed in /usr/lib 30*7c478bd9Sstevel@tonic-gate * where it will be picked up by gcc, along with crti.o and crtn.o 31*7c478bd9Sstevel@tonic-gate */ 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate .ident "%Z%%M% %I% %E% SMI" 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate .file "crt1.s" 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate .globl _start 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate/* global entities defined elsewhere but used here */ 40*7c478bd9Sstevel@tonic-gate .globl main 41*7c478bd9Sstevel@tonic-gate .globl __fpstart 42*7c478bd9Sstevel@tonic-gate .globl exit 43*7c478bd9Sstevel@tonic-gate .globl _exit 44*7c478bd9Sstevel@tonic-gate .weak _DYNAMIC 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate .section .data 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate .weak environ 49*7c478bd9Sstevel@tonic-gate .set environ,_environ 50*7c478bd9Sstevel@tonic-gate .globl _environ 51*7c478bd9Sstevel@tonic-gate .type _environ,@object 52*7c478bd9Sstevel@tonic-gate .size _environ,4 53*7c478bd9Sstevel@tonic-gate .align 4 54*7c478bd9Sstevel@tonic-gate_environ: 55*7c478bd9Sstevel@tonic-gate .4byte 0x0 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate .globl ___Argv 58*7c478bd9Sstevel@tonic-gate .type ___Argv,@object 59*7c478bd9Sstevel@tonic-gate .size ___Argv,4 60*7c478bd9Sstevel@tonic-gate .align 4 61*7c478bd9Sstevel@tonic-gate___Argv: 62*7c478bd9Sstevel@tonic-gate .4byte 0x0 63*7c478bd9Sstevel@tonic-gate 64*7c478bd9Sstevel@tonic-gate .section .text 65*7c478bd9Sstevel@tonic-gate .align 4 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate/* 68*7c478bd9Sstevel@tonic-gate * C language startup routine. 69*7c478bd9Sstevel@tonic-gate * Assume that exec code has cleared the direction flag in the TSS. 70*7c478bd9Sstevel@tonic-gate * Assume that %esp is set to the addr after the last word pushed. 71*7c478bd9Sstevel@tonic-gate * The stack contains (in order): argc, argv[],envp[],... 72*7c478bd9Sstevel@tonic-gate * Assume that all of the segment registers are initialized. 73*7c478bd9Sstevel@tonic-gate * 74*7c478bd9Sstevel@tonic-gate * Allocate a NULL return address and a NULL previous %ebp as if 75*7c478bd9Sstevel@tonic-gate * there was a genuine call to _start. 76*7c478bd9Sstevel@tonic-gate * sdb stack trace shows _start(argc,argv[0],argv[1],...,envp[0],...) 77*7c478bd9Sstevel@tonic-gate */ 78*7c478bd9Sstevel@tonic-gate .type _start,@function 79*7c478bd9Sstevel@tonic-gate_start: 80*7c478bd9Sstevel@tonic-gate pushl $0 81*7c478bd9Sstevel@tonic-gate pushl $0 82*7c478bd9Sstevel@tonic-gate movl %esp,%ebp /* The first stack frame */ 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate movl $_DYNAMIC,%eax 85*7c478bd9Sstevel@tonic-gate testl %eax,%eax 86*7c478bd9Sstevel@tonic-gate jz 1f 87*7c478bd9Sstevel@tonic-gate pushl %edx /* register rt_do_exit */ 88*7c478bd9Sstevel@tonic-gate call atexit 89*7c478bd9Sstevel@tonic-gate addl $4,%esp 90*7c478bd9Sstevel@tonic-gate1: 91*7c478bd9Sstevel@tonic-gate pushl $_fini 92*7c478bd9Sstevel@tonic-gate call atexit 93*7c478bd9Sstevel@tonic-gate addl $4,%esp 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate/* 96*7c478bd9Sstevel@tonic-gate * The following code provides almost standard static destructor handling 97*7c478bd9Sstevel@tonic-gate * for systems that do not have the modified atexit processing in their 98*7c478bd9Sstevel@tonic-gate * system libraries. It checks for the existence of the new routine 99*7c478bd9Sstevel@tonic-gate * "_get_exit_frame_monitor()", which is in libc.so when the new exit-handling 100*7c478bd9Sstevel@tonic-gate * code is there. It then check for the existence of "__Crun::do_exit_code()" 101*7c478bd9Sstevel@tonic-gate * which will be in libCrun.so whenever the code was linked with the C++ 102*7c478bd9Sstevel@tonic-gate * compiler. If there is no enhanced atexit, and we do have do_exit_code, 103*7c478bd9Sstevel@tonic-gate * we register the latter with atexit. There are 5 extra slots in 104*7c478bd9Sstevel@tonic-gate * atexit, so this will still be standard conforming. Since the code 105*7c478bd9Sstevel@tonic-gate * is registered after the .fini section, it runs before the library 106*7c478bd9Sstevel@tonic-gate * cleanup code, leaving nothing for the calls to _do_exit_code_in_range 107*7c478bd9Sstevel@tonic-gate * to handle. 108*7c478bd9Sstevel@tonic-gate * 109*7c478bd9Sstevel@tonic-gate * Remove this code and the associated code in libCrun when the earliest 110*7c478bd9Sstevel@tonic-gate * system to be supported is Solaris 8. 111*7c478bd9Sstevel@tonic-gate */ 112*7c478bd9Sstevel@tonic-gate .weak _get_exit_frame_monitor 113*7c478bd9Sstevel@tonic-gate .weak __1cG__CrunMdo_exit_code6F_v_ 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate .section .data 116*7c478bd9Sstevel@tonic-gate .align 4 117*7c478bd9Sstevel@tonic-gate__get_exit_frame_monitor_ptr: 118*7c478bd9Sstevel@tonic-gate .4byte _get_exit_frame_monitor 119*7c478bd9Sstevel@tonic-gate .type __get_exit_frame_monitor_ptr,@object 120*7c478bd9Sstevel@tonic-gate .size __get_exit_frame_monitor_ptr,4 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate .align 4 123*7c478bd9Sstevel@tonic-gate__do_exit_code_ptr: 124*7c478bd9Sstevel@tonic-gate .4byte __1cG__CrunMdo_exit_code6F_v_ 125*7c478bd9Sstevel@tonic-gate .type __do_exit_code_ptr,@object 126*7c478bd9Sstevel@tonic-gate .size __do_exit_code_ptr,4 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate .section .text 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate lea __get_exit_frame_monitor_ptr, %eax 131*7c478bd9Sstevel@tonic-gate movl (%eax), %eax 132*7c478bd9Sstevel@tonic-gate testl %eax,%eax 133*7c478bd9Sstevel@tonic-gate jz 1f 134*7c478bd9Sstevel@tonic-gate lea __do_exit_code_ptr, %eax 135*7c478bd9Sstevel@tonic-gate movl (%eax), %eax 136*7c478bd9Sstevel@tonic-gate testl %eax, %eax 137*7c478bd9Sstevel@tonic-gate jz 1f 138*7c478bd9Sstevel@tonic-gate pushl %eax 139*7c478bd9Sstevel@tonic-gate call atexit /* atexit(__Crun::do_exit_code()) */ 140*7c478bd9Sstevel@tonic-gate addl $4,%esp 141*7c478bd9Sstevel@tonic-gate1: 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate/* 144*7c478bd9Sstevel@tonic-gate * End of destructor handling code 145*7c478bd9Sstevel@tonic-gate */ 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate/* 148*7c478bd9Sstevel@tonic-gate * Calculate the location of the envp array by adding the size of 149*7c478bd9Sstevel@tonic-gate * the argv array to the start of the argv array. 150*7c478bd9Sstevel@tonic-gate */ 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate movl 8(%ebp),%eax /* argc */ 153*7c478bd9Sstevel@tonic-gate movl _environ, %edx /* fixed bug 4302802 */ 154*7c478bd9Sstevel@tonic-gate testl %edx, %edx /* check if _enviorn==0 */ 155*7c478bd9Sstevel@tonic-gate jne 1f /* fixed bug 4203802 */ 156*7c478bd9Sstevel@tonic-gate leal 16(%ebp,%eax,4),%edx /* envp */ 157*7c478bd9Sstevel@tonic-gate movl %edx,_environ /* copy to _environ */ 158*7c478bd9Sstevel@tonic-gate1: 159*7c478bd9Sstevel@tonic-gate andl $-16,%esp 160*7c478bd9Sstevel@tonic-gate pushl %edx 161*7c478bd9Sstevel@tonic-gate leal 12(%ebp),%edx /* argv */ 162*7c478bd9Sstevel@tonic-gate movl %edx,___Argv 163*7c478bd9Sstevel@tonic-gate pushl %edx 164*7c478bd9Sstevel@tonic-gate pushl %eax /* argc */ 165*7c478bd9Sstevel@tonic-gate call __fpstart 166*7c478bd9Sstevel@tonic-gate call __fsr /* support for ftrap/fround/fprecision */ 167*7c478bd9Sstevel@tonic-gate call _init 168*7c478bd9Sstevel@tonic-gate call main /* main(argc,argv,envp) */ 169*7c478bd9Sstevel@tonic-gate addl $12,%esp 170*7c478bd9Sstevel@tonic-gate pushl %eax /* return value from main */ 171*7c478bd9Sstevel@tonic-gate pushl %eax /* push it again (for _exit(), below) */ 172*7c478bd9Sstevel@tonic-gate call exit 173*7c478bd9Sstevel@tonic-gate addl $4,%esp 174*7c478bd9Sstevel@tonic-gate call _exit /* if user redefined exit, call _exit */ 175*7c478bd9Sstevel@tonic-gate addl $4,%esp 176*7c478bd9Sstevel@tonic-gate hlt 177*7c478bd9Sstevel@tonic-gate .size _start, .-_start 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate#include "fsr.s" 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate/* 182*7c478bd9Sstevel@tonic-gate * The following is here in case any object module compiled with cc -p 183*7c478bd9Sstevel@tonic-gate * was linked into this module. 184*7c478bd9Sstevel@tonic-gate */ 185*7c478bd9Sstevel@tonic-gate .section .text 186*7c478bd9Sstevel@tonic-gate .align 4 187*7c478bd9Sstevel@tonic-gate .globl _mcount 188*7c478bd9Sstevel@tonic-gate .type _mcount,@function 189*7c478bd9Sstevel@tonic-gate_mcount: 190*7c478bd9Sstevel@tonic-gate ret 191*7c478bd9Sstevel@tonic-gate .size _mcount, .-_mcount 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate .section .data 194*7c478bd9Sstevel@tonic-gate 195*7c478bd9Sstevel@tonic-gate .globl __longdouble_used 196*7c478bd9Sstevel@tonic-gate .type __longdouble_used,@object 197*7c478bd9Sstevel@tonic-gate .size __longdouble_used,4 198*7c478bd9Sstevel@tonic-gate .align 4 199*7c478bd9Sstevel@tonic-gate__longdouble_used: 200*7c478bd9Sstevel@tonic-gate .4byte 0x0 201