tasking: continue working on page directory switching

This commit is contained in:
2025-05-31 19:43:38 +03:00
parent 33aa97c6ec
commit 9000d76441
4 changed files with 29 additions and 1 deletions
+2
View File
@@ -41,6 +41,8 @@ extern uint32_t *kpage_dir;
void grub_memory_map(unsigned int magic, struct multiboot_info* mbi);
uint32_t* get_page_dir();
void set_page_dir(uint32_t new_page_dir);
uint32_t phys_to_virt(uint32_t phys);
uint32_t create_page_dir();
void enablePaging();
void loadPageDirectory(uint32_t* page_directory);
+23
View File
@@ -123,6 +123,29 @@ void set_page_dir(uint32_t new_page_dir) {
asm volatile("mov %0, %%cr3" : : "r" (new_page_dir));
}
uint32_t phys_to_virt(uint32_t phys)
{
return phys+0xC0000000;
}
uint32_t create_page_dir()
{
void* ppp = alloc_page();
memset(ppp, 0, 0x1000);
uint32_t* current_pd = (uint32_t*)0xFFFFF000; // Current PD (self-mapped)
uint32_t* new_pd = (uint32_t*)phys_to_virt((uint32_t)ppp);
for(int i = 768; i < 1023; i++)
{
new_pd[i] = current_pd[i];
}
new_pd[1023] = (uint32_t)ppp | 0x03; // Present + Read/Write
return (uint32_t)new_pd;
}
void enablePaging() {
asm volatile (
"mov %%cr0, %%eax\n"
+3
View File
@@ -32,6 +32,9 @@ switchProcess:
mov esp, [edx + 4] ; esp = next_process_ptr->kesp
mov [current], edx ; current = next_process_ptr
mov eax, [edx + 40]
mov cr3, eax
pop edi
pop esi
pop ebx
+1 -1
View File
@@ -71,7 +71,7 @@ Process* task_create(uint32_t func, void** args, uint32_t arg_count, uint32_t ri
p->context->eip = (uint32_t)trapret;
p->kesp = (uint32_t)sp;
p->page_directory = kpage_dir;
p->page_directory = ring == 0 ? kpage_dir : (uint32_t*)create_page_dir();
p->next = 0;