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