1 /* $NetBSD: rtld_start.S,v 1.14 2011/01/16 01:22:29 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>
40 stw %r3,12(%r1) # argc
41 stw %r4,16(%r1) # argv
42 stw %r5,20(%r1) # envp
43 /* stw %r6,24(%r1) # obj (always 0) */
44 /* stw %r7,28(%r1) # cleanup (always 0) */
45 stw %r8,32(%r1) # ps_strings
49 mr %r3,%r30 # save for _DYNAMIC
50 addis %r30,%r30,_GLOBAL_OFFSET_TABLE_-1b@ha
51 addi %r30,%r30,_GLOBAL_OFFSET_TABLE_-1b@l
52 addis %r3,%r3,_DYNAMIC-1b@ha # get _DYNAMIC actual address
53 addi %r3,%r3,_DYNAMIC-1b@l
54 lwz %r28,0(%r30) # get base-relative &_DYNAMIC
55 sub %r28,%r3,%r28 # r28 = relocbase
56 mr %r4,%r28 # r4 = relocbase
57 bl _rtld_relocate_nonplt_self
60 addi %r3,%r3,-12 # sp = &argv[-3] /* XXX */
61 mr %r4,%r28 # r4 = relocbase
62 bl _rtld # _start = _rtld(sp, relocbase)
65 lwz %r3,12(%r1) # argc
66 lwz %r4,16(%r1) # argv
67 lwz %r5,20(%r1) # envp
68 lwz %r6,-8(%r4) # obj = sp[1] (== argv[-2])
69 lwz %r7,-12(%r4) # cleanup = sp[0] (== argv[-3])
70 lwz %r8,32(%r1) # ps_strings
73 blrl # _start(argc, argv, envp, obj, cleanup, ps_strings)
83 * secure-plt expects %r11 to be the offset to the rela entry.
84 * bss-plt expects %r11 to be index of the rela entry.
85 * So for bss-plt, we multiply the index by 12 to get the offset.
87 ENTRY_NOPROFILE(_rtld_bind_bssplt_start)
91 ENTRY_NOPROFILE(_rtld_bind_secureplt_start)
96 stw %r0,16(%r1) # save lr
98 stw %r0,12(%r1) # save cr
99 stmw %r3,24(%r1) # save r3-r31
103 bl _rtld_bind # _rtld_bind(obj, reloff)
106 lmw %r3,24(%r1) # load r3-r31
107 lwz %r0,12(%r1) # restore cr
109 lwz %r0,16(%r1) # restore lr
115 END(_rtld_bind_start)
117 .globl _rtld_powerpc_pltcall
118 .globl _rtld_powerpc_pltresolve
120 _rtld_powerpc_pltcall:
122 addis %r11,%r11,0 # addis 11,11,jmptab@ha
123 lwz %r11,0(%r11) # lwz 11,jmptab@l(11)
127 _rtld_powerpc_pltresolve:
128 lis %r12,0 # lis 12,_rtld_bind_bssplt_start@ha
129 addi %r12,%r12,0 # addi 12,12,_rtld_bind_bssplt_start@l
131 lis %r12,0 # lis 12,obj@ha
132 addi %r12,%r12,0 # addi 12,12,obj@l