rtld_start.S revision 34192
134192Sjdp/*- 234192Sjdp * Copyright 1996-1998 John D. Polstra. 334192Sjdp * All rights reserved. 434192Sjdp * 534192Sjdp * Redistribution and use in source and binary forms, with or without 634192Sjdp * modification, are permitted provided that the following conditions 734192Sjdp * are met: 834192Sjdp * 1. Redistributions of source code must retain the above copyright 934192Sjdp * notice, this list of conditions and the following disclaimer. 1034192Sjdp * 2. Redistributions in binary form must reproduce the above copyright 1134192Sjdp * notice, this list of conditions and the following disclaimer in the 1234192Sjdp * documentation and/or other materials provided with the distribution. 1334192Sjdp * 1434192Sjdp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1534192Sjdp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1634192Sjdp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1734192Sjdp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1834192Sjdp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1934192Sjdp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2034192Sjdp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2134192Sjdp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2234192Sjdp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2334192Sjdp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2434192Sjdp * 2534192Sjdp * $Id: rtld_start.S,v 1.6 1998/03/05 21:05:53 jdp Exp $ 2634192Sjdp */ 2734192Sjdp 2834192Sjdp .text 2934192Sjdp .align 4 3034192Sjdp .globl .rtld_start 3134192Sjdp .type .rtld_start,@function 3234192Sjdp.rtld_start: 3334192Sjdp xorl %ebp,%ebp # Clear frame pointer for good form 3434192Sjdp movl %esp,%eax # Save initial stack pointer 3534192Sjdp subl $4,%esp # A place to store exit procedure addr 3634192Sjdp pushl %esp # Pass its address to rtld 3734192Sjdp pushl %eax # Pass initial stack pointer to rtld 3834192Sjdp call _rtld@PLT # Call rtld(sp); returns entry point 3934192Sjdp addl $8,%esp # Remove arguments from stack 4034192Sjdp popl %edx # Get exit procedure address 4134192Sjdp/* 4234192Sjdp * At this point, %eax contains the entry point of the main program, and 4334192Sjdp * %edx contains a pointer to a termination function that should be 4434192Sjdp * registered with atexit(). (crt1.o registers it.) 4534192Sjdp */ 4634192Sjdp.globl .rtld_goto_main 4734192Sjdp.rtld_goto_main: # This symbol exists just to make debugging easier. 4834192Sjdp jmp *%eax # Enter main program 4934192Sjdp 5034192Sjdp 5134192Sjdp/* 5234192Sjdp * Binder entry point. Control is transferred to here by code in the PLT. 5334192Sjdp * On entry, there are two arguments on the stack. In ascending address 5434192Sjdp * order, they are (1) "obj", a pointer to the calling object's Obj_Entry, 5534192Sjdp * and (2) "reloff", the byte offset of the appropriate relocation entry 5634192Sjdp * in the PLT relocation table. 5734192Sjdp * 5834192Sjdp * We are careful to preserve all registers, even the the caller-save 5934192Sjdp * registers. That is because this code may be invoked by low-level 6034192Sjdp * assembly-language code that is not ABI-compliant. 6134192Sjdp */ 6234192Sjdp .align 4 6334192Sjdp .globl _rtld_bind_start 6434192Sjdp .type _rtld_bind_start,@function 6534192Sjdp_rtld_bind_start: 6634192Sjdp pushf # Save eflags 6734192Sjdp pushl %eax # Save %eax 6834192Sjdp pushl %edx # Save %edx 6934192Sjdp pushl %ecx # Save %ecx 7034192Sjdp pushl 20(%esp) # Copy reloff argument 7134192Sjdp pushl 20(%esp) # Copy obj argument 7234192Sjdp 7334192Sjdp call _rtld_bind@PLT # Transfer control to the binder 7434192Sjdp /* Now %eax contains the entry point of the function being called. */ 7534192Sjdp 7634192Sjdp addl $8,%esp # Discard binder arguments 7734192Sjdp movl %eax,20(%esp) # Store target over obj argument 7834192Sjdp popl %ecx # Restore %ecx 7934192Sjdp popl %edx # Restore %edx 8034192Sjdp popl %eax # Restore %eax 8134192Sjdp popf # Restore eflags 8234192Sjdp leal 4(%esp),%esp # Discard reloff, do not change eflags 8334192Sjdp ret # "Return" to target address 84