Home | History | Annotate | Line # | Download | only in mips
rtld_start.S revision 1.9
      1  1.9  mycroft /*	$NetBSD: rtld_start.S,v 1.9 2002/10/05 11:59:05 mycroft Exp $	*/
      2  1.1   mhitch 
      3  1.1   mhitch /*
      4  1.1   mhitch  * Copyright 1997 Michael L. Hitch <mhitch (at) montana.edu>
      5  1.9  mycroft  * Portions copyright 2002 Charles M. Hannum <root (at) ihack.net>
      6  1.1   mhitch  * All rights reserved.
      7  1.1   mhitch  *
      8  1.1   mhitch  * Redistribution and use in source and binary forms, with or without
      9  1.1   mhitch  * modification, are permitted provided that the following conditions
     10  1.1   mhitch  * are met:
     11  1.1   mhitch  * 1. Redistributions of source code must retain the above copyright
     12  1.1   mhitch  *    notice, this list of conditions and the following disclaimer.
     13  1.1   mhitch  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1   mhitch  *    notice, this list of conditions and the following disclaimer in the
     15  1.1   mhitch  *    documentation and/or other materials provided with the distribution.
     16  1.1   mhitch  * 3. The name of the author may not be used to endorse or promote products
     17  1.1   mhitch  *    derived from this software without specific prior written permission.
     18  1.1   mhitch  *
     19  1.1   mhitch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  1.1   mhitch  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  1.1   mhitch  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  1.1   mhitch  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  1.1   mhitch  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24  1.1   mhitch  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  1.1   mhitch  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  1.1   mhitch  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  1.1   mhitch  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28  1.1   mhitch  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  1.1   mhitch  */
     30  1.1   mhitch 
     31  1.1   mhitch #include <mips/asm.h>
     32  1.1   mhitch 
     33  1.5  mycroft .globl _C_LABEL(_rtld_relocate_nonplt_self)
     34  1.5  mycroft .globl _C_LABEL(_rtld)
     35  1.5  mycroft 
     36  1.1   mhitch LEAF(rtld_start)
     37  1.1   mhitch 	.set	noreorder
     38  1.1   mhitch 
     39  1.1   mhitch 	.cpload t9
     40  1.1   mhitch 	addu	sp, sp, -12		# adjust stack pointer
     41  1.3   castor 	.cprestore 0			# -> 0(sp) for gp
     42  1.3   castor 					# -> 4(sp) for atexit
     43  1.3   castor 					# -> 8(sp) for obj_main
     44  1.1   mhitch 	move	s0,a0			# save stack pointer from a0
     45  1.2   mhitch 	move	s1,a3			# save ps_strings pointer
     46  1.5  mycroft 
     47  1.5  mycroft 	la	a1, 1f
     48  1.5  mycroft 	bal	1f
     49  1.5  mycroft 	 la	t9,_C_LABEL(_rtld_relocate_nonplt_self)
     50  1.5  mycroft 1:	subu	a1, ra, a1		# relocbase
     51  1.5  mycroft 	move	s2,a1
     52  1.5  mycroft 	la	a0,_DYNAMIC
     53  1.5  mycroft 	addu	t9, a1, t9
     54  1.5  mycroft 	jalr	t9
     55  1.5  mycroft 	 addu	a0, a1, a0		# &_DYNAMIC
     56  1.5  mycroft 
     57  1.5  mycroft 	move	a1,s2			# relocbase
     58  1.5  mycroft 	addu	a0, sp, 4		# sp
     59  1.5  mycroft 	jal	_C_LABEL(_rtld)		# v0 = _rtld(sp, relocbase)
     60  1.5  mycroft 	 nop
     61  1.5  mycroft 
     62  1.1   mhitch 	lw	a1, 4(sp)		# our atexit function
     63  1.1   mhitch 	lw	a2, 8(sp)		# obj_main entry
     64  1.1   mhitch 	addu	sp, sp,12		# readjust stack
     65  1.1   mhitch 	move	a0,s0			# stack pointer
     66  1.1   mhitch 	move	t9,v0
     67  1.1   mhitch 	jr	t9			# _start(sp, cleanup, obj);
     68  1.1   mhitch 	move	a3,s1			# restore ps_strings
     69  1.1   mhitch 
     70  1.1   mhitch END(rtld_start)
     71  1.1   mhitch 
     72  1.1   mhitch 	.globl	_rtld_bind_start
     73  1.1   mhitch 	.ent	_rtld_bind_start
     74  1.1   mhitch _rtld_bind_start:
     75  1.1   mhitch 
     76  1.1   mhitch 	move	v1,gp			# save old GP
     77  1.1   mhitch 	add	t9,8			# modify T9 to point at .cpload
     78  1.1   mhitch 	.cpload	t9
     79  1.7  mycroft 	subu	sp,44			# save arguments and sp value in stack
     80  1.7  mycroft 	.cprestore 36
     81  1.7  mycroft 	sw	t7,40(sp)
     82  1.7  mycroft 	sw	a0,16(sp)
     83  1.7  mycroft 	sw	a1,20(sp)
     84  1.7  mycroft 	sw	a2,24(sp)
     85  1.7  mycroft 	sw	a3,28(sp)
     86  1.7  mycroft 	sw	s0,32(sp)
     87  1.1   mhitch 	move	s0,sp
     88  1.1   mhitch 	move	a0,t8			# symbol index
     89  1.1   mhitch 	move	a1,t7			# old RA
     90  1.1   mhitch 	move	a2,v1			# old GP
     91  1.1   mhitch 	move	a3,ra			# current RA
     92  1.8  mycroft 	jal	_C_LABEL(_rtld_bind)
     93  1.1   mhitch 	nop
     94  1.1   mhitch 	move	sp,s0
     95  1.7  mycroft 	lw	ra,40(sp)
     96  1.7  mycroft 	lw	a0,16(sp)
     97  1.7  mycroft 	lw	a1,20(sp)
     98  1.7  mycroft 	lw	a2,24(sp)
     99  1.7  mycroft 	lw	a3,28(sp)
    100  1.7  mycroft 	lw	s0,32(sp)
    101  1.7  mycroft 	addu	sp,44
    102  1.1   mhitch 	move	t9,v0
    103  1.1   mhitch 	jr	t9
    104  1.1   mhitch 	nop
    105  1.1   mhitch 	.end	_rtld_bind_start
    106