1*0Sstevel@tonic-gate/* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate/* 23*0Sstevel@tonic-gate * Copyright (c) 1988 AT&T 24*0Sstevel@tonic-gate * All Rights Reserved 25*0Sstevel@tonic-gate * 26*0Sstevel@tonic-gate * 27*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 28*0Sstevel@tonic-gate * Use is subject to license terms. 29*0Sstevel@tonic-gate */ 30*0Sstevel@tonic-gate#pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate/* 33*0Sstevel@tonic-gate * Bootstrap routine for run-time linker. 34*0Sstevel@tonic-gate * We get control from exec which has loaded our text and 35*0Sstevel@tonic-gate * data into the process' address space and created the process 36*0Sstevel@tonic-gate * stack. 37*0Sstevel@tonic-gate * 38*0Sstevel@tonic-gate * On entry, the process stack looks like this: 39*0Sstevel@tonic-gate * 40*0Sstevel@tonic-gate * # # <- %esp 41*0Sstevel@tonic-gate * #_______________________# high addresses 42*0Sstevel@tonic-gate * # strings # 43*0Sstevel@tonic-gate * #_______________________# 44*0Sstevel@tonic-gate * # 0 word # 45*0Sstevel@tonic-gate * #_______________________# 46*0Sstevel@tonic-gate * # Auxiliary # 47*0Sstevel@tonic-gate * # entries # 48*0Sstevel@tonic-gate * # ... # 49*0Sstevel@tonic-gate * # (size varies) # 50*0Sstevel@tonic-gate * #_______________________# 51*0Sstevel@tonic-gate * # 0 word # 52*0Sstevel@tonic-gate * #_______________________# 53*0Sstevel@tonic-gate * # Environment # 54*0Sstevel@tonic-gate * # pointers # 55*0Sstevel@tonic-gate * # ... # 56*0Sstevel@tonic-gate * # (one word each) # 57*0Sstevel@tonic-gate * #_______________________# 58*0Sstevel@tonic-gate * # 0 word # 59*0Sstevel@tonic-gate * #_______________________# 60*0Sstevel@tonic-gate * # Argument # low addresses 61*0Sstevel@tonic-gate * # pointers # 62*0Sstevel@tonic-gate * # Argc words # 63*0Sstevel@tonic-gate * #_______________________# 64*0Sstevel@tonic-gate * # argc # 65*0Sstevel@tonic-gate * #_______________________# <- %ebp 66*0Sstevel@tonic-gate * 67*0Sstevel@tonic-gate * 68*0Sstevel@tonic-gate * We must calculate the address at which ld.so was loaded, 69*0Sstevel@tonic-gate * find the addr of the dynamic section of ld.so, of argv[0], and of 70*0Sstevel@tonic-gate * the process' environment pointers - and pass the thing to _setup 71*0Sstevel@tonic-gate * to handle. We then call _rtld - on return we jump to the entry 72*0Sstevel@tonic-gate * point for the a.out. 73*0Sstevel@tonic-gate */ 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate#if defined(lint) 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gateextern unsigned long _setup(); 78*0Sstevel@tonic-gateextern void atexit_fini(); 79*0Sstevel@tonic-gatevoid 80*0Sstevel@tonic-gatemain() 81*0Sstevel@tonic-gate{ 82*0Sstevel@tonic-gate (void) _setup(); 83*0Sstevel@tonic-gate atexit_fini(); 84*0Sstevel@tonic-gate} 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate#else 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate#include <link.h> 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate .file "boot.s" 91*0Sstevel@tonic-gate .text 92*0Sstevel@tonic-gate .globl _rt_boot 93*0Sstevel@tonic-gate .globl _setup 94*0Sstevel@tonic-gate .globl _GLOBAL_OFFSET_TABLE_ 95*0Sstevel@tonic-gate .type _rt_boot,@function 96*0Sstevel@tonic-gate .align 4 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate_rt_alias: 99*0Sstevel@tonic-gate jmp .get_ip / in case we were invoked from libc.so 100*0Sstevel@tonic-gate_rt_boot: 101*0Sstevel@tonic-gate movl %esp,%ebp / save for referencing args 102*0Sstevel@tonic-gate subl $EB_MAX_SIZE32,%esp / make room for a max sized boot vector 103*0Sstevel@tonic-gate movl %esp,%esi / use esi as a pointer to &eb[0] 104*0Sstevel@tonic-gate movl $EB_ARGV,0(%esi) / set up tag for argv 105*0Sstevel@tonic-gate leal 4(%ebp),%eax / get address of argv 106*0Sstevel@tonic-gate movl %eax,4(%esi) / put after tag 107*0Sstevel@tonic-gate movl $EB_ENVP,8(%esi) / set up tag for envp 108*0Sstevel@tonic-gate movl (%ebp),%eax / get # of args 109*0Sstevel@tonic-gate addl $2,%eax / one for the zero & one for argc 110*0Sstevel@tonic-gate leal (%ebp,%eax,4),%edi / now points past args & @ envp 111*0Sstevel@tonic-gate movl %edi,12(%esi) / set envp 112*0Sstevel@tonic-gate.L0: addl $4,%edi / next 113*0Sstevel@tonic-gate cmpl $0,-4(%edi) / search for 0 at end of env 114*0Sstevel@tonic-gate jne .L0 115*0Sstevel@tonic-gate movl $EB_AUXV,16(%esi) / set up tag for auxv 116*0Sstevel@tonic-gate movl %edi,20(%esi) / point to auxv 117*0Sstevel@tonic-gate movl $EB_NULL,24(%esi) / set up NULL tag 118*0Sstevel@tonic-gate.get_ip: 119*0Sstevel@tonic-gate call .L1 / only way to get IP into a register 120*0Sstevel@tonic-gate.L1: 121*0Sstevel@tonic-gate popl %ebx / pop the IP we just "pushed" 122*0Sstevel@tonic-gate addl $_GLOBAL_OFFSET_TABLE_+[.-.L1],%ebx 123*0Sstevel@tonic-gate pushl (%ebx) / address of dynamic structure 124*0Sstevel@tonic-gate pushl %esi / push &eb[0] 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate call _setup@PLT / _setup(&eb[0], _DYNAMIC) 127*0Sstevel@tonic-gate movl %ebp,%esp / release stack frame 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate movl atexit_fini@GOT(%ebx), %edx 130*0Sstevel@tonic-gate jmp *%eax / transfer control to a.out 131*0Sstevel@tonic-gate .size _rt_boot,.-_rt_boot 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate#endif 134