xref: /titanic_41/usr/src/cmd/sgs/rtld/sparc/boot_a.out.s (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate/*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate/*
23*7c478bd9Sstevel@tonic-gate *	Copyright (c) 1991,1992 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate */
25*7c478bd9Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate#include	"machdep.h"
28*7c478bd9Sstevel@tonic-gate#if	defined(lint)
29*7c478bd9Sstevel@tonic-gate#include	<sys/types.h>
30*7c478bd9Sstevel@tonic-gate#include	"sgs.h"
31*7c478bd9Sstevel@tonic-gate#include	"_a.out.h"
32*7c478bd9Sstevel@tonic-gate#else
33*7c478bd9Sstevel@tonic-gate
34*7c478bd9Sstevel@tonic-gate	.file	"boot_a.out.s"
35*7c478bd9Sstevel@tonic-gate	.seg	".text"
36*7c478bd9Sstevel@tonic-gate#endif
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate/*
39*7c478bd9Sstevel@tonic-gate * We got here because the initial call to a function resolved to a procedure
40*7c478bd9Sstevel@tonic-gate * linkage table entry.  That entry did a branch to the first PLT entry, which
41*7c478bd9Sstevel@tonic-gate * in turn did a call to aout_rtbndr (refer aout_plt_init()).
42*7c478bd9Sstevel@tonic-gate *
43*7c478bd9Sstevel@tonic-gate * the code sequence that got us here was:
44*7c478bd9Sstevel@tonic-gate *
45*7c478bd9Sstevel@tonic-gate * PLT entry for foo():
46*7c478bd9Sstevel@tonic-gate *	save	%sp, -0x60, %sp			! patched first
47*7c478bd9Sstevel@tonic-gate *	call	.PLT0				! patched second
48*7c478bd9Sstevel@tonic-gate *	sethi	%hi(XXXXXXX), %g0		! unchanged
49*7c478bd9Sstevel@tonic-gate *
50*7c478bd9Sstevel@tonic-gate * Therefore on entry, %i7 has the address of the call, which will be added
51*7c478bd9Sstevel@tonic-gate * to the offset to the plt entry in %g1 to calculate the plt entry address
52*7c478bd9Sstevel@tonic-gate * we must also subtract 4 for because the address of PLT0 points to the
53*7c478bd9Sstevel@tonic-gate * save instruction before the call
54*7c478bd9Sstevel@tonic-gate *
55*7c478bd9Sstevel@tonic-gate * the plt entry is rewritten:
56*7c478bd9Sstevel@tonic-gate *
57*7c478bd9Sstevel@tonic-gate * PLT entry for foo():
58*7c478bd9Sstevel@tonic-gate *	sethi	%hi(entry_pt), %g1
59*7c478bd9Sstevel@tonic-gate *	jmpl	%g1 + %lo(entry_pt), %g0
60*7c478bd9Sstevel@tonic-gate */
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate#if	defined(lint)
63*7c478bd9Sstevel@tonic-gate
64*7c478bd9Sstevel@tonic-gatevoid
65*7c478bd9Sstevel@tonic-gateaout_rtbndr(caddr_t pc)
66*7c478bd9Sstevel@tonic-gate{
67*7c478bd9Sstevel@tonic-gate	(void) aout_bndr(pc);
68*7c478bd9Sstevel@tonic-gate}
69*7c478bd9Sstevel@tonic-gate
70*7c478bd9Sstevel@tonic-gate#else
71*7c478bd9Sstevel@tonic-gate	.global	aout_rtbndr
72*7c478bd9Sstevel@tonic-gate	.type   aout_rtbndr, #function
73*7c478bd9Sstevel@tonic-gate	.align	4
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gateaout_rtbndr:
76*7c478bd9Sstevel@tonic-gate	save	%sp, -80, %sp
77*7c478bd9Sstevel@tonic-gate	call	aout_bndr		! returns function address in %o0
78*7c478bd9Sstevel@tonic-gate	add	%i7, -0x4, %o0		! %o0 now has address of PLT0
79*7c478bd9Sstevel@tonic-gate	mov	%o0, %g1		! save address of routine binded
80*7c478bd9Sstevel@tonic-gate	restore				! how many restores needed ? 2
81*7c478bd9Sstevel@tonic-gate	jmp	%g1			! jump to it
82*7c478bd9Sstevel@tonic-gate	restore
83*7c478bd9Sstevel@tonic-gate	nop
84*7c478bd9Sstevel@tonic-gate	.size	aout_rtbndr, . - aout_rtbndr
85*7c478bd9Sstevel@tonic-gate
86*7c478bd9Sstevel@tonic-gate#endif
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate
89*7c478bd9Sstevel@tonic-gate/*
90*7c478bd9Sstevel@tonic-gate * After the first call to a plt, aout_bndr() will have determined the true
91*7c478bd9Sstevel@tonic-gate * address of the function being bound.  The plt is now rewritten so that
92*7c478bd9Sstevel@tonic-gate * any subsequent calls go directly to the bound function.
93*7c478bd9Sstevel@tonic-gate *
94*7c478bd9Sstevel@tonic-gate * the new plt entry is:
95*7c478bd9Sstevel@tonic-gate *
96*7c478bd9Sstevel@tonic-gate *	sethi	%hi(function address), %g1	! patched first
97*7c478bd9Sstevel@tonic-gate *	jmpl	%g1 + %lo(function address, %g0	! patched second
98*7c478bd9Sstevel@tonic-gate */
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gate#if	defined(lint)
101*7c478bd9Sstevel@tonic-gate
102*7c478bd9Sstevel@tonic-gatevoid
103*7c478bd9Sstevel@tonic-gateaout_plt_write(caddr_t pc, unsigned long symval)
104*7c478bd9Sstevel@tonic-gate{
105*7c478bd9Sstevel@tonic-gate	/* LINTED */
106*7c478bd9Sstevel@tonic-gate	*(unsigned long *)(pc) = (M_SETHIG1 | (symval >> (32 - 22)));
107*7c478bd9Sstevel@tonic-gate	/* LINTED */
108*7c478bd9Sstevel@tonic-gate	*(unsigned long *)(pc + 4) = (M_JMPL | (symval & S_MASK(10)));
109*7c478bd9Sstevel@tonic-gate
110*7c478bd9Sstevel@tonic-gate}
111*7c478bd9Sstevel@tonic-gate
112*7c478bd9Sstevel@tonic-gate#else
113*7c478bd9Sstevel@tonic-gate	.global	aout_plt_write
114*7c478bd9Sstevel@tonic-gate	.type	aout_plt_write, #function
115*7c478bd9Sstevel@tonic-gate	.align	4
116*7c478bd9Sstevel@tonic-gate
117*7c478bd9Sstevel@tonic-gateaout_plt_write:
118*7c478bd9Sstevel@tonic-gate	srl	%o1, 10, %o2		! Get high part of function address
119*7c478bd9Sstevel@tonic-gate	sethi	%hi(M_SETHIG1), %o3	! Get sethi instruction
120*7c478bd9Sstevel@tonic-gate	or	%o3, %o2, %o3		! Add sethi and function address
121*7c478bd9Sstevel@tonic-gate	st	%o3, [%o0]		! Store instruction in plt[0]
122*7c478bd9Sstevel@tonic-gate	iflush  %o0
123*7c478bd9Sstevel@tonic-gate	stbar
124*7c478bd9Sstevel@tonic-gate	sethi	%hi(M_JMPL), %o3	! Get jmpl instruction
125*7c478bd9Sstevel@tonic-gate	and	%o1, 0x3ff, %o2		! Lower part of function address
126*7c478bd9Sstevel@tonic-gate	or	%o3, %o2, %o3		!	is or'ed into instruction
127*7c478bd9Sstevel@tonic-gate	st	%o3, [%o0 + 4]		! Store instruction in plt[1]
128*7c478bd9Sstevel@tonic-gate	retl
129*7c478bd9Sstevel@tonic-gate	iflush	%o0 + 4
130*7c478bd9Sstevel@tonic-gate	.size	aout_plt_write, . - aout_plt_write
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate#endif
133