From d9d283e5ac12d2d298a9e556ec2445f59d7e4349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Quei=C3=9Fner?= Date: Fri, 6 May 2016 12:35:22 +0200 Subject: [PATCH] PMM::alloc now dies with a BSOD instead of returning an invalid value. Adds stub of scheduler driver. --- prototypes/base/include/driver/scheduler.hpp | 34 +++++++++++++ prototypes/base/include/errors.hpp | 1 + prototypes/base/include/pmm.hpp | 4 +- prototypes/base/include/pointer.hpp | 2 +- prototypes/base/init.cpp | 4 ++ prototypes/base/src/pmm.cpp | 10 ++-- prototypes/base/src/scheduler.cpp | 50 ++++++++++++++++++++ 7 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 prototypes/base/include/driver/scheduler.hpp create mode 100644 prototypes/base/src/scheduler.cpp diff --git a/prototypes/base/include/driver/scheduler.hpp b/prototypes/base/include/driver/scheduler.hpp new file mode 100644 index 0000000..84da410 --- /dev/null +++ b/prototypes/base/include/driver/scheduler.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include "base.hpp" +#include "cpustate.hpp" +#include "pointer.hpp" + +namespace driver +{ + class Task + { + private: + physical_t stackBottom; + CpuState *cpu; + public: + Task(); + Task(const Task &) = delete; + Task(Task &&) = delete; + ~Task(); + }; + + class Scheduler : + public Driver + { + private: + static Scheduler *current; + static void dispatch(CpuState *cpu); + + void next(CpuState *cpu); + public: + Scheduler(); + + void install() override; + }; +} \ No newline at end of file diff --git a/prototypes/base/include/errors.hpp b/prototypes/base/include/errors.hpp index da59d7a..50c8db4 100644 --- a/prototypes/base/include/errors.hpp +++ b/prototypes/base/include/errors.hpp @@ -6,4 +6,5 @@ enum class Error OutOfMemory = 1, UnhandledException = 2, UnhandledInterrupt = 3, + DriverAlreadyInstalled = 4, }; \ No newline at end of file diff --git a/prototypes/base/include/pmm.hpp b/prototypes/base/include/pmm.hpp index c31cd6b..e5aa39b 100644 --- a/prototypes/base/include/pmm.hpp +++ b/prototypes/base/include/pmm.hpp @@ -22,9 +22,9 @@ public: /** * Allocates a single page. - * @param success This boolean will contain true if the allocation was successful. + * @remarks This method will either return a valid value or die with a BSOD if out of memory. */ - static physical_t alloc(bool &success); + static physical_t alloc(); /** * Frees a given page by pointer. diff --git a/prototypes/base/include/pointer.hpp b/prototypes/base/include/pointer.hpp index 76c0356..8f93c00 100644 --- a/prototypes/base/include/pointer.hpp +++ b/prototypes/base/include/pointer.hpp @@ -72,7 +72,7 @@ public: * Allow explicit conversion to a raw pointer. */ explicit operator void * () const { - return this->ptr; + return this->data(); } /** diff --git a/prototypes/base/init.cpp b/prototypes/base/init.cpp index e088e8a..e17dd49 100644 --- a/prototypes/base/init.cpp +++ b/prototypes/base/init.cpp @@ -11,6 +11,7 @@ #include "io.hpp" #include "driver/keyboard.hpp" +#include "driver/scheduler.hpp" using namespace multiboot; using namespace console_tools; @@ -22,6 +23,7 @@ extern dummy kernelStartMarker; extern dummy kernelEndMarker; driver::Keyboard keyboardDriver; +driver::Scheduler scheduler; void timer(CpuState *cpu) { @@ -94,7 +96,9 @@ extern "C" void init(Structure const & data) IDT::initialize(); IDT::interrupt(0x20) = Interrupt(timer); + keyboardDriver.install(); + scheduler.install(); Console::main << "Interrupts set up.\n"; diff --git a/prototypes/base/src/pmm.cpp b/prototypes/base/src/pmm.cpp index 2e9dea2..ebe5e1e 100644 --- a/prototypes/base/src/pmm.cpp +++ b/prototypes/base/src/pmm.cpp @@ -1,6 +1,7 @@ #include #include #include "pmm.hpp" +#include "bsod.hpp" /** * Number stored of pages in the bitmap @@ -53,7 +54,7 @@ void PMM::markUsed(physical_t page) bitmap[idx] &= ~(1<next(cpu); + } else { + + } + } + + + + Task::Task() : + stackBottom(PMM::alloc()), cpu(nullptr) + { + + } + + Task::~Task() + { + PMM::free(this->stackBottom); + } +} \ No newline at end of file