1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-10-30 12:03:52 -04:00
kernel/arch/x86/init.c

50 lines
1.3 KiB
C
Raw Normal View History

2017-11-04 07:07:04 -04:00
#include "multiboot.h"
2017-11-04 10:45:58 -04:00
#include "paging.h"
2017-11-04 07:07:04 -04:00
2017-11-04 06:09:53 -04:00
#include <kernelmq/info.h>
2017-11-04 06:19:53 -04:00
#include <kernelmq/stdlib.h>
// Defined in linker script
extern char _kernel_offset;
2017-11-04 08:12:20 -04:00
extern char _kernel_size;
2017-11-04 06:19:53 -04:00
extern char _kernel_phys_base;
extern char _kernel_virt_base;
2017-11-05 10:26:30 -05:00
extern char _kernel_stack_top;
2017-11-04 06:09:53 -04:00
static struct KernelMQ_Info kinfo;
const struct KernelMQ_Info *init(unsigned long multiboot_magic, unsigned long multiboot_info_base)
2017-11-01 00:43:42 -04:00
{
2017-11-04 06:51:03 -04:00
if (multiboot_magic != MULTIBOOT_MAGIC) {
return 0;
}
2017-11-04 07:07:04 -04:00
kmemset(&kinfo, 0, sizeof(struct KernelMQ_Info));
if (!multiboot_parse(&kinfo, multiboot_info_base)) {
2017-11-04 06:51:03 -04:00
return 0;
}
2017-11-04 06:19:53 -04:00
kinfo.kernel_offset = (unsigned long)&_kernel_offset;
2017-11-04 08:12:20 -04:00
kinfo.kernel_size = (unsigned long)&_kernel_size;
2017-11-04 06:19:53 -04:00
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-04 08:12:20 -04: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-04 10:03:45 -04:00
kinfo.kernel_and_modules_total_size = kinfo.kernel_size + kinfo.modules_total_size;
2017-11-05 10:26:30 -05:00
kinfo.kernel_stack_top = (unsigned long)&_kernel_stack_top;
2017-11-04 10:45:58 -04:00
paging_clear();
2017-11-05 01:56:53 -04:00
paging_identity();
2017-11-04 10:45:58 -04:00
/* kinfo.freepde_start = */ paging_mapkernel(&kinfo);
paging_load();
2017-11-04 10:59:01 -04:00
paging_enable();
2017-11-04 06:38:28 -04:00
return &kinfo;
2017-11-03 01:10:07 -04:00
}