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
= "";
43 " movl 4(%ebp),%ebx\n"
45 " leal 8(%ebp),%ecx\n"
46 " movl %ecx,4(%esp)\n"
50 " movl %ebx,8(%esp)\n"
57 _start(int argc
, char *argv
[], char *envp
[])
65 if ((namep
= argv
[0]) != NULL
) {
66 if ((__progname
= _strrchr(namep
, '/')) == NULL
)
73 * Initialise hooks inside libc
75 if (mach_init_routine
)
76 (*mach_init_routine
)();
77 if (_cthread_init_routine
)
78 (*_cthread_init_routine
)();
88 exit(main(argc
, argv
, environ
));
95 * dylib constructors/destructors
100 " .long __dyld_init\n"
103 " .long __dyld_fini\n"
107 * void _dyld_func_lookup(const char *, void **);
109 * jump to the linker via the pointer in the __dyld section
113 " .private_extern __dyld_func_lookup\n"
114 "__dyld_func_lookup:\n"
115 " jmp *Ldyld_func_lookup\n"
119 * void dyld_stub_binding_helper(void)
123 " .private_extern dyld_stub_binding_helper\n"
124 "dyld_stub_binding_helper:\n"
125 " pushl $__mh_execute_header\n"
126 " jmp *Ldyld_lazy_binder\n"
135 "Ldyld_lazy_binder:\n"
136 " .long 0x8fe01000\n"
137 "Ldyld_func_lookup:\n"
138 " .long 0x8fe01008\n"
139 " .long __mh_execute_header\n"
143 " .long ___progname\n"
148 asm("\t.subsections_via_symbols\n");
152 IDENT("$Id: crt0.c,v 1.1.1.2 2009/09/04 00:27:35 gmcgarry Exp $");