From 8d48bbd9746228b63bafa5f92b621998d7d8f3d3 Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Sun, 4 Oct 2026 10:49:41 -0400 Subject: move init fully to proc. remove init pages prealloc. prepare for scheduling --- arch/x86_64/proc/init.c | 33 ++++++++++++--------------------- arch/x86_64/proc/process.c | 4 +++- arch/x86_64/proc/process.h | 3 --- 3 files changed, 15 insertions(+), 25 deletions(-) (limited to 'arch/x86_64/proc') diff --git a/arch/x86_64/proc/init.c b/arch/x86_64/proc/init.c index be1d556..3787c7b 100644 --- a/arch/x86_64/proc/init.c +++ b/arch/x86_64/proc/init.c @@ -1,4 +1,4 @@ -#include "init.h" +#include "proc/init.h" #include "arch/x86_64/hal/msr.h" #include "config.h" #include "proc/process.h" @@ -12,10 +12,6 @@ #include "boot/cmdline.h" #include "boot/initrd.h" -PAGEALIGN static uint8_t s_init_program_pages[INIT_PROGRAM_PAGES_MAX][0x1000]; -PAGEALIGN static uint8_t s_init_stack_pages[INIT_STACK_PAGES + 3][0x1000]; -PAGEALIGN static uint8_t s_init_message_page[0x1000]; - static int elf_is_valid(struct elf_header *ehdr) { @@ -78,7 +74,6 @@ init_setup(void) size_t last_base = 0; //Load the init ELF - size_t last_page = 0; for(size_t i = 0; i < init_ehdr->e_phnum; i++) { struct elf_phdr *phdr = init_data + init_ehdr->e_phoff + i * init_ehdr->e_phentsize; if(phdr->p_type != PT_LOAD) continue; @@ -93,18 +88,15 @@ init_setup(void) for(size_t i = 0; i < pages; i++) { uintptr_t page_virt = page_base + (i << 12); - if(last_page >= INIT_PROGRAM_PAGES_MAX) { - kpanic("Program exceeds size limit! (%i > %i)\n", last_page, INIT_PROGRAM_PAGES_MAX); - } int tblres = 0; + jove_owned_obj_t page_frame; do { - uintptr_t tbl_frame = KPTR_TOPHYS(&s_init_program_pages[last_page++]); - tblres = pagedir_map_table(pml4, tbl_frame, page_virt); - if(tblres == EHASMAP) last_page--; - }while(!tblres); + page_frame = init_pop_alloc(); + tblres = pagedir_map_table(pml4, obj_getvalue(&page_frame), page_virt); + }while(tblres == 0); - pagedir_map_frame(pml4, KPTR_TOPHYS(&s_init_program_pages[last_page++]), page_virt, + pagedir_map_frame(pml4, obj_getvalue(&page_frame), page_virt, PAGE_WRITEABLE | PAGE_USER); } @@ -116,25 +108,24 @@ init_setup(void) size_t stack_base = 0x00007FFFFFFFF000; int stack_mapres = 0; - last_page = 0; for(size_t i = 0; i < INIT_STACK_PAGES; i++) { uintptr_t page_virt = stack_base - (i << 12); int tblres = 0; + jove_owned_obj_t page_frame; do { - uintptr_t tbl_frame = KPTR_TOPHYS(&s_init_stack_pages[last_page++]); - tblres = pagedir_map_table(pml4, tbl_frame, page_virt); - if(tblres == EHASMAP) last_page--; + page_frame = init_pop_alloc(); + tblres = pagedir_map_table(pml4, obj_getvalue(&page_frame), page_virt); }while(!tblres); - pagedir_map_frame(pml4, KPTR_TOPHYS(&s_init_stack_pages[last_page++]), page_virt, + pagedir_map_frame(pml4, obj_getvalue(&page_frame), page_virt, PAGE_WRITEABLE | PAGE_USER | PAGE_XD); } //Map the syscall message. last_base = (last_base + 0xFFF) & ~0xFFF; - uintptr_t message_pptr = KPTR_TOPHYS(s_init_message_page); - pagedir_map_frame(pml4, message_pptr, last_base, + jove_owned_obj_t message_frame = init_pop_alloc(); + pagedir_map_frame(pml4, obj_getvalue(&message_frame), last_base, PAGE_WRITEABLE | PAGE_USER | PAGE_XD); extern struct init_payload _init_payload; diff --git a/arch/x86_64/proc/process.c b/arch/x86_64/proc/process.c index 6165585..d5513bc 100644 --- a/arch/x86_64/proc/process.c +++ b/arch/x86_64/proc/process.c @@ -6,7 +6,7 @@ #include "hal/obj.h" #include "hal/smp.h" #include "lib/string.h" -#include "init.h" +#include "proc/init.h" #include "jove.h" PAGEALIGN uint8_t s_init_iopb[0x2000]; @@ -28,6 +28,8 @@ processing_setup(void (*process_main)) init_pcb->header.pagedir = obj_release(objdir_getlocal(_rootdir_obj, ROOTDIR_PAGEDIR_I)); init_pcb->header.pid = 1; + init_pcb->header.state = PCB_STATE_RUNNING; + init_pcb->ksp = (void*)ksp; jove_owned_obj_t *iopb_obj = objdir_getlocal(_rootdir_obj, ROOTDIR_IOPB_I); diff --git a/arch/x86_64/proc/process.h b/arch/x86_64/proc/process.h index 534c8d5..6a0aa96 100644 --- a/arch/x86_64/proc/process.h +++ b/arch/x86_64/proc/process.h @@ -8,13 +8,10 @@ typedef struct process_control_block { struct pcb_expected_header header; - struct process_control_block *sched_next; jove_obj_t *iopb; - enum pcb_state state; int killed; - struct pcb_mailbox send, recv; struct cpu_context context; void *ksp; -- cgit v1.2.3