1 /* $NetBSD: rtld_start64.S,v 1.2 2014/03/06 19:19:40 matt Exp $ */
4 * Copyright (C) 1998 Tsubai Masanari
5 * Portions copyright 2002 Charles M. Hannum <root@ihack.net>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <machine/asm.h>
33 .globl _rtld_relocate_nonplt_self
37 ENTRY_NOPROFILE(_rtld_start)
41 /* mr %r26,%r6 // obj (always 0) */
42 /* mr %r27,%r7 // cleanup (always 0) */
43 mr %r28,%r8 // ps_strings
45 stdu %r0,-64(%r1) // terminate stack chain
46 std %r2,40(%r1) // save TOC
47 std %r0,16(%r1) // ditto
51 ld %r3,0(%r2) // TOC[0] = &TOC
52 sub %r29,%r2,%r3 // compute relocbase
54 addis %r3,%r3,_DYNAMIC-1b@ha // get _DYNAMIC actual address
55 addi %r3,%r3,_DYNAMIC-1b@l
56 mr %r4,%r29 // r4 = relocbase
57 CALL(_rtld_relocate_nonplt_self)
59 addi %r3,%r1,48 // sp = <local variable space>
60 mr %r4,%r29 // r4 = relocbase
61 CALL(_rtld) // _start = _rtld(sp, relocbase)
63 ld %r0,0(%r3) // func address
64 ld %r2,8(%r3) // TOC address
65 ld %r11,16(%r3) // environment pointer
66 mtctr %r0 // so we can call it.
71 ld %r6,56(%r1) // obj = <localvar>[1]
72 ld %r7,48(%r1) // cleanup = <localvar>[0]
73 mr %r8,%r28 // ps_strings
75 bctrl // _start(argc, argv, envp, obj, cleanup, ps_strings)
85 * %r0 has the index of the rela, %r12 has a pointer to the plt entry.
87 ENTRY_NOPROFILE(_rtld_bind_start)
88 std %r3,-72(%r1) // save argument register
89 std %r4,-64(%r1) // save argument register
90 std %r5,-56(%r1) // save argument register
91 std %r6,-48(%r1) // save argument register
92 std %r7,-40(%r1) // save argument register
93 std %r8,-32(%r1) // save argument register
94 std %r9,-24(%r1) // save argument register
95 std %r10,-16(%r1) // save argument register
96 std %r31,-8(%r1) // save register
97 stdu %r1,-(48+80)(%r1) // create back chain
99 std %r10,16(%r1) // save LR
101 std %r9,8(%r1) // save CR to be safe
103 mr %r31, %r12 // save this across bind call
105 mr %r4, %r0 // reloff
107 CALL(_rtld_bind) // _rtld_bind(obj, reloff)
110 mr %r12,%r31 // restore r12
112 ld %r0,8(%r1) // get saved CR
113 mtcr %r0 // restore it
114 ld %r0,16(%r1) // get saved LR
115 mtlr %r0 // restore it
117 addi %r1,%r1,(48+80) // adjust stack
118 ld %r3,-72(%r1) // restore argument register
119 ld %r4,-64(%r1) // restore argument register
120 ld %r5,-56(%r1) // restore argument register
121 ld %r6,-48(%r1) // restore argument register
122 ld %r7,-40(%r1) // restore argument register
123 ld %r8,-32(%r1) // restore argument register
124 ld %r9,-24(%r1) // restore argument register
125 ld %r10,-16(%r1) // restore argument register
126 ld %r31,-8(%r1) // restore register
128 END(_rtld_bind_start)