1 /* $NetBSD: mdprologue.S,v 1.8 2004/07/15 03:00:21 chs Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * SPARC run-time link editor entry points.
36 #define CRT_VERSION_SUN 1
38 .seg "text" ! [internal]
45 ! use mprotect() to make the data segment executable.
46 ! this is needed because the PLT is there. doh!
58 ! now we can continue as before.
62 sethi %hi((__GLOBAL_OFFSET_TABLE_-(L.1B-.))),%l7
65 or %l7,%lo((__GLOBAL_OFFSET_TABLE_-(L.1B-.))),%l7
68 cmp %i0, CRT_VERSION_SUN ! is crtp passed in Sun style,
69 bne 1f ! ie. relative to stack frame ?
71 add %i1, %fp, %i1 ! if so, adjust to absolute address
73 ld [%i1], %o3 ! load base address (crtp->crt_ba)
74 ld [%l7], %o2 ! get __DYNAMIC address
76 add %o2, %o3, %o2 ! relocate and make it 3rd arg.
78 ld [%l7 + _rtld], %g1 ! get address of rtld()
79 add %g1, %o3, %g1 ! relocate
81 mov %i1, %o1 ! set up args, #2: crtp
82 call %g1 ! rtld(version, crtp, dp)
83 mov %i0, %o0 ! arg #1: version
85 mov %o0, %i0 ! pass on rtld() return value
88 .seg "data" ! [internal]
97 ! sethi %hi((__GLOBAL_OFFSET_TABLE_-(L.1C-.))),%l7
99 ! or %l7,%lo((__GLOBAL_OFFSET_TABLE_-(L.1C-.))),%l7
102 sub %i7, 4, %o0 ! get to jmpslot through pc
103 ld [%i7+4], %o1 ! get relocation index
104 sethi %hi(0x3fffff), %o2 ! -> reloc_index & 0x003fffff
105 or %o2, %lo(0x3fffff), %o2 ! [internal]
106 call _binder ! and call binder(jsp, reloc_index)
109 mov %o0, %g1 ! return value == function address
111 restore ! get rid of our context
113 restore ! and the jmpslot context
116 .seg "data" ! [internal]