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