10Sstevel@tonic-gate/* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57298SMark.J.Nelson@Sun.COM * Common Development and Distribution License (the "License"). 67298SMark.J.Nelson@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*11798SRoger.Faulkner@Sun.COM 220Sstevel@tonic-gate/* 23*11798SRoger.Faulkner@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 277298SMark.J.Nelson@Sun.COM .file "_rtboot.s" 280Sstevel@tonic-gate 290Sstevel@tonic-gate/ bootstrap routine for run-time linker 300Sstevel@tonic-gate/ we get control from exec which has loaded our text and 310Sstevel@tonic-gate/ data into the process' address space and created the process 320Sstevel@tonic-gate/ stack 330Sstevel@tonic-gate/ 340Sstevel@tonic-gate/ on entry, the process stack looks like this: 350Sstevel@tonic-gate/ 360Sstevel@tonic-gate/ # <- %esp 370Sstevel@tonic-gate/_______________________# high addresses 380Sstevel@tonic-gate/ strings # 390Sstevel@tonic-gate/_______________________# 400Sstevel@tonic-gate/ 0 word # 410Sstevel@tonic-gate/_______________________# 420Sstevel@tonic-gate/ Auxiliary # 430Sstevel@tonic-gate/ entries # 440Sstevel@tonic-gate/ ... # 450Sstevel@tonic-gate/ (size varies) # 460Sstevel@tonic-gate/_______________________# 470Sstevel@tonic-gate/ 0 word # 480Sstevel@tonic-gate/_______________________# 490Sstevel@tonic-gate/ Environment # 500Sstevel@tonic-gate/ pointers # 510Sstevel@tonic-gate/ ... # 520Sstevel@tonic-gate/ (one word each) # 530Sstevel@tonic-gate/_______________________# 540Sstevel@tonic-gate/ 0 word # 550Sstevel@tonic-gate/_______________________# 560Sstevel@tonic-gate/ Argument # low addresses 570Sstevel@tonic-gate/ pointers # 580Sstevel@tonic-gate/ Argc words # 590Sstevel@tonic-gate/_______________________# 600Sstevel@tonic-gate/ argc # 610Sstevel@tonic-gate/_______________________# <- %ebp 620Sstevel@tonic-gate 630Sstevel@tonic-gate#include <SYS.h> 640Sstevel@tonic-gate 650Sstevel@tonic-gate .set EB_NULL,0 660Sstevel@tonic-gate .set EB_DYNAMIC,1 670Sstevel@tonic-gate .set EB_LDSO_BASE,2 680Sstevel@tonic-gate .set EB_ARGV,3 690Sstevel@tonic-gate .set EB_ENVP,4 700Sstevel@tonic-gate .set EB_AUXV,5 710Sstevel@tonic-gate .set EB_DEVZERO,6 720Sstevel@tonic-gate .set EB_PAGESIZE,7 730Sstevel@tonic-gate .set EB_MAX,8 740Sstevel@tonic-gate .set EB_MAX_SIZE32,64 750Sstevel@tonic-gate 760Sstevel@tonic-gate .text 770Sstevel@tonic-gate .globl __rtboot 780Sstevel@tonic-gate .globl __rtld 790Sstevel@tonic-gate .type __rtboot,@function 800Sstevel@tonic-gate .align 4 810Sstevel@tonic-gate__rtboot: 820Sstevel@tonic-gate movl %esp,%ebp 830Sstevel@tonic-gate subl $EB_MAX_SIZE32,%esp / make room for a max sized boot vector 840Sstevel@tonic-gate movl %esp,%esi / use esi as a pointer to &eb[0] 850Sstevel@tonic-gate movl $EB_ARGV,0(%esi) / set up tag for argv 860Sstevel@tonic-gate leal 4(%ebp),%eax / get address of argv 870Sstevel@tonic-gate movl %eax,4(%esi) / put after tag 880Sstevel@tonic-gate movl $EB_ENVP,8(%esi) / set up tag for envp 890Sstevel@tonic-gate movl (%ebp),%eax / get # of args 900Sstevel@tonic-gate addl $2,%eax / one for the zero & one for argc 910Sstevel@tonic-gate leal (%ebp,%eax,4),%edi / now points past args & @ envp 920Sstevel@tonic-gate movl %edi,12(%esi) / set envp 930Sstevel@tonic-gate addl $-4,%edi / start loop at &env[-1] 940Sstevel@tonic-gate.L00: addl $4,%edi / next 950Sstevel@tonic-gate cmpl $0,(%edi) / search for 0 at end of env 960Sstevel@tonic-gate jne .L00 970Sstevel@tonic-gate addl $4,%edi / advance past 0 980Sstevel@tonic-gate movl $EB_AUXV,16(%esi) / set up tag for auxv 990Sstevel@tonic-gate movl %edi,20(%esi) / point to auxv 1000Sstevel@tonic-gate movl $EB_NULL,24(%esi) / set up NULL tag 1010Sstevel@tonic-gate call .L01 / only way to get IP into a register 1020Sstevel@tonic-gate.L01: popl %ebx / pop the IP we just "pushed" 1030Sstevel@tonic-gate leal s.EMPTY - .L01(%ebx),%eax 1040Sstevel@tonic-gate pushl %eax 1050Sstevel@tonic-gate leal s.ZERO - .L01(%ebx),%eax 1060Sstevel@tonic-gate pushl %eax 1070Sstevel@tonic-gate leal s.LDSO - .L01(%ebx),%eax 1080Sstevel@tonic-gate pushl %eax 1090Sstevel@tonic-gate movl %esp,%edi / save pointer to strings 1100Sstevel@tonic-gate leal f.MUNMAP - .L01(%ebx),%eax 1110Sstevel@tonic-gate pushl %eax 1120Sstevel@tonic-gate leal f.CLOSE - .L01(%ebx),%eax 1130Sstevel@tonic-gate pushl %eax 1140Sstevel@tonic-gate leal f.SYSCONFIG - .L01(%ebx),%eax 1150Sstevel@tonic-gate pushl %eax 116*11798SRoger.Faulkner@Sun.COM leal f.FSTATAT - .L01(%ebx),%eax 1170Sstevel@tonic-gate pushl %eax 1180Sstevel@tonic-gate leal f.MMAP - .L01(%ebx),%eax 1190Sstevel@tonic-gate pushl %eax 120*11798SRoger.Faulkner@Sun.COM leal f.OPENAT - .L01(%ebx),%eax 1210Sstevel@tonic-gate pushl %eax 1220Sstevel@tonic-gate leal f.PANIC - .L01(%ebx),%eax 1230Sstevel@tonic-gate pushl %eax 1240Sstevel@tonic-gate movl %esp,%ecx / save pointer to functions 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate pushl %ecx / address of functions 1270Sstevel@tonic-gate pushl %edi / address of strings 1280Sstevel@tonic-gate pushl %esi / &eb[0] 1290Sstevel@tonic-gate call __rtld / __rtld(&eb[0], strings, funcs) 1300Sstevel@tonic-gate movl %esi,%esp / restore the stack (but leaving boot vector) 1310Sstevel@tonic-gate jmp *%eax / transfer control to ld.so.1 1320Sstevel@tonic-gate .size __rtboot,.-__rtboot 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate .align 4 1350Sstevel@tonic-gates.LDSO: .string "/usr/lib/ld.so.1" 1360Sstevel@tonic-gates.ZERO: .string "/dev/zero" 1370Sstevel@tonic-gates.EMPTY: .string "(null)" 1380Sstevel@tonic-gates.ERROR: .string ": no (or bad) /usr/lib/ld.so.1\n" 1390Sstevel@tonic-gatel.ERROR: 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate .align 4 1420Sstevel@tonic-gatef.PANIC: 1430Sstevel@tonic-gate movl %esp,%ebp 1440Sstevel@tonic-gate/ Add using of argument string 1450Sstevel@tonic-gate pushl $l.ERROR - s.ERROR 1460Sstevel@tonic-gate call .L02 1470Sstevel@tonic-gate.L02: popl %ebx 1480Sstevel@tonic-gate leal s.ERROR - .L02(%ebx),%eax 1490Sstevel@tonic-gate pushl %eax 1500Sstevel@tonic-gate pushl $2 1510Sstevel@tonic-gate call f.WRITE 1520Sstevel@tonic-gate jmp f.EXIT 1530Sstevel@tonic-gate/ Not reached 1540Sstevel@tonic-gate 155*11798SRoger.Faulkner@Sun.COMf.OPENAT: 156*11798SRoger.Faulkner@Sun.COM movl $SYS_openat,%eax 1570Sstevel@tonic-gate jmp __syscall 1580Sstevel@tonic-gatef.MMAP: 1590Sstevel@tonic-gate movl $SYS_mmap,%eax 1600Sstevel@tonic-gate jmp __syscall 1610Sstevel@tonic-gatef.MUNMAP: 1620Sstevel@tonic-gate movl $SYS_munmap,%eax 1630Sstevel@tonic-gate jmp __syscall 1640Sstevel@tonic-gatef.READ: 1650Sstevel@tonic-gate movl $SYS_read,%eax 1660Sstevel@tonic-gate jmp __syscall 1670Sstevel@tonic-gatef.WRITE: 1680Sstevel@tonic-gate movl $SYS_write,%eax 1690Sstevel@tonic-gate jmp __syscall 1700Sstevel@tonic-gatef.LSEEK: 1710Sstevel@tonic-gate movl $SYS_lseek,%eax 1720Sstevel@tonic-gate jmp __syscall 1730Sstevel@tonic-gatef.CLOSE: 1740Sstevel@tonic-gate movl $SYS_close,%eax 1750Sstevel@tonic-gate jmp __syscall 176*11798SRoger.Faulkner@Sun.COMf.FSTATAT: 177*11798SRoger.Faulkner@Sun.COM movl $SYS_fstatat,%eax 1780Sstevel@tonic-gate jmp __syscall 1790Sstevel@tonic-gatef.SYSCONFIG: 1800Sstevel@tonic-gate movl $SYS_sysconfig,%eax 1810Sstevel@tonic-gate jmp __syscall 1820Sstevel@tonic-gatef.EXIT: 1830Sstevel@tonic-gate movl $SYS_exit,%eax 1840Sstevel@tonic-gate/ jmp __syscall 1850Sstevel@tonic-gate__syscall: 1860Sstevel@tonic-gate int $T_SYSCALLINT 1870Sstevel@tonic-gate jc __err_exit 1880Sstevel@tonic-gate ret 1890Sstevel@tonic-gate__err_exit: 1900Sstevel@tonic-gate movl $-1,%eax 1910Sstevel@tonic-gate ret 192