2 * Copyright 1996-1998 John D. Polstra.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * $FreeBSD: src/libexec/rtld-elf/i386/rtld_start.S,v 1.3 1999/08/28 00:10:15 peter Exp $
26 * $DragonFly: src/libexec/rtld-elf/i386/rtld_start.S,v 1.4 2008/01/08 00:02:04 corecode Exp $
33 .type .rtld_start,@function
36 xorl %ebp,%ebp # Clear frame pointer for good form
37 movl %esp,%eax # Save initial stack pointer
38 subl $8,%esp # A place to store exit procedure addr
39 movl %esp,%ebx # save address of exit proc
40 movl %esp,%ecx # construct address of obj_main
42 pushl %ecx # Pass address of obj_main
43 pushl %ebx # Pass address of exit proc
44 pushl %eax # Pass initial stack pointer to rtld
45 call _rtld@PLT # Call rtld(sp); returns entry point
46 addl $12,%esp # Remove arguments from stack
47 popl %edx # Get exit procedure address
48 addl $4,%esp # Ignore obj_main
50 * At this point, %eax contains the entry point of the main program, and
51 * %edx contains a pointer to a termination function that should be
52 * registered with atexit(). (crt1.o registers it.)
54 .globl .rtld_goto_main
55 .rtld_goto_main: # This symbol exists just to make debugging easier.
56 jmp *%eax # Enter main program
60 * Binder entry point. Control is transferred to here by code in the PLT.
61 * On entry, there are two arguments on the stack. In ascending address
62 * order, they are (1) "obj", a pointer to the calling object's Obj_Entry,
63 * and (2) "reloff", the byte offset of the appropriate relocation entry
64 * in the PLT relocation table.
66 * We are careful to preserve all registers, even the the caller-save
67 * registers. That is because this code may be invoked by low-level
68 * assembly-language code that is not ABI-compliant.
71 .globl _rtld_bind_start
72 .type _rtld_bind_start,@function
75 pushl %eax # Save %eax
76 pushl %edx # Save %edx
77 pushl %ecx # Save %ecx
78 leal 24(%esp),%eax # Calculate original stack addr
79 pushl %eax # Pass stack addr as 3. arg
80 pushl 24(%esp) # Copy reloff argument
81 pushl 24(%esp) # Copy obj argument
83 call _rtld_bind@PLT # Transfer control to the binder
84 /* Now %eax contains the entry point of the function being called. */
86 addl $12,%esp # Discard binder arguments
87 movl %eax,20(%esp) # Store target over obj argument
88 popl %ecx # Restore %ecx
89 popl %edx # Restore %edx
90 popl %eax # Restore %eax
92 leal 4(%esp),%esp # Discard reloff, do not change eflags
93 ret # "Return" to target address