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