1/* $NetBSD: rtld_start.S,v 1.6 2006/01/11 22:24:34 uwe 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include <machine/asm.h> 33 34 .text 35 .align 2 36 .globl .rtld_start 37 .type .rtld_start,@function 38 39.rtld_start: 40 mova 2f,r0 41 mov.l @r0,r2 42 add r0,r2 /* GOT */ 43 mov.l @(4,r0),r4 /* _DYNAMIC@GOTOFF */ 44 add r2,r4 /* _DYNAMIC */ 45 mov.l @(12,r0),r1 /* _rtld_relocate_nonplt_self offset */ 46 mov.l @(8,r0),r0 /* _DYNAMIC@GOT */ 47 mov r4,r5 48 mov.l @(r0,r2),r0 /* where linker thinks _DYNAMIC is */ 49 sub r0,r5 /* compute relocation base */ 50 bsrf r1 /* _rtld_relocate_nonplt_self(dynp, relocbase) */ 51 mov.l r5,@-r15 /* save relocbase */ 52 534: 54 mov.l @r15+,r5 /* restore relocbase */ 55 add #-8,r15 /* room for values returned by _rtld */ 56 mov r15,r4 57 mov.l 1f,r0 58 bsrf r0 /* _rtld(sp, relocbase) */ 59 mov.l r9,@-r15 /* save ps_strings */ 603: 61 mov.l @r15+,r9 /* restore ps_strings */ 62 63 mov.l @r15+,r7 /* from _rtld: exit procedure */ 64 mov.l @r15+,r8 /* from _rtld: main object */ 65 66 mov.l @r15,r4 /* restore argc */ 67 68 mov r15,r5 /* restore argv */ 69 add #4,r5 70 71 mov r4,r6 /* restore envp */ 72 shll2 r6 73 add r15,r6 74 jmp @r0 /* entry point returned by _rtld */ 75 add #8,r6 76 .align 2 771: .long _rtld-3b 782: .long _GLOBAL_OFFSET_TABLE_ 79 .long _DYNAMIC@GOTOFF 80 .long _DYNAMIC@GOT 81 .long _rtld_relocate_nonplt_self-4b 82 .size .rtld_start,.-.rtld_start 83 84 .align 2 85 .globl _rtld_bind_start 86 .type _rtld_bind_start,@function 87_rtld_bind_start: /* r0 = obj, r1 = reloff */ 88 mov.l r2,@-r15 /* save registers */ 89 mov.l r3,@-r15 90 mov.l r4,@-r15 91 mov.l r5,@-r15 92 mov.l r6,@-r15 93 mov.l r7,@-r15 94 sts.l mach,@-r15 95 sts.l macl,@-r15 96 sts.l pr,@-r15 97 98 mov r0,r4 /* copy of obj */ 99 mov.l 2f,r0 100 bsrf r0 /* call the binder */ 101 mov r1,r5 /* copy of reloff */ 1024: 103 lds.l @r15+,pr /* restore registers */ 104 lds.l @r15+,macl 105 lds.l @r15+,mach 106 mov.l @r15+,r7 107 mov.l @r15+,r6 108 mov.l @r15+,r5 109 mov.l @r15+,r4 110 mov.l @r15+,r3 111 jmp @r0 112 mov.l @r15+,r2 113 .align 2 1142: .long _rtld_bind-4b 115 .size _rtld_bind_start,.-_rtld_bind_start 116 117 .end 118