2 * Copyright (c) 1999-2005 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@
24 * C runtime startup for i386 and ppc interface to the dynamic linker.
25 * This is the same as the entry point in crt0.o with the addition of the
26 * address of the mach header passed as the an extra first argument.
28 * Kernel sets up stack frame to look like:
60 * sp-> | mh | address of where the a.out's file offset 0 is in memory
63 * Where arg[i] and env[i] point into the STRING AREA
71 __dyld_start_static_picbase:
72 .long L__dyld_start_picbase
77 # stable entry points into dyld
78 .globl _stub_binding_helper
80 jmp _stub_binding_helper_interface
84 .globl _dyld_func_lookup
86 jmp __Z18lookupDyldFunctionPKcPm
92 pushl $0 # push a zero for debugger end of frames marker
93 movl %esp,%ebp # pointer to base of kernel frame
94 andl $-16,%esp # force SSE alignment
96 # call dyldbootstrap::start(app_mh, argc, argv, slide)
97 call L__dyld_start_picbase
98 L__dyld_start_picbase:
99 popl %ebx # set %ebx to runtime value of picbase
100 movl __dyld_start_static_picbase-L__dyld_start_picbase(%ebx), %eax
101 subl %eax, %ebx # slide = L__dyld_start_picbase - [__dyld_start_static_picbase]
102 pushl %ebx # param4 = slide
104 pushl %ebx # param3 = argv
106 pushl %ebx # param2 = argc
108 pushl %ebx # param1 = mh
109 call __ZN13dyldbootstrap5startEPK11mach_headeriPPKcl
111 # clean up stack and jump to result
112 movl %ebp,%esp # restore the unaligned stack pointer
113 addl $8,%esp # remove the mh argument, and debugger end
115 movl $0,%ebp # restore ebp back to zero
116 jmp *%eax # jump to the entry point
119 .globl dyld_stub_binding_helper
120 dyld_stub_binding_helper:
123 #endif /* __i386__ */
132 # stable entry points into dyld
135 .globl _stub_binding_helper
136 _stub_binding_helper:
137 jmp _stub_binding_helper_interface
141 .globl _dyld_func_lookup
143 jmp __Z18lookupDyldFunctionPKcPm
149 pushq $0 # push a zero for debugger end of frames marker
150 movq %rsp,%rbp # pointer to base of kernel frame
151 andq $-16,%rsp # force SSE alignment
153 # call dyldbootstrap::start(app_mh, argc, argv, slide)
154 movq 8(%rbp),%rdi # param1 = mh into %rdi
155 movl 16(%rbp),%esi # param2 = argc into %esi
156 leaq 24(%rbp),%rdx # param3 = &argv[0] into %rdx
157 movq __dyld_start_static(%rip), %r8
158 leaq __dyld_start(%rip), %rcx
159 subq %r8, %rcx # param4 = slide into %rcx
160 call __ZN13dyldbootstrap5startEPK11mach_headeriPPKcl
162 # clean up stack and jump to result
163 movq %rbp,%rsp # restore the unaligned stack pointer
164 addq $16,%rsp # remove the mh argument, and debugger end frame marker
165 movq $0,%rbp # restore ebp back to zero
166 jmp *%rax # jump to the entry point
168 #endif /* __x86_64__ */
171 #if __ppc__ || __ppc64__
172 #include <architecture/ppc/mode_independent_asm.h>
176 __dyld_start_static_picbase:
177 .g_long L__dyld_start_picbase
185 .set L_argc_offset,8 ; stack is 8-byte aligned and there is a 4-byte hole between argc and argv
186 .set L_argv_offset,16
191 ; stable entry points into dyld
192 .globl _stub_binding_helper
193 _stub_binding_helper:
194 b _stub_binding_helper_interface
196 .globl _dyld_func_lookup
198 b __Z18lookupDyldFunctionPKcPm
205 mr r26,r1 ; save original stack pointer into r26
206 subi r1,r1,GPR_BYTES ; make space for linkage
207 clrrgi r1,r1,5 ; align to 32 bytes
208 addi r0,0,0 ; load 0 into r0
209 stg r0,0(r1) ; terminate initial stack frame
210 stgu r1,-SF_MINSIZE(r1); allocate minimal stack frame
212 ; call dyldbootstrap::start(app_mh, argc, argv, slide)
213 lg r3,L_mh_offset(r26) ; r3 = mach_header
214 lwz r4,L_argc_offset(r26) ; r4 = argc (int == 4 bytes)
215 addi r5,r26,L_argv_offset ; r5 = argv
216 bcl 20,31,L__dyld_start_picbase
217 L__dyld_start_picbase:
218 mflr r31 ; put address of L__dyld_start_picbase in r31
219 addis r6,r31,ha16(__dyld_start_static_picbase-L__dyld_start_picbase)
220 lg r6,lo16(__dyld_start_static_picbase-L__dyld_start_picbase)(r6)
221 subf r6,r6,r31 ; r6 = slide
222 bl __ZN13dyldbootstrap5startEPK11mach_headeriPPKcl
224 ; clean up stack and jump to result
225 mtctr r3 ; Put entry point in count register
226 mr r12,r3 ; also put in r12 for ABI convention.
227 addi r1,r26,GPR_BYTES; Restore the stack pointer and remove the
228 ; mach_header argument.
229 bctr ; jump to the program's entry point
231 .globl dyld_stub_binding_helper
232 dyld_stub_binding_helper:
239 * dyld calls this function to terminate a process.
240 * It has a label so that CrashReporter can distinguish this
241 * termination from a random crash. rdar://problem/4764143
245 .globl _dyld_fatal_error
247 #if __ppc__ || __ppc64__
249 #elif __x86_64__ || __i386__
252 #error unknown architecture