1*e83f7ba2SBen Gras/* $NetBSD: rtld_start.S,v 1.7 2008/04/28 20:23:03 martin Exp $ */ 2*e83f7ba2SBen Gras 3*e83f7ba2SBen Gras/*- 4*e83f7ba2SBen Gras * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc. 5*e83f7ba2SBen Gras * All rights reserved. 6*e83f7ba2SBen Gras * 7*e83f7ba2SBen Gras * This code is derived from software contributed to The NetBSD Foundation 8*e83f7ba2SBen Gras * by Marcus Comstedt. 9*e83f7ba2SBen Gras * 10*e83f7ba2SBen Gras * Redistribution and use in source and binary forms, with or without 11*e83f7ba2SBen Gras * modification, are permitted provided that the following conditions 12*e83f7ba2SBen Gras * are met: 13*e83f7ba2SBen Gras * 1. Redistributions of source code must retain the above copyright 14*e83f7ba2SBen Gras * notice, this list of conditions and the following disclaimer. 15*e83f7ba2SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 16*e83f7ba2SBen Gras * notice, this list of conditions and the following disclaimer in the 17*e83f7ba2SBen Gras * documentation and/or other materials provided with the distribution. 18*e83f7ba2SBen Gras * 19*e83f7ba2SBen Gras * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20*e83f7ba2SBen Gras * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21*e83f7ba2SBen Gras * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22*e83f7ba2SBen Gras * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23*e83f7ba2SBen Gras * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24*e83f7ba2SBen Gras * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25*e83f7ba2SBen Gras * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26*e83f7ba2SBen Gras * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27*e83f7ba2SBen Gras * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28*e83f7ba2SBen Gras * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29*e83f7ba2SBen Gras * POSSIBILITY OF SUCH DAMAGE. 30*e83f7ba2SBen Gras */ 31*e83f7ba2SBen Gras 32*e83f7ba2SBen Gras#include <machine/asm.h> 33*e83f7ba2SBen Gras 34*e83f7ba2SBen Gras .text 35*e83f7ba2SBen Gras .align 2 36*e83f7ba2SBen Gras .globl .rtld_start 37*e83f7ba2SBen Gras .type .rtld_start,@function 38*e83f7ba2SBen Gras 39*e83f7ba2SBen Gras.rtld_start: 40*e83f7ba2SBen Gras mova 2f,r0 41*e83f7ba2SBen Gras mov.l @r0,r2 42*e83f7ba2SBen Gras add r0,r2 /* GOT */ 43*e83f7ba2SBen Gras mov.l @(4,r0),r4 /* _DYNAMIC@GOTOFF */ 44*e83f7ba2SBen Gras add r2,r4 /* _DYNAMIC */ 45*e83f7ba2SBen Gras mov.l @(12,r0),r1 /* _rtld_relocate_nonplt_self offset */ 46*e83f7ba2SBen Gras mov.l @(8,r0),r0 /* _DYNAMIC@GOT */ 47*e83f7ba2SBen Gras mov r4,r5 48*e83f7ba2SBen Gras mov.l @(r0,r2),r0 /* where linker thinks _DYNAMIC is */ 49*e83f7ba2SBen Gras sub r0,r5 /* compute relocation base */ 50*e83f7ba2SBen Gras bsrf r1 /* _rtld_relocate_nonplt_self(dynp, relocbase) */ 51*e83f7ba2SBen Gras mov.l r5,@-r15 /* save relocbase */ 52*e83f7ba2SBen Gras 53*e83f7ba2SBen Gras4: 54*e83f7ba2SBen Gras mov.l @r15+,r5 /* restore relocbase */ 55*e83f7ba2SBen Gras add #-8,r15 /* room for values returned by _rtld */ 56*e83f7ba2SBen Gras mov r15,r4 57*e83f7ba2SBen Gras mov.l 1f,r0 58*e83f7ba2SBen Gras bsrf r0 /* _rtld(sp, relocbase) */ 59*e83f7ba2SBen Gras mov.l r9,@-r15 /* save ps_strings */ 60*e83f7ba2SBen Gras3: 61*e83f7ba2SBen Gras mov.l @r15+,r9 /* restore ps_strings */ 62*e83f7ba2SBen Gras 63*e83f7ba2SBen Gras mov.l @r15+,r7 /* from _rtld: exit procedure */ 64*e83f7ba2SBen Gras mov.l @r15+,r8 /* from _rtld: main object */ 65*e83f7ba2SBen Gras 66*e83f7ba2SBen Gras mov.l @r15,r4 /* restore argc */ 67*e83f7ba2SBen Gras 68*e83f7ba2SBen Gras mov r15,r5 /* restore argv */ 69*e83f7ba2SBen Gras add #4,r5 70*e83f7ba2SBen Gras 71*e83f7ba2SBen Gras mov r4,r6 /* restore envp */ 72*e83f7ba2SBen Gras shll2 r6 73*e83f7ba2SBen Gras add r15,r6 74*e83f7ba2SBen Gras jmp @r0 /* entry point returned by _rtld */ 75*e83f7ba2SBen Gras add #8,r6 76*e83f7ba2SBen Gras .align 2 77*e83f7ba2SBen Gras1: .long _rtld-3b 78*e83f7ba2SBen Gras2: .long _GLOBAL_OFFSET_TABLE_ 79*e83f7ba2SBen Gras .long _DYNAMIC@GOTOFF 80*e83f7ba2SBen Gras .long _DYNAMIC@GOT 81*e83f7ba2SBen Gras .long _rtld_relocate_nonplt_self-4b 82*e83f7ba2SBen Gras .size .rtld_start,.-.rtld_start 83*e83f7ba2SBen Gras 84*e83f7ba2SBen Gras .align 2 85*e83f7ba2SBen Gras .globl _rtld_bind_start 86*e83f7ba2SBen Gras .type _rtld_bind_start,@function 87*e83f7ba2SBen Gras_rtld_bind_start: /* r0 = obj, r1 = reloff */ 88*e83f7ba2SBen Gras mov.l r2,@-r15 /* save registers */ 89*e83f7ba2SBen Gras mov.l r3,@-r15 90*e83f7ba2SBen Gras mov.l r4,@-r15 91*e83f7ba2SBen Gras mov.l r5,@-r15 92*e83f7ba2SBen Gras mov.l r6,@-r15 93*e83f7ba2SBen Gras mov.l r7,@-r15 94*e83f7ba2SBen Gras sts.l mach,@-r15 95*e83f7ba2SBen Gras sts.l macl,@-r15 96*e83f7ba2SBen Gras sts.l pr,@-r15 97*e83f7ba2SBen Gras 98*e83f7ba2SBen Gras mov r0,r4 /* copy of obj */ 99*e83f7ba2SBen Gras mov.l 2f,r0 100*e83f7ba2SBen Gras bsrf r0 /* call the binder */ 101*e83f7ba2SBen Gras mov r1,r5 /* copy of reloff */ 102*e83f7ba2SBen Gras4: 103*e83f7ba2SBen Gras lds.l @r15+,pr /* restore registers */ 104*e83f7ba2SBen Gras lds.l @r15+,macl 105*e83f7ba2SBen Gras lds.l @r15+,mach 106*e83f7ba2SBen Gras mov.l @r15+,r7 107*e83f7ba2SBen Gras mov.l @r15+,r6 108*e83f7ba2SBen Gras mov.l @r15+,r5 109*e83f7ba2SBen Gras mov.l @r15+,r4 110*e83f7ba2SBen Gras mov.l @r15+,r3 111*e83f7ba2SBen Gras jmp @r0 112*e83f7ba2SBen Gras mov.l @r15+,r2 113*e83f7ba2SBen Gras .align 2 114*e83f7ba2SBen Gras2: .long _rtld_bind-4b 115*e83f7ba2SBen Gras .size _rtld_bind_start,.-_rtld_bind_start 116*e83f7ba2SBen Gras 117*e83f7ba2SBen Gras .end 118