]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - libexec/rtld-elf/mips/rtld_start.S
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / libexec / rtld-elf / mips / rtld_start.S
1 /*      $NetBSD: rtld_start.S,v 1.9 2002/10/05 11:59:05 mycroft Exp $   */
2 /* $FreeBSD$ */
3
4 /*
5  * Copyright 1997 Michael L. Hitch <mhitch@montana.edu>
6  * Portions copyright 2002 Charles M. Hannum <root@ihack.net>
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 #include <machine/asm.h>
33
34 .globl _C_LABEL(_rtld_relocate_nonplt_self)
35 .globl _C_LABEL(_rtld)
36
37 LEAF(rtld_start)
38         .abicalls
39         .set    noreorder
40
41         .cpload t9
42         addu    sp, sp, -16             /* adjust stack pointer         */
43                                         /*      keep it aligned         */
44         .cprestore 0                    /* -> 0(sp) for gp              */
45                                         /* -> 4(sp) for atexit          */
46                                         /* -> 8(sp) for obj_main        */
47         move    s0,a0                   /* save stack pointer from a0   */
48         move    s1,a3                   /* save ps_strings pointer      */
49
50         la      a1, 1f
51         bal     1f
52         nop
53 1:      subu    a1, ra, a1              /* relocbase */
54         la      t9,_C_LABEL(_rtld_relocate_nonplt_self)
55         move    s2,a1
56         la      a0,_DYNAMIC
57         addu    t9, a1, t9
58         jalr    t9
59         addu    a0, a1, a0              /* &_DYNAMIC */
60
61
62         move    a0, s0                  /* stack pointer                */
63         addu    a1, sp, 4               /* &exit_proc                   */
64         addu    a2, sp, 8               /* &objp                        */
65         addu    sp, sp, -16             /* arguments slot               */
66         jal     _C_LABEL(_rtld)         /* v0 = _rtld(sp, exit_proc, objp) */
67         nop
68         addu    sp, sp, 16              
69
70         move    a0, s0                  /* arguments pointer            */
71         move    a3, s1                  /* arguments pointer            */
72         lw      a1, 4(sp)               /* our atexit function          */
73         lw      a2, 8(sp)               /* obj_main entry               */
74         addu    sp, sp, 16              /* readjust stack               */
75         move    t9,v0
76         move    a2,s1                   /* restore ps_strings           */
77         jr      t9                      /* _start(ap, cleanup, obj, ps_strings);        */
78         nop
79
80 END(rtld_start)
81
82         .globl  _rtld_bind_start
83         .ent    _rtld_bind_start
84 _rtld_bind_start:
85         /* ABI conventions for stubs:
86          *   t8 contains symbol index 
87          *   t7 contains return address 
88          */
89         .frame sp, 0, ra                /* satisfy compiler             */
90
91         move    v1,gp                   /* save old GP                  */
92         add     t9,8                    /* modify T9 to point at .cpload */
93         .cpload t9
94         subu    sp,48                   /* save arguments and sp value  */
95         .cprestore 36
96         sw      a0,16(sp)
97         sw      a1,20(sp)
98         sw      a2,24(sp)
99         sw      a3,28(sp)
100         sw      s0,32(sp)
101         sw      t7,40(sp)
102         move    s0,sp
103         move    a0,v1                   /* old GP                       */
104         subu    a0,a0,0x7ff0            /* The offset of $gp from the   */
105                                         /* beginning of the .got section: */
106                                         /* $gp = .got + 0x7ff0, so      */
107                                         /* .got = $gp - 0x7ff0          */
108                                         /* Simple math as you can see.  */
109
110         lw      a0,4(a0)                /* object = pltgot[1] & 0x7fffffff */
111         and     a0,a0,0x7fffffff
112         move    a1,t8                   /* symbol index */
113                                         
114         jal     _C_LABEL(_mips_rtld_bind)
115         nop
116         move    sp,s0
117         lw      ra,40(sp)
118         lw      a0,16(sp)
119         lw      a1,20(sp)
120         lw      a2,24(sp)
121         lw      a3,28(sp)
122         lw      s0,32(sp)
123         addu    sp,48
124         move    t9,v0
125         jr      t9
126         nop
127         .end    _rtld_bind_start