2017-11-08 07:22:46 -05:00
|
|
|
#include "multiboot.h"
|
2017-11-04 11:08:59 -04:00
|
|
|
#include "paging.h"
|
2017-11-03 22:32:23 -04:00
|
|
|
|
2017-11-09 11:00:36 -05:00
|
|
|
#include "info.h"
|
|
|
|
#include "stdlib.h"
|
2017-11-08 07:22:46 -05:00
|
|
|
|
|
|
|
// Defined in linker script
|
|
|
|
extern char _kernel_offset;
|
|
|
|
extern char _kernel_size;
|
|
|
|
extern char _kernel_phys_base;
|
|
|
|
extern char _kernel_virt_base;
|
|
|
|
extern char _kernel_stack_top;
|
2017-11-04 06:38:28 -04:00
|
|
|
|
|
|
|
static struct KernelMQ_Info kinfo;
|
|
|
|
|
2017-11-08 07:22:46 -05:00
|
|
|
const struct KernelMQ_Info *main(unsigned long multiboot_magic, unsigned long multiboot_info_base)
|
2017-11-03 22:32:23 -04:00
|
|
|
{
|
2017-11-08 07:22:46 -05:00
|
|
|
if (multiboot_magic != MULTIBOOT_MAGIC) {
|
|
|
|
return 0;
|
|
|
|
}
|
2017-11-04 07:45:48 -04:00
|
|
|
|
2017-11-04 06:38:28 -04:00
|
|
|
kmemset(&kinfo, 0, sizeof(struct KernelMQ_Info));
|
|
|
|
|
2017-11-08 07:22:46 -05:00
|
|
|
if (!multiboot_parse(&kinfo, multiboot_info_base)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
kinfo.kernel_offset = (unsigned long)&_kernel_offset;
|
|
|
|
kinfo.kernel_size = (unsigned long)&_kernel_size;
|
|
|
|
|
|
|
|
kinfo.kernel_phys_base = (unsigned long)&_kernel_phys_base;
|
|
|
|
kinfo.kernel_virt_base = (unsigned long)&_kernel_virt_base;
|
2017-11-04 06:38:28 -04:00
|
|
|
|
2017-11-08 07:22:46 -05:00
|
|
|
kinfo.kernel_phys_limit = kinfo.kernel_phys_base + kinfo.kernel_size - 1;
|
|
|
|
kinfo.kernel_virt_limit = kinfo.kernel_virt_base + kinfo.kernel_size - 1;
|
2017-11-05 02:13:54 -05:00
|
|
|
|
2017-11-08 07:22:46 -05:00
|
|
|
kinfo.kernel_and_modules_total_size = kinfo.kernel_size + kinfo.modules_total_size;
|
|
|
|
|
|
|
|
kinfo.kernel_stack_top = (unsigned long)&_kernel_stack_top;
|
2017-11-03 22:32:23 -04:00
|
|
|
|
2017-11-04 11:08:59 -04:00
|
|
|
paging_clear();
|
2017-11-08 07:22:46 -05:00
|
|
|
paging_identity();
|
|
|
|
/* kinfo.freepde_start = */ paging_mapkernel(&kinfo);
|
2017-11-04 11:08:59 -04:00
|
|
|
paging_load();
|
2017-11-08 07:22:46 -05:00
|
|
|
|
|
|
|
paging_enable();
|
|
|
|
|
|
|
|
return &kinfo;
|
2017-11-03 22:32:23 -04:00
|
|
|
}
|