/* $NetBSD: rtld_start.S,v 1.7 2002/09/12 17:18:38 mycroft Exp $ */12/*-3* Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.4* All rights reserved.5*6* This code is derived from software contributed to The NetBSD Foundation7* by Matt Thomas and by Charles M. Hannum.8*9* Redistribution and use in source and binary forms, with or without10* modification, are permitted provided that the following conditions11* are met:12* 1. Redistributions of source code must retain the above copyright13* notice, this list of conditions and the following disclaimer.14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS19* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED20* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR21* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS22* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR23* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF24* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS25* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN26* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)27* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE28* POSSIBILITY OF SUCH DAMAGE.29*/3031#include <machine/asm.h>32.text33.align 034.globl .rtld_start35.type .rtld_start,%function36.rtld_start:37mov r6, sp /* save the stack pointer */38bic sp, sp, #7 /* align the stack pointer */39sub sp, sp, #8 /* make room for obj_main & exit proc */40mov r4, r0 /* save ps_strings */41ldr sl, .L242ldr r5, .L2+443ldr r0, .L2+844.L1:45add sl, pc, sl46ldr r5, [sl, r5]47ldr r0, [sl, r0]4849sub r1, sl, r5 /* relocbase */50add r0, r1, r0 /* &_DYNAMIC */51bl _rtld_relocate_nonplt_self52mov r1, sp53add r2, sp, #454mov r0, r6 /* load the sp the kernel gave us */55bl _rtld /* call the shared loader */56mov r3, r0 /* save entry point */5758ldr r2, [sp, #0] /* r2 = cleanup */59ldr r1, [sp, #4] /* r1 = obj_main */60mov sp, r6 /* restore stack */61mov r0, r4 /* restore ps_strings */62mov pc, r3 /* jump to the entry point */63.L2:64.word _GLOBAL_OFFSET_TABLE_ - (.L1+8)65.word _GLOBAL_OFFSET_TABLE_(GOT)66.word _DYNAMIC(GOT)6768.align 069.globl _rtld_bind_start70.type _rtld_bind_start,%function71/*72* stack[0] = RA73* ip = &GOT[n+3]74* lr = &GOT[2]75*/76_rtld_bind_start:77stmdb sp!,{r0-r5,sl,fp}7879sub r1, ip, lr /* r1 = 4 * (n + 1) */80sub r1, r1, #4 /* r1 = 4 * n */81add r1, r1, r1 /* r1 = 8 * n */8283ldr r0, [lr, #-4] /* get obj ptr from GOT[1] */84mov r4, ip /* save GOT location */8586mov r5, sp /* Save the stack pointer */87bic sp, sp, #7 /* Align the stack pointer */88bl _rtld_bind /* Call the binder */89mov sp, r5 /* Restore the old stack pointer */9091str r0, [r4] /* save address in GOT */92mov ip, r0 /* save new address */9394ldmia sp!,{r0-r5,sl,fp,lr} /* restore the stack */95mov pc, ip /* jump to the new address */9697.section .note.GNU-stack,"",%progbits9899100