]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - libexec/rtld-elf/alpha/rtld_start.S
unfinished sblive driver, playback/mixer only for now - not enabled in
[FreeBSD/FreeBSD.git] / libexec / rtld-elf / alpha / rtld_start.S
1 /* $FreeBSD$    */
2 /*      From: NetBSD: rtld_start.S,v 1.1 1996/12/16 20:38:09 cgd Exp    */
3
4 /*
5  * Copyright 1996 Matt Thomas <matt@3am-software.com>
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 OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include <machine/asm.h>
32 #include <machine/pal.h>
33
34 .extern _GLOBAL_OFFSET_TABLE_
35
36 LEAF(_rtld_start, 0)            /* XXX */
37         .set    noreorder
38         br      pv, $33
39 $33:    LDGP(pv)
40
41         /* save away the stack pointer */
42
43         lda     s0, 0(sp)       /* get argc from stack */
44         lda     sp, -16(sp)     /* space for arguments */
45
46         /* save ps_strings pointer */
47         mov     a3, s1
48
49         /* Step 1 -- Figure out the displacement */
50
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 */
54
55
56         /* Step 2 -- Find bounds of global offset table */
57
58         lda     t5, _GLOBAL_OFFSET_TABLE_
59         addq    t8, t5, t9      /* add the displacement */
60         lda     t4, _DYNAMIC
61         addq    t8, t4, t10     /* add the displacement */
62
63         /*
64          * Step 3 -- Every entry in the global offset table needs to
65          * modified for the displacement before any code will work.
66          */
67
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 */
74
75         /*
76          *  Ya!  Things are far enough so we can do some dynamic linking!
77          */
78
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); */
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         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 */
135         addq    a1, a1, a1
136         CALL(_rtld_bind)
137
138         /* Move the destination address into position.  */
139         mov     $0, $27
140         /* Restore program registers.  */
141         ldq     $26, 0(sp)
142         ldq     $0, 8(sp)
143         ldq     $1, 16(sp)
144         ldq     $2, 24(sp)
145         ldq     $3, 32(sp)
146         ldq     $4, 40(sp)
147         ldq     $5, 48(sp)
148         ldq     $6, 56(sp)
149         ldq     $7, 64(sp)
150         ldq     $8, 72(sp)
151         ldq     $16, 80(sp)
152         ldq     $17, 88(sp)
153         ldq     $18, 96(sp)
154         ldq     $19, 104(sp)
155         ldq     $20, 112(sp)
156         ldq     $21, 120(sp)
157         ldq     $22, 128(sp)
158         ldq     $23, 136(sp)
159         ldq     $24, 144(sp)
160         ldq     $25, 152(sp)
161         ldq     $29, 160(sp)
162         /* Flush the Icache after having modified the .plt code.  */
163         imb
164         /* Clean up and turn control to the destination */
165         lda     sp, 168(sp)
166         jmp     $31, ($27)
167         .end _rtld_bind_start
168  
169
170
171