Skip to content

Commit

Permalink
Move save_current_task_state() to idt.c
Browse files Browse the repository at this point in the history
  • Loading branch information
taikiy committed Dec 31, 2023
1 parent f7607d1 commit f65341e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
32 changes: 31 additions & 1 deletion src/idt/idt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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()
{
Expand Down
28 changes: 0 additions & 28 deletions src/task/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 0 additions & 2 deletions src/task/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f65341e

Please sign in to comment.