This commit is contained in:
2025-05-19 21:44:07 +03:00
parent e2b596dcbd
commit bc0bd99f95
+23 -37
View File
@@ -1,6 +1,7 @@
#include "../include/task.h"
#include "../include/stdio.h"
#include "../include/paging.h"
#include "../include/string.h"
#include <stddef.h>
@@ -38,50 +39,35 @@ Process* task_create(EntryPoint func, void** args, uint32_t arg_count, uint32_t
// Выделяем стек ядра
p->kstack = alloc_page();//heap_alloc(KSTACKSIZE);
uint32_t* sp = (uint32_t*)(p->kstack + KSTACKSIZE);
map_page(p->kstack, p->kstack, 0x7);
printf("kstack: %X!!!!!!!!!!!!\n", p->kstack);
uint8_t* sp = (uint8_t*)(p->kstack);
if (ring == DPL_USER) {
void* user_stack = alloc_page();
map_page(user_stack, (void*)0x800000, 0x7); // U/S=1, R/W=1
// Настраиваем trap frame для ring 3
sp -= sizeof(TrapFrame) / 4;
p->tf = (TrapFrame*)sp;
p->tf->cs = (SEG_UCODE) | DPL_USER;
p->tf->ds = (SEG_UDATA) | DPL_USER;
p->tf->es = p->tf->ds;
p->tf->fs = p->tf->ds;
p->tf->gs = p->tf->ds;
p->tf->ss = p->tf->ds;
p->tf->eflags = FL_IF;
p->tf->eip = (uint32_t)func;
p->tf->esp = 0x800000 + USTACKSIZE - 4; // Предполагаем, что пользовательский стек настроен
sp -= sizeof(TrapFrame);
p->tf = (TrapFrame*)sp;
memset(p->tf, 0, sizeof(TrapFrame));
p->tf->cs = ring == 3 ? (SEG_UCODE) | DPL_USER : (SEG_KCODE);
p->tf->ds = ring == 3 ? (SEG_UDATA) | DPL_USER : (SEG_KDATA);
p->tf->es = p->tf->ds;
p->tf->fs = p->tf->ds;
p->tf->gs = p->tf->ds;
p->tf->ss = p->tf->ds;
p->tf->eflags = FL_IF;
p->tf->eip = (uint32_t)func;
p->tf->esp = 0x800000; // Предполагаем, что пользовательский стек настроен
// Добавляем адрес возврата для trapret
sp -= 1;
*sp = (uint32_t)trapret;
sp -= sizeof(Context) / 4;
p->context = (Context*)sp;
p->context->eip = (uint32_t)processStartup;
} else {
p->tf = NULL; // Для ring 0 TrapFrame не нужен!
sp -= sizeof(Context) / 4; // Только контекст
p->context = (Context*)sp;
p->context->eip = (uint32_t)func; // Прямой переход в func
}
sp -= sizeof(Context);
p->context = (Context*)sp;
p->context->eip = (uint32_t)trapret;
// Настраиваем начальный контекст
sp -= 5; // Место для edi, esi, ebx, ebp, eip
//sp -= 5; // Место для edi, esi, ebx, ebp, eip
//sp -= sizeof(Context);
p->context->edi = 0;
p->context->esi = 0;
p->context->ebx = 0;
p->context->ebp = 0;
if (ring == DPL_USER) {
p->context->eip = (uint32_t)processStartup;
} else {
p->context->eip = (uint32_t)func; // Прямо в ring 0
}
p->page_directory = kernel_page_directory;
@@ -155,10 +141,10 @@ void scheduler_init()
//task_create((EntryPoint)&idle, NULL, 0, 0);
void* args1[] = {(void*)42, (void*)"ebalo"};
//task_create((EntryPoint)&task1, args1, 2, 0);
task_create((EntryPoint)&task1, args1, 2, 0);
void* args2[] = {(void*)69, (void*)420};
//task_create((EntryPoint)&task2, args2, 2, 0);
jump_usermode2();
//jump_usermode2();
}
#include "../include/string.h"