xref: /titanic_50/usr/src/cmd/sgs/rtld.4.x/rtldlib.s (revision 8fd04b8338ed5093ec2d1e668fa620b7de44c177)
17c478bd9Sstevel@tonic-gate! CDDL HEADER START
27c478bd9Sstevel@tonic-gate!
37c478bd9Sstevel@tonic-gate! The contents of this file are subject to the terms of the
4*8fd04b83SRoger A. Faulkner! Common Development and Distribution License (the "License").
5*8fd04b83SRoger A. Faulkner! You may not use this file except in compliance with the License.
67c478bd9Sstevel@tonic-gate!
77c478bd9Sstevel@tonic-gate! You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
87c478bd9Sstevel@tonic-gate! or http://www.opensolaris.org/os/licensing.
97c478bd9Sstevel@tonic-gate! See the License for the specific language governing permissions
107c478bd9Sstevel@tonic-gate! and limitations under the License.
117c478bd9Sstevel@tonic-gate!
127c478bd9Sstevel@tonic-gate! When distributing Covered Code, include this CDDL HEADER in each
137c478bd9Sstevel@tonic-gate! file and include the License file at usr/src/OPENSOLARIS.LICENSE.
147c478bd9Sstevel@tonic-gate! If applicable, add the following below this CDDL HEADER, with the
157c478bd9Sstevel@tonic-gate! fields enclosed by brackets "[]" replaced with your own identifying
167c478bd9Sstevel@tonic-gate! information: Portions Copyright [yyyy] [name of copyright owner]
177c478bd9Sstevel@tonic-gate!
187c478bd9Sstevel@tonic-gate! CDDL HEADER END
197c478bd9Sstevel@tonic-gate!
20*8fd04b83SRoger A. Faulkner! Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
21*8fd04b83SRoger A. Faulkner! Use is subject to license terms.
22*8fd04b83SRoger A. Faulkner!
237c478bd9Sstevel@tonic-gate!	SPARC support routines for 4.x compatibility dynamic linker.
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>		! N.B.: although this is the 4.x
267c478bd9Sstevel@tonic-gate#include <sys/syscall.h>		! compatibility stuff, it actually
277c478bd9Sstevel@tonic-gate					! runs only on the SVR4 base, and
287c478bd9Sstevel@tonic-gate					! is compiled in an SVR4 .h environment
297c478bd9Sstevel@tonic-gate
30*8fd04b83SRoger A. Faulkner#define	AT_FDCWD	0xffd19553
31*8fd04b83SRoger A. Faulkner
327c478bd9Sstevel@tonic-gate! ld.so bootstrap.  Called from crt0 of a dynamically linked program with:
337c478bd9Sstevel@tonic-gate!	%i0:	version number (always 1)
347c478bd9Sstevel@tonic-gate!	%i1:	address of crt0 structure, which contains:
357c478bd9Sstevel@tonic-gate!		+0	base address of where we are mapped
367c478bd9Sstevel@tonic-gate!		+4	open file descriptor for /dev/zero
377c478bd9Sstevel@tonic-gate!		+8	open file descriptor for ld.so
387c478bd9Sstevel@tonic-gate!		+c	a.out _DYNAMIC address
397c478bd9Sstevel@tonic-gate!		+10	environment strings
407c478bd9Sstevel@tonic-gate!		+14	break address for adb/dbx
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gatestart_rtld:
437c478bd9Sstevel@tonic-gate	save	%sp,-SA(MINFRAME),%sp	! build frame
447c478bd9Sstevel@tonic-gateL1:
457c478bd9Sstevel@tonic-gate	call    1f			! get absolute address of _GOT_
467c478bd9Sstevel@tonic-gate        nop
477c478bd9Sstevel@tonic-gate1:
487c478bd9Sstevel@tonic-gate        sethi	%hi(__GLOBAL_OFFSET_TABLE_ - (L1 - 1b)), %l7
497c478bd9Sstevel@tonic-gateL2:
507c478bd9Sstevel@tonic-gate	or	%l7, %lo(__GLOBAL_OFFSET_TABLE_ - (L1 - L2)), %l7
517c478bd9Sstevel@tonic-gate	add	%l7, %o7, %l7
527c478bd9Sstevel@tonic-gate	mov	%i0, %o0		! pass version through
537c478bd9Sstevel@tonic-gate	add	%fp, %i1, %l0		! get interface pointer
547c478bd9Sstevel@tonic-gate	mov	%l0, %o1		! ptr to interface structure
557c478bd9Sstevel@tonic-gate	ld	[%l0], %l2		! address where ld.so is mapped in
567c478bd9Sstevel@tonic-gate	ld	[%l7], %l1		! ptr to ld.so first entry in globtable
577c478bd9Sstevel@tonic-gate	add	%l2, %l1, %o2		! relocate ld.so _DYNAMIC
587c478bd9Sstevel@tonic-gate	add	%fp, 0xd8, %o3		! point to arg count (is it safe?)
597c478bd9Sstevel@tonic-gate	ld	[%l7 + _rtld], %g1	! manually fix pic reference to rtld
607c478bd9Sstevel@tonic-gate	add	%g1, %l2, %g1		!   by adding offset to GOT entry
617c478bd9Sstevel@tonic-gate	jmpl	%g1, %o7		! go there
627c478bd9Sstevel@tonic-gate	nop				! delay
637c478bd9Sstevel@tonic-gate	mov	0,%o0
647c478bd9Sstevel@tonic-gate	mov	%o0,%i0
657c478bd9Sstevel@tonic-gate	ret
667c478bd9Sstevel@tonic-gate	restore
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate!
707c478bd9Sstevel@tonic-gate! aout_reloc_write
717c478bd9Sstevel@tonic-gate!	Update a relocation offset, the value replaces any original
727c478bd9Sstevel@tonic-gate!	value in the relocation offset.
737c478bd9Sstevel@tonic-gate!
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate	.global _aout_reloc_write
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate_aout_reloc_write:
787c478bd9Sstevel@tonic-gate	st	%o1, [%o0]		! Store value in the offset
797c478bd9Sstevel@tonic-gate	retl
807c478bd9Sstevel@tonic-gate	iflush	%o0			! Flush instruction memory
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate! Special system call stubs to save system call overhead
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate	.global	_open, _mmap, _munmap, _read, _write, _lseek, _close
867c478bd9Sstevel@tonic-gate	.global	_fstat, _sysconfig, __exit
87*8fd04b83SRoger A. Faulkner_open:				! open(path, oflags, mode) =>
88*8fd04b83SRoger A. Faulkner	mov	%o2, %o3	! openat(AT_FDCWD, path, oflag, mode)
89*8fd04b83SRoger A. Faulkner	mov	%o1, %o2
90*8fd04b83SRoger A. Faulkner	mov	%o0, %o1
91*8fd04b83SRoger A. Faulkner	sethi	%hi(AT_FDCWD), %o0
92*8fd04b83SRoger A. Faulkner	or	%o0, %lo(AT_FDCWD), %o0
937c478bd9Sstevel@tonic-gate	ba	__syscall
94*8fd04b83SRoger A. Faulkner	mov	SYS_openat, %g1
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate_mmap:
977c478bd9Sstevel@tonic-gate	sethi	%hi(0x80000000), %g1	! MAP_NEW
987c478bd9Sstevel@tonic-gate	or	%g1, %o3, %o3
997c478bd9Sstevel@tonic-gate	ba	__syscall
1007c478bd9Sstevel@tonic-gate	mov	SYS_mmap, %g1
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate_munmap:
1037c478bd9Sstevel@tonic-gate	ba	__syscall
1047c478bd9Sstevel@tonic-gate	mov	SYS_munmap, %g1
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate_read:
1077c478bd9Sstevel@tonic-gate	ba	__syscall
1087c478bd9Sstevel@tonic-gate	mov	SYS_read, %g1
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate_write:
1117c478bd9Sstevel@tonic-gate	ba	__syscall
1127c478bd9Sstevel@tonic-gate	mov	SYS_write, %g1
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate_lseek:
1157c478bd9Sstevel@tonic-gate	ba	__syscall
1167c478bd9Sstevel@tonic-gate	mov	SYS_lseek, %g1
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate_close:
1197c478bd9Sstevel@tonic-gate	ba	__syscall
1207c478bd9Sstevel@tonic-gate	mov	SYS_close, %g1
1217c478bd9Sstevel@tonic-gate
122*8fd04b83SRoger A. Faulkner_fstat:				! fstat(fd, statb) =>
123*8fd04b83SRoger A. Faulkner	mov	%g0, %o3	! fstatat(fd, NULL, statb, 0)
124*8fd04b83SRoger A. Faulkner	mov	%o1, %o2
125*8fd04b83SRoger A. Faulkner	mov	%g0, %o1
1267c478bd9Sstevel@tonic-gate	ba	__syscall
127*8fd04b83SRoger A. Faulkner	mov	SYS_fstatat, %g1
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate_sysconfig:
1307c478bd9Sstevel@tonic-gate	ba	__syscall
1317c478bd9Sstevel@tonic-gate	mov	SYS_sysconfig, %g1
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate__exit:
1347c478bd9Sstevel@tonic-gate	mov	SYS_exit, %g1
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate__syscall:
1377c478bd9Sstevel@tonic-gate	t	0x8			! call the system call
1387c478bd9Sstevel@tonic-gate	bcs	__err_exit		! test for error
1397c478bd9Sstevel@tonic-gate	nop
1407c478bd9Sstevel@tonic-gate	retl				! return
1417c478bd9Sstevel@tonic-gate	nop
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate__err_exit:
1447c478bd9Sstevel@tonic-gate	retl				! return
1457c478bd9Sstevel@tonic-gate	mov	-1, %o0
146