Rev 5198 | Rev 6074 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5198 | Rev 6068 | ||
---|---|---|---|
Line 17... | Line 17... | ||
17 | #include |
17 | #include |
18 | #include |
18 | #include |
19 | #include |
19 | #include |
20 | #include |
20 | #include |
Line -... | Line 21... | ||
- | 21 | ||
- | 22 | struct app_hdr |
|
- | 23 | { |
|
- | 24 | char banner[8]; |
|
- | 25 | int version; |
|
- | 26 | int start; |
|
- | 27 | int iend; |
|
- | 28 | int memsize; |
|
- | 29 | int stacktop; |
|
21 | 30 | char *cmdline; |
|
- | 31 | char *path; |
|
Line -... | Line 32... | ||
- | 32 | }; |
|
Line 22... | Line 33... | ||
22 | #include "cpu_features.h" |
33 | |
23 | 34 | extern int main (int, char **, char **); |
|
24 | 35 | ||
25 | /* NOTE: The code for initializing the _argv, _argc, and environ variables |
36 | /* NOTE: The code for initializing the _argv, _argc, and environ variables |
26 | * has been moved to a separate .c file which is included in both |
37 | * has been moved to a separate .c file which is included in both |
Line -... | Line 38... | ||
- | 38 | * crt1.c and dllcrt1.c. This means changes in the code don't have to |
|
- | 39 | * be manually synchronized, but it does lead to this not-generally- |
|
Line 27... | Line -... | ||
27 | * crt1.c and dllcrt1.c. This means changes in the code don't have to |
- | |
28 | * be manually synchronized, but it does lead to this not-generally- |
40 | * a-good-idea use of include. */ |
29 | * a-good-idea use of include. */ |
- | |
30 | - | ||
31 | - | ||
32 | extern char __cmdline[]; |
- | |
33 | extern char __pgmname[]; |
- | |
34 | - | ||
35 | extern int main (int, char **, char **); |
- | |
36 | - | ||
37 | int _errno; |
- | |
38 | int _fmode; |
- | |
39 | - | ||
40 | int _argc; |
- | |
41 | char **_argv; |
- | |
Line 42... | Line 41... | ||
42 | 41 | ||
43 | static char *arg[2]; |
42 | char* __appenv; |
44 | 43 | int __appenv_size; |
|
45 | void _exit(int __status) __attribute__((noreturn)); |
44 | |
Line 46... | Line -... | ||
46 | - | ||
47 | - | ||
48 | char * __libc_getenv(const char *name) |
45 | extern char _tls_map[128]; |
49 | { |
46 | |
50 | return NULL; |
47 | char * __libc_getenv(const char *name) |
51 | } |
48 | { |
- | 49 | return NULL; |
|
52 | 50 | } |
|
- | 51 | ||
53 | void __main (){}; |
52 | static int split_cmdline(char *cmdline, char **argv) |
- | 53 | { |
|
54 | 54 | enum quote_state |
|
55 | struct app_hdr |
55 | { |
56 | { |
56 | QUOTE_NONE, /* no " active in current parm */ |
57 | char banner[8]; |
57 | QUOTE_DELIMITER, /* " was first char and must be last */ |
58 | int version; |
- | |
Line 59... | Line 58... | ||
59 | int start; |
58 | QUOTE_STARTED /* " was seen, look for a match */ |
60 | int iend; |
- | |
61 | int memsize; |
59 | }; |
62 | int stacktop; |
- | |
63 | char *cmdline; |
- | |
64 | char *path; |
- | |
65 | }; |
60 | |
66 | 61 | enum quote_state state; |
|
- | 62 | unsigned int argc; |
|
- | 63 | char *p = cmdline; |
|
- | 64 | char *new_arg, *start; |
|
- | 65 | ||
- | 66 | argc = 0; |
|
- | 67 | ||
- | 68 | for(;;) |
|
- | 69 | { |
|
- | 70 | /* skip over spaces and tabs */ |
|
- | 71 | if ( *p ) |
|
- | 72 | { |
|
- | 73 | while (*p == ' ' || *p == '\t') |
|
- | 74 | ++p; |
|
- | 75 | } |
|
- | 76 | ||
- | 77 | if (*p == '\0') |
|
- | 78 | break; |
|
- | 79 | ||
- | 80 | state = QUOTE_NONE; |
|
- | 81 | if( *p == '\"' ) |
|
- | 82 | { |
|
67 | typedef void (*ctp)(); |
83 | p++; |
- | 84 | state = QUOTE_DELIMITER; |
|
- | 85 | } |
|
- | 86 | new_arg = start = p; |
|
- | 87 | for (;;) |
|
- | 88 | { |
|
- | 89 | if( *p == '\"' ) |
|
- | 90 | { |
|
- | 91 | p++; |
|
- | 92 | if( state == QUOTE_NONE ) |
|
- | 93 | { |
|
- | 94 | state = QUOTE_STARTED; |
|
- | 95 | } |
|
- | 96 | else |
|
- | 97 | { |
|
- | 98 | state = QUOTE_NONE; |
|
- | 99 | } |
|
- | 100 | continue; |
|
- | 101 | } |
|
- | 102 | ||
- | 103 | if( *p == ' ' || *p == '\t' ) |
|
- | 104 | { |
|
- | 105 | if( state == QUOTE_NONE ) |
|
- | 106 | { |
|
- | 107 | break; |
|
- | 108 | } |
|
- | 109 | } |
|
- | 110 | ||
- | 111 | if( *p == '\0' ) |
|
- | 112 | break; |
|
- | 113 | ||
- | 114 | if( *p == '\\' ) |
|
- | 115 | { |
|
- | 116 | if( p[1] == '\"' ) |
|
- | 117 | { |
|
- | 118 | ++p; |
|
- | 119 | if( p[-2] == '\\' ) |
|
- | 120 | { |
|
- | 121 | continue; |
|
68 | static void __do_global_ctors () |
122 | } |
- | 123 | } |
|
- | 124 | } |
|
- | 125 | if( argv ) |
|
- | 126 | { |
|
- | 127 | *(new_arg++) = *p; |
|
- | 128 | } |
|
- | 129 | ++p; |
|
- | 130 | }; |
|
- | 131 | ||
- | 132 | if( argv ) |
|
- | 133 | { |
|
- | 134 | argv[ argc ] = start; |
|
- | 135 | ++argc; |
|
- | 136 | ||
- | 137 | /* |
|
- | 138 | The *new = '\0' is req'd in case there was a \" to " |
|
- | 139 | translation. It must be after the *p check against |
|
- | 140 | '\0' because new and p could point to the same char |
|
- | 141 | in which case the scan would be terminated too soon. |
|
- | 142 | */ |
|
- | 143 | ||
- | 144 | if( *p == '\0' ) |
|
- | 145 | { |
|
- | 146 | *new_arg = '\0'; |
|
- | 147 | break; |
|
- | 148 | } |
|
- | 149 | *new_arg = '\0'; |
|
- | 150 | ++p; |
|
- | 151 | } |
|
69 | { |
152 | else |
70 | extern int __CTOR_LIST__; |
153 | { |
- | 154 | ++argc; |
|
- | 155 | if( *p == '\0' ) |
|
71 | int *c = &__CTOR_LIST__; |
156 | { |
Line 72... | Line 157... | ||
72 | c++; |
157 | break; |
73 | while (*c) |
158 | } |
74 | { |
159 | ++p; |
75 | ctp d = (ctp)*c; |
- | |
76 | (d)(); |
160 | } |
77 | c++; |
- | |
78 | } |
- | |
79 | } |
161 | } |
Line 80... | Line -... | ||
80 | - | ||
81 | void __attribute__((noreturn)) |
162 | |
82 | __crt_startup (void) |
163 | return argc; |
83 | { |
- | |
84 | int nRet; |
- | |
Line -... | Line 164... | ||
- | 164 | }; |
|
- | 165 | ||
- | 166 | void __attribute__((noreturn)) |
|
85 | struct app_hdr *header; |
167 | __crt_startup (void) |
Line 86... | Line -... | ||
86 | - | ||
Line 87... | Line 168... | ||
87 | 168 | { |
|
88 | init_global_reent(); |
169 | struct app_hdr *header = NULL; |
89 | - | ||
90 | /* |
170 | int retval = 0; |
91 | * Initialize floating point unit. |
- | |
92 | */ |
- | |
93 | __cpu_features_init (); /* Do we have SSE, etc.*/ |
- | |
94 | // _fpreset (); /* Supplied by the runtime library. */ |
- | |
95 | - | ||
96 | __do_global_ctors(); |
- | |
97 | - | ||
98 | arg[0] = &__pgmname[0]; |
- | |
99 | - | ||
100 | if( __cmdline[0] != 0) |
- | |
101 | { |
- | |
102 | _argc = 2; |
- | |
103 | arg[1] = &__cmdline[0]; |
- | |
104 | } else _argc = 1; |
171 | |
105 | - | ||
106 | _argv = arg; |
- | |
107 | - | ||
108 | /* |
- | |
109 | * Sets the default file mode. |
- | |
110 | * If _CRT_fmode is set, also set mode for stdin, stdout |
172 | char **argv; |
111 | * and stderr, as well |
- | |
Line -... | Line 173... | ||
- | 173 | int argc; |
|
- | 174 | ||
- | 175 | memset(_tls_map, 0xFF, 32*4); |
|
- | 176 | _tls_map[0] = 0xE0; |
|
- | 177 | init_reent(); |
|
- | 178 | init_stdio(); |
|
- | 179 | ||
- | 180 | ||
- | 181 | if( header->cmdline[0] != 0) |
|
Line -... | Line 182... | ||
- | 182 | { |
|
- | 183 | argc = split_cmdline(header->cmdline, NULL) + 1; |
|
- | 184 | argv = alloca((argc+1)*sizeof(char*)); |
|
- | 185 | argv[0] = header->path; |