From 7c870636c53c5fa8fe53fe11a053d15057f04269 Mon Sep 17 00:00:00 2001 From: Ruslan Isaev Date: Thu, 29 May 2025 23:13:03 +0300 Subject: [PATCH] a little cleanup in task.c and paging.h --- include/paging.h | 2 -- src/tasking/task.c | 47 ++++++---------------------------------------- 2 files changed, 6 insertions(+), 43 deletions(-) diff --git a/include/paging.h b/include/paging.h index 081339f..741d2fe 100644 --- a/include/paging.h +++ b/include/paging.h @@ -22,8 +22,6 @@ #define GET_PGDIR(address) ((uint32_t)((address) >> 22) & 0x3FF) #define GET_PGTBL(address) ((uint32_t)((address) >> 12) & 0x3FF) -#define PAGE_SIZE 0x1000 // 4 КБ - // Общий размер памяти #define MEMORY_SIZE (0xFFFFFFFF-0xC0000000) diff --git a/src/tasking/task.c b/src/tasking/task.c index 58846b3..d872dca 100644 --- a/src/tasking/task.c +++ b/src/tasking/task.c @@ -22,25 +22,17 @@ extern Process* current; extern uint32_t pid_counter; extern uint32_t task_count; -// Функция запуска процесса в ядре, после которой произойдёт переход в ring 3 -static void processStartup() -{ - printf("startup\n"); - scheduler_unlock(); - // Возврат из этой функции приведёт к вызову trapret -} - Process* task_create(uint32_t func, void** args, uint32_t arg_count, uint32_t ring) { - Process* p = (Process*)alloc_page();//heap_alloc(sizeof(Process)); + Process* p = (Process*)alloc_page(); memset(p, 0, sizeof(Process)); p->pid = ++pid_counter; p->state = Ready; p->ring = ring; // Выделяем стек ядра - p->kstack = (char*)alloc_page();//heap_alloc(KSTACKSIZE); - map_page(p->kstack, p->kstack, 0x3); + p->kstack = (char*)alloc_page(); + map_page(p->kstack, p->kstack, PAGE_PRESENT | PAGE_RW); printf("kstack: %X!!!!!!!!!!!!\n", p->kstack); uint8_t* sp = (uint8_t*)(p->kstack + KSTACKSIZE); @@ -68,7 +60,7 @@ Process* task_create(uint32_t func, void** args, uint32_t arg_count, uint32_t ri uint32_t user_stack_virtual_top = 0xBFFFF000 - ((p->pid -1) * (USTACKSIZE + 4096)); // Уникальный верх стека для каждого процесса uint32_t user_stack_virtual_base = user_stack_virtual_top - USTACKSIZE; - map_page(user_stack_physical, (void*)user_stack_virtual_base, 0x7/*PTE_PRESENT | PTE_READ_WRITE | PTE_USER*/); // Флаги 0x7 + map_page(user_stack_physical, (void*)user_stack_virtual_base, PAGE_PRESENT | PAGE_RW | PAGE_USER); // Флаги 0x7 } @@ -120,8 +112,6 @@ void schedule() next = queue; if (next != current) { - //loadPageDirectory(next->page_directory); - //printf("switching to %X\n", next->pid); switchProcess(next); } } @@ -149,12 +139,11 @@ void jump_usermode2(void) ; void scheduler_init() { task_create((uint32_t)idle, NULL, 0, 0); - task_create((uint32_t)idle, NULL, 0, 0); void* args1[] = {(void*)42, (void*)"ebalo"}; task_create((uint32_t)task1, args1, 2, 0); void* args2[] = {(void*)69, (void*)420}; - //task_create((EntryPoint)&task2, args2, 2, 0); + task_create((uint32_t)task2, args2, 2, 0); jump_usermode2(); } @@ -221,29 +210,5 @@ void jump_usermode2(void) { (code_pte & 0x4) ? "user" : "supervisor"); task_create((uint32_t)user_code_virt, NULL, 0, 3); - task_create((uint32_t)second_user_code_virt, NULL, 0, 3); - - return; - // Switch to user mode with interrupts enabled - asm volatile ( - "pushf\n" - "pop %%eax\n" - "or $0x200, %%eax\n" // Enable interrupts (IF) - "push %%eax\n" - "mov $0x23, %%dx\n" - "mov %%dx, %%ds\n" - "mov %%dx, %%es\n" - "mov %%dx, %%fs\n" - "mov %%dx, %%gs\n" - "push $0x23\n" // SS (user data segment) - "push %0\n" // ESP (user_stack_top) - "push %%eax\n" // EFLAGS (with IF) - "push $0x1B\n" // CS (user code segment) - "push %1\n" // EIP (user_code_virt) - "iret\n" - : - : "r" (user_stack_top), "r" (user_code_virt) - : "dx", "eax", "memory", "cc" - ); - __builtin_unreachable(); + //task_create((uint32_t)second_user_code_virt, NULL, 0, 3); }