rtld_start.S revision 1.14 1 1.14 matt /* $NetBSD: rtld_start.S,v 1.14 2011/01/16 01:22:29 matt Exp $ */
2 1.1 tsubai
3 1.1 tsubai /*-
4 1.1 tsubai * Copyright (C) 1998 Tsubai Masanari
5 1.11 mycroft * Portions copyright 2002 Charles M. Hannum <root (at) ihack.net>
6 1.1 tsubai * All rights reserved.
7 1.1 tsubai *
8 1.1 tsubai * Redistribution and use in source and binary forms, with or without
9 1.1 tsubai * modification, are permitted provided that the following conditions
10 1.1 tsubai * are met:
11 1.1 tsubai * 1. Redistributions of source code must retain the above copyright
12 1.1 tsubai * notice, this list of conditions and the following disclaimer.
13 1.1 tsubai * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 tsubai * notice, this list of conditions and the following disclaimer in the
15 1.1 tsubai * documentation and/or other materials provided with the distribution.
16 1.1 tsubai * 3. The name of the author may not be used to endorse or promote products
17 1.1 tsubai * derived from this software without specific prior written permission.
18 1.1 tsubai *
19 1.1 tsubai * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 1.1 tsubai * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 1.1 tsubai * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 1.1 tsubai * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 1.1 tsubai * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 1.1 tsubai * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 1.1 tsubai * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 1.1 tsubai * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 1.1 tsubai * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 1.1 tsubai * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 1.1 tsubai */
30 1.1 tsubai
31 1.1 tsubai #include <machine/asm.h>
32 1.1 tsubai
33 1.1 tsubai .globl _rtld_start
34 1.1 tsubai .globl _rtld
35 1.1 tsubai
36 1.1 tsubai .text
37 1.1 tsubai
38 1.1 tsubai _rtld_start:
39 1.12 matt stwu %r1,-48(%r1)
40 1.12 matt stw %r3,12(%r1) # argc
41 1.12 matt stw %r4,16(%r1) # argv
42 1.12 matt stw %r5,20(%r1) # envp
43 1.12 matt /* stw %r6,24(%r1) # obj (always 0) */
44 1.12 matt /* stw %r7,28(%r1) # cleanup (always 0) */
45 1.12 matt stw %r8,32(%r1) # ps_strings
46 1.1 tsubai
47 1.14 matt bcl 20,31,1f
48 1.14 matt 1: mflr %r30
49 1.14 matt mr %r3,%r30 # save for _DYNAMIC
50 1.14 matt addis %r30,%r30,_GLOBAL_OFFSET_TABLE_-1b@ha
51 1.14 matt addi %r30,%r30,_GLOBAL_OFFSET_TABLE_-1b@l
52 1.14 matt addis %r3,%r3,_DYNAMIC-1b@ha # get _DYNAMIC actual address
53 1.14 matt addi %r3,%r3,_DYNAMIC-1b@l
54 1.14 matt lwz %r28,0(%r30) # get base-relative &_DYNAMIC
55 1.14 matt sub %r28,%r3,%r28 # r28 = relocbase
56 1.13 thorpej mr %r4,%r28 # r4 = relocbase
57 1.14 matt bl _rtld_relocate_nonplt_self
58 1.1 tsubai
59 1.12 matt lwz %r3,16(%r1)
60 1.12 matt addi %r3,%r3,-12 # sp = &argv[-3] /* XXX */
61 1.13 thorpej mr %r4,%r28 # r4 = relocbase
62 1.14 matt bl _rtld # _start = _rtld(sp, relocbase)
63 1.12 matt mtlr %r3
64 1.1 tsubai
65 1.12 matt lwz %r3,12(%r1) # argc
66 1.12 matt lwz %r4,16(%r1) # argv
67 1.12 matt lwz %r5,20(%r1) # envp
68 1.12 matt lwz %r6,-8(%r4) # obj = sp[1] (== argv[-2])
69 1.12 matt lwz %r7,-12(%r4) # cleanup = sp[0] (== argv[-3])
70 1.12 matt lwz %r8,32(%r1) # ps_strings
71 1.1 tsubai
72 1.12 matt addi %r1,%r1,48
73 1.1 tsubai blrl # _start(argc, argv, envp, obj, cleanup, ps_strings)
74 1.1 tsubai
75 1.12 matt li %r0,1 # _exit()
76 1.1 tsubai sc
77 1.1 tsubai
78 1.14 matt END(_rtld_start)
79 1.1 tsubai
80 1.10 mycroft .globl _rtld_bind
81 1.1 tsubai
82 1.14 matt /*
83 1.14 matt * secure-plt expects %r11 to be the offset to the rela entry.
84 1.14 matt * bss-plt expects %r11 to be index of the rela entry.
85 1.14 matt * So for bss-plt, we multiply the index by 12 to get the offset.
86 1.14 matt */
87 1.14 matt ENTRY_NOPROFILE(_rtld_bind_bssplt_start)
88 1.14 matt slwi %r11,%r11,2
89 1.14 matt add %r0,%r11,%r11
90 1.14 matt add %r11,%r11,%r0
91 1.14 matt ENTRY_NOPROFILE(_rtld_bind_secureplt_start)
92 1.12 matt stwu %r1,-160(%r1)
93 1.4 mycroft
94 1.12 matt stw %r0,20(%r1)
95 1.12 matt mflr %r0
96 1.12 matt stw %r0,16(%r1) # save lr
97 1.12 matt mfcr %r0
98 1.12 matt stw %r0,12(%r1) # save cr
99 1.12 matt stmw %r3,24(%r1) # save r3-r31
100 1.1 tsubai
101 1.12 matt mr %r3,%r12 # obj
102 1.12 matt mr %r4,%r11 # reloff
103 1.14 matt bl _rtld_bind # _rtld_bind(obj, reloff)
104 1.12 matt mtctr %r3
105 1.1 tsubai
106 1.12 matt lmw %r3,24(%r1) # load r3-r31
107 1.12 matt lwz %r0,12(%r1) # restore cr
108 1.12 matt mtcr %r0
109 1.12 matt lwz %r0,16(%r1) # restore lr
110 1.12 matt mtlr %r0
111 1.12 matt lwz %r0,20(%r1)
112 1.4 mycroft
113 1.12 matt addi %r1,%r1,160
114 1.1 tsubai bctr
115 1.14 matt END(_rtld_bind_start)
116 1.1 tsubai
117 1.1 tsubai .globl _rtld_powerpc_pltcall
118 1.1 tsubai .globl _rtld_powerpc_pltresolve
119 1.1 tsubai
120 1.1 tsubai _rtld_powerpc_pltcall:
121 1.12 matt slwi %r11,%r11,2
122 1.12 matt addis %r11,%r11,0 # addis 11,11,jmptab@ha
123 1.12 matt lwz %r11,0(%r11) # lwz 11,jmptab@l(11)
124 1.12 matt mtctr %r11
125 1.1 tsubai bctr
126 1.1 tsubai
127 1.1 tsubai _rtld_powerpc_pltresolve:
128 1.14 matt lis %r12,0 # lis 12,_rtld_bind_bssplt_start@ha
129 1.14 matt addi %r12,%r12,0 # addi 12,12,_rtld_bind_bssplt_start@l
130 1.12 matt mtctr %r12
131 1.12 matt lis %r12,0 # lis 12,obj@ha
132 1.12 matt addi %r12,%r12,0 # addi 12,12,obj@l
133 1.1 tsubai bctr
134