Rev 3000 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3000 | Rev 3400 | ||
---|---|---|---|
Line 35... | Line 35... | ||
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <stdio.h> |
37 | #include <stdio.h> |
38 | #include <unistd.h> |
38 | #include <unistd.h> |
39 | #include <fcntl.h> |
39 | #include <fcntl.h> |
- | 40 | #include <loader/pcb.h> |
|
40 | 41 | ||
41 | #include <rtld.h> |
42 | #include <rtld.h> |
42 | #include <dynamic.h> |
43 | #include <dynamic.h> |
43 | #include <pcb.h> |
- | |
44 | #include <elf_load.h> |
44 | #include <elf_load.h> |
45 | #include <module.h> |
45 | #include <module.h> |
46 | #include <arch.h> |
46 | #include <rtld_arch.h> |
47 | 47 | ||
48 | runtime_env_t runtime_env; |
48 | runtime_env_t runtime_env; |
49 | 49 | ||
- | 50 | void program_run(void *entry, pcb_t *pcb); |
|
- | 51 | ||
50 | void _rtld_main(void) |
52 | void _rtld_main(void) |
51 | { |
53 | { |
52 | pcb_t *pcb; |
- | |
53 | static module_t prog; |
54 | static module_t prog; |
54 | module_t *rtld; |
55 | module_t *rtld; |
55 | 56 | ||
56 | printf("Hello, world! (from rtld)\n"); |
57 | printf("Hello, world! (from rtld)\n"); |
57 | 58 | ||
Line 64... | Line 65... | ||
64 | /* rtld_dynamic and rtld->bias were filled out by the bootstrap code */ |
65 | /* rtld_dynamic and rtld->bias were filled out by the bootstrap code */ |
65 | rtld = &runtime_env.rtld; |
66 | rtld = &runtime_env.rtld; |
66 | printf("Parse rtld .dynamic section at 0x%x\n", runtime_env.rtld_dynamic); |
67 | printf("Parse rtld .dynamic section at 0x%x\n", runtime_env.rtld_dynamic); |
67 | dynamic_parse(runtime_env.rtld_dynamic, rtld->bias, &rtld->dyn); |
68 | dynamic_parse(runtime_env.rtld_dynamic, rtld->bias, &rtld->dyn); |
68 | 69 | ||
69 | pcb = __pcb_get(); |
- | |
70 | printf("Parse program .dynamic section at 0x%x\n", pcb->dynamic); |
70 | printf("Parse program .dynamic section at 0x%x\n", __pcb->dynamic); |
71 | dynamic_parse(pcb->dynamic, 0, &prog.dyn); |
71 | dynamic_parse(__pcb->dynamic, 0, &prog.dyn); |
72 | prog.bias = 0; |
72 | prog.bias = 0; |
73 | prog.dyn.soname = "[program]"; |
73 | prog.dyn.soname = "[program]"; |
74 | 74 | ||
75 | /* Initialize list of loaded modules */ |
75 | /* Initialize list of loaded modules */ |
76 | list_initialize(&runtime_env.modules_head); |
76 | list_initialize(&runtime_env.modules_head); |
Line 96... | Line 96... | ||
96 | modules_process_relocs(); |
96 | modules_process_relocs(); |
97 | 97 | ||
98 | /* |
98 | /* |
99 | * Finally, run the main program. |
99 | * Finally, run the main program. |
100 | */ |
100 | */ |
101 | printf("Run program.. (at 0x%x)\n", (uintptr_t)pcb->entry); |
101 | printf("Run program.. (at 0x%x)\n", (uintptr_t)__pcb->entry); |
102 | pcb->entry(); |
102 | //__pcb->entry(); |
- | 103 | program_run(__pcb->entry, __pcb); |
|
- | 104 | } |
|
- | 105 | ||
- | 106 | /** Fake main to satisfy dependency from libc */ |
|
- | 107 | int main(int argc, char *argv[]) |
|
- | 108 | { |
|
- | 109 | return 0; |
|
- | 110 | } |
|
- | 111 | ||
- | 112 | typedef void (*ep2)(void *); |
|
- | 113 | ||
- | 114 | void program_run(void *entry, pcb_t *pcb) |
|
- | 115 | { |
|
- | 116 | asm ( |
|
- | 117 | // "xorl %%ebx, %%ebx\n" |
|
- | 118 | // "movl 0(%%ebx), %%ecx\n" |
|
- | 119 | "mov %%eax, %%ebx\n" |
|
- | 120 | "jmp *%0\n" |
|
- | 121 | :: "m" (entry), "a" (pcb) |
|
- | 122 | ); |
|
103 | } |
123 | } |
104 | 124 | ||
105 | /** @} |
125 | /** @} |
106 | */ |
126 | */ |