Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / pcc / dist / pcc-libs / csu / darwin / i386 / crt0.c
bloba54d74397894dc56ebeaf8fcf0d21db0befefeb9
1 /* $Id: crt0.c,v 1.1.1.2 2009/09/04 00:27:35 gmcgarry Exp $ */
2 /*-
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.
18 #include "common.h"
20 void _start(int, char **, char **);
22 char **environ;
23 char *__progname = "";
24 int NXArgc;
25 char **NXArgv;
27 asm(
28 #ifdef DYNAMIC
29 " .text\n"
30 " .symbol_stub\n"
31 " .picsymbol_stub\n"
32 #endif
33 " .text\n"
34 " .globl start\n"
35 " .globl _start\n"
36 " .p2align 2\n"
37 "start:\n"
38 "_start:\n"
39 " pushl $0\n"
40 " movl %esp,%ebp\n"
41 " subl $16,%esp\n"
42 " andl $-16,%esp\n"
43 " movl 4(%ebp),%ebx\n"
44 " movl %ebx,(%esp)\n"
45 " leal 8(%ebp),%ecx\n"
46 " movl %ecx,4(%esp)\n"
47 " addl $1,%ebx\n"
48 " shll $2,%ebx\n"
49 " addl %ecx,%ebx\n"
50 " movl %ebx,8(%esp)\n"
51 " call __start\n"
52 " hlt\n"
56 void
57 _start(int argc, char *argv[], char *envp[])
59 char *namep;
61 environ = envp;
62 NXArgc = argc;
63 NXArgv = argv;
65 if ((namep = argv[0]) != NULL) {
66 if ((__progname = _strrchr(namep, '/')) == NULL)
67 __progname = namep;
68 else
69 __progname++;
73 * Initialise hooks inside libc
75 if (mach_init_routine)
76 (*mach_init_routine)();
77 if (_cthread_init_routine)
78 (*_cthread_init_routine)();
80 #ifdef PROFILE
81 atexit(_mcleanup);
82 moninit();
83 #endif
85 atexit(_fini);
86 _init();
88 exit(main(argc, argv, environ));
92 #ifdef DYNAMIC
95 * dylib constructors/destructors
97 asm(
98 " .constructor\n"
99 " .p2align 2\n"
100 " .long __dyld_init\n"
101 " .destructor\n"
102 " .p2align 2\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
111 asm(
112 " .text\n"
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)
121 asm(
122 " .text\n"
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"
130 * __dyld section
132 asm(
133 " .dyld\n"
134 " .p2align 2\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"
140 " .long _NXArgc\n"
141 " .long _NXArgv\n"
142 " .long _environ\n"
143 " .long ___progname\n"
146 #endif
148 asm("\t.subsections_via_symbols\n");
150 #include "common.c"
152 IDENT("$Id: crt0.c,v 1.1.1.2 2009/09/04 00:27:35 gmcgarry Exp $");