Rev 3677 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3677 | Rev 3681 | ||
---|---|---|---|
Line 32... | Line 32... | ||
32 | */ |
32 | */ |
33 | /** |
33 | /** |
34 | * @file |
34 | * @file |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <stdio.h> |
- | |
38 | #include <unistd.h> |
- | |
39 | #include <fcntl.h> |
- | |
40 | #include <loader/pcb.h> |
- | |
41 | - | ||
42 | #include <rtld.h> |
37 | #include <rtld.h> |
43 | #include <dynamic.h> |
- | |
44 | #include <elf_load.h> |
- | |
45 | #include <module.h> |
- | |
46 | #include <rtld_arch.h> |
- | |
47 | 38 | ||
48 | runtime_env_t runtime_env; |
39 | runtime_env_t runtime_env; |
49 | 40 | ||
50 | void program_run(void *entry, pcb_t *pcb); |
- | |
51 | - | ||
52 | static void rtld_main(void) |
- | |
53 | { |
- | |
54 | static module_t prog; |
- | |
55 | - | ||
56 | DPRINTF("Hello, world! (from rtld)\n"); |
- | |
57 | - | ||
58 | /* |
- | |
59 | * First we need to process dynamic sections of the executable |
- | |
60 | * program and insert it into the module graph. |
- | |
61 | */ |
- | |
62 | - | ||
63 | DPRINTF("Parse program .dynamic section at 0x%x\n", __pcb->dynamic); |
- | |
64 | dynamic_parse(__pcb->dynamic, 0, &prog.dyn); |
- | |
65 | prog.bias = 0; |
- | |
66 | prog.dyn.soname = "[program]"; |
- | |
67 | - | ||
68 | /* Initialize list of loaded modules */ |
- | |
69 | list_initialize(&runtime_env.modules_head); |
- | |
70 | list_append(&prog.modules_link, &runtime_env.modules_head); |
- | |
71 | - | ||
72 | /* Pointer to program module. Used as root of the module graph. */ |
- | |
73 | runtime_env.program = &prog; |
- | |
74 | - | ||
75 | /* |
- | |
76 | * Now we can continue with loading all other modules. |
- | |
77 | */ |
- | |
78 | - | ||
79 | DPRINTF("Load all program dependencies\n"); |
- | |
80 | module_load_deps(&prog); |
- | |
81 | - | ||
82 | /* |
- | |
83 | * Now relocate/link all modules together. |
- | |
84 | */ |
- | |
85 | - | ||
86 | /* Process relocations in all modules */ |
- | |
87 | DPRINTF("Relocate all modules\n"); |
- | |
88 | modules_process_relocs(); |
- | |
89 | - | ||
90 | /* |
- | |
91 | * Finally, run the main program. |
- | |
92 | */ |
- | |
93 | DPRINTF("Run program.. (at 0x%lx)\n", (uintptr_t)__pcb->entry); |
- | |
94 | - | ||
95 | #ifndef RTLD_DEBUG |
- | |
96 | close_console(); |
- | |
97 | #endif |
- | |
98 | program_run(__pcb->entry, __pcb); |
- | |
99 | } |
- | |
100 | - | ||
101 | int main(int argc, char *argv[]) |
- | |
102 | { |
- | |
103 | rtld_main(); |
- | |
104 | return 0; |
- | |
105 | } |
- | |
106 | - | ||
107 | /** @} |
41 | /** @} |
108 | */ |
42 | */ |