Permalink
Browse files

Files for part 15, https://www.youtube.com/watch?v=VxZnBkMQ258

  • Loading branch information...
Viktor Engelmann Viktor Engelmann
Viktor Engelmann authored and Viktor Engelmann committed Jul 4, 2016
1 parent 15e5fa7 commit 49a2efa4bf490ce6152deb82071fce30a5d76aca
@@ -3,6 +3,7 @@
#define __MYOS__HARDWARECOMMUNICATION__INTERRUPTMANAGER_H
#include <gdt.h>
#include <multitasking.h>
#include <common/types.h>
#include <hardwarecommunication/port.h>
@@ -33,6 +34,7 @@ namespace myos
static InterruptManager* ActiveInterruptManager;
InterruptHandler* handlers[256];
TaskManager *taskManager;
struct GateDescriptor
{
@@ -107,7 +109,7 @@ namespace myos
Port8BitSlow programmableInterruptControllerSlaveDataPort;
public:
InterruptManager(myos::common::uint16_t hardwareInterruptOffset, myos::GlobalDescriptorTable* globalDescriptorTable);
InterruptManager(myos::common::uint16_t hardwareInterruptOffset, myos::GlobalDescriptorTable* globalDescriptorTable, myos::TaskManager* taskManager);
~InterruptManager();
myos::common::uint16_t HardwareInterruptOffset();
void Activate();
View
@@ -0,0 +1,68 @@
#ifndef __MYOS__MULTITASKING_H
#define __MYOS__MULTITASKING_H
#include <common/types.h>
#include <gdt.h>
namespace myos
{
struct CPUState
{
common::uint32_t eax;
common::uint32_t ebx;
common::uint32_t ecx;
common::uint32_t edx;
common::uint32_t esi;
common::uint32_t edi;
common::uint32_t ebp;
/*
common::uint32_t gs;
common::uint32_t fs;
common::uint32_t es;
common::uint32_t ds;
*/
common::uint32_t error;
common::uint32_t eip;
common::uint32_t cs;
common::uint32_t eflags;
common::uint32_t esp;
common::uint32_t ss;
} __attribute__((packed));
class Task
{
friend class TaskManager;
private:
common::uint8_t stack[4096]; // 4 KiB
CPUState* cpustate;
public:
Task(GlobalDescriptorTable *gdt, void entrypoint());
~Task();
};
class TaskManager
{
private:
Task* tasks[256];
int numTasks;
int currentTask;
public:
TaskManager();
~TaskManager();
bool AddTask(Task* task);
CPUState* Schedule(CPUState* cpustate);
};
}
#endif
View
@@ -12,6 +12,7 @@ objects = obj/loader.o \
obj/hardwarecommunication/port.o \
obj/hardwarecommunication/interruptstubs.o \
obj/hardwarecommunication/interrupts.o \
obj/multitasking.o \
obj/hardwarecommunication/pci.o \
obj/drivers/keyboard.o \
obj/drivers/mouse.o \
@@ -1,5 +1,6 @@
#include <hardwarecommunication/interrupts.h>
using namespace myos;
using namespace myos::common;
using namespace myos::hardwarecommunication;
@@ -59,12 +60,13 @@ void InterruptManager::SetInterruptDescriptorTableEntry(uint8_t interrupt,
}
InterruptManager::InterruptManager(uint16_t hardwareInterruptOffset, GlobalDescriptorTable* globalDescriptorTable)
InterruptManager::InterruptManager(uint16_t hardwareInterruptOffset, GlobalDescriptorTable* globalDescriptorTable, TaskManager* taskManager)
: programmableInterruptControllerMasterCommandPort(0x20),
programmableInterruptControllerMasterDataPort(0x21),
programmableInterruptControllerSlaveCommandPort(0xA0),
programmableInterruptControllerSlaveDataPort(0xA1)
{
this->taskManager = taskManager;
this->hardwareInterruptOffset = hardwareInterruptOffset;
uint32_t CodeSegment = globalDescriptorTable->CodeSegmentSelector();
@@ -184,6 +186,11 @@ uint32_t InterruptManager::DoHandleInterrupt(uint8_t interrupt, uint32_t esp)
printf("UNHANDLED INTERRUPT 0x");
printfHex(interrupt);
}
if(interrupt == hardwareInterruptOffset)
{
esp = (uint32_t)taskManager->Schedule((CPUState*)esp);
}
// hardware interrupts must be acknowledged
if(hardwareInterruptOffset <= interrupt && interrupt < hardwareInterruptOffset+16)
@@ -19,6 +19,7 @@ _ZN4myos21hardwarecommunication16InterruptManager19HandleException\num\()Ev:
.global _ZN4myos21hardwarecommunication16InterruptManager26HandleInterruptRequest\num\()Ev
_ZN4myos21hardwarecommunication16InterruptManager26HandleInterruptRequest\num\()Ev:
movb $\num + IRQ_BASE, (interruptnumber)
pushl $0
jmp int_bottom
.endm
@@ -64,32 +65,51 @@ HandleInterruptRequest 0x31
int_bottom:
# register sichern
pusha
pushl %ds
pushl %es
pushl %fs
pushl %gs
# ring 0 segment register laden
# save registers
#pusha
#pushl %ds
#pushl %es
#pushl %fs
#pushl %gs
pushl %ebp
pushl %edi
pushl %esi
pushl %edx
pushl %ecx
pushl %ebx
pushl %eax
# load ring 0 segment register
#cld
#mov $0x10, %eax
#mov %eax, %eds
#mov %eax, %ees
# C++ Handler aufrufen
# call C++ Handler
pushl %esp
push (interruptnumber)
call _ZN4myos21hardwarecommunication16InterruptManager15HandleInterruptEhj
add %esp, 6
mov %eax, %esp # den stack wechseln
# register laden
pop %gs
pop %fs
pop %es
pop %ds
popa
#add %esp, 6
mov %eax, %esp # switch the stack
# restore registers
popl %eax
popl %ebx
popl %ecx
popl %edx
popl %esi
popl %edi
popl %ebp
#pop %gs
#pop %fs
#pop %es
#pop %ds
#popa
add $4, %esp
.global _ZN4myos21hardwarecommunication16InterruptManager15InterruptIgnoreEv
_ZN4myos21hardwarecommunication16InterruptManager15InterruptIgnoreEv:
View
@@ -9,6 +9,7 @@
#include <drivers/vga.h>
#include <gui/desktop.h>
#include <gui/window.h>
#include <multitasking.h>
// #define GRAPHICSMODE
@@ -122,6 +123,18 @@ class MouseToConsole : public MouseEventHandler
void taskA()
{
while(true)
printf("A");
}
void taskB()
{
while(true)
printf("B");
}
@@ -142,7 +155,14 @@ extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot
printf("Hello World! --- http://www.AlgorithMan.de\n");
GlobalDescriptorTable gdt;
InterruptManager interrupts(0x20, &gdt);
TaskManager taskManager;
Task task1(&gdt, taskA);
Task task2(&gdt, taskB);
taskManager.AddTask(&task1);
taskManager.AddTask(&task2);
InterruptManager interrupts(0x20, &gdt, &taskManager);
printf("Initializing Hardware, Stage 1\n");
View
@@ -0,0 +1,74 @@
#include <multitasking.h>
using namespace myos;
using namespace myos::common;
Task::Task(GlobalDescriptorTable *gdt, void entrypoint())
{
cpustate = (CPUState*)(stack + 4096 - sizeof(CPUState));
cpustate -> eax = 0;
cpustate -> ebx = 0;
cpustate -> ecx = 0;
cpustate -> edx = 0;
cpustate -> esi = 0;
cpustate -> edi = 0;
cpustate -> ebp = 0;
/*
cpustate -> gs = 0;
cpustate -> fs = 0;
cpustate -> es = 0;
cpustate -> ds = 0;
*/
// cpustate -> error = 0;
// cpustate -> esp = ;
cpustate -> eip = (uint32_t)entrypoint;
cpustate -> cs = gdt->CodeSegmentSelector();
// cpustate -> ss = ;
cpustate -> eflags = 0x202;
}
Task::~Task()
{
}
TaskManager::TaskManager()
{
numTasks = 0;
currentTask = -1;
}
TaskManager::~TaskManager()
{
}
bool TaskManager::AddTask(Task* task)
{
if(numTasks >= 256)
return false;
tasks[numTasks++] = task;
return true;
}
CPUState* TaskManager::Schedule(CPUState* cpustate)
{
if(numTasks <= 0)
return cpustate;
if(currentTask >= 0)
tasks[currentTask]->cpustate = cpustate;
if(++currentTask >= numTasks)
currentTask %= numTasks;
return tasks[currentTask]->cpustate;
}

0 comments on commit 49a2efa

Please sign in to comment.