2017-11-08 07:22:46 -05:00
|
|
|
#include "panic.h"
|
|
|
|
#include "protected.h"
|
2017-11-04 10:45:58 -04:00
|
|
|
#include "paging.h"
|
2017-11-04 07:07:04 -04:00
|
|
|
|
2017-11-09 11:00:36 -05:00
|
|
|
#include "info.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
#include "module.h"
|
2017-11-04 06:09:53 -04:00
|
|
|
|
2020-11-25 04:06:27 -05:00
|
|
|
#include "tasks.h"
|
2020-11-25 05:35:16 -05:00
|
|
|
#include "elf.h"
|
2020-11-25 05:44:36 -05:00
|
|
|
#include "logger.h"
|
2020-11-25 04:06:27 -05:00
|
|
|
|
2017-11-04 06:09:53 -04:00
|
|
|
static struct KernelMQ_Info kinfo;
|
|
|
|
|
2017-11-08 07:22:46 -05:00
|
|
|
void init(const struct KernelMQ_Info *const kinfo_ptr)
|
2017-11-01 00:43:42 -04:00
|
|
|
{
|
2017-11-04 07:07:04 -04:00
|
|
|
kmemset(&kinfo, 0, sizeof(struct KernelMQ_Info));
|
|
|
|
|
2017-11-08 07:22:46 -05:00
|
|
|
assert(kernelmq_info_validate_and_copy(&kinfo, kinfo_ptr), "Invalid kernel information.");
|
2017-11-04 06:38:28 -04:00
|
|
|
|
2017-11-08 07:22:46 -05:00
|
|
|
protected_initialize(&kinfo);
|
2017-11-05 10:26:30 -05:00
|
|
|
|
2017-11-08 07:22:46 -05:00
|
|
|
// Set up a new post-relocate bootstrap pagetable so that
|
|
|
|
// we can map in VM, and we no longer rely on pre-relocated
|
|
|
|
// data.
|
2017-11-04 10:45:58 -04:00
|
|
|
paging_clear();
|
2017-11-08 07:22:46 -05:00
|
|
|
paging_identity(); // Still need 1:1 for lapic and video mem and such.
|
|
|
|
paging_mapkernel(&kinfo);
|
2017-11-04 10:45:58 -04:00
|
|
|
paging_load();
|
2020-11-25 03:14:21 -05:00
|
|
|
|
|
|
|
if (kinfo.modules_count > 0) {
|
2020-11-25 05:44:36 -05:00
|
|
|
const struct KernelMQ_ELF_Header *const elf_header =
|
|
|
|
(void*)kinfo.modules[0].base;
|
|
|
|
|
2020-11-25 09:02:15 -05:00
|
|
|
if (KernelMQ_ELF_Header_is_valid(elf_header)) {
|
2020-11-25 08:38:00 -05:00
|
|
|
const unsigned long real_entrypoint =
|
|
|
|
kinfo.modules[0].base + elf_header->entrypoint;
|
|
|
|
|
|
|
|
tasks_switch_to_user(real_entrypoint);
|
2020-11-25 05:44:36 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
logger_warn_from("init", "Invalid ELF header");
|
|
|
|
}
|
2020-11-25 03:14:21 -05:00
|
|
|
}
|
2017-11-03 01:10:07 -04:00
|
|
|
}
|