17c478bd9Sstevel@tonic-gate/* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*24da5b34Srie * Common Development and Distribution License (the "License"). 6*24da5b34Srie * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21*24da5b34Srie 227c478bd9Sstevel@tonic-gate/* 23*24da5b34Srie * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate/* 287c478bd9Sstevel@tonic-gate * This crt1.o module is provided as the bare minimum required to build 297c478bd9Sstevel@tonic-gate * a 32-bit executable with gcc. It is installed in /usr/lib 307c478bd9Sstevel@tonic-gate * where it will be picked up by gcc, along with crti.o and crtn.o 317c478bd9Sstevel@tonic-gate */ 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate .ident "%Z%%M% %I% %E% SMI" 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate .file "crt1.s" 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate .globl _start 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate/* global entities defined elsewhere but used here */ 407c478bd9Sstevel@tonic-gate .globl main 417c478bd9Sstevel@tonic-gate .globl __fpstart 427c478bd9Sstevel@tonic-gate .globl exit 437c478bd9Sstevel@tonic-gate .globl _exit 447c478bd9Sstevel@tonic-gate .weak _DYNAMIC 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate .section .data 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate .weak environ 497c478bd9Sstevel@tonic-gate .set environ,_environ 507c478bd9Sstevel@tonic-gate .globl _environ 517c478bd9Sstevel@tonic-gate .type _environ,@object 527c478bd9Sstevel@tonic-gate .size _environ,4 537c478bd9Sstevel@tonic-gate .align 4 547c478bd9Sstevel@tonic-gate_environ: 557c478bd9Sstevel@tonic-gate .4byte 0x0 567c478bd9Sstevel@tonic-gate 57*24da5b34Srie .globl __environ_lock 58*24da5b34Srie .type __environ_lock,@object 59*24da5b34Srie .size __environ_lock,24 60*24da5b34Srie .align 4 61*24da5b34Srie__environ_lock: 62*24da5b34Srie .zero 24 63*24da5b34Srie 647c478bd9Sstevel@tonic-gate .globl ___Argv 657c478bd9Sstevel@tonic-gate .type ___Argv,@object 667c478bd9Sstevel@tonic-gate .size ___Argv,4 677c478bd9Sstevel@tonic-gate .align 4 687c478bd9Sstevel@tonic-gate___Argv: 697c478bd9Sstevel@tonic-gate .4byte 0x0 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate .section .text 727c478bd9Sstevel@tonic-gate .align 4 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate/* 757c478bd9Sstevel@tonic-gate * C language startup routine. 767c478bd9Sstevel@tonic-gate * Assume that exec code has cleared the direction flag in the TSS. 777c478bd9Sstevel@tonic-gate * Assume that %esp is set to the addr after the last word pushed. 787c478bd9Sstevel@tonic-gate * The stack contains (in order): argc, argv[],envp[],... 797c478bd9Sstevel@tonic-gate * Assume that all of the segment registers are initialized. 807c478bd9Sstevel@tonic-gate * 817c478bd9Sstevel@tonic-gate * Allocate a NULL return address and a NULL previous %ebp as if 827c478bd9Sstevel@tonic-gate * there was a genuine call to _start. 837c478bd9Sstevel@tonic-gate * sdb stack trace shows _start(argc,argv[0],argv[1],...,envp[0],...) 847c478bd9Sstevel@tonic-gate */ 857c478bd9Sstevel@tonic-gate .type _start,@function 867c478bd9Sstevel@tonic-gate_start: 877c478bd9Sstevel@tonic-gate pushl $0 887c478bd9Sstevel@tonic-gate pushl $0 897c478bd9Sstevel@tonic-gate movl %esp,%ebp /* The first stack frame */ 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate movl $_DYNAMIC,%eax 927c478bd9Sstevel@tonic-gate testl %eax,%eax 937c478bd9Sstevel@tonic-gate jz 1f 947c478bd9Sstevel@tonic-gate pushl %edx /* register rt_do_exit */ 957c478bd9Sstevel@tonic-gate call atexit 967c478bd9Sstevel@tonic-gate addl $4,%esp 977c478bd9Sstevel@tonic-gate1: 987c478bd9Sstevel@tonic-gate pushl $_fini 997c478bd9Sstevel@tonic-gate call atexit 1007c478bd9Sstevel@tonic-gate addl $4,%esp 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate/* 1037c478bd9Sstevel@tonic-gate * The following code provides almost standard static destructor handling 1047c478bd9Sstevel@tonic-gate * for systems that do not have the modified atexit processing in their 1057c478bd9Sstevel@tonic-gate * system libraries. It checks for the existence of the new routine 1067c478bd9Sstevel@tonic-gate * "_get_exit_frame_monitor()", which is in libc.so when the new exit-handling 1077c478bd9Sstevel@tonic-gate * code is there. It then check for the existence of "__Crun::do_exit_code()" 1087c478bd9Sstevel@tonic-gate * which will be in libCrun.so whenever the code was linked with the C++ 1097c478bd9Sstevel@tonic-gate * compiler. If there is no enhanced atexit, and we do have do_exit_code, 1107c478bd9Sstevel@tonic-gate * we register the latter with atexit. There are 5 extra slots in 1117c478bd9Sstevel@tonic-gate * atexit, so this will still be standard conforming. Since the code 1127c478bd9Sstevel@tonic-gate * is registered after the .fini section, it runs before the library 1137c478bd9Sstevel@tonic-gate * cleanup code, leaving nothing for the calls to _do_exit_code_in_range 1147c478bd9Sstevel@tonic-gate * to handle. 1157c478bd9Sstevel@tonic-gate * 1167c478bd9Sstevel@tonic-gate * Remove this code and the associated code in libCrun when the earliest 1177c478bd9Sstevel@tonic-gate * system to be supported is Solaris 8. 1187c478bd9Sstevel@tonic-gate */ 1197c478bd9Sstevel@tonic-gate .weak _get_exit_frame_monitor 1207c478bd9Sstevel@tonic-gate .weak __1cG__CrunMdo_exit_code6F_v_ 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate .section .data 1237c478bd9Sstevel@tonic-gate .align 4 1247c478bd9Sstevel@tonic-gate__get_exit_frame_monitor_ptr: 1257c478bd9Sstevel@tonic-gate .4byte _get_exit_frame_monitor 1267c478bd9Sstevel@tonic-gate .type __get_exit_frame_monitor_ptr,@object 1277c478bd9Sstevel@tonic-gate .size __get_exit_frame_monitor_ptr,4 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate .align 4 1307c478bd9Sstevel@tonic-gate__do_exit_code_ptr: 1317c478bd9Sstevel@tonic-gate .4byte __1cG__CrunMdo_exit_code6F_v_ 1327c478bd9Sstevel@tonic-gate .type __do_exit_code_ptr,@object 1337c478bd9Sstevel@tonic-gate .size __do_exit_code_ptr,4 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate .section .text 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate lea __get_exit_frame_monitor_ptr, %eax 1387c478bd9Sstevel@tonic-gate movl (%eax), %eax 1397c478bd9Sstevel@tonic-gate testl %eax,%eax 1407c478bd9Sstevel@tonic-gate jz 1f 1417c478bd9Sstevel@tonic-gate lea __do_exit_code_ptr, %eax 1427c478bd9Sstevel@tonic-gate movl (%eax), %eax 1437c478bd9Sstevel@tonic-gate testl %eax, %eax 1447c478bd9Sstevel@tonic-gate jz 1f 1457c478bd9Sstevel@tonic-gate pushl %eax 1467c478bd9Sstevel@tonic-gate call atexit /* atexit(__Crun::do_exit_code()) */ 1477c478bd9Sstevel@tonic-gate addl $4,%esp 1487c478bd9Sstevel@tonic-gate1: 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate/* 1517c478bd9Sstevel@tonic-gate * End of destructor handling code 1527c478bd9Sstevel@tonic-gate */ 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate/* 1557c478bd9Sstevel@tonic-gate * Calculate the location of the envp array by adding the size of 1567c478bd9Sstevel@tonic-gate * the argv array to the start of the argv array. 1577c478bd9Sstevel@tonic-gate */ 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate movl 8(%ebp),%eax /* argc */ 1607c478bd9Sstevel@tonic-gate movl _environ, %edx /* fixed bug 4302802 */ 1617c478bd9Sstevel@tonic-gate testl %edx, %edx /* check if _enviorn==0 */ 1627c478bd9Sstevel@tonic-gate jne 1f /* fixed bug 4203802 */ 1637c478bd9Sstevel@tonic-gate leal 16(%ebp,%eax,4),%edx /* envp */ 1647c478bd9Sstevel@tonic-gate movl %edx,_environ /* copy to _environ */ 1657c478bd9Sstevel@tonic-gate1: 1667c478bd9Sstevel@tonic-gate andl $-16,%esp 1677c478bd9Sstevel@tonic-gate pushl %edx 1687c478bd9Sstevel@tonic-gate leal 12(%ebp),%edx /* argv */ 1697c478bd9Sstevel@tonic-gate movl %edx,___Argv 1707c478bd9Sstevel@tonic-gate pushl %edx 1717c478bd9Sstevel@tonic-gate pushl %eax /* argc */ 1727c478bd9Sstevel@tonic-gate call __fpstart 1737c478bd9Sstevel@tonic-gate call __fsr /* support for ftrap/fround/fprecision */ 1747c478bd9Sstevel@tonic-gate call _init 1757c478bd9Sstevel@tonic-gate call main /* main(argc,argv,envp) */ 1767c478bd9Sstevel@tonic-gate addl $12,%esp 1777c478bd9Sstevel@tonic-gate pushl %eax /* return value from main */ 1787c478bd9Sstevel@tonic-gate pushl %eax /* push it again (for _exit(), below) */ 1797c478bd9Sstevel@tonic-gate call exit 1807c478bd9Sstevel@tonic-gate addl $4,%esp 1817c478bd9Sstevel@tonic-gate call _exit /* if user redefined exit, call _exit */ 1827c478bd9Sstevel@tonic-gate addl $4,%esp 1837c478bd9Sstevel@tonic-gate hlt 1847c478bd9Sstevel@tonic-gate .size _start, .-_start 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate#include "fsr.s" 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate/* 1897c478bd9Sstevel@tonic-gate * The following is here in case any object module compiled with cc -p 1907c478bd9Sstevel@tonic-gate * was linked into this module. 1917c478bd9Sstevel@tonic-gate */ 1927c478bd9Sstevel@tonic-gate .section .text 1937c478bd9Sstevel@tonic-gate .align 4 1947c478bd9Sstevel@tonic-gate .globl _mcount 1957c478bd9Sstevel@tonic-gate .type _mcount,@function 1967c478bd9Sstevel@tonic-gate_mcount: 1977c478bd9Sstevel@tonic-gate ret 1987c478bd9Sstevel@tonic-gate .size _mcount, .-_mcount 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate .section .data 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate .globl __longdouble_used 2037c478bd9Sstevel@tonic-gate .type __longdouble_used,@object 2047c478bd9Sstevel@tonic-gate .size __longdouble_used,4 2057c478bd9Sstevel@tonic-gate .align 4 2067c478bd9Sstevel@tonic-gate__longdouble_used: 2077c478bd9Sstevel@tonic-gate .4byte 0x0 208