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 524da5b34Srie * Common Development and Distribution License (the "License"). 624da5b34Srie * 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 */ 2124da5b34Srie 227c478bd9Sstevel@tonic-gate/* 237257d1b4Sraf * Copyright 2008 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 33*9a70fc3bSMark J. Nelson .file "crt1.s" 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate .globl _start 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate/* global entities defined elsewhere but used here */ 387c478bd9Sstevel@tonic-gate .globl main 397c478bd9Sstevel@tonic-gate .globl __fpstart 407c478bd9Sstevel@tonic-gate .globl exit 417c478bd9Sstevel@tonic-gate .globl _exit 427c478bd9Sstevel@tonic-gate .weak _DYNAMIC 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate .section .data 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate .weak environ 477c478bd9Sstevel@tonic-gate .set environ,_environ 487c478bd9Sstevel@tonic-gate .globl _environ 497c478bd9Sstevel@tonic-gate .type _environ,@object 507c478bd9Sstevel@tonic-gate .size _environ,4 517c478bd9Sstevel@tonic-gate .align 4 527c478bd9Sstevel@tonic-gate_environ: 537c478bd9Sstevel@tonic-gate .4byte 0x0 547c478bd9Sstevel@tonic-gate 5524da5b34Srie .globl __environ_lock 5624da5b34Srie .type __environ_lock,@object 5724da5b34Srie .size __environ_lock,24 587257d1b4Sraf .align 8 5924da5b34Srie__environ_lock: 6024da5b34Srie .zero 24 6124da5b34Srie 627c478bd9Sstevel@tonic-gate .globl ___Argv 637c478bd9Sstevel@tonic-gate .type ___Argv,@object 647c478bd9Sstevel@tonic-gate .size ___Argv,4 657c478bd9Sstevel@tonic-gate .align 4 667c478bd9Sstevel@tonic-gate___Argv: 677c478bd9Sstevel@tonic-gate .4byte 0x0 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate .section .text 707c478bd9Sstevel@tonic-gate .align 4 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate/* 737c478bd9Sstevel@tonic-gate * C language startup routine. 747c478bd9Sstevel@tonic-gate * Assume that exec code has cleared the direction flag in the TSS. 757c478bd9Sstevel@tonic-gate * Assume that %esp is set to the addr after the last word pushed. 767c478bd9Sstevel@tonic-gate * The stack contains (in order): argc, argv[],envp[],... 777c478bd9Sstevel@tonic-gate * Assume that all of the segment registers are initialized. 787c478bd9Sstevel@tonic-gate * 797c478bd9Sstevel@tonic-gate * Allocate a NULL return address and a NULL previous %ebp as if 807c478bd9Sstevel@tonic-gate * there was a genuine call to _start. 817c478bd9Sstevel@tonic-gate * sdb stack trace shows _start(argc,argv[0],argv[1],...,envp[0],...) 827c478bd9Sstevel@tonic-gate */ 837c478bd9Sstevel@tonic-gate .type _start,@function 847c478bd9Sstevel@tonic-gate_start: 857c478bd9Sstevel@tonic-gate pushl $0 867c478bd9Sstevel@tonic-gate pushl $0 877c478bd9Sstevel@tonic-gate movl %esp,%ebp /* The first stack frame */ 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate movl $_DYNAMIC,%eax 907c478bd9Sstevel@tonic-gate testl %eax,%eax 917c478bd9Sstevel@tonic-gate jz 1f 927c478bd9Sstevel@tonic-gate pushl %edx /* register rt_do_exit */ 937c478bd9Sstevel@tonic-gate call atexit 947c478bd9Sstevel@tonic-gate addl $4,%esp 957c478bd9Sstevel@tonic-gate1: 967c478bd9Sstevel@tonic-gate pushl $_fini 977c478bd9Sstevel@tonic-gate call atexit 987c478bd9Sstevel@tonic-gate addl $4,%esp 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate/* 1017c478bd9Sstevel@tonic-gate * The following code provides almost standard static destructor handling 1027c478bd9Sstevel@tonic-gate * for systems that do not have the modified atexit processing in their 1037c478bd9Sstevel@tonic-gate * system libraries. It checks for the existence of the new routine 1047c478bd9Sstevel@tonic-gate * "_get_exit_frame_monitor()", which is in libc.so when the new exit-handling 1057c478bd9Sstevel@tonic-gate * code is there. It then check for the existence of "__Crun::do_exit_code()" 1067c478bd9Sstevel@tonic-gate * which will be in libCrun.so whenever the code was linked with the C++ 1077c478bd9Sstevel@tonic-gate * compiler. If there is no enhanced atexit, and we do have do_exit_code, 1087c478bd9Sstevel@tonic-gate * we register the latter with atexit. There are 5 extra slots in 1097c478bd9Sstevel@tonic-gate * atexit, so this will still be standard conforming. Since the code 1107c478bd9Sstevel@tonic-gate * is registered after the .fini section, it runs before the library 1117c478bd9Sstevel@tonic-gate * cleanup code, leaving nothing for the calls to _do_exit_code_in_range 1127c478bd9Sstevel@tonic-gate * to handle. 1137c478bd9Sstevel@tonic-gate * 1147c478bd9Sstevel@tonic-gate * Remove this code and the associated code in libCrun when the earliest 1157c478bd9Sstevel@tonic-gate * system to be supported is Solaris 8. 1167c478bd9Sstevel@tonic-gate */ 1177c478bd9Sstevel@tonic-gate .weak _get_exit_frame_monitor 1187c478bd9Sstevel@tonic-gate .weak __1cG__CrunMdo_exit_code6F_v_ 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate .section .data 1217c478bd9Sstevel@tonic-gate .align 4 1227c478bd9Sstevel@tonic-gate__get_exit_frame_monitor_ptr: 1237c478bd9Sstevel@tonic-gate .4byte _get_exit_frame_monitor 1247c478bd9Sstevel@tonic-gate .type __get_exit_frame_monitor_ptr,@object 1257c478bd9Sstevel@tonic-gate .size __get_exit_frame_monitor_ptr,4 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate .align 4 1287c478bd9Sstevel@tonic-gate__do_exit_code_ptr: 1297c478bd9Sstevel@tonic-gate .4byte __1cG__CrunMdo_exit_code6F_v_ 1307c478bd9Sstevel@tonic-gate .type __do_exit_code_ptr,@object 1317c478bd9Sstevel@tonic-gate .size __do_exit_code_ptr,4 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate .section .text 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate lea __get_exit_frame_monitor_ptr, %eax 1367c478bd9Sstevel@tonic-gate movl (%eax), %eax 1377c478bd9Sstevel@tonic-gate testl %eax,%eax 1387c478bd9Sstevel@tonic-gate jz 1f 1397c478bd9Sstevel@tonic-gate lea __do_exit_code_ptr, %eax 1407c478bd9Sstevel@tonic-gate movl (%eax), %eax 1417c478bd9Sstevel@tonic-gate testl %eax, %eax 1427c478bd9Sstevel@tonic-gate jz 1f 1437c478bd9Sstevel@tonic-gate pushl %eax 1447c478bd9Sstevel@tonic-gate call atexit /* atexit(__Crun::do_exit_code()) */ 1457c478bd9Sstevel@tonic-gate addl $4,%esp 1467c478bd9Sstevel@tonic-gate1: 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate/* 1497c478bd9Sstevel@tonic-gate * End of destructor handling code 1507c478bd9Sstevel@tonic-gate */ 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate/* 1537c478bd9Sstevel@tonic-gate * Calculate the location of the envp array by adding the size of 1547c478bd9Sstevel@tonic-gate * the argv array to the start of the argv array. 1557c478bd9Sstevel@tonic-gate */ 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate movl 8(%ebp),%eax /* argc */ 1587c478bd9Sstevel@tonic-gate movl _environ, %edx /* fixed bug 4302802 */ 1597c478bd9Sstevel@tonic-gate testl %edx, %edx /* check if _enviorn==0 */ 1607c478bd9Sstevel@tonic-gate jne 1f /* fixed bug 4203802 */ 1617c478bd9Sstevel@tonic-gate leal 16(%ebp,%eax,4),%edx /* envp */ 1627c478bd9Sstevel@tonic-gate movl %edx,_environ /* copy to _environ */ 1637c478bd9Sstevel@tonic-gate1: 1647c478bd9Sstevel@tonic-gate andl $-16,%esp 1657c478bd9Sstevel@tonic-gate pushl %edx 1667c478bd9Sstevel@tonic-gate leal 12(%ebp),%edx /* argv */ 1677c478bd9Sstevel@tonic-gate movl %edx,___Argv 1687c478bd9Sstevel@tonic-gate pushl %edx 1697c478bd9Sstevel@tonic-gate pushl %eax /* argc */ 1707c478bd9Sstevel@tonic-gate call __fpstart 1717c478bd9Sstevel@tonic-gate call __fsr /* support for ftrap/fround/fprecision */ 1727c478bd9Sstevel@tonic-gate call _init 1737c478bd9Sstevel@tonic-gate call main /* main(argc,argv,envp) */ 1747c478bd9Sstevel@tonic-gate addl $12,%esp 1757c478bd9Sstevel@tonic-gate pushl %eax /* return value from main */ 1767c478bd9Sstevel@tonic-gate pushl %eax /* push it again (for _exit(), below) */ 1777c478bd9Sstevel@tonic-gate call exit 1787c478bd9Sstevel@tonic-gate addl $4,%esp 1797c478bd9Sstevel@tonic-gate call _exit /* if user redefined exit, call _exit */ 1807c478bd9Sstevel@tonic-gate addl $4,%esp 1817c478bd9Sstevel@tonic-gate hlt 1827c478bd9Sstevel@tonic-gate .size _start, .-_start 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate#include "fsr.s" 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate/* 1877c478bd9Sstevel@tonic-gate * The following is here in case any object module compiled with cc -p 1887c478bd9Sstevel@tonic-gate * was linked into this module. 1897c478bd9Sstevel@tonic-gate */ 1907c478bd9Sstevel@tonic-gate .section .text 1917c478bd9Sstevel@tonic-gate .align 4 1927c478bd9Sstevel@tonic-gate .globl _mcount 1937c478bd9Sstevel@tonic-gate .type _mcount,@function 1947c478bd9Sstevel@tonic-gate_mcount: 1957c478bd9Sstevel@tonic-gate ret 1967c478bd9Sstevel@tonic-gate .size _mcount, .-_mcount 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate .section .data 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate .globl __longdouble_used 2017c478bd9Sstevel@tonic-gate .type __longdouble_used,@object 2027c478bd9Sstevel@tonic-gate .size __longdouble_used,4 2037c478bd9Sstevel@tonic-gate .align 4 2047c478bd9Sstevel@tonic-gate__longdouble_used: 2057c478bd9Sstevel@tonic-gate .4byte 0x0 206