Initial import from FreeBSD RELENG_4:
[dragonfly.git] / gnu / usr.bin / ld / sparc / mdprologue.S
1 /*
2  * Copyright (c) 1993 Paul Kranenburg
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Paul Kranenburg.
16  * 4. 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  * $FreeBSD: src/gnu/usr.bin/ld/sparc/mdprologue.S,v 1.7 1999/08/27 23:36:05 peter Exp $
31  */
32
33 /*
34  * SPARC run-time link editor entry points.
35  */
36
37 #define CRT_VERSION_SUN         1
38
39         .seg    "text"                  ! [internal]
40         .proc   16
41         .global _rtld_entry
42 _rtld_entry:
43 !#PROLOGUE# 0
44         save    %sp,-96,%sp
45 L.1B:
46         call    L.2B
47         sethi   %hi((__GLOBAL_OFFSET_TABLE_-(L.1B-.))),%l7
48 L.2B:
49 !#PROLOGUE# 1
50         or      %l7,%lo((__GLOBAL_OFFSET_TABLE_-(L.1B-.))),%l7
51         add     %l7,%o7,%l7
52
53         cmp     %i0, CRT_VERSION_SUN    ! is crtp passed in Sun style,
54         bne     1f                      !  ie. relative to stack frame ?
55         nop
56         add     %i1, %fp, %i1           ! if so, adjust to absolute address
57 1:
58         ld      [%i1], %o3              ! load base address (crtp->crt_ba)
59         ld      [%l7], %o2              ! get __DYNAMIC address
60                                         !   from 1st GOT entry
61         add     %o2, %o3, %o2           ! relocate and make it 3rd arg.
62
63         ld      [%l7 + _rtld], %g1      ! get address of rtld()
64         add     %g1, %o3, %g1           ! relocate
65
66         mov     %i1, %o1                ! set up args, #2: crtp
67         call    %g1                     ! rtld(version, crtp, dp)
68         mov     %i0, %o0                ! arg #1: version
69
70         ret
71         restore
72         .seg    "data"                  ! [internal]
73
74         .seg    "text"
75         .global _binder_entry
76 _binder_entry:
77 !#PROLOGUE# 0
78         save    %sp,-96,%sp
79 !L.1C:
80 !       call    L.2C
81 !       sethi   %hi((__GLOBAL_OFFSET_TABLE_-(L.1C-.))),%l7
82 !L.2C:
83 !       or      %l7,%lo((__GLOBAL_OFFSET_TABLE_-(L.1C-.))),%l7
84 !#PROLOGUE# 1
85
86         sub     %i7, 4, %o0             ! get to jmpslot through pc
87         ld      [%i7+4], %o1            ! get relocation index
88         sethi   %hi(0x3fffff), %o2      ! -> reloc_index & 0x003fffff
89         or      %o2, %lo(0x3fffff), %o2 ! [internal]
90         call    _binder                 ! and call binder(jsp, reloc_index)
91         and     %o1, %o2, %o1
92
93         mov     %o0, %g1                ! return value == function address
94
95         restore                         ! get rid of our context
96         jmp     %g1                     ! and go.
97         restore                         ! and the jmpslot context
98         nop
99
100         .seg    "data"                  ! [internal]
101