1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22/* 23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 .file "_rtboot.s" 28 29/ bootstrap routine for run-time linker 30/ we get control from exec which has loaded our text and 31/ data into the process' address space and created the process 32/ stack 33/ 34/ on entry, the process stack looks like this: 35/ 36/ # <- %esp 37/_______________________# high addresses 38/ strings # 39/_______________________# 40/ 0 word # 41/_______________________# 42/ Auxiliary # 43/ entries # 44/ ... # 45/ (size varies) # 46/_______________________# 47/ 0 word # 48/_______________________# 49/ Environment # 50/ pointers # 51/ ... # 52/ (one word each) # 53/_______________________# 54/ 0 word # 55/_______________________# 56/ Argument # low addresses 57/ pointers # 58/ Argc words # 59/_______________________# 60/ argc # 61/_______________________# <- %ebp 62 63#include <SYS.h> 64 65 .set EB_NULL,0 66 .set EB_DYNAMIC,1 67 .set EB_LDSO_BASE,2 68 .set EB_ARGV,3 69 .set EB_ENVP,4 70 .set EB_AUXV,5 71 .set EB_DEVZERO,6 72 .set EB_PAGESIZE,7 73 .set EB_MAX,8 74 .set EB_MAX_SIZE32,64 75 76 .text 77 .globl __rtboot 78 .globl __rtld 79 .type __rtboot,@function 80 .align 4 81__rtboot: 82 movl %esp,%ebp 83 subl $EB_MAX_SIZE32,%esp / make room for a max sized boot vector 84 movl %esp,%esi / use esi as a pointer to &eb[0] 85 movl $EB_ARGV,0(%esi) / set up tag for argv 86 leal 4(%ebp),%eax / get address of argv 87 movl %eax,4(%esi) / put after tag 88 movl $EB_ENVP,8(%esi) / set up tag for envp 89 movl (%ebp),%eax / get # of args 90 addl $2,%eax / one for the zero & one for argc 91 leal (%ebp,%eax,4),%edi / now points past args & @ envp 92 movl %edi,12(%esi) / set envp 93 addl $-4,%edi / start loop at &env[-1] 94.L00: addl $4,%edi / next 95 cmpl $0,(%edi) / search for 0 at end of env 96 jne .L00 97 addl $4,%edi / advance past 0 98 movl $EB_AUXV,16(%esi) / set up tag for auxv 99 movl %edi,20(%esi) / point to auxv 100 movl $EB_NULL,24(%esi) / set up NULL tag 101 call .L01 / only way to get IP into a register 102.L01: popl %ebx / pop the IP we just "pushed" 103 leal s.EMPTY - .L01(%ebx),%eax 104 pushl %eax 105 leal s.ZERO - .L01(%ebx),%eax 106 pushl %eax 107 leal s.LDSO - .L01(%ebx),%eax 108 pushl %eax 109 movl %esp,%edi / save pointer to strings 110 leal f.MUNMAP - .L01(%ebx),%eax 111 pushl %eax 112 leal f.CLOSE - .L01(%ebx),%eax 113 pushl %eax 114 leal f.SYSCONFIG - .L01(%ebx),%eax 115 pushl %eax 116 leal f.FSTATAT - .L01(%ebx),%eax 117 pushl %eax 118 leal f.MMAP - .L01(%ebx),%eax 119 pushl %eax 120 leal f.OPENAT - .L01(%ebx),%eax 121 pushl %eax 122 leal f.PANIC - .L01(%ebx),%eax 123 pushl %eax 124 movl %esp,%ecx / save pointer to functions 125 126 pushl %ecx / address of functions 127 pushl %edi / address of strings 128 pushl %esi / &eb[0] 129 call __rtld / __rtld(&eb[0], strings, funcs) 130 movl %esi,%esp / restore the stack (but leaving boot vector) 131 jmp *%eax / transfer control to ld.so.1 132 .size __rtboot,.-__rtboot 133 134 .align 4 135s.LDSO: .string "/usr/lib/ld.so.1" 136s.ZERO: .string "/dev/zero" 137s.EMPTY: .string "(null)" 138s.ERROR: .string ": no (or bad) /usr/lib/ld.so.1\n" 139l.ERROR: 140 141 .align 4 142f.PANIC: 143 movl %esp,%ebp 144/ Add using of argument string 145 pushl $l.ERROR - s.ERROR 146 call .L02 147.L02: popl %ebx 148 leal s.ERROR - .L02(%ebx),%eax 149 pushl %eax 150 pushl $2 151 call f.WRITE 152 jmp f.EXIT 153/ Not reached 154 155f.OPENAT: 156 movl $SYS_openat,%eax 157 jmp __syscall 158f.MMAP: 159 movl $SYS_mmap,%eax 160 jmp __syscall 161f.MUNMAP: 162 movl $SYS_munmap,%eax 163 jmp __syscall 164f.READ: 165 movl $SYS_read,%eax 166 jmp __syscall 167f.WRITE: 168 movl $SYS_write,%eax 169 jmp __syscall 170f.LSEEK: 171 movl $SYS_lseek,%eax 172 jmp __syscall 173f.CLOSE: 174 movl $SYS_close,%eax 175 jmp __syscall 176f.FSTATAT: 177 movl $SYS_fstatat,%eax 178 jmp __syscall 179f.SYSCONFIG: 180 movl $SYS_sysconfig,%eax 181 jmp __syscall 182f.EXIT: 183 movl $SYS_exit,%eax 184/ jmp __syscall 185__syscall: 186 int $T_SYSCALLINT 187 jc __err_exit 188 ret 189__err_exit: 190 movl $-1,%eax 191 ret 192