summaryrefslogtreecommitdiff
path: root/Source/Kernel/DeviceManager
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Kernel/DeviceManager')
-rw-r--r--Source/Kernel/DeviceManager/Dev.ns.cpp51
-rw-r--r--Source/Kernel/DeviceManager/Dev.ns.h19
-rw-r--r--Source/Kernel/DeviceManager/Disp.ns.cpp36
-rw-r--r--Source/Kernel/DeviceManager/Disp.ns.h21
-rw-r--r--Source/Kernel/DeviceManager/Time.ns.cpp19
-rw-r--r--Source/Kernel/DeviceManager/Time.ns.h14
6 files changed, 160 insertions, 0 deletions
diff --git a/Source/Kernel/DeviceManager/Dev.ns.cpp b/Source/Kernel/DeviceManager/Dev.ns.cpp
new file mode 100644
index 0000000..71ac3c7
--- /dev/null
+++ b/Source/Kernel/DeviceManager/Dev.ns.cpp
@@ -0,0 +1,51 @@
+#include "Dev.ns.h"
+
+namespace Dev {
+
+Vector<Device*> devices;
+Device* irqHandler[16] = { NULL };
+
+void handleIRQ(registers_t *regs, int irq) {
+ if (irqHandler[irq] != NULL)
+ irqHandler[irq]->handleIRQ(regs, irq);
+}
+
+void registerDevice(Device* dev) {
+ unregisterDevice(dev); //Bad things could have happened
+ devices.push(dev);
+}
+
+void unregisterDevice(Device* dev) {
+ for (u32int i = 0; i < devices.size(); i++) {
+ if (devices[i] == dev) {
+ devices[i] = devices.back();
+ devices.pop();
+ return;
+ }
+ }
+}
+
+bool requestIRQ(Device* dev, int irq) {
+ if (irqHandler[irq] == NULL) {
+ irqHandler[irq] = dev;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+Vector<Device*> findDevice(String _class) {
+ if (_class.empty()) return devices;
+ Vector<Device*> ret;
+ for (u32int i = 0; i < devices.size(); i++) {
+ String devclass = devices[i]->getClass();
+ if (devclass == _class) {
+ ret.push(devices[i]);
+ } else if (devclass.size() > _class.size()) {
+ if (devclass.substr(0, _class.size()) == _class) ret.push(devices[i]);
+ }
+ }
+ return ret;
+}
+
+}
diff --git a/Source/Kernel/DeviceManager/Dev.ns.h b/Source/Kernel/DeviceManager/Dev.ns.h
new file mode 100644
index 0000000..c2651c2
--- /dev/null
+++ b/Source/Kernel/DeviceManager/Dev.ns.h
@@ -0,0 +1,19 @@
+#ifndef DEF_DEV_NS_H
+#define DEF_DEV_NS_H
+
+#include <Devices/Device.proto.h>
+#include <Library/Vector.class.h>
+
+namespace Dev {
+ void handleIRQ(registers_t *regs, int irq);
+
+ void registerDevice(Device* dev);
+ void unregisterDevice(Device* dev);
+
+ bool requestIRQ(Device* dev, int irq);
+
+ Vector<Device*> findDevice(String _class = "");
+}
+
+#endif
+
diff --git a/Source/Kernel/DeviceManager/Disp.ns.cpp b/Source/Kernel/DeviceManager/Disp.ns.cpp
new file mode 100644
index 0000000..8db9503
--- /dev/null
+++ b/Source/Kernel/DeviceManager/Disp.ns.cpp
@@ -0,0 +1,36 @@
+#include "Disp.ns.h"
+
+namespace Disp {
+
+mode_t mode;
+
+u16int textCols() {
+ return mode.textCols;
+}
+
+u16int textRows() {
+ return mode.textRows;
+}
+
+void putChar(u16int line, u16int col, char c, u8int color) {
+ if (line >= mode.textRows or col >= mode.textCols) return;
+ mode.device->putChar(line, col, c, color);
+}
+
+void moveCursor(u16int line, u16int col) {
+ if (line >= mode.textRows or col >= mode.textCols) return;
+ mode.device->moveCursor(line, col);
+}
+
+void clear() {
+ mode.device->clear();
+}
+
+void setDisplay(Display* disp) {
+ mode.device = disp;
+ disp->clear();
+ mode.textCols = disp->textCols();
+ mode.textRows = disp->textRows();
+}
+
+}
diff --git a/Source/Kernel/DeviceManager/Disp.ns.h b/Source/Kernel/DeviceManager/Disp.ns.h
new file mode 100644
index 0000000..a815836
--- /dev/null
+++ b/Source/Kernel/DeviceManager/Disp.ns.h
@@ -0,0 +1,21 @@
+#ifndef DEF_DISP_NS_H
+#define DEF_DISP_NS_H
+
+#include <Devices/Display/Display.proto.h>
+
+namespace Disp {
+ struct mode_t {
+ int textCols, textRows;
+ Display *device;
+ };
+
+ u16int textCols();
+ u16int textRows();
+ void putChar(u16int line, u16int col, char c, u8int color);
+ void moveCursor(u16int line, u16int col);
+ void clear();
+
+ void setDisplay(Display* disp);
+}
+
+#endif
diff --git a/Source/Kernel/DeviceManager/Time.ns.cpp b/Source/Kernel/DeviceManager/Time.ns.cpp
new file mode 100644
index 0000000..104db1d
--- /dev/null
+++ b/Source/Kernel/DeviceManager/Time.ns.cpp
@@ -0,0 +1,19 @@
+#include "Time.ns.h"
+
+namespace Time {
+
+Timer* timer;
+
+void setTimer(Timer* t) {
+ timer = t;
+}
+
+u32int uptime() {
+ return timer->uptime();
+}
+
+u32int time() {
+ return timer->time();
+}
+
+}
diff --git a/Source/Kernel/DeviceManager/Time.ns.h b/Source/Kernel/DeviceManager/Time.ns.h
new file mode 100644
index 0000000..6b8a40f
--- /dev/null
+++ b/Source/Kernel/DeviceManager/Time.ns.h
@@ -0,0 +1,14 @@
+#ifndef DEF_TIME_NS_H
+#define DEF_TIME_NS_H
+
+#include <Devices/Timer.class.h>
+
+namespace Time {
+ void setTimer(Timer* t);
+
+ u32int uptime();
+ u32int time();
+}
+
+
+#endif