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