1 /* $NetBSD: mdprologue.S,v 1.10 1999/06/28 17:28:56 ragge Exp $ */
4 * Copyright (c) 1998 Matt Thomas <matt@3am-software.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * i386 run-time link editor entry points.
35 .globl _binder, _binder_entry
40 * _rtl(int version, struct crt_ldso *crtp)
44 _rtl: /* crt0 calls us here */
45 .word 0 /* no registers to save */
46 movl 8(%ap),%r0 /* load crtp into %r0 */
47 /* setup arguments for rtld() */
49 * Add the 1st entry in the GOT (e.g. __DYNAMIC) to the base
50 * address of ld.so and pushd that onto the stack.
52 addl3 __GLOBAL_OFFSET_TABLE_,(%r0),-(%sp)
53 pushl %r0 /* 2nd arg == crtp */
54 pushl 4(%ap) /* 1st arg == version */
55 calls $3,_rtld /* _rtld(version, crtp, DYNAMIC) */
56 movpsl -(%sp) /* flush the instruction cache */
57 pushab 1f /* by issuing an */
62 * First call to a procedure generally comes through here for binding.
63 * We got here via JSB so now (%sp) is inside our jmpslot_t. So we
64 * simply preserve our registers, push the address of jmpslot_t for
65 * _binder. Save the address we are supported to call (which was
66 * returned in R0) in the stack location that the JSB used to store
67 * its return address (which we don't care about anymore).
69 * Check to see the function has a zero entry mask. Since we
70 * were called with a zero entry, if the function we need to call
71 * also has a zero entry mask, we can let it use our call frame
72 * and jump inside of it to its first instruction. Otherwise we'll
73 * call the actual function the slow way and return.
75 * The above optimization is required in order for vfork(2) to
76 * work properly in shared libraries. DO NOT REMOVE IT.
79 .type _binder_entry,@label
81 pushr $0x3f /* save %r0 to %r5 */
88 subl3 $8, 24(%sp), -(%sp) /* point to beginning of jmpslot */
90 calls $1, _binder /* _binder(jsp) */
91 movpsl -(%sp) /* flush the instruction cache */
92 pushab 1f /* by issuing an */
94 1: movl %r0, 24(%sp) /* save return address onto stack */
95 bicw3 6(%fp),(%r0),%r0 /* does the entry mask save any additional regs */
96 popr $0x3f /* restore %r0 to %r5 (cond flags aren't modified) */
97 bneq 2f /* yes? do it the hard way */
98 addl2 $2,(%sp) /* no? skip past the mask */
99 rsb /* and jump to it */
100 2: callg (%ap), *(%sp)+ /* return value from _binder() == actual */
103 LC1: .asciz "ld.so: entered _binder_entry\n"