Fix braces + init_paging args
This commit is contained in:
@@ -39,8 +39,7 @@ static uint64_t* alloc_page_table()
|
||||
{
|
||||
uint64_t* virt = (uint64_t*)PHYS_TO_VIRT(pmm_alloc());
|
||||
|
||||
for (size_t i=0; i<512; i++)
|
||||
{
|
||||
for (size_t i=0; i<512; i++) {
|
||||
virt[i] = 0;
|
||||
}
|
||||
return virt;
|
||||
@@ -70,32 +69,26 @@ void paging_map_page(uint64_t* root_table, uint64_t virt, uint64_t phys, uint64_
|
||||
// PML4
|
||||
// If the entry at index is not present, allocate enough space for it
|
||||
// then populate the entry with correct addr + flags
|
||||
if (!(root_table[pml4_i] & PTE_PRESENT))
|
||||
{
|
||||
if (!(root_table[pml4_i] & PTE_PRESENT)) {
|
||||
pdpt = alloc_page_table();
|
||||
root_table[pml4_i] = VIRT_TO_PHYS(pdpt) | PTE_PRESENT | PTE_WRITABLE;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pdpt = (uint64_t *)PHYS_TO_VIRT(root_table[pml4_i] & PTE_ADDR_MASK);
|
||||
}
|
||||
|
||||
// PDPT: same here
|
||||
if (!(pdpt[pdpt_i] & PTE_PRESENT))
|
||||
{
|
||||
if (!(pdpt[pdpt_i] & PTE_PRESENT)) {
|
||||
pd = alloc_page_table();
|
||||
pdpt[pdpt_i] = VIRT_TO_PHYS(pd) | PTE_PRESENT | PTE_WRITABLE;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pd = (uint64_t *)PHYS_TO_VIRT(pdpt[pdpt_i] & PTE_ADDR_MASK);
|
||||
}
|
||||
|
||||
// PD: and here
|
||||
if (!(pd[pd_i] & PTE_PRESENT))
|
||||
{
|
||||
if (!(pd[pd_i] & PTE_PRESENT)) {
|
||||
pt = alloc_page_table();
|
||||
pd[pd_i] = VIRT_TO_PHYS(pt) | PTE_PRESENT | PTE_WRITABLE;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pt = (uint64_t *)PHYS_TO_VIRT(pd[pd_i] & PTE_ADDR_MASK);
|
||||
}
|
||||
|
||||
@@ -109,9 +102,7 @@ void paging_map_page(uint64_t* root_table, uint64_t virt, uint64_t phys, uint64_
|
||||
uint64_t kernel_phys_base;
|
||||
uint64_t kernel_virt_base;
|
||||
|
||||
extern struct boot_context boot_ctx;
|
||||
|
||||
void paging_init()
|
||||
void paging_init(struct boot_context boot_ctx)
|
||||
{
|
||||
// We should map the kernel, GDT, IDT, stack, framebuffer.
|
||||
// Optionally we could map ACPI tables (we can find them in the Limine memmap)
|
||||
@@ -129,31 +120,25 @@ void paging_init()
|
||||
|
||||
// Find max physical address from limine memmap
|
||||
uint64_t max_phys = 0;
|
||||
for (uint64_t i=0; i<boot_ctx.mmap->entry_count; i++)
|
||||
{
|
||||
for (uint64_t i=0; i<boot_ctx.mmap->entry_count; i++) {
|
||||
struct limine_memmap_entry* entry = boot_ctx.mmap->entries[i];
|
||||
if (entry->length == 0)
|
||||
{
|
||||
if (entry->length == 0) {
|
||||
continue;
|
||||
}
|
||||
uint64_t top = entry->base + entry->length;
|
||||
if (top > max_phys)
|
||||
{
|
||||
if (top > max_phys) {
|
||||
max_phys = top;
|
||||
}
|
||||
}
|
||||
|
||||
// 4GB
|
||||
if (max_phys > 0x100000000)
|
||||
{
|
||||
DEBUG("WARNING: max_phys capped to 4GB (0x100000000) (from max_phys=%p)", max_phys);
|
||||
max_phys = 0x100000000;
|
||||
if (max_phys > PAGING_MAX_PHYS) {
|
||||
DEBUG("WARNING: max_phys capped to 4GB (%x) (from max_phys=%p)", PAGING_MAX_PHYS, max_phys);
|
||||
max_phys = PAGING_MAX_PHYS;
|
||||
}
|
||||
|
||||
// HHDM map up to max_phys or 4GB, whichever is smaller, using given offset
|
||||
for (uint64_t i=0; i<max_phys; i += PAGE_SIZE)
|
||||
{
|
||||
//paging_kmap_page(i+hhdm_off, i, PTE_WRITABLE);
|
||||
// HHDM map up to max_phys or PAGING_MAX_PHYS, whichever is smaller, using given offset
|
||||
for (uint64_t i=0; i<max_phys; i += PAGE_SIZE) {
|
||||
paging_map_page(kernel_pml4, i+hhdm_off, i, PTE_WRITABLE | PTE_PRESENT);
|
||||
page_count++;
|
||||
}
|
||||
@@ -163,9 +148,7 @@ void paging_init()
|
||||
// SOME DAY when we want a safer kernel we should map .text as Read/Exec
|
||||
// .rodata as Read and .data as Read/Write
|
||||
// For now who gives a shit, let's RWX all kernel
|
||||
for (uint64_t i = 0; i < KERNEL_SIZE; i += PAGE_SIZE)
|
||||
{
|
||||
//paging_kmap_page(kernel_virt_base+i, kernel_phys_base+i, PTE_WRITABLE);
|
||||
for (uint64_t i = 0; i < KERNEL_SIZE; i += PAGE_SIZE) {
|
||||
paging_map_page(kernel_pml4, kernel_virt_base+i, kernel_phys_base+i, PTE_WRITABLE);
|
||||
page_count++;
|
||||
}
|
||||
@@ -178,9 +161,7 @@ void paging_init()
|
||||
uint64_t fb_pages = (fb_size + PAGE_SIZE-1)/PAGE_SIZE;
|
||||
|
||||
// Map the framebuffer (with cache-disable & write-through)
|
||||
for (uint64_t i=0; i<fb_pages; i++)
|
||||
{
|
||||
//paging_kmap_page(fb_virt+i*PAGE_SIZE, fb_phys+i*PAGE_SIZE, PTE_WRITABLE | PTE_PCD | PTE_PWT);
|
||||
for (uint64_t i=0; i<fb_pages; i++) {
|
||||
paging_map_page(kernel_pml4, fb_virt+i*PAGE_SIZE, fb_phys+i*PAGE_SIZE, PTE_WRITABLE | PTE_PCD | PTE_PWT);
|
||||
page_count++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user