diff --git a/kernel/hal/dummy/include/Multitasking.h b/kernel/hal/dummy/include/Multitasking.h index cca8158..41f4b9c 100644 --- a/kernel/hal/dummy/include/Multitasking.h +++ b/kernel/hal/dummy/include/Multitasking.h @@ -11,8 +11,6 @@ namespace MTGosHAL { uint32_t tss[32]; protected: private: - static auto task_a() -> void; - static auto task_b() -> void; Task* first_task; Task* curr_task; }; @@ -26,6 +24,7 @@ namespace MTGosHAL { auto unpause() -> struct cpu_state*; auto pause(struct cpu_state*) -> Task *; auto addTask(Task*) -> void; + auto hasNext() -> bool; }; } // namespace MTGosHAL diff --git a/kernel/hal/x86/include/Multitasking.hpp b/kernel/hal/x86/include/Multitasking.hpp index 3949622..2afe622 100644 --- a/kernel/hal/x86/include/Multitasking.hpp +++ b/kernel/hal/x86/include/Multitasking.hpp @@ -14,8 +14,6 @@ namespace MTGosHAL { uint32_t tss[32]; protected: private: - static auto task_a() -> void; - static auto task_b() -> void; Task* first_task; Task* curr_task; }; @@ -29,6 +27,7 @@ namespace MTGosHAL { auto unpause() -> struct cpu_state*; auto pause(struct cpu_state*) -> Task *; auto addTask(Task*) -> void; + auto hasNext() -> bool; }; } // namespace MTGosHAL diff --git a/kernel/hal/x86/init/Multitasking.cpp b/kernel/hal/x86/init/Multitasking.cpp index b0ea7ec..94443d1 100644 --- a/kernel/hal/x86/init/Multitasking.cpp +++ b/kernel/hal/x86/init/Multitasking.cpp @@ -55,40 +55,24 @@ auto Multitasking::initTask(void(* entry)()) -> struct cpu_state* else { first_task=task; } - curr_task=first_task; return state; } - -auto Multitasking::task_a() -> void -{ - while(true) { - char arr[513]; - arr[512]=0; - disk.readSector(disk.getDriveNumByName("ATA0m"),0,(uint8_t*)arr); - out << arr; - } -} - -auto Multitasking::task_b() -> void -{ - while(true) { - char arr[513]; - arr[512]=0; - disk.readSector(disk.getDriveNumByName("ATA0m"),1,(uint8_t*)arr); - out << arr; - } -} auto Multitasking::schedule(struct cpu_state* cpu) -> struct cpu_state* { - Task* next=curr_task->pause(cpu); - if(next==nullptr) + Task* next=nullptr; + if(curr_task) { + next=curr_task->pause(cpu); + } + if (!next) { next=first_task; + } curr_task=next; return next->unpause(); } Task::Task(struct cpu_state* cpu): cpu_state(cpu), next(nullptr) {}; //This is run every time this task is chosen by the scheduler auto Task::unpause() -> struct cpu_state* { + MTGosHAL::tasks.tss[1] = (uint32_t) (cpu_state + 1); return cpu_state; } //This is run every time the timer ticks and a task is running @@ -101,4 +85,7 @@ auto Task::addTask(Task* task) -> void { return next->addTask(task); next=task; } +auto Task::hasNext() -> bool { + return next!=nullptr; +} } // namespace MTGosHAL diff --git a/kernel/kernel/init.cpp b/kernel/kernel/init.cpp index cd8c0d6..277fe18 100644 --- a/kernel/kernel/init.cpp +++ b/kernel/kernel/init.cpp @@ -6,20 +6,28 @@ #include #include using namespace MTGosHAL; +void pid_null() { + for(;;); +} void task_a() { - MTGosHAL::out << "a"; + while(true) + MTGosHAL::out << "a"; } void task_b() { - MTGosHAL::out << "b"; + while(true) + MTGosHAL::out << "b"; } void task_c() { - MTGosHAL::out << "c"; + while(true) + MTGosHAL::out << "c"; } void task_d() { - MTGosHAL::out << "d"; + while(true) + MTGosHAL::out << "d"; } void main() { MTGosHAL::out << "Initializing Kernel!\n"; + MTGosHAL::tasks.initTask(&pid_null); MTGosHAL::tasks.initTask(&task_a); MTGosHAL::tasks.initTask(&task_b); MTGosHAL::tasks.initTask(&task_c);