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