1998-09-05 17:08:38 +04:00
|
|
|
/* $NetBSD: mdprologue.S,v 1.9 1998/09/05 13:08:38 pk Exp $ */
|
1998-01-06 01:00:34 +03:00
|
|
|
|
1998-09-05 17:08:38 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
1993-10-17 00:53:13 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1998-09-05 17:08:38 +04:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Paul Kranenburg.
|
|
|
|
*
|
1993-10-17 00:53:13 +03:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1998-09-05 17:08:38 +04:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
1993-10-17 00:53:13 +03:00
|
|
|
*
|
1998-09-05 17:08:38 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
1993-10-17 00:53:13 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* i386 run-time link editor entry points.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
|
|
|
|
.text
|
|
|
|
.globl _binder, _binder_entry
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _rtl(int version, struct crt_ldso *crtp)
|
|
|
|
*/
|
|
|
|
|
|
|
|
_rtl: # crt0 calls us here
|
|
|
|
pushl %ebp # Allocate stack frame
|
1994-10-26 22:41:13 +03:00
|
|
|
movl %esp,%ebp
|
1993-10-17 00:53:13 +03:00
|
|
|
pushl %ebx
|
1994-10-26 22:41:13 +03:00
|
|
|
|
1993-10-17 00:53:13 +03:00
|
|
|
call 1f # PIC function prologue
|
|
|
|
1:
|
|
|
|
popl %ebx
|
1994-10-26 22:41:13 +03:00
|
|
|
addl $_GLOBAL_OFFSET_TABLE_+[.-1b],%ebx
|
1993-10-17 00:53:13 +03:00
|
|
|
|
1994-10-26 22:41:13 +03:00
|
|
|
movl 12(%ebp),%eax # Extract data from interface structure
|
1993-10-17 00:53:13 +03:00
|
|
|
movl (%eax),%eax # base address of ld.so (first field)
|
|
|
|
# setup arguments for rtld()
|
1994-10-26 22:41:13 +03:00
|
|
|
movl (%ebx),%ecx # 1st entry in GOT is our __DYNAMIC
|
|
|
|
addl %eax,%ecx # add load address
|
1993-10-17 00:53:13 +03:00
|
|
|
pushl %ecx # 3rd arg
|
|
|
|
pushl 12(%ebp) # 2nd arg == &crt.
|
|
|
|
pushl 8(%ebp) # 1st arg == version
|
1994-10-26 22:41:13 +03:00
|
|
|
addl _rtld@GOT(%ebx),%eax # relocate address of function
|
1993-10-17 00:53:13 +03:00
|
|
|
call %eax # _rtld(version, crtp, DYNAMIC)
|
|
|
|
addl $12,%esp # pop arguments
|
|
|
|
|
1994-10-26 22:41:13 +03:00
|
|
|
popl %ebx
|
|
|
|
leave # remove stack frame
|
1994-12-04 10:42:44 +03:00
|
|
|
ret
|
1993-10-17 00:53:13 +03:00
|
|
|
|
|
|
|
# First call to a procedure generally comes through here for
|
|
|
|
# binding.
|
|
|
|
|
|
|
|
_binder_entry:
|
|
|
|
pushl %ebp # setup a stack frame
|
1994-10-26 22:41:13 +03:00
|
|
|
movl %esp,%ebp
|
1993-10-17 00:53:13 +03:00
|
|
|
pusha # save all regs
|
|
|
|
|
1994-10-26 22:41:13 +03:00
|
|
|
xorl %eax,%eax # clear
|
|
|
|
movl 4(%ebp),%esi # return address in PLT
|
|
|
|
movw (%esi),%ax # get hold of relocation number
|
|
|
|
subl $6,%esi # make it point to the jmpslot
|
1993-10-17 00:53:13 +03:00
|
|
|
|
|
|
|
pushl %eax # pushd arguments
|
|
|
|
pushl %esi #
|
|
|
|
call _binder@PLT # _binder(rpc, index)
|
1994-10-26 22:41:13 +03:00
|
|
|
addl $8,%esp # pop arguments
|
|
|
|
movl %eax,4(%ebp) # return value from _binder() == actual
|
1993-10-17 00:53:13 +03:00
|
|
|
# address of function
|
|
|
|
popa # restore regs
|
|
|
|
leave # remove our stack frame
|
|
|
|
ret
|