Deleted Added
full compact
rtld_start.S (217397) rtld_start.S (218824)
1/* $NetBSD: rtld_start.S,v 1.4 2001/09/26 04:06:43 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 *
1/* $NetBSD: rtld_start.S,v 1.4 2001/09/26 04:06:43 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 * $FreeBSD: head/libexec/rtld-elf/powerpc64/rtld_start.S 217397 2011-01-14 11:32:31Z kib $
29 * $FreeBSD: head/libexec/rtld-elf/powerpc64/rtld_start.S 218824 2011-02-18 21:44:53Z nwhitehorn $
30 */
31
32#include <machine/asm.h>
33
34.extern _GLOBAL_OFFSET_TABLE_
35.extern _DYNAMIC
36
37_ENTRY(_rtld_start)
38 stdu %r1,-144(%r1) /* 16-byte aligned stack for reg saves +
39 exit_proc & obj _rtld args +
40 backchain & lrsave stack frame */
41 std %r3,96(%r1) /* argc */
42 std %r4,104(%r1) /* argv */
43 std %r5,112(%r1) /* envp */
44/* std %r6,120(%r1) *//* obj (always 0) */
45/* std %r7,128(%r1) *//* cleanup (always 0) */
46 std %r8,136(%r1) /* ps_strings */
47
48 /*
49 * Perform initial relocation of ld-elf.so. Not as easy as it
50 * sounds.
51 * - perform small forward branch to put PC into link reg
52 * - use link-time constants to determine offset to the
53 * _DYNAMIC section and the GOT. Add these to the PC to
54 * convert to absolute addresses.
55 * - call reloc_non_plt_self() to fix up ld-elf.so's relocations
56 */
57
58 bl 1f
59 .llong _DYNAMIC-.
601:
61 mflr %r3 /* PC value at .llong */
62 ld %r4,0(%r3) /* offset to _DYNAMIC */
63 add %r3,%r4,%r3 /* r3 = &_DYNAMIC, absolute value */
64
65 ld %r4,-0x8000(%r2) /* First TOC entry is TOC base */
66 subf %r4,%r4,%r2 /* Subtract from real TOC base to get base */
67
30 */
31
32#include <machine/asm.h>
33
34.extern _GLOBAL_OFFSET_TABLE_
35.extern _DYNAMIC
36
37_ENTRY(_rtld_start)
38 stdu %r1,-144(%r1) /* 16-byte aligned stack for reg saves +
39 exit_proc & obj _rtld args +
40 backchain & lrsave stack frame */
41 std %r3,96(%r1) /* argc */
42 std %r4,104(%r1) /* argv */
43 std %r5,112(%r1) /* envp */
44/* std %r6,120(%r1) *//* obj (always 0) */
45/* std %r7,128(%r1) *//* cleanup (always 0) */
46 std %r8,136(%r1) /* ps_strings */
47
48 /*
49 * Perform initial relocation of ld-elf.so. Not as easy as it
50 * sounds.
51 * - perform small forward branch to put PC into link reg
52 * - use link-time constants to determine offset to the
53 * _DYNAMIC section and the GOT. Add these to the PC to
54 * convert to absolute addresses.
55 * - call reloc_non_plt_self() to fix up ld-elf.so's relocations
56 */
57
58 bl 1f
59 .llong _DYNAMIC-.
601:
61 mflr %r3 /* PC value at .llong */
62 ld %r4,0(%r3) /* offset to _DYNAMIC */
63 add %r3,%r4,%r3 /* r3 = &_DYNAMIC, absolute value */
64
65 ld %r4,-0x8000(%r2) /* First TOC entry is TOC base */
66 subf %r4,%r4,%r2 /* Subtract from real TOC base to get base */
67
68 bl .reloc_non_plt_self /* reloc_non_plt_self(&_DYNAMIC,base) */
68 bl reloc_non_plt_self /* reloc_non_plt_self(&_DYNAMIC,base) */
69 nop
70
71 /*
72 * The _rtld() function likes to see a stack layout containing
73 * { argc, argv[0], argv[1] ... argv[N], 0, env[0], ... , env[N] }
74 * Since the PowerPC stack was 16-byte aligned at exec time, the
75 * original stack layout has to be found by moving back a word
76 * from the argv pointer.
77 */
78 ld %r4,104(%r1)
79 addi %r3,%r4,-8 /* locate argc ptr, &argv[-1] */
80 addi %r4,%r1,128 /* &exit_proc on stack */
81 addi %r5,%r1,120 /* &obj_main on stack */
82
69 nop
70
71 /*
72 * The _rtld() function likes to see a stack layout containing
73 * { argc, argv[0], argv[1] ... argv[N], 0, env[0], ... , env[N] }
74 * Since the PowerPC stack was 16-byte aligned at exec time, the
75 * original stack layout has to be found by moving back a word
76 * from the argv pointer.
77 */
78 ld %r4,104(%r1)
79 addi %r3,%r4,-8 /* locate argc ptr, &argv[-1] */
80 addi %r4,%r1,128 /* &exit_proc on stack */
81 addi %r5,%r1,120 /* &obj_main on stack */
82
83 bl ._rtld /* &_start = _rtld(sp, &exit_proc, &obj_main)*/
83 bl _rtld /* &_start = _rtld(sp, &exit_proc, &obj_main)*/
84 nop
85 ld %r2,8(%r3)
86 ld %r11,16(%r3)
87 ld %r3,0(%r3)
88 mtlr %r3
89
90 /*
91 * Restore args, with new obj/exit proc
92 */
93 ld %r3,96(%r1) /* argc */
94 ld %r4,104(%r1) /* argv */
95 ld %r5,112(%r1) /* envp */
96 ld %r6,120(%r1) /* obj */
97 ld %r7,128(%r1) /* exit proc */
98 ld %r8,136(%r1) /* ps_strings */
99
100 blrl /* _start(argc, argv, envp, obj, cleanup, ps_strings) */
101
102 li %r0,1 /* _exit() */
103 sc
104
105/*
106 * _rtld_bind_start()
107 *
108 * Call into the MI binder. This routine is reached via the PLT call cell
109 * On entry, %r11 contains a pointer to the (object, relocation) tuple.
110 *
111 * Save all registers, call into the binder to resolve and fixup the external
112 * routine, and then transfer to the external routine on return.
113 */
114 .globl _rtld_bind
115
116_ENTRY(_rtld_bind_start)
117 mflr %r0
118 std %r0,16(%r1) # save lr
119 mfcr %r0
120 std %r0,8(%r1) # save cr
121
122 stdu %r1,-48-12*8(%r1) # stack space for 8 regs + header
123 # + 2 save regs
124 std %r3,64+0*8(%r1) # save r3-r31
125 std %r4,64+1*8(%r1)
126 std %r5,64+2*8(%r1)
127 std %r6,64+3*8(%r1)
128 std %r7,64+4*8(%r1)
129 std %r8,64+5*8(%r1)
130 std %r9,64+6*8(%r1)
131 std %r10,64+7*8(%r1)
132 std %r12,64+8*8(%r1)
133
134 ld %r3,0(%r11)
135 ld %r4,8(%r11)
84 nop
85 ld %r2,8(%r3)
86 ld %r11,16(%r3)
87 ld %r3,0(%r3)
88 mtlr %r3
89
90 /*
91 * Restore args, with new obj/exit proc
92 */
93 ld %r3,96(%r1) /* argc */
94 ld %r4,104(%r1) /* argv */
95 ld %r5,112(%r1) /* envp */
96 ld %r6,120(%r1) /* obj */
97 ld %r7,128(%r1) /* exit proc */
98 ld %r8,136(%r1) /* ps_strings */
99
100 blrl /* _start(argc, argv, envp, obj, cleanup, ps_strings) */
101
102 li %r0,1 /* _exit() */
103 sc
104
105/*
106 * _rtld_bind_start()
107 *
108 * Call into the MI binder. This routine is reached via the PLT call cell
109 * On entry, %r11 contains a pointer to the (object, relocation) tuple.
110 *
111 * Save all registers, call into the binder to resolve and fixup the external
112 * routine, and then transfer to the external routine on return.
113 */
114 .globl _rtld_bind
115
116_ENTRY(_rtld_bind_start)
117 mflr %r0
118 std %r0,16(%r1) # save lr
119 mfcr %r0
120 std %r0,8(%r1) # save cr
121
122 stdu %r1,-48-12*8(%r1) # stack space for 8 regs + header
123 # + 2 save regs
124 std %r3,64+0*8(%r1) # save r3-r31
125 std %r4,64+1*8(%r1)
126 std %r5,64+2*8(%r1)
127 std %r6,64+3*8(%r1)
128 std %r7,64+4*8(%r1)
129 std %r8,64+5*8(%r1)
130 std %r9,64+6*8(%r1)
131 std %r10,64+7*8(%r1)
132 std %r12,64+8*8(%r1)
133
134 ld %r3,0(%r11)
135 ld %r4,8(%r11)
136 bl ._rtld_bind # target addr = _rtld_bind(obj, reloff)
136 bl _rtld_bind # target addr = _rtld_bind(obj, reloff)
137 nop
138
139 ld %r2,8(%r3)
140 ld %r11,16(%r3)
141 ld %r3,0(%r3)
142 mtctr %r3 # move absolute target addr into ctr
143
144 ld %r3,64+0*8(%r1) # restore r3-r31
145 ld %r4,64+1*8(%r1)
146 ld %r5,64+2*8(%r1)
147 ld %r6,64+3*8(%r1)
148 ld %r7,64+4*8(%r1)
149 ld %r8,64+5*8(%r1)
150 ld %r9,64+6*8(%r1)
151 ld %r10,64+7*8(%r1)
152 ld %r12,64+8*8(%r1)
153
154 ld %r1,0(%r1) # restore stack
155 ld %r0,8(%r1) # restore cr
156 mtcr %r0
157 ld %r0,16(%r1) # restore lr
158 mtlr %r0
159
160 bctr # jump to target
161
162 .section .note.GNU-stack,"",%progbits
137 nop
138
139 ld %r2,8(%r3)
140 ld %r11,16(%r3)
141 ld %r3,0(%r3)
142 mtctr %r3 # move absolute target addr into ctr
143
144 ld %r3,64+0*8(%r1) # restore r3-r31
145 ld %r4,64+1*8(%r1)
146 ld %r5,64+2*8(%r1)
147 ld %r6,64+3*8(%r1)
148 ld %r7,64+4*8(%r1)
149 ld %r8,64+5*8(%r1)
150 ld %r9,64+6*8(%r1)
151 ld %r10,64+7*8(%r1)
152 ld %r12,64+8*8(%r1)
153
154 ld %r1,0(%r1) # restore stack
155 ld %r0,8(%r1) # restore cr
156 mtcr %r0
157 ld %r0,16(%r1) # restore lr
158 mtlr %r0
159
160 bctr # jump to target
161
162 .section .note.GNU-stack,"",%progbits