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 * # # <- %rsp 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 * #_______________________# <- %rbp 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 / in case we were invoked from libc.so 100*0Sstevel@tonic-gate jmp .get_got 101*0Sstevel@tonic-gate_rt_boot: 102*0Sstevel@tonic-gate / save for referencing args 103*0Sstevel@tonic-gate movq %rsp,%rbp 104*0Sstevel@tonic-gate / make room for a max sized boot vector 105*0Sstevel@tonic-gate subq $EB_MAX_SIZE64,%rsp 106*0Sstevel@tonic-gate / use esi as a pointer to &eb[0] 107*0Sstevel@tonic-gate movq %rsp,%rsi 108*0Sstevel@tonic-gate / set up tag for argv 109*0Sstevel@tonic-gate movq $EB_ARGV,0(%rsi) 110*0Sstevel@tonic-gate / get address of argv 111*0Sstevel@tonic-gate leaq 8(%rbp),%rax 112*0Sstevel@tonic-gate / put after tag 113*0Sstevel@tonic-gate movq %rax,8(%rsi) 114*0Sstevel@tonic-gate / set up tag for envp 115*0Sstevel@tonic-gate movq $EB_ENVP,16(%rsi) 116*0Sstevel@tonic-gate / get # of args 117*0Sstevel@tonic-gate movq (%rbp),%rax 118*0Sstevel@tonic-gate / one for the zero & one for argc 119*0Sstevel@tonic-gate addq $2,%rax 120*0Sstevel@tonic-gate / now points past args & @ envp 121*0Sstevel@tonic-gate leaq (%rbp,%rax,8),%rdi 122*0Sstevel@tonic-gate / set envp 123*0Sstevel@tonic-gate movq %rdi,24(%rsi) 124*0Sstevel@tonic-gate / next 125*0Sstevel@tonic-gate.L0: addq $8,%rdi 126*0Sstevel@tonic-gate / search for 0 at end of env 127*0Sstevel@tonic-gate cmpq $0,-8(%rdi) 128*0Sstevel@tonic-gate jne .L0 129*0Sstevel@tonic-gate / set up tag for auxv 130*0Sstevel@tonic-gate movq $EB_AUXV,32(%rsi) 131*0Sstevel@tonic-gate / point to auxv 132*0Sstevel@tonic-gate movq %rdi,40(%rsi) 133*0Sstevel@tonic-gate / set up NULL tag 134*0Sstevel@tonic-gate movq $EB_NULL,48(%rsi) 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate / arg1 - address of &eb[0] 137*0Sstevel@tonic-gate movq %rsi, %rdi 138*0Sstevel@tonic-gate.get_got: 139*0Sstevel@tonic-gate leaq _GLOBAL_OFFSET_TABLE_(%rip), %rbx 140*0Sstevel@tonic-gate / addq $_GLOBAL_OFFSET_TABLE_, %rbx 141*0Sstevel@tonic-gate movq %rbx,%r9 142*0Sstevel@tonic-gate // addq $[.L2-.L1], %rbx 143*0Sstevel@tonic-gate movq %rbx,%r10 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate movq (%rbx),%rsi 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate / _setup(&eb[0], _DYNAMIC) 148*0Sstevel@tonic-gate call _setup@PLT 149*0Sstevel@tonic-gate / release stack frame 150*0Sstevel@tonic-gate movq %rbp,%rsp 151*0Sstevel@tonic-gate 152*0Sstevel@tonic-gate movq atexit_fini@GOTPCREL(%rip), %rdx 153*0Sstevel@tonic-gate / transfer control to a.out 154*0Sstevel@tonic-gate jmp *%rax 155*0Sstevel@tonic-gate .size _rt_boot,.-_rt_boot 156*0Sstevel@tonic-gate#endif 157