gonna ask tsoding for help, fuck this shit

This commit is contained in:
2025-05-20 00:10:37 +03:00
parent bc0bd99f95
commit b8752ee39d
4 changed files with 39 additions and 48 deletions
+2 -2
View File
@@ -106,9 +106,9 @@ __attribute__((interrupt)) void isr_timer(struct interrupt_frame *frame)
pit_init(100);
pic_end_int(0x0);
scheduler_lock();
//scheduler_lock();
schedule();
scheduler_unlock();
//scheduler_unlock();
}
__attribute__((interrupt)) void isr_custom(struct interrupt_frame *frame)
+15 -19
View File
@@ -16,39 +16,33 @@ extern current
extern trapret
switchProcess:
; Сохраняем регистры текущего процесса
mov eax, [esp + 4] ; eax = old
mov edx, [esp + 8] ; edx = new
push ebp
push ebx
push esi
push edi
push ebp
; Сохраняем указатель стека в current->context
mov edi, [current]
mov [edi + 12], esp ; PCB.CONTEXT находится по смещению 12
mov [eax+4], esp
mov esp, [edx+4]
; Загружаем следующий процесс
mov esi, [esp + 20] ; next (первый аргумент)
mov [current], esi
mov esp, [esi + 12] ; Загружаем esp из next->context
;mov eax, [edx+12]
;sub eax, 0xC0000000
;mov cr3, eax
; Восстанавливаем регистры
pop ebp
pop edi
pop esi
pop ebx
pop ebp
; Проверяем ring процесса
mov eax, [esi + 20] ; PCB.RING находится по смещению 20
cmp eax, 3
je .ring3
sti
ret ; Для ring 0 просто возвращаемся
.ring3:
jmp trapret ; Для ring 3 переходим через trapret
trapret:
; Восстанавливаем общие регистры из trap frame
popal ; edi, esi, ebp, oesp, ebx, edx, ecx, eax
;popal ; edi, esi, ebp, oesp, ebx, edx, ecx, eax
; Восстанавливаем сегментные регистры
pop gs
@@ -56,6 +50,8 @@ trapret:
pop es
pop ds
popad
; Пропускаем trapno и err
add esp, 8 ; trapno (4 байта) + err (4 байта)
+9 -8
View File
@@ -30,7 +30,7 @@ static void processStartup()
// Возврат из этой функции приведёт к вызову trapret
}
Process* task_create(EntryPoint func, void** args, uint32_t arg_count, uint32_t ring)
Process* task_create(uint32_t func, void** args, uint32_t arg_count, uint32_t ring)
{
Process* p = alloc_page();//heap_alloc(sizeof(Process));
p->pid = ++pid_counter;
@@ -53,10 +53,10 @@ Process* task_create(EntryPoint func, void** args, uint32_t arg_count, uint32_t
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->usermode_ss = p->tf->ds;
p->tf->eflags = FL_IF;
p->tf->eip = (uint32_t)func;
p->tf->esp = 0x800000; // Предполагаем, что пользовательский стек настроен
p->tf->usermode_esp = 0x800000; // Предполагаем, что пользовательский стек настроен
sp -= sizeof(Context);
p->context = (Context*)sp;
@@ -111,6 +111,7 @@ void schedule()
if (next != current)
{
//loadPageDirectory(next->page_directory);
printf("switching to %X\n", next->pid);
switchProcess(next);
}
}
@@ -137,11 +138,11 @@ void jump_usermode2(void) ;
void scheduler_init()
{
task_create((EntryPoint)&idle, NULL, 0, 0);
//task_create((EntryPoint)&idle, NULL, 0, 0);
task_create((uint32_t)idle, NULL, 0, 0);
task_create((uint32_t)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();
@@ -209,8 +210,8 @@ void jump_usermode2(void) {
(code_pte & 0x2) ? "writable" : "read-only",
(code_pte & 0x4) ? "user" : "supervisor");
task_create(user_code_virt, NULL, 0, 3);
task_create(second_user_code_virt, NULL, 0, 3);
task_create((uint32_t)user_code_virt, NULL, 0, 3);
//task_create(second_user_code_virt, NULL, 0, 3);
return;
// Switch to user mode with interrupts enabled