Home | History | Annotate | Line # | Download | only in powerpc
rtld_start.S revision 1.8
      1 /*	$NetBSD: rtld_start.S,v 1.8 2002/09/12 17:07:26 mycroft Exp $	*/
      2 
      3 /*-
      4  * Copyright (C) 1998	Tsubai Masanari
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #include <machine/asm.h>
     31 
     32 	.globl	_rtld_start
     33 	.globl	_rtld
     34 
     35 	.text
     36 
     37 _rtld_start:
     38 	stwu	1,-48(1)
     39 	stw	3,12(1)			# argc
     40 	stw	4,16(1)			# argv
     41 	stw	5,20(1)			# envp
     42 /*	stw	6,24(1)			# obj		(always 0) */
     43 /*	stw	7,28(1)			# cleanup	(always 0) */
     44 	stw	8,32(1)			# ps_strings
     45 
     46 	bl	_GLOBAL_OFFSET_TABLE_@local-4
     47 	mflr	31			# r31 = (real) GOT
     48 	lwz	30,_GLOBAL_OFFSET_TABLE_@got(31)
     49 					# the linker thought GOT were ...
     50 	lwz	3,_DYNAMIC@got(31)
     51 
     52 	subf	4,30,31			# r4 = relocbase
     53 	add	3,3,4			# r3 = &_DYNAMIC
     54 	bl	_rtld_relocate_nonplt_self@plt
     55 
     56 	subf	4,30,31			# r4 = relocbase
     57 	lwz	3,16(1)
     58 	addi	3,3,-12			# sp = &argv[-3]	/* XXX */
     59 	bl	_rtld@plt		# _start = _rtld(sp, relocbase)
     60 	mtlr	3
     61 
     62 	lwz	3,12(1)			# argc
     63 	lwz	4,16(1)			# argv
     64 	lwz	5,20(1)			# envp
     65 	lwz	6,-8(4)			# obj = sp[1] (== argv[-2])
     66 	lwz	7,-12(4)		# cleanup = sp[0] (== argv[-3])
     67 	lwz	8,32(1)			# ps_strings
     68 
     69 	addi	1,1,48
     70 	blrl		# _start(argc, argv, envp, obj, cleanup, ps_strings)
     71 
     72 	li	0,1			# _exit()
     73 	sc
     74 
     75 
     76 	.globl	_rtld_bind_start
     77 	.globl	_rtld_bind_powerpc
     78 
     79 _rtld_bind_start:
     80 	stwu	1,-160(1)
     81 
     82 	stw	0,20(1)
     83 	mflr	0
     84 	stw	0,16(1)			# save lr
     85 	mfcr	0
     86 	stw	0,12(1)			# save cr
     87 	stmw	3,24(1)			# save r3-r31
     88 
     89 	mr	3,12			# obj
     90 	mr	4,11			# reloff
     91 	bl	_rtld_bind_powerpc@plt	# _rtld_bind(obj, reloff)
     92 	mtctr	3
     93 
     94 	lmw	3,24(1)			# load r3-r31
     95 	lwz	0,12(1)			# restore cr
     96 	mtcr	0
     97 	lwz	0,16(1)			# restore lr
     98 	mtlr	0
     99 	lwz	0,20(1)
    100 
    101 	addi	1,1,160
    102 	bctr
    103 
    104 	.globl	_rtld_powerpc_pltcall
    105 	.globl	_rtld_powerpc_pltresolve
    106 
    107 _rtld_powerpc_pltcall:
    108 	slwi	11,11,2
    109 	addis	11,11,0			# addis	11,11,jmptab@ha
    110 	lwz	11,0(11)		# lwz	11,jmptab@l(11)
    111 	mtctr	11
    112 	bctr
    113 
    114 _rtld_powerpc_pltresolve:
    115 	lis	12,0			# lis	12,_rtld_bind_start@ha
    116 	addi	12,12,0			# addi	12,12,_rtld_bind_start@l
    117 	mtctr	12
    118 	lis	12,0			# lis	12,obj@ha
    119 	addi	12,12,0			# addi	12,12,obj@l
    120 	bctr
    121