RIP gzip, we found a nicer playmate.
[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  * $DragonFly: src/gnu/usr.bin/ld/sparc/Attic/mdprologue.S,v 1.2 2003/06/17 04:25:46 dillon Exp $
32  */
33
34 /*
35  * SPARC run-time link editor entry points.
36  */
37
38 #define CRT_VERSION_SUN         1
39
40         .seg    "text"                  ! [internal]
41         .proc   16
42         .global _rtld_entry
43 _rtld_entry:
44 !#PROLOGUE# 0
45         save    %sp,-96,%sp
46 L.1B:
47         call    L.2B
48         sethi   %hi((__GLOBAL_OFFSET_TABLE_-(L.1B-.))),%l7
49 L.2B:
50 !#PROLOGUE# 1
51         or      %l7,%lo((__GLOBAL_OFFSET_TABLE_-(L.1B-.))),%l7
52         add     %l7,%o7,%l7
53
54         cmp     %i0, CRT_VERSION_SUN    ! is crtp passed in Sun style,
55         bne     1f                      !  ie. relative to stack frame ?
56         nop
57         add     %i1, %fp, %i1           ! if so, adjust to absolute address
58 1:
59         ld      [%i1], %o3              ! load base address (crtp->crt_ba)
60         ld      [%l7], %o2              ! get __DYNAMIC address
61                                         !   from 1st GOT entry
62         add     %o2, %o3, %o2           ! relocate and make it 3rd arg.
63
64         ld      [%l7 + _rtld], %g1      ! get address of rtld()
65         add     %g1, %o3, %g1           ! relocate
66
67         mov     %i1, %o1                ! set up args, #2: crtp
68         call    %g1                     ! rtld(version, crtp, dp)
69         mov     %i0, %o0                ! arg #1: version
70
71         ret
72         restore
73         .seg    "data"                  ! [internal]
74
75         .seg    "text"
76         .global _binder_entry
77 _binder_entry:
78 !#PROLOGUE# 0
79         save    %sp,-96,%sp
80 !L.1C:
81 !       call    L.2C
82 !       sethi   %hi((__GLOBAL_OFFSET_TABLE_-(L.1C-.))),%l7
83 !L.2C:
84 !       or      %l7,%lo((__GLOBAL_OFFSET_TABLE_-(L.1C-.))),%l7
85 !#PROLOGUE# 1
86
87         sub     %i7, 4, %o0             ! get to jmpslot through pc
88         ld      [%i7+4], %o1            ! get relocation index
89         sethi   %hi(0x3fffff), %o2      ! -> reloc_index & 0x003fffff
90         or      %o2, %lo(0x3fffff), %o2 ! [internal]
91         call    _binder                 ! and call binder(jsp, reloc_index)
92         and     %o1, %o2, %o1
93
94         mov     %o0, %g1                ! return value == function address
95
96         restore                         ! get rid of our context
97         jmp     %g1                     ! and go.
98         restore                         ! and the jmpslot context
99         nop
100
101         .seg    "data"                  ! [internal]
102