Interface cleanup
This commit is contained in:
parent
9a479b1132
commit
8711fee390
@ -16,28 +16,11 @@ void kmain(uint64_t multiboot_magic, void *multiboot_data)
|
|||||||
|
|
||||||
debug_info("Kernel was loaded with command line \"%s\", by <%s>\n", kernel_boot_data.commandline, kernel_boot_data.bootloader);
|
debug_info("Kernel was loaded with command line \"%s\", by <%s>\n", kernel_boot_data.commandline, kernel_boot_data.bootloader);
|
||||||
|
|
||||||
|
memory_init();
|
||||||
|
|
||||||
cpu_init();
|
cpu_init();
|
||||||
|
|
||||||
|
|
||||||
uintptr_t start, end;
|
|
||||||
uint32_t type, i=0;
|
|
||||||
while(!multiboot_get_memory_area(i++, &start, &end, &type))
|
|
||||||
{
|
|
||||||
debug("Mem %d 0x%x-0x%x\n", type, start, end);
|
|
||||||
for(uintptr_t p = start; p < end; p += PAGE_SIZE)
|
|
||||||
{
|
|
||||||
if(p >= V2P(&kernel_start) && p < V2P(&kernel_end))
|
|
||||||
continue;
|
|
||||||
if(vmm_get_page(&BootP4, (uintptr_t)P2V(p)) == (uintptr_t)-1)
|
|
||||||
{
|
|
||||||
touch_page(&BootP4, (uintptr_t)P2V(p), PAGE_GLOBAL | PAGE_WRITE | PAGE_HUGE);
|
|
||||||
vmm_set_page(&BootP4, (uintptr_t)P2V(p), p, PAGE_GLOBAL | PAGE_HUGE | PAGE_WRITE | PAGE_PRESENT);
|
|
||||||
}
|
|
||||||
if(type == 1)
|
|
||||||
pmm_free(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
debug_ok("Boot \"Complete\"\n");
|
debug_ok("Boot \"Complete\"\n");
|
||||||
|
|
||||||
PANIC("Reached end of kernel main function\n");
|
PANIC("Reached end of kernel main function\n");
|
||||||
|
@ -43,4 +43,6 @@ void free_page(void *P4, uintptr_t addr, int free);
|
|||||||
|
|
||||||
extern union PTE BootP4;
|
extern union PTE BootP4;
|
||||||
extern int kernel_start, kernel_end;
|
extern int kernel_start, kernel_end;
|
||||||
|
|
||||||
|
void memory_init();
|
||||||
#endif
|
#endif
|
||||||
|
@ -10,6 +10,8 @@ struct kernel_boot_data_st
|
|||||||
void *mmap;
|
void *mmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define MMAP_FREE 1
|
||||||
|
|
||||||
extern struct kernel_boot_data_st kernel_boot_data;
|
extern struct kernel_boot_data_st kernel_boot_data;
|
||||||
|
|
||||||
int multiboot_init(uint64_t magic, void *mboot_info);
|
int multiboot_init(uint64_t magic, void *mboot_info);
|
||||||
|
30
src/kernel/memory/memory.c
Normal file
30
src/kernel/memory/memory.c
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include <memory.h>
|
||||||
|
#include <multiboot.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
void memory_init()
|
||||||
|
{
|
||||||
|
uintptr_t start, end;
|
||||||
|
uint32_t type, i = 0;
|
||||||
|
debug_info("Parsing memory map\n");
|
||||||
|
while(!multiboot_get_memory_area(i++, &start, &end, &type))
|
||||||
|
{
|
||||||
|
debug("0x%016x-0x%016x (%d)\n", start, end, type);
|
||||||
|
for(uintptr_t p = start; p < end; p += PAGE_SIZE)
|
||||||
|
{
|
||||||
|
if(p >= V2P(&kernel_start) && p < V2P(&kernel_end))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
uintptr_t page = vmm_get_page(&BootP4, (uintptr_t)P2V(p));
|
||||||
|
if(page == (uintptr_t)-1 || !(page & PAGE_PRESENT))
|
||||||
|
{
|
||||||
|
uint16_t flags = PAGE_GLOBAL | PAGE_HUGE | PAGE_WRITE;
|
||||||
|
touch_page(&BootP4, (uintptr_t)P2V(p), flags);
|
||||||
|
vmm_set_page(&BootP4, (uintptr_t)P2V(p), p, flags | PAGE_PRESENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(type == MMAP_FREE)
|
||||||
|
pmm_free(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user