rtld_start.S revision 1.10 1 /* $NetBSD: rtld_start.S,v 1.10 2002/09/25 07:27:53 mycroft Exp $ */
2
3 /*-
4 * Copyright (C) 1998 Tsubai Masanari
5 * Portions copyright 2002 Charles M. Hannum.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
18 *
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.
29 */
30
31 #include <machine/asm.h>
32
33 .globl _rtld_start
34 .globl _rtld
35
36 .text
37
38 _rtld_start:
39 stwu 1,-48(1)
40 stw 3,12(1) # argc
41 stw 4,16(1) # argv
42 stw 5,20(1) # envp
43 /* stw 6,24(1) # obj (always 0) */
44 /* stw 7,28(1) # cleanup (always 0) */
45 stw 8,32(1) # ps_strings
46
47 bl _GLOBAL_OFFSET_TABLE_@local-4
48 mflr 31 # r31 = (real) GOT
49 lwz 30,_GLOBAL_OFFSET_TABLE_@got(31)
50 # the linker thought GOT were ...
51 lwz 3,_DYNAMIC@got(31)
52
53 subf 4,30,31 # r4 = relocbase
54 add 3,3,4 # r3 = &_DYNAMIC
55 bl _rtld_relocate_nonplt_self@plt
56
57 subf 4,30,31 # r4 = relocbase
58 lwz 3,16(1)
59 addi 3,3,-12 # sp = &argv[-3] /* XXX */
60 bl _rtld@plt # _start = _rtld(sp, relocbase)
61 mtlr 3
62
63 lwz 3,12(1) # argc
64 lwz 4,16(1) # argv
65 lwz 5,20(1) # envp
66 lwz 6,-8(4) # obj = sp[1] (== argv[-2])
67 lwz 7,-12(4) # cleanup = sp[0] (== argv[-3])
68 lwz 8,32(1) # ps_strings
69
70 addi 1,1,48
71 blrl # _start(argc, argv, envp, obj, cleanup, ps_strings)
72
73 li 0,1 # _exit()
74 sc
75
76
77 .globl _rtld_bind_start
78 .globl _rtld_bind
79
80 _rtld_bind_start:
81 stwu 1,-160(1)
82
83 stw 0,20(1)
84 mflr 0
85 stw 0,16(1) # save lr
86 mfcr 0
87 stw 0,12(1) # save cr
88 stmw 3,24(1) # save r3-r31
89
90 mr 3,12 # obj
91 mr 4,11 # reloff
92 bl _rtld_bind@plt # _rtld_bind(obj, reloff)
93 mtctr 3
94
95 lmw 3,24(1) # load r3-r31
96 lwz 0,12(1) # restore cr
97 mtcr 0
98 lwz 0,16(1) # restore lr
99 mtlr 0
100 lwz 0,20(1)
101
102 addi 1,1,160
103 bctr
104
105 .globl _rtld_powerpc_pltcall
106 .globl _rtld_powerpc_pltresolve
107
108 _rtld_powerpc_pltcall:
109 slwi 11,11,2
110 addis 11,11,0 # addis 11,11,jmptab@ha
111 lwz 11,0(11) # lwz 11,jmptab@l(11)
112 mtctr 11
113 bctr
114
115 _rtld_powerpc_pltresolve:
116 lis 12,0 # lis 12,_rtld_bind_start@ha
117 addi 12,12,0 # addi 12,12,_rtld_bind_start@l
118 mtctr 12
119 lis 12,0 # lis 12,obj@ha
120 addi 12,12,0 # addi 12,12,obj@l
121 bctr
122