test map/unmap

This commit is contained in:
2026-02-24 10:50:12 +01:00
parent 50dfd49d43
commit 6c9e7d8a27
3 changed files with 67 additions and 21 deletions

View File

@@ -14,7 +14,6 @@ void *operator new(size_t, void *);
uint8_t mapNumber = 0;
uint32_t next_start_v = 0x4000;
namespace Syscall {
namespace Skeleton {
@@ -163,6 +162,7 @@ namespace Syscall {
void* getFreeVirtSpace(four_lvl_paging_t* search_table, uint8_t num_pages){
uint32_t start_v = 0x4000;
uint32_t stop_v = 0x6000;
static uint32_t next_start_v = 0x4000;
//static uint32_t next_start_v = start_v;
//start from last found address
@@ -174,7 +174,7 @@ namespace Syscall {
}
}
if(space_is_free){
next_start_v = v+num_pages;
//next_start_v = v+num_pages;
return (void*) ((uintptr_t) (v <<12));
}
}
@@ -202,6 +202,7 @@ namespace Syscall {
if(!(flpt->l4->entries[l4Index].present)){
pagetable_t* newl3 = (pagetable_t*)PageFrameAllocator::alloc(true);
memset(newl3, 0, 4096);
flpt->l4->entries[l4Index] = {
.present = 1,
.write = 1,
@@ -213,6 +214,7 @@ namespace Syscall {
pagetable_t* lvl3 = (pagetable_t*)(flpt->l4->entries[l4Index].address<<12);
if(!(lvl3->entries[l3Index].present)){
pagetable_t* newl2 = (pagetable_t*)PageFrameAllocator::alloc(true);
memset(newl2, 0, 4096);
lvl3->entries[l3Index] = {
.present = 1,
.write = 1,
@@ -224,6 +226,7 @@ namespace Syscall {
pagetable_t* lvl2 = (pagetable_t*)(lvl3->entries[l3Index].address<<12);
if(!(lvl2->entries[l2Index].present)){
pagetable_t* newl1 = (pagetable_t*)PageFrameAllocator::alloc(true);
memset(newl1, 0, 4096);
lvl2->entries[l2Index] = {
.present = 1,
.write = 1,
@@ -233,15 +236,16 @@ namespace Syscall {
}
pagetable_t* lvl1 = (pagetable_t*)(lvl2->entries[l2Index].address<<12);
assert(!(lvl1->entries[l1Index].present)); // should not be present, bc its a new mapping
if(frame)
if(frame){
assert(!(lvl1->entries[l1Index].present)); // should not be present, bc its a new mapping
lvl1->entries[l1Index] = {
.present = 1,
.write = 1,
.user = 1,
.address = (uintptr_t)frame >> 12
};
}
else //unmap if nullptr
lvl1->entries[l1Index].present = 0;
}

View File

@@ -38,8 +38,14 @@ Thread::Thread (bool kernel, void * startframe, int num_pages): queue_link(null
StackPointer.user = (void*)(0x61FF000+STACK_SIZE);
paging_tree = (four_lvl_paging_t*)PageFrameAllocator::alloc(true);
memset(paging_tree, 0, 4096);
create_basic_page_table(paging_tree, &identity_table);
appcode_table = (pagetable_t*) PageFrameAllocator::alloc(true);
memset(appcode_table, 0, 4096);
appstack_table = (pagetable_t*) PageFrameAllocator::alloc(true);
memset(appstack_table, 0, 4096);
assert(num_pages < 512); //limit for application code size is 2M
for(uint8_t i=0; i<num_pages; i++){