Rev 2959 | Rev 2962 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2959 | Rev 2961 | ||
---|---|---|---|
Line 45... | Line 45... | ||
45 | 45 | ||
46 | unsigned int elf_load(int fd, elf_header_t *header); |
46 | unsigned int elf_load(int fd, elf_header_t *header); |
47 | 47 | ||
48 | typedef void (*entry_point_t)(void); |
48 | typedef void (*entry_point_t)(void); |
49 | 49 | ||
50 | int elf_load_file(char *file_name, elf_header_t *header) |
50 | static int elf_load_file(char *file_name, elf_header_t *header) |
51 | { |
51 | { |
52 | int fd; |
52 | int fd; |
53 | int rc; |
53 | int rc; |
54 | 54 | ||
55 | printf("open and read '%s'...\n", file_name); |
55 | printf("open and read '%s'...\n", file_name); |
Line 66... | Line 66... | ||
66 | close(fd); |
66 | close(fd); |
67 | 67 | ||
68 | return rc; |
68 | return rc; |
69 | } |
69 | } |
70 | 70 | ||
71 | void elf_run(elf_header_t *header) |
71 | static void elf_run(elf_header_t *header) |
72 | { |
72 | { |
73 | entry_point_t entry_point; |
73 | entry_point_t entry_point; |
74 | 74 | ||
75 | entry_point = (entry_point_t)header->e_entry; |
75 | entry_point = (entry_point_t)header->e_entry; |
76 | (*entry_point)(); |
76 | (*entry_point)(); |
77 | 77 | ||
78 | /* not reached */ |
78 | /* not reached */ |
79 | } |
79 | } |
80 | 80 | ||
81 | void elf_create_pcb(elf_header_t *header) |
81 | static int elf_create_pcb(elf_header_t *header) |
82 | { |
82 | { |
83 | pcb_t *pcb; |
83 | pcb_t *pcb; |
84 | void *a; |
84 | void *a; |
85 | 85 | ||
86 | pcb = (pcb_t *)PCB_ADDRESS; |
86 | pcb = (pcb_t *)PCB_ADDRESS; |
Line 90... | Line 90... | ||
90 | printf("elf_create_pcb: memory mapping failed\n"); |
90 | printf("elf_create_pcb: memory mapping failed\n"); |
91 | return EE_MEMORY; |
91 | return EE_MEMORY; |
92 | } |
92 | } |
93 | 93 | ||
94 | pcb->entry = (entry_point_t)header->e_entry; |
94 | pcb->entry = (entry_point_t)header->e_entry; |
- | 95 | ||
- | 96 | return 0; |
|
95 | } |
97 | } |
96 | 98 | ||
97 | int main(int argc, char *argv[]) |
99 | int main(int argc, char *argv[]) |
98 | { |
100 | { |
99 | elf_header_t prog_header; |
101 | elf_header_t prog_header; |
Line 111... | Line 113... | ||
111 | printf("failed to load program\n"); |
113 | printf("failed to load program\n"); |
112 | return 1; |
114 | return 1; |
113 | } |
115 | } |
114 | 116 | ||
115 | printf("Create PCB\n"); |
117 | printf("Create PCB\n"); |
116 | elf_create_pcb(&prog_header); |
118 | if (elf_create_pcb(&prog_header) < 0) return 1; |
117 | 119 | ||
118 | printf("Load dynamic linker\n"); |
120 | printf("Load dynamic linker\n"); |
119 | file_name = "/rtld.so"; |
121 | file_name = "/rtld.so"; |
120 | printf("open and read '%s'...\n", file_name); |
122 | printf("open and read '%s'...\n", file_name); |
121 | rc = elf_load_file(file_name, &interp_header); |
123 | rc = elf_load_file(file_name, &interp_header); |