summaryrefslogtreecommitdiff
path: root/Source/Kernel
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-11-14 14:17:39 +0100
committerAlexis211 <alexis211@gmail.com>2009-11-14 14:17:39 +0100
commit972e9d53d243b698e9dce7125a08804a43b70534 (patch)
treee50cfc590ad2ec090cc774369c744f637e11cfc5 /Source/Kernel
parent6055ef45a39b62bffa5f4c194e5d62a177c3b9df (diff)
downloadMelon-972e9d53d243b698e9dce7125a08804a43b70534.tar.gz
Melon-972e9d53d243b698e9dce7125a08804a43b70534.zip
Changed the way keyboard handling works, fixing a bug.
Diffstat (limited to 'Source/Kernel')
-rw-r--r--Source/Kernel/Core/kmain.wtf.cpp7
-rw-r--r--Source/Kernel/Shell/KernelShell.class.cpp2
-rw-r--r--Source/Kernel/VTManager/PipeVT.class.cpp9
-rw-r--r--Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp24
-rw-r--r--Source/Kernel/VTManager/VirtualTerminal.proto.cpp4
-rw-r--r--Source/Kernel/VTManager/VirtualTerminal.proto.h7
6 files changed, 31 insertions, 22 deletions
diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp
index b6543ae..0486702 100644
--- a/Source/Kernel/Core/kmain.wtf.cpp
+++ b/Source/Kernel/Core/kmain.wtf.cpp
@@ -201,7 +201,10 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
if (init.empty()) {
*kvt << "\n\n";
new KernelShell(cwd, kvt);
- while (1) asm volatile("sti; hlt");
+ while (KernelShell::getInstances() > 0) {
+ Task::currThread()->sleep(100);
+ }
+ Sys::halt();
} else {
selectVideoMode(*kvt);
//Create a VT for handling the Melon bootup logo
@@ -222,7 +225,7 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
p->setOutVT(vt);
p->start();
while (p->getState() != P_FINISHED) Task::currThread()->sleep(100);
- Sys::halt();
+ PANIC("Init has terminated");
}
}
diff --git a/Source/Kernel/Shell/KernelShell.class.cpp b/Source/Kernel/Shell/KernelShell.class.cpp
index f3cd340..d62d822 100644
--- a/Source/Kernel/Shell/KernelShell.class.cpp
+++ b/Source/Kernel/Shell/KernelShell.class.cpp
@@ -19,7 +19,6 @@ void KernelShell::setup(DirectoryNode* cwd, VirtualTerminal *vt) {
m_vt = vt;
Task::currProcess()->setInVT(vt);
Task::currProcess()->setOutVT(vt);
- Kbd::setFocus(m_vt);
m_cwd = cwd;
*m_vt << "Welcome to Melon's kernel shell !\n";
m_thread = new Thread(shellRun, (void*)this, true);
@@ -33,6 +32,7 @@ KernelShell::KernelShell(DirectoryNode* cwd, VirtualTerminal* vt) {
KernelShell::KernelShell(DirectoryNode* cwd) {
ScrollableVT* vt = new ScrollableVT(15, 76, 200, KVT_FGCOLOR, KVT_BGCOLOR);
vt->map(9);
+ Kbd::setFocus(vt);
setup(cwd, vt);
}
diff --git a/Source/Kernel/VTManager/PipeVT.class.cpp b/Source/Kernel/VTManager/PipeVT.class.cpp
index 7e67161..f4a5ca9 100644
--- a/Source/Kernel/VTManager/PipeVT.class.cpp
+++ b/Source/Kernel/VTManager/PipeVT.class.cpp
@@ -1,4 +1,5 @@
#include "PipeVT.class.h"
+#include <TaskManager/Task.ns.h>
PipeVT::PipeVT() {
m_col = 0;
@@ -29,7 +30,9 @@ void PipeVT::put(WChar c, bool updatecsr) {
kp.character = c;
m_col++;
}
- m_kbdbuffMutex.waitLock();
- m_kbdbuff.push(kp);
- m_kbdbuffMutex.unlock();
+ while (m_kbdbuffEnd == m_kbdbuffStart - 1 or (m_kbdbuffEnd == KBDBUFFSIZE - 1 and m_kbdbuffStart == 0))
+ Task::currThread()->sleep(10);
+ m_kbdbuff[m_kbdbuffEnd] = kp;
+ m_kbdbuffEnd++;
+ if (m_kbdbuffEnd == KBDBUFFSIZE) m_kbdbuffEnd = 0;
}
diff --git a/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp b/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp
index 9f3e349..5b551eb 100644
--- a/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp
+++ b/Source/Kernel/VTManager/VirtualTerminal-kbd.proto.cpp
@@ -4,8 +4,10 @@
using namespace Kbd;
void VirtualTerminal::keyPress(keypress_t kp) {
- m_kbdbuffMutex.waitLock();
- m_kbdbuff.push(kp);
+ if (m_kbdbuffEnd == m_kbdbuffStart - 1 or (m_kbdbuffEnd == KBDBUFFSIZE - 1 and m_kbdbuffStart == 0)) return;
+ m_kbdbuff[m_kbdbuffEnd] = kp;
+ m_kbdbuffEnd++;
+ if (m_kbdbuffEnd == KBDBUFFSIZE) m_kbdbuffEnd = 0;
if (!m_kbdMutex.locked()) {
if (kp.haschar && !kp.hascmd) {
put(kp.character);
@@ -17,29 +19,26 @@ void VirtualTerminal::keyPress(keypress_t kp) {
put("\b");
}
}
- m_kbdbuffMutex.unlock();
}
keypress_t VirtualTerminal::getKeypress(bool show, bool block) {
m_kbdMutex.waitLock();
- if (m_kbdbuff.empty() && !block) {
+ if (m_kbdbuffStart == m_kbdbuffEnd && !block) {
m_kbdMutex.unlock();
return keypress_t();
}
- while (m_kbdbuff.empty()) {
+ while (m_kbdbuffStart == m_kbdbuffEnd) {
Task::currThread()->sleep(10);
}
- m_kbdbuffMutex.waitLock();
- keypress_t ret = m_kbdbuff[0];
+ keypress_t ret = m_kbdbuff[m_kbdbuffStart];
- for (u32int i = 1; i < m_kbdbuff.size(); i++) {
- m_kbdbuff[i - 1] = m_kbdbuff[i];
- }
- m_kbdbuff.pop();
- m_kbdbuffMutex.unlock();
+ m_kbdbuffStart++;
+ if (m_kbdbuffStart == KBDBUFFSIZE) m_kbdbuffStart = 0;
+
+ m_kbdMutex.unlock();
if (show) {
if (ret.haschar && !ret.hascmd) {
@@ -53,7 +52,6 @@ keypress_t VirtualTerminal::getKeypress(bool show, bool block) {
}
}
- m_kbdMutex.unlock();
return ret;
}
diff --git a/Source/Kernel/VTManager/VirtualTerminal.proto.cpp b/Source/Kernel/VTManager/VirtualTerminal.proto.cpp
index 0079707..34c10d0 100644
--- a/Source/Kernel/VTManager/VirtualTerminal.proto.cpp
+++ b/Source/Kernel/VTManager/VirtualTerminal.proto.cpp
@@ -6,7 +6,9 @@
#include <VirtualTerminal.iface.h>
VirtualTerminal::VirtualTerminal() :
- Ressource(VTIF_OBJTYPE, m_callTable), m_kbdMutex(false), m_kbdbuffMutex(false), m_kbdbuff() {
+ Ressource(VTIF_OBJTYPE, m_callTable), m_kbdMutex(false), m_kbdbuff() {
+ m_kbdbuffStart = 0;
+ m_kbdbuffEnd = 0;
}
VirtualTerminal::~VirtualTerminal() {
diff --git a/Source/Kernel/VTManager/VirtualTerminal.proto.h b/Source/Kernel/VTManager/VirtualTerminal.proto.h
index 5f874b4..ceb994c 100644
--- a/Source/Kernel/VTManager/VirtualTerminal.proto.h
+++ b/Source/Kernel/VTManager/VirtualTerminal.proto.h
@@ -14,10 +14,13 @@ struct vtchr {
WChar c;
};
+#define KBDBUFFSIZE 10
+
class VirtualTerminal : public Ressource {
protected:
- Mutex m_kbdMutex, m_kbdbuffMutex;
- Vector<keypress_t> m_kbdbuff; //Key press events buffer
+ Mutex m_kbdMutex;
+ keypress_t m_kbdbuff[KBDBUFFSIZE]; //Key press events buffer
+ int m_kbdbuffStart, m_kbdbuffEnd;
//SYSCALLS :
static call_t m_callTable[];