2 /* From: NetBSD: rtld_start.S,v 1.1 1996/12/16 20:38:09 cgd Exp */
5 * Copyright 1996 Matt Thomas <matt@3am-software.com>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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 OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <machine/asm.h>
32 #include <machine/pal.h>
34 .extern _GLOBAL_OFFSET_TABLE_
36 LEAF(_rtld_start, 0) /* XXX */
41 /* save away the stack pointer */
43 lda s0, 0(sp) /* get argc from stack */
44 lda sp, -16(sp) /* space for arguments */
46 /* save ps_strings pointer */
49 /* Step 1 -- Figure out the displacement */
51 br t2, $34 /* get our PC */
52 $34: ldiq t3, $34 /* get where the linker thought we were */
53 subq t2, t3, t8 /* calculate the displacement */
56 /* Step 2 -- Find bounds of global offset table */
58 lda t5, _GLOBAL_OFFSET_TABLE_
59 addq t8, t5, t9 /* add the displacement */
61 addq t8, t4, t10 /* add the displacement */
64 * Step 3 -- Every entry in the global offset table needs to
65 * modified for the displacement before any code will work.
68 $35: ldq t1, 0(t9) /* load the value */
69 addq t8, t1, t1 /* add the displacement */
70 stq t1, 0(t9) /* save the new value */
71 lda t9, 8(t9) /* point to next entry */
72 cmpult t9, t10, t1 /* are we done? */
73 bne t1, $35 /* no, do more */
76 * Ya! Things are far enough so we can do some dynamic linking!
79 lda a0, 0(s0) /* initial sp */
80 lda a1, -16(s0) /* address for exit proc */
81 lda a2, -8(s0) /* address for obj_main */
82 CALL(_rtld) /* v0 = _rtld(sp, &exit_proc, &obj_main); */
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 */
90 jsr ra, (v0), 0 /* (*_start)(sp, cleanup, obj); */
98 .globl _rtld_bind_start
104 /* Preserve all registers that C normally doesn't. */
126 .mask 0x27ff01ff, -168
131 /* Set up the arguments for _rtld_bind. */
132 subq at_reg, t12, a1 /* calculate reloc offset */
133 ldq a0, 8(t12) /* object structure */
134 subq a1, 20, a1 /* = (at - t11 - 20) / 12 * 24 */
138 /* Move the destination address into position. */
140 /* Restore program registers. */
162 /* Flush the Icache after having modified the .plt code. */
164 /* Clean up and turn control to the destination */
167 .end _rtld_bind_start