rtld_start.S revision 100265
192195Sjake/* $NetBSD: rtld_start.S,v 1.5 2001/08/14 22:17:48 eeh Exp $ */ 292195Sjake 392195Sjake/*- 492195Sjake * Copyright (c) 2001 Jake Burkholder. 592195Sjake * Copyright (c) 2000 Eduardo Horvath. 692195Sjake * Copyright (c) 1999 The NetBSD Foundation, Inc. 792195Sjake * All rights reserved. 892195Sjake * 992195Sjake * This code is derived from software contributed to The NetBSD Foundation 1092195Sjake * by Christos Zoulas and Paul Kranenburg. 1192195Sjake * 1292195Sjake * Redistribution and use in source and binary forms, with or without 1392195Sjake * modification, are permitted provided that the following conditions 1492195Sjake * are met: 1592195Sjake * 1. Redistributions of source code must retain the above copyright 1692195Sjake * notice, this list of conditions and the following disclaimer. 1792195Sjake * 2. Redistributions in binary form must reproduce the above copyright 1892195Sjake * notice, this list of conditions and the following disclaimer in the 1992195Sjake * documentation and/or other materials provided with the distribution. 2092195Sjake * 3. All advertising materials mentioning features or use of this software 2192195Sjake * must display the following acknowledgement: 2292195Sjake * This product includes software developed by the NetBSD 2392195Sjake * Foundation, Inc. and its contributors. 2492195Sjake * 4. Neither the name of The NetBSD Foundation nor the names of its 2592195Sjake * contributors may be used to endorse or promote products derived 2692195Sjake * from this software without specific prior written permission. 2792195Sjake * 2892195Sjake * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2992195Sjake * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 3092195Sjake * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 3192195Sjake * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 3292195Sjake * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3392195Sjake * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3492195Sjake * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3592195Sjake * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3692195Sjake * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3792195Sjake * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3892195Sjake * POSSIBILITY OF SUCH DAMAGE. 3992195Sjake * 4092195Sjake * $FreeBSD: head/libexec/rtld-elf/sparc64/rtld_start.S 100265 2002-07-17 22:20:41Z jake $ 4192195Sjake */ 4292195Sjake 4392195Sjake#include <machine/asm.h> 4492195Sjake 4592195Sjake/* 4692195Sjake * ELF: 4792195Sjake * On startup the stack should contain 16 extended word register save 4892195Sjake * area, followed by the arg count, etc. 4992195Sjake */ 5092195Sjake 5192195SjakeENTRY(.rtld_start) 5292195Sjake clr %fp 5392195Sjake mov %o0, %l0 5492195Sjake mov %o3, %l1 5592195Sjake 5692195Sjake sub %sp, 16, %sp 5792195Sjake add %sp, SPOFF + CCFSZ + 0x0, %o1 5892195Sjake call _rtld 5992195Sjake add %sp, SPOFF + CCFSZ + 0x8, %o2 6092195Sjake 6192195Sjake ldx [%sp + SPOFF + CCFSZ + 0x0], %o1 6292195Sjake ldx [%sp + SPOFF + CCFSZ + 0x8], %o2 6392195Sjake add %sp, 16, %sp 6492195Sjake 6592195Sjake mov %l1, %o3 6692195Sjake jmp %o0 6792195Sjake mov %l0, %o0 68100265SjakeEND(.rtld_start) 6992195Sjake 7092195Sjake /* 7192195Sjake * We have two separate entry points to the runtime linker. 7292195Sjake * I'm implementing this following the SPARC v9 ABI spec. 7392195Sjake * 7492195Sjake * _rtld_bind_start_0(x, y) is called from .PLT0, and is used for 7592195Sjake * PLT entries above 32768. 7692195Sjake * 7792195Sjake * _rtld_bind_start_1(x, y) is called from .PLT1, and is used for 7892195Sjake * PLT entries below 32768. 7992195Sjake * 8092195Sjake * The first two entries of PLT2 contain the xword object pointer. 8192195Sjake * 8292195Sjake * These routines are called with two longword arguments, 8392195Sjake * x and y. To calculate the address of the entry, 8492195Sjake * _rtld_bind_start_1(x, y) does: 8592195Sjake * 8692195Sjake * n = x >> 15; 8792195Sjake * 8892195Sjake * and _rtld_bind_start_0(x, y) does: 8992195Sjake * 9092195Sjake * i = x - y + 1048596; 9192195Sjake * n = 32768 + (i/5120)*160 + (i%5120)/24; 9292195Sjake * 9392195Sjake * Neither routine needs to issue a save since it's already been 9492195Sjake * done in the PLT entry. 9592195Sjake */ 9692195Sjake 9792195SjakeENTRY(_rtld_bind_start_0) 9892195Sjake sethi %hi(1048596), %l1 9992195Sjake sub %o0, %o1, %l0 /* x - y */ 10092195Sjake or %l1, %lo(1048596), %l1 10192195Sjake add %l0, %l1, %l0 /* x - y + 1048596 */ 10292195Sjake 10392195Sjake sdivx %l0, 5120, %l1 /* Calculate i/5120 */ 10492195Sjake ldx [%o1 + (10*4)], %o0 /* Load object pointer from PLT2 */ 10592195Sjake sub %l0, %l1, %l2 /* And i%5120 */ 10692195Sjake 10792195Sjake /* Let the division churn for a bit. */ 10892195Sjake sdivx %l2, 14, %l4 /* (i%5120)/24 */ 10992195Sjake 11092195Sjake /* 160 is (32 * 5) or (32 * (4 + 1)) */ 11192195Sjake sllx %l1, 2, %l3 /* 4 * (i/5120) */ 11292195Sjake add %l1, %l3, %l3 /* 5 * (i/5120) */ 11392195Sjake sllx %l3, 5, %l3 /* 32 * 5 * (i/5120) */ 11492195Sjake 11592195Sjake sethi %hi(32768), %l6 11692195Sjake add %l3, %l4, %l5 /* %l5 = (i/5120)*160 + (i%5120)/24; */ 11792195Sjake add %l5, %l6, %l5 11892195Sjake 11992195Sjake sllx %l5, 1, %l6 /* Each element is an Elf_Rela which */ 12092195Sjake add %l6, %l5, %l5 /* is 3 longwords or 24 bytes. */ 12192195Sjake sllx %l5, 3, %l5 /* So multiply by 24. */ 12292195Sjake 12392195Sjake call _rtld_bind /* Call _rtld_bind(obj, offset) */ 12492195Sjake mov %l5, %o1 12592195Sjake 12692195Sjake jmp %o0 /* return value == function address */ 12792195Sjake restore /* Dump our stack frame */ 128100265SjakeEND(_rtld_bind_start_0) 12992195Sjake 13092195SjakeENTRY(_rtld_bind_start_1) 13192195Sjake srax %o0, 15, %o2 /* %o0 is the index to our PLT slot */ 13292195Sjake sub %o2, 4, %o2 /* XXX: 4 entries are reserved */ 13392195Sjake 13492195Sjake sllx %o2, 1, %o3 /* Each element is an Elf_Rela which */ 13592195Sjake add %o3, %o2, %o2 /* is 3 longwords or 24 bytes. */ 13692195Sjake sllx %o2, 3, %o2 /* So multiply by 24. */ 13792195Sjake 13892195Sjake ldx [%o1 + 8], %o0 /* The object pointer is at [%o1 + 8] */ 13992195Sjake 14092195Sjake call _rtld_bind /* Call _rtld_bind(obj, offset) */ 14192195Sjake mov %o2, %o1 14292195Sjake 14392195Sjake jmp %o0 /* return value == function address */ 14492195Sjake restore /* Dump our stack frame */ 145100265SjakeEND(_rtld_bind_start_1) 146