diff --git a/include/task.h b/include/task.h index d06f240..fdd108e 100644 --- a/include/task.h +++ b/include/task.h @@ -38,8 +38,7 @@ typedef struct __attribute__((packed)) TrapFrame { uint32_t edi; uint32_t esi; uint32_t ebp; - uint32_t oesp; - uint32_t ebx; + uint32_t ebx; // Убрано oesp uint32_t edx; uint32_t ecx; uint32_t eax; diff --git a/src/tasking/switch.asm b/src/tasking/switch.asm index 6682df7..9a2b7be 100644 --- a/src/tasking/switch.asm +++ b/src/tasking/switch.asm @@ -49,7 +49,6 @@ switchProcess: trapret: ; Восстанавливаем общие регистры из trap frame popal ; edi, esi, ebp, oesp, ebx, edx, ecx, eax - add esp, 4 ; Пропускаем oesp (не используется) ; Восстанавливаем сегментные регистры pop gs diff --git a/src/tasking/task.c b/src/tasking/task.c index c6c9782..74568f6 100644 --- a/src/tasking/task.c +++ b/src/tasking/task.c @@ -48,19 +48,23 @@ Process* task_create(EntryPoint func, void** args, uint32_t arg_count, uint32_t // Настраиваем trap frame для ring 3 sp -= sizeof(TrapFrame) / 4; p->tf = (TrapFrame*)sp; - p->tf->cs = (SEG_UCODE << 3) | DPL_USER; - p->tf->ds = (SEG_UDATA << 3) | DPL_USER; + 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; // Предполагаем, что пользовательский стек настроен + p->tf->esp = 0x800000 + USTACKSIZE - 4; // Предполагаем, что пользовательский стек настроен // Добавляем адрес возврата для 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; // Только контекст @@ -69,7 +73,6 @@ Process* task_create(EntryPoint func, void** args, uint32_t arg_count, uint32_t } // Настраиваем начальный контекст sp -= 5; // Место для edi, esi, ebx, ebp, eip - p->context = (Context*)sp; p->context->edi = 0; p->context->esi = 0; p->context->ebx = 0; @@ -149,12 +152,12 @@ void jump_usermode2(void) ; void scheduler_init() { task_create((EntryPoint)&idle, NULL, 0, 0); - task_create((EntryPoint)&idle, NULL, 0, 0); + //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); + //task_create((EntryPoint)&task2, args2, 2, 0); jump_usermode2(); } @@ -221,7 +224,7 @@ void jump_usermode2(void) { (code_pte & 0x4) ? "user" : "supervisor"); task_create(user_code_virt, NULL, 0, 3); - //task_create(second_user_code_virt, NULL, 0, 3); + task_create(second_user_code_virt, NULL, 0, 3); return; // Switch to user mode with interrupts enabled