rtld_start.S revision 1.1 1 /* $NetBSD: rtld_start.S,v 1.1 1996/12/16 20:38:09 cgd Exp $ */
2
3 /*
4 * Copyright 1996 Matt Thomas <matt (at) 3am-software.com>
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 OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <machine/asm.h>
31
32 .extern _GLOBAL_OFFSET_TABLE_
33
34 LEAF(_rtld_start, 0) /* XXX */
35 .set noreorder
36 br pv, $33
37 $33: LDGP(pv)
38
39 /* save away the stack pointer */
40
41 lda s0, 0(sp) /* get argc from stack */
42 lda sp, -16(sp)
43
44 /* save ps_strings pointer */
45 mov a3, s1
46
47 /* Step 1 -- Figure out the displacement */
48
49 br t2, $34 /* get our PC */
50 $34: ldiq t3, $34 /* get where the linker thought we were */
51 subq t2, t3, t8 /* calculate the displacement */
52
53
54 /* Step 2 -- Find bounds of global offset table */
55
56 lda t5, _GLOBAL_OFFSET_TABLE_
57 addq t8, t5, t9 /* add the displacement */
58 #if defined(OLD_GOT)
59 ldq t4, 0(t9) /* Get the address of dynamic table */
60 #else
61 lda t4, _DYNAMIC
62 #endif
63 addq t8, t4, t10 /* add the displacement */
64
65 /*
66 * Step 3 -- Every entry in the global offset table needs to
67 * modified for the displacement before any code will work.
68 */
69
70 $35: ldq t1, 0(t9) /* load the value */
71 addq t8, t1, t1 /* add the displacement */
72 stq t1, 0(t9) /* save the new value */
73 lda t9, 8(t9) /* point to next entry */
74 cmpult t9, t10, t1 /* are we done? */
75 bne t1, $35 /* no, do more */
76
77 /*
78 * Ya! Things are far enough so we can do some dynamic linking!
79 */
80
81 lda a0, -16(s0)
82 CALL(_rtld) /* v0 = _rtld(sp); */
83
84 ldq a1, -16(s0) /* our atexit function */
85 ldq a2, -8(s0) /* obj_main entry */
86 lda sp, 16(sp) /* readjust our stack */
87 mov s0, a0 /* stack pointer */
88 mov s1, a3 /* ps_strings pointer */
89 mov v0, t12
90 jsr ra, (v0), 0 /* (*_start)(sp, cleanup, obj); */
91 ldgp gp, 0(ra)
92
93 CALL(exit)
94 halt
95 END(_rtld_start)
96
97 .set noat
98 .globl _rtld_bind_start
99 .ent _rtld_bind_start
100 _rtld_bind_start:
101
102 lda sp, -168(sp)
103 .frame sp, 168, $26
104 /* Preserve all registers that C normally doesn't. */
105 stq $26, 0(sp)
106 stq $0, 8(sp)
107 stq $1, 16(sp)
108 stq $2, 24(sp)
109 stq $3, 32(sp)
110 stq $4, 40(sp)
111 stq $5, 48(sp)
112 stq $6, 56(sp)
113 stq $7, 64(sp)
114 stq $8, 72(sp)
115 stq $16, 80(sp)
116 stq $17, 88(sp)
117 stq $18, 96(sp)
118 stq $19, 104(sp)
119 stq $20, 112(sp)
120 stq $21, 120(sp)
121 stq $22, 128(sp)
122 stq $23, 136(sp)
123 stq $24, 144(sp)
124 stq $25, 152(sp)
125 stq $29, 160(sp)
126 .mask 0x27ff01ff, -168
127 /* Set up our $gp */
128 br gp, $100
129 $100: ldgp gp, 0(gp)
130 .prologue 1
131 /* Set up the arguments for _rtld_bind. */
132 ldq a0, 8(t12) /* object structure */
133 mov at_reg, a1 /* offset of reloc entry */
134 CALL(_rtld_bind)
135
136 /* Move the destination address into position. */
137 mov $0, $27
138 /* Restore program registers. */
139 ldq $26, 0(sp)
140 ldq $0, 8(sp)
141 ldq $1, 16(sp)
142 ldq $2, 24(sp)
143 ldq $3, 32(sp)
144 ldq $4, 40(sp)
145 ldq $5, 48(sp)
146 ldq $6, 56(sp)
147 ldq $7, 64(sp)
148 ldq $8, 72(sp)
149 ldq $16, 80(sp)
150 ldq $17, 88(sp)
151 ldq $18, 96(sp)
152 ldq $19, 104(sp)
153 ldq $20, 112(sp)
154 ldq $21, 120(sp)
155 ldq $22, 128(sp)
156 ldq $23, 136(sp)
157 ldq $24, 144(sp)
158 ldq $25, 152(sp)
159 ldq $29, 160(sp)
160 /* Flush the Icache after having modified the .plt code. */
161 imb
162 /* Clean up and turn control to the destination */
163 lda sp, 168(sp)
164 jmp $31, ($27)
165 .end _rtld_bind_start
166
167
168
169
170