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