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