diff --git a/kernel/include/thread/Task.h b/kernel/include/thread/Task.h index 59239d24..77551e5a 100644 --- a/kernel/include/thread/Task.h +++ b/kernel/include/thread/Task.h @@ -36,6 +36,8 @@ struct Task char floating_region[512] __attribute__((aligned(16))); bool floating_saved = false; + bool user_task = true; + bool is_user_task(); ELFImage* image = nullptr; diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index efadec98..fe8cef85 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -41,6 +41,7 @@ void Scheduler::init() idle_task.regs.ss = 0x10; idle_task.regs.rflags = (1 << 21) | (1 << 9); idle_task.task_sleep = 1000; + idle_task.user_task = false; idle_task.state = idle_task.Idle; base_task = new Task; @@ -51,6 +52,7 @@ void Scheduler::init() sched_current_task->next_task = sched_current_task; sched_current_task->prev_task = sched_current_task; sched_current_task->state = sched_current_task->Running; + sched_current_task->user_task = false; task_num++; // the other registers will be saved next task switch @@ -61,6 +63,7 @@ void Scheduler::add_kernel_task(void (*task)(void)) { Task* new_task = new Task; ASSERT(new_task); + new_task->user_task = false; new_task->id = free_tid++; new_task->regs.rip = (uint64_t)task; new_task->allocated_stack = @@ -88,6 +91,7 @@ void Scheduler::add_user_task(void* task) { Task* new_task = new Task; ASSERT(new_task); + new_task->user_task = true; new_task->id = free_tid++; new_task->regs.rip = (uint64_t)task; new_task->allocated_stack = (uint64_t)MemoryManager::get_pages( @@ -124,6 +128,7 @@ void Scheduler::load_user_task(const char* filename) delete new_task; return; } + new_task->user_task = true; new_task->regs.rip = image->entry; new_task->image = image; new_task->allocated_stack = (uint64_t)MemoryManager::get_pages( diff --git a/kernel/src/thread/Task.cpp b/kernel/src/thread/Task.cpp index 17226a60..0c924d91 100644 --- a/kernel/src/thread/Task.cpp +++ b/kernel/src/thread/Task.cpp @@ -25,5 +25,5 @@ void task_restore_floating(Task& task) bool Task::is_user_task() { - return (regs.cs & 3) > 0; + return user_task; } \ No newline at end of file