2 * Copyright (c) 1999-2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
28 * This is the interface for the stub_binding_helper for i386:
29 * The caller has pushed the address of the a lazy pointer to be filled in with
30 * the value for the defined symbol and pushed the address of the the mach
31 * header this pointer comes from.
33 * sp+4 address of lazy pointer
34 * sp+0 address of mach header
36 * Some inter-image function calls pass parameters in registers EAX, ECX, EDX, or XXM0-3,
37 * Therefore those registers need to be preserved during the lazy binding.
39 * After the symbol has been resolved and the pointer filled in this is to pop
40 * these arguments off the stack and jump to the address of the defined symbol.
44 #define RESULT_BP 8 /* in order to trash no registers, the target is stored back on the stack then ret it done to it */
46 #define MH_PARAM_OUT 0
47 #define LP_PARAM_OUT 4
51 #define XMMM0_SAVE 32 /* 16-byte align */
55 #define STACK_SIZE 96 /* (XMMM3_SAVE+16) must be 16 byte aligned too */
60 .globl _fast_stub_binding_helper_interface
61 _fast_stub_binding_helper_interface:
63 .globl _stub_binding_helper_interface
64 _stub_binding_helper_interface:
67 subl $STACK_SIZE,%esp # at this point stack is 16-byte aligned because two meta-parameters where pushed
68 movl %eax,EAX_SAVE(%esp) # save registers that might be used as parameters
69 movl %ecx,ECX_SAVE(%esp)
70 movl %edx,EDX_SAVE(%esp)
71 movdqa %xmm0,XMMM0_SAVE(%esp)
72 movdqa %xmm1,XMMM1_SAVE(%esp)
73 movdqa %xmm2,XMMM2_SAVE(%esp)
74 movdqa %xmm3,XMMM3_SAVE(%esp)
75 movl MH_PARAM_BP(%ebp),%eax # call dyld::bindLazySymbol(mh, lazy_ptr)
76 movl %eax,MH_PARAM_OUT(%esp)
77 movl LP_PARAM_BP(%ebp),%eax
78 movl %eax,LP_PARAM_OUT(%esp)
79 call __ZN4dyld14bindLazySymbolEPK11mach_headerPm
80 movl %eax,RESULT_BP(%ebp) # store target for ret
81 movdqa XMMM0_SAVE(%esp),%xmm0 # restore registers
82 movdqa XMMM1_SAVE(%esp),%xmm1
83 movdqa XMMM2_SAVE(%esp),%xmm2
84 movdqa XMMM3_SAVE(%esp),%xmm3
85 movl EAX_SAVE(%esp),%eax
86 movl ECX_SAVE(%esp),%ecx
87 movl EDX_SAVE(%esp),%edx
90 addl $4,%esp # remove meta-parameter, other meta-parmaeter now holds target for ret
98 * This is the interface for the stub_binding_helper for x86_64:
99 * The caller has pushed the address of the a lazy pointer to be filled in with
100 * the value for the defined symbol and pushed the address of the the mach
101 * header this pointer comes from.
103 * sp+4 address of lazy pointer
104 * sp+0 address of mach header
106 * All parameters registers must be preserved.
108 * After the symbol has been resolved and the pointer filled in this is to pop
109 * these arguments off the stack and jump to the address of the defined symbol.
111 #define MH_PARAM_BP 8
112 #define LP_PARAM_BP 16
121 #define XMMM0_SAVE 64 /* 16-byte align */
122 #define XMMM1_SAVE 80
123 #define XMMM2_SAVE 96
124 #define XMMM3_SAVE 112
125 #define XMMM4_SAVE 128
126 #define XMMM5_SAVE 144
127 #define XMMM6_SAVE 160
128 #define XMMM7_SAVE 176
129 #define STACK_SIZE 192 /* (XMMM7_SAVE+16) must be 16 byte aligned too */
133 .globl _stub_binding_helper_interface
134 _stub_binding_helper_interface:
137 subq $STACK_SIZE,%rsp # at this point stack is 16-byte aligned because two meta-parameters where pushed
138 movq %rdi,RDI_SAVE(%rsp) # save registers that might be used as parameters
139 movq %rsi,RSI_SAVE(%rsp)
140 movq %rdx,RDX_SAVE(%rsp)
141 movq %rcx,RCX_SAVE(%rsp)
142 movq %r8,R8_SAVE(%rsp)
143 movq %r9,R9_SAVE(%rsp)
144 movq %rax,RAX_SAVE(%rsp)
145 movdqa %xmm0,XMMM0_SAVE(%rsp)
146 movdqa %xmm1,XMMM1_SAVE(%rsp)
147 movdqa %xmm2,XMMM2_SAVE(%rsp)
148 movdqa %xmm3,XMMM3_SAVE(%rsp)
149 movdqa %xmm4,XMMM4_SAVE(%rsp)
150 movdqa %xmm5,XMMM5_SAVE(%rsp)
151 movdqa %xmm6,XMMM6_SAVE(%rsp)
152 movdqa %xmm7,XMMM7_SAVE(%rsp)
153 movq MH_PARAM_BP(%rbp),%rdi # call dyld::bindLazySymbol(mh, lazy_ptr)
154 movq LP_PARAM_BP(%rbp),%rsi
155 call __ZN4dyld14bindLazySymbolEPK11mach_headerPm
156 movq %rax,%r11 # save target
157 movdqa XMMM0_SAVE(%rsp),%xmm0 # restore registers
158 movdqa XMMM1_SAVE(%rsp),%xmm1
159 movdqa XMMM2_SAVE(%rsp),%xmm2
160 movdqa XMMM3_SAVE(%rsp),%xmm3
161 movdqa XMMM4_SAVE(%rsp),%xmm4
162 movdqa XMMM5_SAVE(%rsp),%xmm5
163 movdqa XMMM6_SAVE(%rsp),%xmm6
164 movdqa XMMM7_SAVE(%rsp),%xmm7
165 movq RDI_SAVE(%rsp),%rdi
166 movq RSI_SAVE(%rsp),%rsi
167 movq RDX_SAVE(%rsp),%rdx
168 movq RCX_SAVE(%rsp),%rcx
169 movq R8_SAVE(%rsp),%r8
170 movq R9_SAVE(%rsp),%r9
171 movq RAX_SAVE(%rsp),%rax
172 addq $STACK_SIZE,%rsp
174 addq $16,%rsp # remove meta-parameters
175 jmp *%r11 # jmp to target
179 #if __ppc__ || __ppc64__
180 #include <architecture/ppc/mode_independent_asm.h>
182 * This is the interface for the stub_binding_helper for the ppc:
183 * The caller has placed in r11 the address of the a lazy pointer to be filled
184 * in with the value for the defined symbol and placed in r12 the address of
185 * the the mach header this pointer comes from.
187 * r11 address of lazy pointer
188 * r12 address of mach header
190 #define LRSAVE MODE_CHOICE(8,16)
191 #define STACK_SIZE MODE_CHOICE(144,288)
192 #define R3SAVE MODE_CHOICE(56,112)
193 #define R4SAVE MODE_CHOICE(60,120)
194 #define R5SAVE MODE_CHOICE(64,128)
195 #define R6SAVE MODE_CHOICE(68,136)
196 #define R7SAVE MODE_CHOICE(72,144)
197 #define R8SAVE MODE_CHOICE(76,152)
198 #define R9SAVE MODE_CHOICE(80,160)
199 #define R10SAVE MODE_CHOICE(84,168)
204 .globl _stub_binding_helper_interface
205 _stub_binding_helper_interface:
206 mflr r0 ; get link register value
207 stg r0,LRSAVE(r1) ; save link register value in the linkage area
208 stgu r1,-STACK_SIZE(r1) ; save stack pointer and update it
210 stg r3,R3SAVE(r1) ; save all registers that could contain
211 stg r4,R4SAVE(r1) ; parameters to the routine that is being
212 stg r5,R5SAVE(r1) ; bound.
219 mr r3,r12 ; move address of mach header to 1st parameter
220 mr r4,r11 ; move address of lazy pointer to 2nd parameter
221 ; call dyld::bindLazySymbol(mh, lazy_symbol_pointer_address)
222 bl __ZN4dyld14bindLazySymbolEPK11mach_headerPm
223 mr r12,r3 ; move the symbol`s address into r12
224 mtctr r12 ; move the symbol`s address into count register
226 lg r0,STACK_SIZE+LRSAVE(r1) ; get old link register value
228 lg r3,R3SAVE(r1) ; restore all registers that could contain
229 lg r4,R4SAVE(r1) ; parameters to the routine that was bound.
237 addi r1,r1,STACK_SIZE; restore old stack pointer
238 mtlr r0 ; restore link register
240 bctr ; jump to the symbol`s address that was bound