Lines 84-94
static pml4_entry_t *PT4;
Link Here
|
84 |
static pdp_entry_t *PT3; |
84 |
static pdp_entry_t *PT3; |
85 |
static pd_entry_t *PT2; |
85 |
static pd_entry_t *PT2; |
86 |
|
86 |
|
87 |
static void (*trampoline)(uint64_t stack, void *copy_finish, uint64_t kernend, |
87 |
static void (*trampoline)(uint64_t stack, uint64_t kernend, |
88 |
uint64_t modulep, pml4_entry_t *pagetable, uint64_t entry); |
88 |
uint64_t modulep, pml4_entry_t *pagetable, uint64_t entry, |
|
|
89 |
uint64_t copy_dst, uint64_t copy_src, uint64_t copy_src_end); |
89 |
|
90 |
|
90 |
extern uintptr_t amd64_tramp; |
91 |
extern uintptr_t amd64_tramp_inline; |
91 |
extern uint32_t amd64_tramp_size; |
92 |
extern uint32_t amd64_tramp_inline_size; |
92 |
|
93 |
|
93 |
/* |
94 |
/* |
94 |
* There is an ELF kernel and one or more ELF modules loaded. |
95 |
* There is an ELF kernel and one or more ELF modules loaded. |
Lines 101-106
elf64_exec(struct preloaded_file *fp)
Link Here
|
101 |
struct file_metadata *md; |
102 |
struct file_metadata *md; |
102 |
Elf_Ehdr *ehdr; |
103 |
Elf_Ehdr *ehdr; |
103 |
vm_offset_t modulep, kernend, trampcode, trampstack; |
104 |
vm_offset_t modulep, kernend, trampcode, trampstack; |
|
|
105 |
uint64_t copy_dst, copy_src, copy_src_end; |
106 |
EFI_STATUS status; |
104 |
int err, i; |
107 |
int err, i; |
105 |
ACPI_TABLE_RSDP *rsdp; |
108 |
ACPI_TABLE_RSDP *rsdp; |
106 |
char buf[24]; |
109 |
char buf[24]; |
Lines 155-170
elf64_exec(struct preloaded_file *fp)
Link Here
|
155 |
ehdr = (Elf_Ehdr *)&(md->md_data); |
158 |
ehdr = (Elf_Ehdr *)&(md->md_data); |
156 |
|
159 |
|
157 |
trampcode = (vm_offset_t)0x0000000040000000; |
160 |
trampcode = (vm_offset_t)0x0000000040000000; |
158 |
err = BS->AllocatePages(AllocateMaxAddress, EfiLoaderData, 1, |
161 |
status = BS->AllocatePages(AllocateMaxAddress, EfiLoaderData, 1, |
159 |
(EFI_PHYSICAL_ADDRESS *)&trampcode); |
162 |
(EFI_PHYSICAL_ADDRESS *)&trampcode); |
|
|
163 |
if (EFI_ERROR(status)) { |
164 |
printf("Failed to allocate pages for trampoline code: %lu\n", |
165 |
EFI_ERROR_CODE(status)); |
166 |
return(ENOMEM); |
167 |
} |
160 |
bzero((void *)trampcode, EFI_PAGE_SIZE); |
168 |
bzero((void *)trampcode, EFI_PAGE_SIZE); |
161 |
trampstack = trampcode + EFI_PAGE_SIZE - 8; |
169 |
trampstack = trampcode + EFI_PAGE_SIZE - 8; |
162 |
bcopy((void *)&amd64_tramp, (void *)trampcode, amd64_tramp_size); |
170 |
bcopy((void *)&amd64_tramp_inline, (void *)trampcode, amd64_tramp_inline_size); |
163 |
trampoline = (void *)trampcode; |
171 |
trampoline = (void *)trampcode; |
164 |
|
172 |
|
165 |
PT4 = (pml4_entry_t *)0x0000000040000000; |
173 |
PT4 = (pml4_entry_t *)0x0000000040000000; |
166 |
err = BS->AllocatePages(AllocateMaxAddress, EfiLoaderData, 3, |
174 |
status = BS->AllocatePages(AllocateMaxAddress, EfiLoaderData, 3, |
167 |
(EFI_PHYSICAL_ADDRESS *)&PT4); |
175 |
(EFI_PHYSICAL_ADDRESS *)&PT4); |
|
|
176 |
if (EFI_ERROR(status)) { |
177 |
printf("Failed to allocate pages for PT4: %lu\n", |
178 |
EFI_ERROR_CODE(status)); |
179 |
return(ENOMEM); |
180 |
} |
168 |
bzero(PT4, 3 * EFI_PAGE_SIZE); |
181 |
bzero(PT4, 3 * EFI_PAGE_SIZE); |
169 |
|
182 |
|
170 |
PT3 = &PT4[512]; |
183 |
PT3 = &PT4[512]; |
Lines 191-196
elf64_exec(struct preloaded_file *fp)
Link Here
|
191 |
|
204 |
|
192 |
printf("Start @ 0x%lx ...\n", ehdr->e_entry); |
205 |
printf("Start @ 0x%lx ...\n", ehdr->e_entry); |
193 |
|
206 |
|
|
|
207 |
/* Check the type of memory pages that will be overwritten |
208 |
* by the trampoline and print a warning message for easier |
209 |
* debugging. The memory map will most likely change until |
210 |
* then, but I don't expect new reserved memory blocks to |
211 |
* suddenly appear. */ |
212 |
if (!efi_verify_destination_type()) { |
213 |
printf("Important memory pages may get overwritten!\n"); |
214 |
} |
215 |
|
194 |
efi_time_fini(); |
216 |
efi_time_fini(); |
195 |
err = bi_load(fp->f_args, &modulep, &kernend, true); |
217 |
err = bi_load(fp->f_args, &modulep, &kernend, true); |
196 |
if (err != 0) { |
218 |
if (err != 0) { |
Lines 200-207
elf64_exec(struct preloaded_file *fp)
Link Here
|
200 |
|
222 |
|
201 |
dev_cleanup(); |
223 |
dev_cleanup(); |
202 |
|
224 |
|
203 |
trampoline(trampstack, efi_copy_finish, kernend, modulep, PT4, |
225 |
efi_copy_get_locations(©_dst, ©_src, ©_src_end); |
204 |
ehdr->e_entry); |
226 |
|
|
|
227 |
trampoline(trampstack, kernend, modulep, PT4, |
228 |
ehdr->e_entry, copy_dst, copy_src, copy_src_end); |
205 |
|
229 |
|
206 |
panic("exec returned"); |
230 |
panic("exec returned"); |
207 |
} |
231 |
} |