wip on pagetable

compiles&runs now
This commit is contained in:
2026-02-24 04:38:16 +01:00
parent dc1c98c091
commit c92b15e2a6
6 changed files with 40 additions and 28 deletions

View File

@@ -142,11 +142,10 @@ void* PageFrameAllocator::alloc(bool kernel){
if(!free_pageframe)
return 0;
assert(free_pageframe->available);
free_pageframe->available = false;
uintptr_t addr = ((free_pageframe - &PageFrames[0]))<<12;
mark_pageframes(addr, addr+1, false);
return (void*)(addr);
}

View File

@@ -1,6 +1,7 @@
#include "pagetable.h"
#include "pageframealloc.h"
#include "../utils/string.h"
void load_cr3( void* cr3_value ) {
asm volatile("mov %0, %%cr3" :: "r"((uint64_t)cr3_value) : "memory");
@@ -18,25 +19,32 @@ void write_identity_map(pagetable_t* identity_table, uint64_t size){
}
void create_basic_page_table(four_lvl_paging_t* table, pagetable_t* kernel_identity){
//pagetable_t* l2 = (pagetable_t*)PageFrameAllocator::alloc(true);
table->l4.entries[0] = {
assert(table);
assert(kernel_identity);
table->l4 = (pagetable_t*)PageFrameAllocator::alloc(true);
table->l3 = (pagetable_t*)PageFrameAllocator::alloc(true);
table->l2 = (pagetable_t*)PageFrameAllocator::alloc(true);
//memset(table, 0, sizeof(four_lvl_paging_t));
table->l4->entries[0] = {
.present = 1,
.write = 1,
.user = 1,
.address = ((uintptr_t)&(table->l3.entries[0])) >> 12,
.address = ((uintptr_t)(table->l3)) >> 12,
};
table->l3.entries[0] = {
table->l3->entries[0] = {
.present = 1,
.write = 1,
.user = 1,
.address = ((uintptr_t)&(table->l2.entries[0])) >> 12,
.address = ((uintptr_t)(table->l2)) >> 12,
};
//kernel memory
for(uint32_t i=0; i<KERNEL_MEMORY_BORDER/4096/512; i++){
table->l2.entries[i] = {
table->l2->entries[i] = {
.present = 1,
.write = 1,
.user = 1,
@@ -55,19 +63,23 @@ void create_basic_page_table(four_lvl_paging_t* table, pagetable_t* kernel_ident
//}
//add ioapic address to pagetable
table->l3.entries[3] = {
table->l2_apic = (pagetable_t*)PageFrameAllocator::alloc(true);
table->ioapic = (pagetable_t*)PageFrameAllocator::alloc(true);
table->lapic = (pagetable_t*)PageFrameAllocator::alloc(true);
table->l3->entries[3] = {
.present = 1,
.write = 1,
.user = 1,
.address = (uintptr_t)&(table->l2_apic) >> 12,
.address = (uintptr_t)(table->l2_apic) >> 12,
};
table->l2_apic.entries[502] = {
table->l2_apic->entries[502] = {
.present = 1,
.write = 1,
.user = 1,
.address = (uintptr_t)&(table->ioapic) >> 12,
.address = (uintptr_t)(table->ioapic) >> 12,
};
table->ioapic.entries[0] = {
table->ioapic->entries[0] = {
.present = 1,
.write = 1,
.user = 0,
@@ -75,13 +87,13 @@ void create_basic_page_table(four_lvl_paging_t* table, pagetable_t* kernel_ident
};
//lapic
table->l2_apic.entries[503] = {
table->l2_apic->entries[503] = {
.present = 1,
.write = 1,
.user = 1,
.address = (uintptr_t)&(table->lapic) >> 12,
.address = (uintptr_t)(table->lapic) >> 12,
};
table->lapic.entries[0] = {
table->lapic->entries[0] = {
.present = 1,
.write = 1,
.user = 0,

View File

@@ -38,13 +38,13 @@ typedef struct {
//} __attribute__((__packed__)) pagedirectory_entry_t;
typedef struct {
alignas(4096) pagetable_t l4;
alignas(4096) pagetable_t l3;
alignas(4096) pagetable_t l2;
//pagetable_t l1_kernel;
alignas(4096) pagetable_t l2_apic;
alignas(4096) pagetable_t ioapic;
alignas(4096) pagetable_t lapic;
pagetable_t* l4;
pagetable_t* l3;
pagetable_t* l2;
pagetable_t* l1_kernel;
pagetable_t* l2_apic;
pagetable_t* ioapic;
pagetable_t* lapic;
} four_lvl_paging_t;
void write_identity_map(pagetable_t* identity_table, uint64_t size);