Rev 3799 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3799 | Rev 3805 | ||
---|---|---|---|
Line 17... | Line 17... | ||
17 | int memsize; |
17 | int memsize; |
18 | int stacktop; |
18 | int stacktop; |
19 | char *cmdline; |
19 | char *cmdline; |
20 | char *path; |
20 | char *path; |
21 | }; |
21 | int reserved; |
- | 22 | void *__idata_start; |
|
- | 23 | void *__idata_end; |
|
- | 24 | void (*main)(int argc, char **argv, char **envp); |
|
- | 25 | }; |
|
22 | 26 | ||
Line 23... | Line 27... | ||
23 | int _argc; |
27 | int _argc; |
24 | char **_argv; |
28 | char **_argv; |
Line 25... | Line -... | ||
25 | - | ||
26 | - | ||
27 | void __fastcall init_loader(void *libc_image); |
- | |
28 | void* __fastcall create_image(void *raw); |
29 | |
29 | int __fastcall link_image(void *img_base); |
30 | |
Line -... | Line 31... | ||
- | 31 | void* get_entry_point(void *raw); |
|
- | 32 | int (*entry)(int, char **, char **); |
|
Line 30... | Line 33... | ||
30 | void* get_entry_point(void *raw); |
33 | |
Line 31... | Line 34... | ||
31 | int (*entry)(int, char **, char **); |
34 | void init_loader(void *libc_image); |
Line 43... | Line 46... | ||
43 | 46 | ||
Line 44... | Line 47... | ||
44 | asm volatile ( "xchgw %bx, %bx"); |
47 | asm volatile ( "xchgw %bx, %bx"); |
Line 45... | Line 48... | ||
45 | 48 | ||
46 | __asm__ __volatile__( // save stack limits |
49 | __asm__ __volatile__( // save stack limits |
47 | "movl %0, %%fs:4 \n\t" // use TLS |
50 | "movl %0, %%fs:8 \n\t" // use TLS |
48 | "movl %1, %%fs:8 \n\t" |
51 | "movl %1, %%fs:12 \n\t" |
Line 49... | Line 52... | ||
49 | ::"r"(stacklow), "r"(stackhigh)); |
52 | ::"r"(stacklow), "r"(stackhigh)); |
Line 50... | Line 53... | ||
50 | 53 | ||
Line 59... | Line 62... | ||
59 | { |
62 | { |
60 | return NULL; |
63 | return NULL; |
61 | } |
64 | } |
62 | 65 | ||
Line -... | Line 66... | ||
- | 66 | void _pei386_runtime_relocator (void); |
|
- | 67 | int link_app(); |
|
- | 68 | ||
63 | char __appcwd[1024]; |
69 | char __appcwd[1024]; |
64 | int __appcwdlen; |
70 | int __appcwdlen; |
65 | char* __appenv; |
71 | char* __appenv; |
66 | int __appenv_size; |
72 | int __appenv_size; |
Line -... | Line 73... | ||
- | 73 | ||
- | 74 | static char *arg[2]; |
|
- | 75 | ||
- | 76 | extern char _tls_map[128]; |
|
67 | 77 | ||
68 | void __attribute__((noreturn)) |
78 | void __attribute__((noreturn)) |
69 | crt_startup (void *libc_base, void *obj_base, uint32_t *params) |
79 | libc_crt_startup (void *libc_base) |
70 | { |
80 | { |
71 | struct app_hdr *header; |
- | |
Line 72... | Line 81... | ||
72 | char *arg[2]; |
81 | struct app_hdr *header = NULL; |
73 | 82 | ||
Line 74... | Line 83... | ||
74 | int len; |
83 | int len; |
75 | char *p; |
84 | char *p; |
Line 76... | Line 85... | ||
76 | 85 | ||
Line -... | Line 86... | ||
- | 86 | void *my_app; |
|
- | 87 | int retval = 0; |
|
77 | void *my_app; |
88 | |
78 | int retval = 0; |
89 | _pei386_runtime_relocator(); |
- | 90 | ||
79 | 91 | memset(_tls_map, 0xFF, 32*4); |
|
Line 80... | Line 92... | ||
80 | // user_free(obj_base); |
92 | _tls_map[0] = 0xE0; |
Line 81... | Line -... | ||
81 | - | ||
82 | init_reent(); |
- | |
83 | __initPOSIXHandles(); |
93 | init_reent(); |
84 | // __appenv = load_file("/sys/system.env", &__appenv_size); |
94 | __initPOSIXHandles(); |
Line 85... | Line -... | ||
85 | - | ||
86 | init_loader(libc_base); |
- | |
87 | 95 | ||
88 | my_app = create_image((void*)(params[0])); |
96 | // __appenv = load_file("/sys/system.env", &__appenv_size); |
89 | 97 | ||
90 | if( link_image(my_app)==0) |
98 | init_loader(libc_base); |
Line 91... | Line -... | ||
91 | goto done; |
- | |
92 | - | ||
93 | header = (struct app_hdr*)NULL; |
- | |
94 | - | ||
95 | __appcwdlen = strrchr(header->path, '/') - header->path; |
- | |
96 | __appcwdlen = __appcwdlen > 1022 ? 1022 : __appcwdlen; |
- | |
97 | memcpy(__appcwd, header->path, __appcwdlen); |
- | |
98 | set_cwd(__appcwd); |
- | |
99 | 99 | ||
100 | #ifdef BRAVE_NEW_WORLD |
- | |
101 | len = strlen(header->path); |
- | |
102 | p = alloca(len+1); |
- | |
Line 103... | Line 100... | ||
103 | memcpy(p, header->path, len); |
100 | if( link_app() == 0) |
104 | p[len]=0; |
101 | goto done; |
105 | - | ||
106 | arg[0] = p; |
- | |
107 | #else |
- | |
108 | arg[0] = header->path; |
- | |
109 | #endif |
- | |
110 | - | ||
111 | _argc = 1; |
- | |
112 | - | ||
113 | if( header->cmdline != 0) |
- | |
114 | { |
- | |
115 | #ifdef BRAVE_NEW_WORLD |
- | |
116 | len = strlen(header->cmdline); |
102 | |
117 | if(len) |
103 | __appcwdlen = strrchr(header->path, '/') - header->path; |
118 | { |
- | |
119 | p = alloca(len+1); |
104 | __appcwdlen = __appcwdlen > 1022 ? 1022 : __appcwdlen; |
- | 105 | memcpy(__appcwd, header->path, __appcwdlen); |
|
Line 120... | Line 106... | ||
120 | memcpy(p, header->cmdline, len); |
106 | set_cwd(__appcwd); |
Line 121... | Line -... | ||
121 | p[len]=0; |
- | |
122 | _argc = 2; |
- | |
123 | arg[1] = p; |
- | |
124 | }; |
- | |
125 | #else |
107 | |
126 | _argc = 2; |
- | |
127 | arg[1] = header->cmdline; |
108 | arg[0] = header->path; |
128 | #endif |
109 | |
129 | }; |
110 | if( header->cmdline[0] != 0) |