Home | History | Annotate | Line # | Download | only in sh3
rtld_start.S revision 1.2
      1 /*	$NetBSD: rtld_start.S,v 1.2 2002/02/04 18:18:51 thorpej 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 
     48 	/* relocate GOT, so that we can use global function calls in rtld.c */
     49 
     50 	mova	1f,r0
     51 	mov.l	@r0,r1
     52 	add	r1,r0		/* r0 = _GLOBAL_OFFSET_TABLE_ */
     53 
     54 	mov.l	2f,r1
     55 	add	r0,r1		/* r1 = GOT end */
     56 	mov.l	3f,r2
     57 	mov.l	@(r0,r2),r3	/* r3 = where the linker thinks GOT end is */
     58 	mov	r1,r2
     59 	sub	r3,r2		/* r2 = displacement */
     60 4:
     61 	mov.l	@r0+,r3		/* add displacement to all GOT entries */
     62 	cmp/hs	r1,r0
     63 	add	#-4,r0
     64 	add	r2,r3
     65 	mov.l	r3,@r0
     66 	bf/s	4b
     67 	add	#4,r0
     68 
     69 	bra	4f		/* all done */
     70 	nop
     71 
     72 	.align	2
     73 1:	.long	_GLOBAL_OFFSET_TABLE_
     74 2:	.long	_DYNAMIC@GOTOFF
     75 3:	.long	_DYNAMIC@GOT
     76 
     77 
     78 4:
     79 	add	#-8,r15		/* Make room for return args */
     80 	mov	r15,r4
     81 	mov.l	1f,r0
     82 	add	#(1f-3f),r0
     83 	bsrf	r0		/* _rtld(sp) */
     84 	mov.l	r9,@-r15	/* save ps_strings */
     85 3:
     86 	mov.l	@r15+,r9	/* restore ps_strings */
     87 
     88 	mov.l	@r15+,r7	/* arg: cleanup */
     89 	mov.l	@r15+,r8	/* arg: obj */
     90 
     91 	mov.l	@r15,r4		/* restore argc */
     92 
     93 	mov	r15,r5		/* restore argv */
     94 	add	#4,r5
     95 
     96 	mov	r4,r6		/* restore envp */
     97 	shll2	r6
     98 	add	r15,r6
     99 	jmp	@r0
    100 	add	#8,r6
    101 	.align	2
    102 1:	.long	_rtld-.
    103 	.size	.rtld_start,.-.rtld_start
    104 
    105 	.align	2
    106 	.globl	_rtld_bind_start
    107 	.type	_rtld_bind_start,@function
    108 _rtld_bind_start:		/* r0 = flag, r1 = reloff, r2 = obj */
    109 	mov.l	r3,@-r15	/* save registers */
    110 	mov.l	r4,@-r15
    111 	mov.l	r5,@-r15
    112 	mov.l	r6,@-r15
    113 	mov.l	r7,@-r15
    114 	sts.l	mach,@-r15
    115 	sts.l	macl,@-r15
    116 	sts.l	pr,@-r15
    117 
    118 	mov.l	2f,r0
    119 	add	#(2f-4f),r0
    120 	mov	r2,r4		/* copy of obj */
    121 	bsrf	r0		/* call the binder */
    122 	mov	r1,r5		/* copy of relobj */
    123 4:
    124 	lds.l	@r15+,pr	/* restore registers */
    125 	lds.l	@r15+,macl
    126 	lds.l	@r15+,mach
    127 	mov.l	@r15+,r7
    128 	mov.l	@r15+,r6
    129 	mov.l	@r15+,r5
    130 	mov.l	@r15+,r4
    131 	jmp	@r0
    132 	mov.l	@r15+,r3
    133 	.align	2
    134 2:	.long	_rtld_bind-.
    135 	.size	_rtld_bind_start,.-_rtld_bind_start
    136 
    137 	.end
    138