1 /* $Id: crt0.c,v 1.1.1.2 2009/09/04 00:27:35 gmcgarry Exp $ */
3 * Copyright (c) 2008 Gregory McGarry <g.mcgarry@ieee.org>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 void _start(int, char **, char **);
23 char *__progname
= "";
56 _start(int argc
, char *argv
[], char *envp
[])
64 if ((namep
= argv
[0]) != NULL
) {
65 if ((__progname
= _strrchr(namep
, '/')) == NULL
)
72 * Initialise hooks inside libc
74 if (mach_init_routine
)
75 (*mach_init_routine
)();
76 if (_cthread_init_routine
)
77 (*_cthread_init_routine
)();
87 exit(main(argc
, argv
, environ
));
94 * dylib constructors/destructors
99 " .long __dyld_init\n"
102 " .long __dyld_fini\n"
106 * void _dyld_func_lookup(const char *, void **);
108 * jump to the linker via the pointer in the __dyld section
113 " .private_extern __dyld_func_lookup\n"
114 "__dyld_func_lookup:\n"
115 " lis r11,ha16(Ldyld_func_lookup)\n"
116 " lwz r11,lo16(Ldyld_func_lookup)(r11)\n"
122 * void dyld_stub_binding_helper(void)
127 " .private_extern dyld_stub_binding_helper\n"
128 "dyld_stub_binding_helper:\n"
129 " lis r12,ha16(Ldyld_lazy_binder)\n"
130 " lwz r12,lo16(Ldyld_lazy_binder)(r12)\n"
132 " lis r12,ha16(__mh_execute_header)\n"
133 " addi r12,r12,lo16(__mh_execute_header)\n"
143 "Ldyld_lazy_binder:\n"
144 " .long 0x8fe01000\n"
145 "Ldyld_func_lookup:\n"
146 " .long 0x8fe01008\n"
147 " .long __mh_execute_header\n"
151 " .long ___progname\n"
156 asm("\t.subsections_via_symbols\n");
160 IDENT("$Id: crt0.c,v 1.1.1.2 2009/09/04 00:27:35 gmcgarry Exp $");