diff options
Diffstat (limited to 'Source/Kernel/Devices')
-rw-r--r-- | Source/Kernel/Devices/Device.proto.h | 16 | ||||
-rw-r--r-- | Source/Kernel/Devices/Display/Display.proto.h | 3 | ||||
-rw-r--r-- | Source/Kernel/Devices/Display/VGATextOutput.class.cpp | 9 | ||||
-rw-r--r-- | Source/Kernel/Devices/Display/VGATextOutput.class.h | 3 | ||||
-rw-r--r-- | Source/Kernel/Devices/Timer.class.cpp | 56 | ||||
-rw-r--r-- | Source/Kernel/Devices/Timer.class.h | 26 |
6 files changed, 112 insertions, 1 deletions
diff --git a/Source/Kernel/Devices/Device.proto.h b/Source/Kernel/Devices/Device.proto.h new file mode 100644 index 0000000..fa31b06 --- /dev/null +++ b/Source/Kernel/Devices/Device.proto.h @@ -0,0 +1,16 @@ +#ifndef DEF_DEVICE_PROTO_H +#define DEF_DEVICE_PROTO_H + +#include <Library/String.class.h> + +#include <SyscallManager/IDT.ns.h> + +class Device { + public: + virtual String getClass() = 0; + virtual String getName() = 0; + + virtual void handleIRQ(registers_t *regs, int irq) {}; +}; + +#endif diff --git a/Source/Kernel/Devices/Display/Display.proto.h b/Source/Kernel/Devices/Display/Display.proto.h index d91023a..1c8e724 100644 --- a/Source/Kernel/Devices/Display/Display.proto.h +++ b/Source/Kernel/Devices/Display/Display.proto.h @@ -2,8 +2,9 @@ #define DEF_DISPLAY_PROTO_H #include <Core/common.wtf.h> +#include <Devices/Device.proto.h> -class Display { +class Display : public Device { public: virtual u16int textCols() = 0; virtual u16int textRows() = 0; diff --git a/Source/Kernel/Devices/Display/VGATextOutput.class.cpp b/Source/Kernel/Devices/Display/VGATextOutput.class.cpp index 28c943a..a424153 100644 --- a/Source/Kernel/Devices/Display/VGATextOutput.class.cpp +++ b/Source/Kernel/Devices/Display/VGATextOutput.class.cpp @@ -1,9 +1,18 @@ #include "VGATextOutput.class.h" +//Virtual address in higher half #define RAM_ADDR 0xC00B8000 using namespace Sys; //For outb +String VGATextOutput::getClass() { + return "display.text"; +} + +String VGATextOutput::getName() { + return "Standard mode0 VGA text display"; +} + u16int VGATextOutput::textCols() { return 80; } diff --git a/Source/Kernel/Devices/Display/VGATextOutput.class.h b/Source/Kernel/Devices/Display/VGATextOutput.class.h index a7968c7..eb3fc99 100644 --- a/Source/Kernel/Devices/Display/VGATextOutput.class.h +++ b/Source/Kernel/Devices/Display/VGATextOutput.class.h @@ -5,6 +5,9 @@ class VGATextOutput : public Display { public: + String getClass(); + String getName(); + u16int textCols(); u16int textRows(); void putChar(u16int line, u16int col, char c, u8int color); diff --git a/Source/Kernel/Devices/Timer.class.cpp b/Source/Kernel/Devices/Timer.class.cpp new file mode 100644 index 0000000..42a6d1c --- /dev/null +++ b/Source/Kernel/Devices/Timer.class.cpp @@ -0,0 +1,56 @@ +#include "Timer.class.h" + +#include <DeviceManager/Dev.ns.h> +#include <DeviceManager/Time.ns.h> + +using namespace Sys; //For outb + +Timer::Timer(u8int frequency) { + m_ticks = 0; + m_seconds = 0; + + Dev::requestIRQ(this, 0); + Time::setTimer(this); + setFrequency(frequency); +} + +String Timer::getClass() { + return String("timer"); +} + +String Timer::getName() { + return String("Programmable interrupt timer"); +} + +void Timer::setFrequency(u8int frequency) { + m_frequency = frequency; + u32int divisor = 1193180 / (u32int)frequency; + outb(0x43, 0x36); + + u8int l = (u8int)(divisor & 0xFF); + u8int h = (u8int)( (divisor >> 8) & 0xFF); + + outb(0x40, l); + outb(0x40, h); +} + +u32int Timer::uptime() { + return m_seconds; +} + +u32int Timer::time() { + return (m_seconds * 1000) + ((m_ticks * 1000) / m_frequency); +} + +void Timer::handleIRQ(registers_t registers, int irq) { + if (irq == 0) { + m_ticks++; + if (m_ticks == m_frequency) { + m_ticks = 0; + m_seconds++; + } + //Switching task is called in Dev::handleInterrupt + } +} + + diff --git a/Source/Kernel/Devices/Timer.class.h b/Source/Kernel/Devices/Timer.class.h new file mode 100644 index 0000000..187a7e9 --- /dev/null +++ b/Source/Kernel/Devices/Timer.class.h @@ -0,0 +1,26 @@ +#ifndef DEF_TIMER_CLASS +#define DEF_TIMER_CLASS + +#include <Devices/Device.proto.h> + +class Timer : public Device { + private: + u8int m_frequency; + u8int m_ticks; + u32int m_seconds; + + public: + Timer(u8int frequency = 100); + + void setFrequency(u8int frequency); + + String getClass(); + String getName(); + + u32int uptime();//Returns seconds since init + u32int time(); //Returns miliseconds since init + + void handleIRQ(registers_t registers, int irq); +}; + +#endif |