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
97 #if __ppc__ || __ppc64__
98 #include <architecture/ppc/mode_independent_asm.h>
100 * This is the interface for the stub_binding_helper for the ppc:
101 * The caller has placed in r11 the address of the a lazy pointer to be filled
102 * in with the value for the defined symbol and placed in r12 the address of
103 * the the mach header this pointer comes from.
105 * r11 address of lazy pointer
106 * r12 address of mach header
108 #define LRSAVE MODE_CHOICE(8,16)
109 #define STACK_SIZE MODE_CHOICE(144,288)
110 #define R3SAVE MODE_CHOICE(56,112)
111 #define R4SAVE MODE_CHOICE(60,120)
112 #define R5SAVE MODE_CHOICE(64,128)
113 #define R6SAVE MODE_CHOICE(68,136)
114 #define R7SAVE MODE_CHOICE(72,144)
115 #define R8SAVE MODE_CHOICE(76,152)
116 #define R9SAVE MODE_CHOICE(80,160)
117 #define R10SAVE MODE_CHOICE(84,168)
122 .globl _stub_binding_helper_interface
123 _stub_binding_helper_interface:
124 mflr r0 ; get link register value
125 stg r0,LRSAVE(r1) ; save link register value in the linkage area
126 stgu r1,-STACK_SIZE(r1) ; save stack pointer and update it
128 stg r3,R3SAVE(r1) ; save all registers that could contain
129 stg r4,R4SAVE(r1) ; parameters to the routine that is being
130 stg r5,R5SAVE(r1) ; bound.
137 mr r3,r12 ; move address of mach header to 1st parameter
138 mr r4,r11 ; move address of lazy pointer to 2nd parameter
139 ; call dyld::bindLazySymbol(mh, lazy_symbol_pointer_address)
140 bl __ZN4dyld14bindLazySymbolEPK11mach_headerPm
141 mr r12,r3 ; move the symbol`s address into r12
142 mtctr r12 ; move the symbol`s address into count register
144 lg r0,STACK_SIZE+LRSAVE(r1) ; get old link register value
146 lg r3,R3SAVE(r1) ; restore all registers that could contain
147 lg r4,R4SAVE(r1) ; parameters to the routine that was bound.
155 addi r1,r1,STACK_SIZE; restore old stack pointer
156 mtlr r0 ; restore link register
158 bctr ; jump to the symbol`s address that was bound