Rev 2932 | Rev 2961 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2932 | Rev 2959 | ||
---|---|---|---|
Line 36... | Line 36... | ||
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 <sys/types.h> |
40 | #include <sys/types.h> |
- | 41 | #include <as.h> |
|
41 | 42 | ||
42 | #include "elf.h" |
43 | #include "elf.h" |
- | 44 | #include "pcb.h" |
|
43 | 45 | ||
44 | unsigned int elf_load(int fd, elf_header_t *header); |
46 | unsigned int elf_load(int fd, elf_header_t *header); |
45 | 47 | ||
46 | typedef void (*entry_point_t)(void); |
48 | typedef void (*entry_point_t)(void); |
47 | 49 | ||
Line 74... | Line 76... | ||
74 | (*entry_point)(); |
76 | (*entry_point)(); |
75 | 77 | ||
76 | /* not reached */ |
78 | /* not reached */ |
77 | } |
79 | } |
78 | 80 | ||
- | 81 | void elf_create_pcb(elf_header_t *header) |
|
- | 82 | { |
|
- | 83 | pcb_t *pcb; |
|
- | 84 | void *a; |
|
- | 85 | ||
- | 86 | pcb = (pcb_t *)PCB_ADDRESS; |
|
- | 87 | ||
- | 88 | a = as_area_create(pcb, sizeof(pcb_t), AS_AREA_READ | AS_AREA_WRITE); |
|
- | 89 | if (a == (void *)(-1)) { |
|
- | 90 | printf("elf_create_pcb: memory mapping failed\n"); |
|
- | 91 | return EE_MEMORY; |
|
- | 92 | } |
|
- | 93 | ||
- | 94 | pcb->entry = (entry_point_t)header->e_entry; |
|
- | 95 | } |
|
- | 96 | ||
79 | int main(int argc, char *argv[]) |
97 | int main(int argc, char *argv[]) |
80 | { |
98 | { |
81 | elf_header_t header; |
99 | elf_header_t prog_header; |
- | 100 | elf_header_t interp_header; |
|
82 | char *file_name; |
101 | char *file_name; |
83 | int rc; |
102 | int rc; |
84 | 103 | ||
85 | printf("This is loader\n"); |
104 | printf("This is loader\n"); |
86 | getchar(); |
105 | getchar(); |
87 | 106 | ||
88 | file_name = "/test"; |
- | |
89 | rc = elf_load_file(file_name, &header); |
- | |
90 | printf("open and read '%s'...\n", file_name); |
107 | printf("Load program\n"); |
91 | 108 | ||
- | 109 | rc = elf_load_file("/tetris", &prog_header); |
|
92 | if (rc < 0) { |
110 | if (rc < 0) { |
93 | printf("failed to load program\n"); |
111 | printf("failed to load program\n"); |
94 | return 1; |
112 | return 1; |
95 | } |
113 | } |
96 | 114 | ||
97 | printf("run program\n"); |
115 | printf("Create PCB\n"); |
- | 116 | elf_create_pcb(&prog_header); |
|
- | 117 | ||
- | 118 | printf("Load dynamic linker\n"); |
|
- | 119 | file_name = "/rtld.so"; |
|
- | 120 | printf("open and read '%s'...\n", file_name); |
|
- | 121 | rc = elf_load_file(file_name, &interp_header); |
|
- | 122 | if (rc < 0) { |
|
- | 123 | printf("failed to load dynamic linker\n"); |
|
- | 124 | return 1; |
|
- | 125 | } |
|
- | 126 | ||
- | 127 | printf("run dynamic linker\n"); |
|
98 | elf_run(&header); |
128 | elf_run(&interp_header); |
99 | 129 | ||
100 | /* not reached */ |
130 | /* not reached */ |
101 | return 0; |
131 | return 0; |
102 | } |
132 | } |
103 | 133 |