syscalls: continue working on fork syscall

This commit is contained in:
2025-07-07 00:19:35 +03:00
parent 2a7baf1184
commit e793e45854
3 changed files with 37 additions and 9 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ debug:
qemu-system-i386 -s -S -kernel katauos.bin -monitor stdio qemu-system-i386 -s -S -kernel katauos.bin -monitor stdio
debug2: debug2:
qemu-system-i386 -s -S -drive file=boot.iso,media=disk,format=raw -monitor stdio qemu-system-i386 -s -S -drive file=boot.iso,media=disk,format=raw -m 4096M -monitor stdio
test-bochs: test-bochs:
bochs -f bochsrc bochs -f bochsrc
+31 -7
View File
@@ -1,6 +1,8 @@
#include "../include/paging.h" #include "../include/paging.h"
#include <stdint.h> #include <stdint.h>
#include "../include/string.h" #include "../include/string.h"
#include "../include/kheap.h"
#include "../include/liballoc.h"
uint32_t *kpage_dir; uint32_t *kpage_dir;
@@ -123,6 +125,11 @@ uint32_t phys_to_virt(uint32_t phys)
return phys+0xC0000000; return phys+0xC0000000;
} }
void* phys_to_virt2(void* phys)
{
return phys+0xC0000000;
}
uint32_t* create_page_dir() uint32_t* create_page_dir()
{ {
void* ppp = alloc_page(); void* ppp = alloc_page();
@@ -190,14 +197,19 @@ void destroy_page_dir(uint32_t* page_dir_virt) {
free_page((void*)virt_to_phys(page_dir_virt)); free_page((void*)virt_to_phys(page_dir_virt));
} }
static void* scratch_src = (void*)0xE1000000;
static void* scratch_dst = (void*)0xE1001000;
uint32_t* copy_page_dir(uint32_t* page_dir_virt) uint32_t* copy_page_dir(uint32_t* page_dir_virt)
{ {
if(page_dir_virt == NULL) if(page_dir_virt == NULL)
return 0; return 0;
debug_log("====%X %X\n", scratch_dst, scratch_src);
uint32_t* new_pagedir = create_page_dir(); uint32_t* new_pagedir = create_page_dir();
for(int i = 0; i < 768; i++) for(int i = 1; i < 768; i++)
{ {
uint32_t pde = page_dir_virt[i]; uint32_t pde = page_dir_virt[i];
@@ -208,6 +220,7 @@ uint32_t* copy_page_dir(uint32_t* page_dir_virt)
if(new_page_table == NULL) { if(new_page_table == NULL) {
return NULL; return NULL;
} }
uint32_t* new_page_table_virt = (uint32_t*)phys_to_virt((uint32_t)new_page_table);
// Get original page table (physical address from PDE) // Get original page table (physical address from PDE)
uint32_t* orig_page_table = (uint32_t*)phys_to_virt(pde & ~0xFFF); uint32_t* orig_page_table = (uint32_t*)phys_to_virt(pde & ~0xFFF);
@@ -225,14 +238,24 @@ uint32_t* copy_page_dir(uint32_t* page_dir_virt)
void* orig_phys_page = (void*)(pte & ~0xFFF); void* orig_phys_page = (void*)(pte & ~0xFFF);
debug_log("copying %X to %X...", orig_phys_page, new_phys_page); map_page(orig_phys_page, scratch_src, PAGE_PRESENT | PAGE_RW);
memcpy(new_phys_page, orig_phys_page, PAGE_SIZE); map_page(new_phys_page, scratch_dst, PAGE_PRESENT | PAGE_RW);
debug_log("done\n");
new_page_table[j] = (uint32_t)new_phys_page | (pte & 0xFFF); //debug_log("copying %X to %X...", orig_phys_page, new_phys_page);
//memcpy(new_phys_page, orig_phys_page, PAGE_SIZE);
//memcpy(new_virt_page, orig_virt_page, PAGE_SIZE);
memcpy(scratch_dst, scratch_src, PAGE_SIZE);
unmap_page(scratch_dst);
unmap_page(scratch_src);
//debug_log("done\n");
new_page_table_virt[j] = (uint32_t)new_phys_page | (pte & 0xFFF);
} }
else else
{ {
new_page_table[j] = pte; new_page_table_virt[j] = pte;
} }
} }
@@ -246,5 +269,6 @@ uint32_t* copy_page_dir(uint32_t* page_dir_virt)
} }
} }
debug_log("ENDENDENDEND\n"); debug_log("ENDENDENDEND\n");
return new_pagedir;
return new_pagedir - 0xC0000000;
} }
+5 -1
View File
@@ -62,7 +62,11 @@ int sys_fork(TrapFrame *tf)
{ {
debug_log("FORKFORKFORKFORK\n"); debug_log("FORKFORKFORKFORK\n");
uint32_t* new_pd = copy_page_dir(current->pagedir); uint32_t* new_pd = copy_page_dir(current->pagedir) - 0xC0000000;
debug_log("got this shit done hehe\n");
set_page_dir((uint32_t)new_pd - 0xC0000000);
while(1){}
Process* child = task_create(0, 0, 3, new_pd); Process* child = task_create(0, 0, 3, new_pd);