diff --git a/src/idt/idt.c b/src/idt/idt.c index 30edfdc..4dcf58d 100644 --- a/src/idt/idt.c +++ b/src/idt/idt.c @@ -3,8 +3,8 @@ #include "io/io.h" #include "memory/memory.h" #include "memory/paging/paging.h" +#include "system/sys.h" #include "system/syscall.h" -#include "task/task.h" #include "terminal/terminal.h" struct idt_desc idt_descriptors[TOTAL_INTERRUPTS]; @@ -15,6 +15,36 @@ extern void int_noop(); extern void int21h(); extern void isr80h(); +/// @brief Saves the current task registers as it was when the interrupt 0x80 was made. This function must be called +/// while the kernel space paging is active. +/// @param frame The interrupt frame that contains the current task registers +static void +save_current_task_state(struct interrupt_frame* frame) +{ + struct task* current_task = get_current_task(); + if (!current_task) { + panic("Cannot save the state of a null task!"); + } + + if (!frame) { + panic("Cannot save the state of a task with a null frame!"); + } + + current_task->registers.ip = frame->ip; + current_task->registers.cs = frame->cs; + current_task->registers.flags = frame->flags; + current_task->registers.esp = frame->esp; + current_task->registers.ss = frame->ss; + + current_task->registers.eax = frame->eax; + current_task->registers.ecx = frame->ecx; + current_task->registers.edx = frame->edx; + current_task->registers.ebp = frame->ebp; + current_task->registers.esi = frame->esi; + current_task->registers.edi = frame->edi; + current_task->registers.ebx = frame->ebx; +} + static void int0h() { diff --git a/src/task/task.c b/src/task/task.c index d6f9711..6dda76b 100644 --- a/src/task/task.c +++ b/src/task/task.c @@ -146,34 +146,6 @@ get_current_task() return current_task; } -/// @brief Saves the current task registers. This function must be called while the kernel space paging is active. -/// @param frame The interrupt frame that contains the current task registers -void -save_current_task_state(struct interrupt_frame* frame) -{ - if (!current_task) { - panic("Cannot save the state of a null task!"); - } - - if (!frame) { - panic("Cannot save the state of a task with a null frame!"); - } - - current_task->registers.ip = frame->ip; - current_task->registers.cs = frame->cs; - current_task->registers.flags = frame->flags; - current_task->registers.esp = frame->esp; - current_task->registers.ss = frame->ss; - - current_task->registers.eax = frame->eax; - current_task->registers.ecx = frame->ecx; - current_task->registers.edx = frame->edx; - current_task->registers.ebp = frame->ebp; - current_task->registers.esi = frame->esi; - current_task->registers.edi = frame->edi; - current_task->registers.ebx = frame->ebx; -} - void start_tasks() { diff --git a/src/task/task.h b/src/task/task.h index fdc4c98..f1de13b 100644 --- a/src/task/task.h +++ b/src/task/task.h @@ -36,8 +36,6 @@ struct task struct task* create_task(struct process* process); status_t free_task(struct task* task); struct task* get_current_task(); -void save_current_task_state(struct interrupt_frame* frame); -void restore_current_task_state(struct interrupt_frame* frame); void start_tasks(); #endif