Removes scheduler.

This commit is contained in:
Felix Queißner 2016-05-18 10:24:36 +02:00
parent 02364038bd
commit 91b72ceb68
3 changed files with 36 additions and 210 deletions

View file

@ -1,44 +0,0 @@
#pragma once
#include "driver.hpp"
#include "cpustate.hpp"
#include "pointer.hpp"
namespace driver
{
using EntryPoint = void (*)();
class Task
{
friend class Scheduler;
private:
Task *previous, *next;
CpuState *cpu;
physical_t stackBottom;
Task(EntryPoint ep);
Task(const Task &) = delete;
Task(Task &&) = delete;
~Task();
public:
};
class Scheduler :
public Driver
{
private:
static Scheduler *current;
static void dispatch(CpuState *& cpu);
Task *currentTask;
Task *firstTask;
Task *lastTask;
CpuState * next(CpuState *cpu);
public:
Scheduler();
void install() override;
Task *spawn(EntryPoint ep);
};
}

View file

@ -13,7 +13,6 @@
#include "driver/timer.hpp"
#include "driver/keyboard.hpp"
#include "driver/scheduler.hpp"
#include <inttypes.h>
#include <new>
@ -31,7 +30,6 @@ extern dummy kernelEndMarker;
driver::Timer timer;
driver::Keyboard keyboardDriver;
// driver::Scheduler scheduler;
VMMContext * kernelContext;
@ -105,57 +103,24 @@ static void dump_elf(elf::Header *header)
}
}
void delay()
static void initializePMM(Structure const & data)
{
for(volatile uint32_t i = 0; i < 0x1000000; i++);
}
void task_a(void)
{
while (1) {
Console::main.put('A');
delay();
}
}
void task_b(void)
{
while (1) {
Console::main.put('B');
delay();
}
}
extern "C" void init(Structure const & data)
{
Console::main
<< "Hello World!\n"
<< FColor(Color::Yellow) << "Hello color!" << FColor() << "\n"
<< BColor(Color::Blue) << "Hello blue!" << BColor() << "\n"
<< "Hello default color.\n";
GDT::initialize();
Console::main
<< "bootloader name: " << data.bootLoaderName << "\n"
<< "command line: " << data.commandline << "\n"
<< "count of modules: " << data.modules.length << "\n"
<< "count of mmaps: " << data.memoryMaps.length << "\n";
for(auto &mmap : data.memoryMaps) {
if(mmap.length == 0) {
continue;
for(auto &mmap : data.memoryMaps) {
if(mmap.length == 0) {
continue;
}
if(mmap.isFree() == false) {
continue;
}
Console::main
<< "mmap: "
<< "start: " << hex(mmap.base) << ", length: " << hex(mmap.length)
<< ", " << mmap.entry_size
<< ", " << sizeof(mmap)
<< "\n";
//Console::main
//<< "mmap: "
//<< "start: " << hex(mmap.base) << ", length: " << hex(mmap.length)
//<< ", " << mmap.entry_size
//<< ", " << sizeof(mmap)
//<< "\n";
if(mmap.base > 0xFFFFFFFF) {
Console::main << "mmap out of 4 gigabyte range." << "\n";
//Console::main << "mmap out of 4 gigabyte range." << "\n";
continue;
}
if(mmap.isFree()) {
@ -180,8 +145,31 @@ extern "C" void init(Structure const & data)
PMM::markUsed(physical_t(ptr));
ptr += 0x1000;
}
// nullptr is not valid.
PMM::markUsed(physical_t(nullptr));
// Mark the video memory as used.
PMM::markUsed(physical_t(0xB8000));
}
extern "C" void init(Structure const & data)
{
Console::main
<< "Hello World!\n"
<< FColor(Color::Yellow) << "Hello color!" << FColor() << "\n"
<< BColor(Color::Blue) << "Hello blue!" << BColor() << "\n"
<< "Hello default color.\n";
GDT::initialize();
Console::main
<< "bootloader name: " << data.bootLoaderName << "\n"
<< "command line: " << data.commandline << "\n"
<< "count of modules: " << data.modules.length << "\n"
<< "count of mmaps: " << data.memoryMaps.length << "\n";
initializePMM(data);
auto freeMemory = PMM::getFreeMemory();
Console::main
@ -218,7 +206,6 @@ extern "C" void init(Structure const & data)
timer.install();
keyboardDriver.install();
//scheduler.install();
Console::main << "Drivers installed.\n";
@ -226,14 +213,7 @@ extern "C" void init(Structure const & data)
Console::main << "Interrupts enabled.\n";
//driver::Task *taskB = scheduler.spawn(task_b);
//driver::Task *taskA = scheduler.spawn(task_a);
//
//Console::main
//<< "Task A: " << taskA << "\n"
//<< "Task B: " << taskB << "\n";
if(data.modules.length > 0 && false)
if(data.modules.length > 0)
{
Console::main << "ELF Modukle:\n";
dump_elf(data.modules[0].start.data<elf::Header>());

View file

@ -1,110 +0,0 @@
#include "driver/scheduler.hpp"
#include "bsod.hpp"
#include "pmm.hpp"
#include "vmm.hpp"
#include "idt.hpp"
#include "console.hpp"
#include <new>
extern VMMContext * kernelContext;
namespace driver
{
Scheduler * Scheduler::current = nullptr;
Scheduler::Scheduler() :
currentTask(nullptr),
firstTask(nullptr),
lastTask(nullptr)
{
}
void Scheduler::install()
{
if(Scheduler::current != nullptr) {
BSOD::die(Error::DriverAlreadyInstalled, "The scheduler is already installed.");
}
Scheduler::current = this;
IDT::interrupt(0x20) = Interrupt(Scheduler::dispatch);
}
CpuState * Scheduler::next(CpuState *cpu)
{
if (this->currentTask != nullptr) {
this->currentTask->cpu = cpu;
}
this->currentTask = this->currentTask->next;
/* Prozessorzustand des neuen Tasks aktivieren */
return this->currentTask->cpu;
}
void Scheduler::dispatch(CpuState *& cpu)
{
if(Scheduler::current != nullptr) {
cpu = Scheduler::current->next(cpu);
}
}
static uint32_t memoryPointer = 0x20000000; // start at 512 MB
static virtual_t alloc()
{
virtual_t ptr(memoryPointer);
kernelContext->provide(ptr, VMMFlags::Writable);
memoryPointer += 0x1000;
Console::main << "Providing " << ptr << "\n";
return ptr;
}
Task *Scheduler::spawn(EntryPoint ep)
{
void *memory = alloc().data();
Task *task = new (memory) Task(ep);
asm volatile("cli");
if(this->firstTask != nullptr) {
task->next = this->firstTask;
this->lastTask->next = task;
this->firstTask = task;
} else {
this->lastTask = task;
this->firstTask = task;
task->next = task;
}
asm volatile("sti");
return task;
}
Task::Task(EntryPoint ep) :
previous(nullptr), next(nullptr),
cpu(nullptr),
stackBottom(alloc().data())
{
this->cpu = (CpuState*)(this->stackBottom.numeric() + 4096 - sizeof(CpuState));
this->cpu->eax = 0;
this->cpu->ebx = 0;
this->cpu->ecx = 0;
this->cpu->edx = 0;
this->cpu->esi = 0;
this->cpu->edi = 0;
this->cpu->ebp = 0;
//this->cpu->.esp = unbenutzt (kein Ring-Wechsel)
this->cpu->eip = reinterpret_cast<uint32_t>(ep);
/* Ring-0-Segmentregister */
this->cpu->cs = 0x08;
//this->cpu->.ss = unbenutzt (kein Ring-Wechsel)
/* IRQs einschalten (IF = 1) */
this->cpu->eflags = 0x202;
}
Task::~Task()
{
PMM::free(this->stackBottom);
}
}