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