PMM::alloc now dies with a BSOD instead of returning an invalid value. Adds stub of scheduler driver.

This commit is contained in:
Felix Queißner 2016-05-06 12:35:22 +02:00
parent ec8eb4a7d8
commit d9d283e5ac
7 changed files with 96 additions and 9 deletions

View file

@ -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;
};
}

View file

@ -6,4 +6,5 @@ enum class Error
OutOfMemory = 1,
UnhandledException = 2,
UnhandledInterrupt = 3,
DriverAlreadyInstalled = 4,
};

View file

@ -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.

View file

@ -72,7 +72,7 @@ public:
* Allow explicit conversion to a raw pointer.
*/
explicit operator void * () const {
return this->ptr;
return this->data();
}
/**

View file

@ -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";

View file

@ -1,6 +1,7 @@
#include <inttypes.h>
#include <stddef.h>
#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<<bit);
}
physical_t PMM::alloc(bool &success)
physical_t PMM::alloc()
{
for(uint32_t idx = 0; idx < BitmapLength; idx++) {
// fast skip when no bit is set
@ -73,13 +74,10 @@ physical_t PMM::alloc(bool &success)
uint32_t pageId = 32 * idx + bit;
uint32_t ptr = 4096 * pageId;
success = true;
return physical_t(ptr);
}
}
// Do something here!
success = false;
BSOD::die(Error::OutOfMemory, "Out of physical memory!");
return physical_t::invalid;
}

View file

@ -0,0 +1,50 @@
#include "driver/scheduler.hpp"
#include "bsod.hpp"
#include "pmm.hpp"
namespace driver
{
Scheduler * Scheduler::current = nullptr;
Scheduler::Scheduler()
{
}
void Scheduler::install()
{
if(Scheduler::current != nullptr) {
BSOD::die(Error::DriverAlreadyInstalled, "The scheduler is already installed.");
}
Scheduler::current = this;
}
void Scheduler::next(CpuState *cpu)
{
}
void Scheduler::dispatch(CpuState *cpu)
{
if(Scheduler::current != nullptr) {
Scheduler::current->next(cpu);
} else {
}
}
Task::Task() :
stackBottom(PMM::alloc()), cpu(nullptr)
{
}
Task::~Task()
{
PMM::free(this->stackBottom);
}
}