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