fuck1
This commit is contained in:
+15
-29
@@ -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;
|
||||
sp -= sizeof(TrapFrame);
|
||||
p->tf = (TrapFrame*)sp;
|
||||
p->tf->cs = (SEG_UCODE) | DPL_USER;
|
||||
p->tf->ds = (SEG_UDATA) | DPL_USER;
|
||||
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 + USTACKSIZE - 4; // Предполагаем, что пользовательский стек настроен
|
||||
p->tf->esp = 0x800000; // Предполагаем, что пользовательский стек настроен
|
||||
|
||||
// Добавляем адрес возврата для trapret
|
||||
sp -= 1;
|
||||
*sp = (uint32_t)trapret;
|
||||
|
||||
sp -= sizeof(Context) / 4;
|
||||
sp -= sizeof(Context);
|
||||
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
|
||||
}
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user