1 /* $NetBSD: rtld_start.S,v 1.12 2002/10/31 20:23:25 matt Exp $ */
4 * Copyright (C) 1998 Tsubai Masanari
5 * Portions copyright 2002 Charles M. Hannum <root@ihack.net>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <machine/asm.h>
40 stw %r3,12(%r1) # argc
41 stw %r4,16(%r1) # argv
42 stw %r5,20(%r1) # envp
43 /* stw %r6,24(%r1) # obj (always 0) */
44 /* stw %r7,28(%r1) # cleanup (always 0) */
45 stw %r8,32(%r1) # ps_strings
47 bl _GLOBAL_OFFSET_TABLE_-4@local
48 mflr %r31 # r31 = (real) GOT
49 lwz %r28,0(%r31) # base-relative &_DYNAMIC
51 bl 0f # lr = next instruction
54 lwz %r29,0(%r30) # load instruction contents
55 rlwinm %r29,%r29,0,6,29 # extract PC offset
56 add %r3,%r29,%r30 # r3 = &_DYNAMIC
58 mr %r4,%r28 # r4 = relocbase
59 bl _rtld_relocate_nonplt_self@plt
62 addi %r3,%r3,-12 # sp = &argv[-3] /* XXX */
63 mr %r4,%r28 # r4 = relocbase
64 bl _rtld@plt # _start = _rtld(sp, relocbase)
67 lwz %r3,12(%r1) # argc
68 lwz %r4,16(%r1) # argv
69 lwz %r5,20(%r1) # envp
70 lwz %r6,-8(%r4) # obj = sp[1] (== argv[-2])
71 lwz %r7,-12(%r4) # cleanup = sp[0] (== argv[-3])
72 lwz %r8,32(%r1) # ps_strings
75 blrl # _start(argc, argv, envp, obj, cleanup, ps_strings)
81 .globl _rtld_bind_start
89 stw %r0,16(%r1) # save lr
91 stw %r0,12(%r1) # save cr
92 stmw %r3,24(%r1) # save r3-r31
96 bl _rtld_bind@plt # _rtld_bind(obj, reloff)
99 lmw %r3,24(%r1) # load r3-r31
100 lwz %r0,12(%r1) # restore cr
102 lwz %r0,16(%r1) # restore lr
109 .globl _rtld_powerpc_pltcall
110 .globl _rtld_powerpc_pltresolve
112 _rtld_powerpc_pltcall:
114 addis %r11,%r11,0 # addis 11,11,jmptab@ha
115 lwz %r11,0(%r11) # lwz 11,jmptab@l(11)
119 _rtld_powerpc_pltresolve:
120 lis %r12,0 # lis 12,_rtld_bind_start@ha
121 addi %r12,%r12,0 # addi 12,12,_rtld_bind_start@l
123 lis %r12,0 # lis 12,obj@ha
124 addi %r12,%r12,0 # addi 12,12,obj@l