xref: /titanic_52/usr/src/cmd/sgs/rtld.4.x/rtldlib.s (revision 7fd791373689a6af05e27efec3b1ab556e02aa23)
1! CDDL HEADER START
2!
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.
6!
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.
11!
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]
17!
18! CDDL HEADER END
19!
20! Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
21! Use is subject to license terms.
22!
23!	SPARC support routines for 4.x compatibility dynamic linker.
24
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
29
30#define	AT_FDCWD	0xffd19553
31
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
41
42start_rtld:
43	save	%sp,-SA(MINFRAME),%sp	! build frame
44L1:
45	call    1f			! get absolute address of _GOT_
46        nop
471:
48        sethi	%hi(__GLOBAL_OFFSET_TABLE_ - (L1 - 1b)), %l7
49L2:
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
67
68
69!
70! aout_reloc_write
71!	Update a relocation offset, the value replaces any original
72!	value in the relocation offset.
73!
74
75	.global _aout_reloc_write
76
77_aout_reloc_write:
78	st	%o1, [%o0]		! Store value in the offset
79	retl
80	iflush	%o0			! Flush instruction memory
81
82
83! Special system call stubs to save system call overhead
84
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
95
96_mmap:
97	sethi	%hi(0x80000000), %g1	! MAP_NEW
98	or	%g1, %o3, %o3
99	ba	__syscall
100	mov	SYS_mmap, %g1
101
102_munmap:
103	ba	__syscall
104	mov	SYS_munmap, %g1
105
106_read:
107	ba	__syscall
108	mov	SYS_read, %g1
109
110_write:
111	ba	__syscall
112	mov	SYS_write, %g1
113
114_lseek:
115	ba	__syscall
116	mov	SYS_lseek, %g1
117
118_close:
119	ba	__syscall
120	mov	SYS_close, %g1
121
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
128
129_sysconfig:
130	ba	__syscall
131	mov	SYS_sysconfig, %g1
132
133__exit:
134	mov	SYS_exit, %g1
135
136__syscall:
137	t	0x8			! call the system call
138	bcs	__err_exit		! test for error
139	nop
140	retl				! return
141	nop
142
143__err_exit:
144	retl				! return
145	mov	-1, %o0
146