8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sgs / rtld.4.x / rtldlib.s
blobdcaf82ac45be320d92f7a1ad4da9c3a2181bb9f7
1 ! CDDL HEADER START
3 ! The contents of this file are subject to the terms of the
4 ! Common Development and Distribution License (the "License").
5 ! You may not use this file except in compliance with the License.
7 ! You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8 ! or http://www.opensolaris.org/os/licensing.
9 ! See the License for the specific language governing permissions
10 ! and limitations under the License.
12 ! When distributing Covered Code, include this CDDL HEADER in each
13 ! file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14 ! If applicable, add the following below this CDDL HEADER, with the
15 ! fields enclosed by brackets "[]" replaced with your own identifying
16 ! information: Portions Copyright [yyyy] [name of copyright owner]
18 ! CDDL HEADER END
20 ! Copyright 2010 Sun Microsystems, Inc. All rights reserved.
21 ! Use is subject to license terms.
23 ! SPARC support routines for 4.x compatibility dynamic linker.
25 #include <sys/asm_linkage.h> ! N.B.: although this is the 4.x
26 #include <sys/syscall.h> ! compatibility stuff, it actually
27 ! runs only on the SVR4 base, and
28 ! is compiled in an SVR4 .h environment
30 #define AT_FDCWD 0xffd19553
32 ! ld.so bootstrap. Called from crt0 of a dynamically linked program with:
33 ! %i0: version number (always 1)
34 ! %i1: address of crt0 structure, which contains:
35 ! +0 base address of where we are mapped
36 ! +4 open file descriptor for /dev/zero
37 ! +8 open file descriptor for ld.so
38 ! +c a.out _DYNAMIC address
39 ! +10 environment strings
40 ! +14 break address for adb/dbx
42 start_rtld:
43 save %sp,-SA(MINFRAME),%sp ! build frame
44 L1:
45 call 1f ! get absolute address of _GOT_
46 nop
48 sethi %hi(__GLOBAL_OFFSET_TABLE_ - (L1 - 1b)), %l7
49 L2:
50 or %l7, %lo(__GLOBAL_OFFSET_TABLE_ - (L1 - L2)), %l7
51 add %l7, %o7, %l7
52 mov %i0, %o0 ! pass version through
53 add %fp, %i1, %l0 ! get interface pointer
54 mov %l0, %o1 ! ptr to interface structure
55 ld [%l0], %l2 ! address where ld.so is mapped in
56 ld [%l7], %l1 ! ptr to ld.so first entry in globtable
57 add %l2, %l1, %o2 ! relocate ld.so _DYNAMIC
58 add %fp, 0xd8, %o3 ! point to arg count (is it safe?)
59 ld [%l7 + _rtld], %g1 ! manually fix pic reference to rtld
60 add %g1, %l2, %g1 ! by adding offset to GOT entry
61 jmpl %g1, %o7 ! go there
62 nop ! delay
63 mov 0,%o0
64 mov %o0,%i0
65 ret
66 restore
70 ! aout_reloc_write
71 ! Update a relocation offset, the value replaces any original
72 ! value in the relocation offset.
75 .global _aout_reloc_write
77 _aout_reloc_write:
78 st %o1, [%o0] ! Store value in the offset
79 retl
80 iflush %o0 ! Flush instruction memory
83 ! Special system call stubs to save system call overhead
85 .global _open, _mmap, _munmap, _read, _write, _lseek, _close
86 .global _fstat, _sysconfig, __exit
87 _open: ! open(path, oflags, mode) =>
88 mov %o2, %o3 ! openat(AT_FDCWD, path, oflag, mode)
89 mov %o1, %o2
90 mov %o0, %o1
91 sethi %hi(AT_FDCWD), %o0
92 or %o0, %lo(AT_FDCWD), %o0
93 ba __syscall
94 mov SYS_openat, %g1
96 _mmap:
97 sethi %hi(0x80000000), %g1 ! MAP_NEW
98 or %g1, %o3, %o3
99 ba __syscall
100 mov SYS_mmap, %g1
102 _munmap:
103 ba __syscall
104 mov SYS_munmap, %g1
106 _read:
107 ba __syscall
108 mov SYS_read, %g1
110 _write:
111 ba __syscall
112 mov SYS_write, %g1
114 _lseek:
115 ba __syscall
116 mov SYS_lseek, %g1
118 _close:
119 ba __syscall
120 mov SYS_close, %g1
122 _fstat: ! fstat(fd, statb) =>
123 mov %g0, %o3 ! fstatat(fd, NULL, statb, 0)
124 mov %o1, %o2
125 mov %g0, %o1
126 ba __syscall
127 mov SYS_fstatat, %g1
129 _sysconfig:
130 ba __syscall
131 mov SYS_sysconfig, %g1
133 __exit:
134 mov SYS_exit, %g1
136 __syscall:
137 t 0x8 ! call the system call
138 bcs __err_exit ! test for error
140 retl ! return
143 __err_exit:
144 retl ! return
145 mov -1, %o0