From f593816bc9c32a8570cf65697183f314348e8e87 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Fri, 18 Sep 2009 14:26:29 +0200 Subject: Changes in mutexes, vectors and VTs : mutexes now use the atomic_exchang defined in Task.wtf.asm some vector methods are now declared const VTs now can display (decimal) 64bit integers --- Source/Kernel/Core/kmain.wtf.cpp | 4 +- Source/Kernel/Library/String.class.cpp | 10 ++-- Source/Kernel/Library/String.class.h | 4 +- Source/Kernel/Library/Vector.class.cpp | 10 ++-- Source/Kernel/Library/Vector.class.h | 10 ++-- Source/Kernel/Melon.ke | Bin 158798 -> 158901 bytes Source/Kernel/Ressources/keymap-fr.wtf.c | 56 --------------------- Source/Kernel/Ressources/keymap-fr.wtf.cxd | 56 +++++++++++++++++++++ Source/Kernel/Ressources/logo.cd | 10 ---- Source/Kernel/Ressources/logo.cxd | 10 ++++ Source/Kernel/TaskManager/Mutex.class.cpp | 14 +++--- Source/Kernel/TaskManager/Mutex.class.h | 9 +++- Source/Kernel/TaskManager/Task.wtf.asm | 7 +++ .../Kernel/VTManager/VirtualTerminal-kbd.class.cpp | 4 ++ Source/Kernel/VTManager/VirtualTerminal.class.cpp | 7 +-- Source/Kernel/VTManager/VirtualTerminal.class.h | 5 +- 16 files changed, 118 insertions(+), 98 deletions(-) delete mode 100644 Source/Kernel/Ressources/keymap-fr.wtf.c create mode 100644 Source/Kernel/Ressources/keymap-fr.wtf.cxd delete mode 100644 Source/Kernel/Ressources/logo.cd create mode 100644 Source/Kernel/Ressources/logo.cxd (limited to 'Source') diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp index 857e167..e263393 100644 --- a/Source/Kernel/Core/kmain.wtf.cpp +++ b/Source/Kernel/Core/kmain.wtf.cpp @@ -25,8 +25,8 @@ #include #include -#include -#include +#include +#include extern u32int end; //Placement address diff --git a/Source/Kernel/Library/String.class.cpp b/Source/Kernel/Library/String.class.cpp index 9d4083b..7c2bbc0 100644 --- a/Source/Kernel/Library/String.class.cpp +++ b/Source/Kernel/Library/String.class.cpp @@ -196,9 +196,10 @@ String String::concat (WChar other) const { return (ret += other); } -s32int String::toInt() const { +s64int String::toInt() const { if (m_string == 0) return 0; - s32int pos = 0, number = 0; + s32int pos = 0; + s64int number = 0; bool negative = false; if (m_string[0].value == '-') { negative = true; @@ -213,9 +214,10 @@ s32int String::toInt() const { return number; } -u32int String::toInt16() const { +u64int String::toInt16() const { if (m_string == 0) return 0; - u32int pos = 0, number = 0; + u32int pos = 0; + u64int number = 0; if (m_string[0].value == '0' && m_string[1].value == 'x') pos = 2; while (1) { char c = m_string[pos]; diff --git a/Source/Kernel/Library/String.class.h b/Source/Kernel/Library/String.class.h index 6a9de64..6216415 100644 --- a/Source/Kernel/Library/String.class.h +++ b/Source/Kernel/Library/String.class.h @@ -46,8 +46,8 @@ class String { String operator+ (const char* other) const { return concat(other); } String operator+ (WChar other) const { return concat(other); } - s32int toInt() const; //Convert from DEC - u32int toInt16() const; //Convert from HEX + s64int toInt() const; //Convert from DEC + u64int toInt16() const; //Convert from HEX WChar& operator[] (int index) const; diff --git a/Source/Kernel/Library/Vector.class.cpp b/Source/Kernel/Library/Vector.class.cpp index 8b032ca..02ae9be 100644 --- a/Source/Kernel/Library/Vector.class.cpp +++ b/Source/Kernel/Library/Vector.class.cpp @@ -66,7 +66,7 @@ Vector::~Vector() { } template -T& Vector::operator[] (u32int index) { +T& Vector::operator[] (u32int index) const { return m_data[index]; } @@ -106,23 +106,23 @@ void Vector::pop() { } template -T& Vector::back() { +T& Vector::back() const { return m_data[m_size - 1]; } template -T& Vector::front() { +T& Vector::front() const { return m_data[0]; } template -u32int Vector::size() { +u32int Vector::size() const { return m_size; } template -bool Vector::empty() { +bool Vector::empty() const { return m_size == 0; } diff --git a/Source/Kernel/Library/Vector.class.h b/Source/Kernel/Library/Vector.class.h index ca86c2a..61c26a4 100644 --- a/Source/Kernel/Library/Vector.class.h +++ b/Source/Kernel/Library/Vector.class.h @@ -17,17 +17,17 @@ class Vector { Vector& operator= (const Vector &other); ~Vector(); - T& operator[] (u32int index); + T& operator[] (u32int index) const; void push(const T& element); //void push(T& element); void pop(); - T& back(); - T& front(); + T& back() const; + T& front() const; - u32int size(); - bool empty(); + u32int size() const; + bool empty() const; void clear(); }; diff --git a/Source/Kernel/Melon.ke b/Source/Kernel/Melon.ke index c1e9c75..79d78db 100755 Binary files a/Source/Kernel/Melon.ke and b/Source/Kernel/Melon.ke differ diff --git a/Source/Kernel/Ressources/keymap-fr.wtf.c b/Source/Kernel/Ressources/keymap-fr.wtf.c deleted file mode 100644 index f24c14d..0000000 --- a/Source/Kernel/Ressources/keymap-fr.wtf.c +++ /dev/null @@ -1,56 +0,0 @@ -//This file is precious !!! Very precious !! - -WChar keymapFR_normal[128] = { -/* 0x00 */ "", "", "&", "é", "\"", "'", "(", "-", "è", "_", "ç", "à", ")", "=", "", "", -/* 0x10 */ "a", "z", "e", "r", "t", "y", "u", "i", "o", "p", "^", "$", "", "", "q", "s", -/* 0x20 */ "d", "f", "g", "h", "j", "k", "l", "m", "ù", "²", "", "*", "w", "x", "c", "v", -/* 0x30 */ "b", "n", ",", ";", ":", "!", "", "*", "", " ", "", "", "", "", "", "", -/* 0x40 */ "", "", "", "", "", "", "", "", "", "", "-", "", "", "", "+", "", -/* 0x50 */ "", "", "", "", "", "", "<", "", "", "", "", "", "", "", "", "", -/* 0x60 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", -/* 0x70 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" -}; - -WChar keymapFR_shift[128] = { -/* 0x00 */ "", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "°", "+", "", "", -/* 0x10 */ "A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", "¨", "£", "", "", "Q", "S", -/* 0x20 */ "D", "F", "G", "H", "J", "K", "L", "M", "%", "~", "", "µ", "W", "X", "C", "V", -/* 0x30 */ "B", "N", "?", ".", "/", "§", "", "*", "", " ", "", "", "", "", "", "", -/* 0x40 */ "", "", "", "", "", "", "", "", "", "", "-", "", "", "", "+", "", -/* 0x50 */ "", "", "", "", "", "", ">", "", "", "", "", "", "", "", "", "", -/* 0x60 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", -/* 0x70 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", -}; - -WChar keymapFR_caps[128] = { -/* 0x00 */ "", "", "&", "É", "\"", "'", "(", "-", "È", "_", "Ç", "À", ")", "=", "", "", -/* 0x10 */ "A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", "¨", "$", "", "", "Q", "S", -/* 0x20 */ "D", "F", "G", "H", "J", "K", "L", "M", "Ù", "²", "", "*", "W", "X", "C", "V", -/* 0x30 */ "B", "N", ",", ";", ":", "!", "", "*", "", " ", "", "", "", "", "", "", -/* 0x40 */ "", "", "", "", "", "", "", "", "", "", "-", "", "", "", "+", "", -/* 0x50 */ "", "", "", "", "", "", ">", "", "", "", "", "", "", "", "", "", -/* 0x60 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", -/* 0x70 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", -}; - -WChar keymapFR_altgr[128] = { -/* 0x00 */ "", "", "¹", "~", "#", "{", "[", "|", "`", "\\", "^", "@", "]", "}", "", "", -/* 0x10 */ "æ", "«", "€", "¶", "ŧ", "←", "↓", "→", "ø", "þ", "¨", "¤", "", "", "@", "ß", -/* 0x20 */ "ð", "đ", "ŋ", "ħ", "j", "ĸ", "ł", "µ", "^", "¬", "", "`", "ł", "»", "¢", "“", -/* 0x30 */ "”", "n", "´", ";", "·", "!", "", "*", "", " ", "", "", "", "", "", "", -/* 0x40 */ "", "", "", "", "", "", "", "", "", "", "-", "", "", "", "+", "", -/* 0x50 */ "", "", "", "", "", "", "|", "", "", "", "", "", "", "", "", "", -/* 0x60 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", -/* 0x70 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", -}; - -WChar keymapFR_shiftaltgr[128] = { -/* 0x00 */ "", "", "¡", "⅛", "£", "$", "⅜", "⅝", "⅞", "™", "±", "°", "¿", "˛", "", "", -/* 0x10 */ "Æ", "<", "¢", "®", "Ŧ", "¥", "↑", "ı", "Ø", "Þ", "°", "¯", "", "", "Ω", "§", -/* 0x20 */ "Ð", "ª", "Ŋ", "Ħ", "J", "&", "Ł", "º", "ˇ", "¬", "", "˘", "Ł", ">", "©", "‘", -/* 0x30 */ "’", "N", "˝", "×", "÷", "˙", "", "*", "", " ", "", "", "", "", "", "", -/* 0x40 */ "", "", "", "", "", "", "", "", "", "", "-", "", "", "", "+", "", -/* 0x50 */ "", "", "", "", "", "", "¦", "", "", "", "", "", "", "", "", "", -/* 0x60 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", -/* 0x70 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", -}; diff --git a/Source/Kernel/Ressources/keymap-fr.wtf.cxd b/Source/Kernel/Ressources/keymap-fr.wtf.cxd new file mode 100644 index 0000000..f24c14d --- /dev/null +++ b/Source/Kernel/Ressources/keymap-fr.wtf.cxd @@ -0,0 +1,56 @@ +//This file is precious !!! Very precious !! + +WChar keymapFR_normal[128] = { +/* 0x00 */ "", "", "&", "é", "\"", "'", "(", "-", "è", "_", "ç", "à", ")", "=", "", "", +/* 0x10 */ "a", "z", "e", "r", "t", "y", "u", "i", "o", "p", "^", "$", "", "", "q", "s", +/* 0x20 */ "d", "f", "g", "h", "j", "k", "l", "m", "ù", "²", "", "*", "w", "x", "c", "v", +/* 0x30 */ "b", "n", ",", ";", ":", "!", "", "*", "", " ", "", "", "", "", "", "", +/* 0x40 */ "", "", "", "", "", "", "", "", "", "", "-", "", "", "", "+", "", +/* 0x50 */ "", "", "", "", "", "", "<", "", "", "", "", "", "", "", "", "", +/* 0x60 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", +/* 0x70 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" +}; + +WChar keymapFR_shift[128] = { +/* 0x00 */ "", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "°", "+", "", "", +/* 0x10 */ "A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", "¨", "£", "", "", "Q", "S", +/* 0x20 */ "D", "F", "G", "H", "J", "K", "L", "M", "%", "~", "", "µ", "W", "X", "C", "V", +/* 0x30 */ "B", "N", "?", ".", "/", "§", "", "*", "", " ", "", "", "", "", "", "", +/* 0x40 */ "", "", "", "", "", "", "", "", "", "", "-", "", "", "", "+", "", +/* 0x50 */ "", "", "", "", "", "", ">", "", "", "", "", "", "", "", "", "", +/* 0x60 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", +/* 0x70 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", +}; + +WChar keymapFR_caps[128] = { +/* 0x00 */ "", "", "&", "É", "\"", "'", "(", "-", "È", "_", "Ç", "À", ")", "=", "", "", +/* 0x10 */ "A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", "¨", "$", "", "", "Q", "S", +/* 0x20 */ "D", "F", "G", "H", "J", "K", "L", "M", "Ù", "²", "", "*", "W", "X", "C", "V", +/* 0x30 */ "B", "N", ",", ";", ":", "!", "", "*", "", " ", "", "", "", "", "", "", +/* 0x40 */ "", "", "", "", "", "", "", "", "", "", "-", "", "", "", "+", "", +/* 0x50 */ "", "", "", "", "", "", ">", "", "", "", "", "", "", "", "", "", +/* 0x60 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", +/* 0x70 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", +}; + +WChar keymapFR_altgr[128] = { +/* 0x00 */ "", "", "¹", "~", "#", "{", "[", "|", "`", "\\", "^", "@", "]", "}", "", "", +/* 0x10 */ "æ", "«", "€", "¶", "ŧ", "←", "↓", "→", "ø", "þ", "¨", "¤", "", "", "@", "ß", +/* 0x20 */ "ð", "đ", "ŋ", "ħ", "j", "ĸ", "ł", "µ", "^", "¬", "", "`", "ł", "»", "¢", "“", +/* 0x30 */ "”", "n", "´", ";", "·", "!", "", "*", "", " ", "", "", "", "", "", "", +/* 0x40 */ "", "", "", "", "", "", "", "", "", "", "-", "", "", "", "+", "", +/* 0x50 */ "", "", "", "", "", "", "|", "", "", "", "", "", "", "", "", "", +/* 0x60 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", +/* 0x70 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", +}; + +WChar keymapFR_shiftaltgr[128] = { +/* 0x00 */ "", "", "¡", "⅛", "£", "$", "⅜", "⅝", "⅞", "™", "±", "°", "¿", "˛", "", "", +/* 0x10 */ "Æ", "<", "¢", "®", "Ŧ", "¥", "↑", "ı", "Ø", "Þ", "°", "¯", "", "", "Ω", "§", +/* 0x20 */ "Ð", "ª", "Ŋ", "Ħ", "J", "&", "Ł", "º", "ˇ", "¬", "", "˘", "Ł", ">", "©", "‘", +/* 0x30 */ "’", "N", "˝", "×", "÷", "˙", "", "*", "", " ", "", "", "", "", "", "", +/* 0x40 */ "", "", "", "", "", "", "", "", "", "", "-", "", "", "", "+", "", +/* 0x50 */ "", "", "", "", "", "", "¦", "", "", "", "", "", "", "", "", "", +/* 0x60 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", +/* 0x70 */ "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", +}; diff --git a/Source/Kernel/Ressources/logo.cd b/Source/Kernel/Ressources/logo.cd deleted file mode 100644 index 6cacdb1..0000000 --- a/Source/Kernel/Ressources/logo.cd +++ /dev/null @@ -1,10 +0,0 @@ -char *melonLogo[] = { -" THE //|| //// ", -" // || // // //==// // /====/ //| // ", -" // || // // // // // // // //|| // ", -" // |// // //==// // // // // || // ", -" // // // // // // // ||// ", -" // // //==== //==== /====/ // |// ", -" OPERATING SYSTEM " -}; -int melonLogoLines = 7, melonLogoCols = 60; diff --git a/Source/Kernel/Ressources/logo.cxd b/Source/Kernel/Ressources/logo.cxd new file mode 100644 index 0000000..6cacdb1 --- /dev/null +++ b/Source/Kernel/Ressources/logo.cxd @@ -0,0 +1,10 @@ +char *melonLogo[] = { +" THE //|| //// ", +" // || // // //==// // /====/ //| // ", +" // || // // // // // // // //|| // ", +" // |// // //==// // // // // || // ", +" // // // // // // // ||// ", +" // // //==== //==== /====/ // |// ", +" OPERATING SYSTEM " +}; +int melonLogoLines = 7, melonLogoCols = 60; diff --git a/Source/Kernel/TaskManager/Mutex.class.cpp b/Source/Kernel/TaskManager/Mutex.class.cpp index 55226ff..67234d8 100644 --- a/Source/Kernel/TaskManager/Mutex.class.cpp +++ b/Source/Kernel/TaskManager/Mutex.class.cpp @@ -1,24 +1,24 @@ #include "Mutex.class.h" #include -Mutex::Mutex(bool locked) { +extern "C" u32int atomic_exchange(u32int* ptr, u32int newval); + +Mutex::Mutex(u32int locked) { m_locked = locked; } bool Mutex::lock() { - if (m_locked) return false; - m_locked = true; - return m_locked; + if (atomic_exchange(&m_locked, MUTEX_TRUE) == MUTEX_TRUE) return false; //The lock was already locked + return true; } void Mutex::waitLock() { - while (m_locked) + while (atomic_exchange(&m_locked, MUTEX_TRUE) == MUTEX_TRUE) Task::currentThread->sleep(10); //Wait 10ms - m_locked = true; } void Mutex::unlock() { - m_locked = false; + m_locked = MUTEX_FALSE; } bool Mutex::locked() { diff --git a/Source/Kernel/TaskManager/Mutex.class.h b/Source/Kernel/TaskManager/Mutex.class.h index 298ed9c..5545559 100644 --- a/Source/Kernel/TaskManager/Mutex.class.h +++ b/Source/Kernel/TaskManager/Mutex.class.h @@ -1,12 +1,17 @@ #ifndef DEF_MUTEX_CLASS_H #define DEF_MUTEX_CLASS_H +#include + +#define MUTEX_FALSE 0 +#define MUTEX_TRUE 1 + class Mutex { private: - bool m_locked; + u32int m_locked; public: - Mutex(bool locked = false); + Mutex(u32int locked = MUTEX_FALSE); bool lock(); //Locks the mutex if it is not locked. Returns true if mutex could be locked, false if already locked void waitLock(); //Locks the mutex, waiting for it to be unlocked before if necessary void unlock(); diff --git a/Source/Kernel/TaskManager/Task.wtf.asm b/Source/Kernel/TaskManager/Task.wtf.asm index 2c14f28..77db18e 100644 --- a/Source/Kernel/TaskManager/Task.wtf.asm +++ b/Source/Kernel/TaskManager/Task.wtf.asm @@ -9,6 +9,13 @@ idle_task: hlt jmp idle_task +[GLOBAL atomic_exchange] +atomic_exchange: + mov ecx, [esp+4] ; Get lock address + mov eax, [esp+8] ; Get new value + xchg eax, [ecx] ; Old value goes in eax + ret + [GLOBAL copy_page_physical] copy_page_physical: push ebx ; According to __cdecl, we must preserve the contents of EBX. diff --git a/Source/Kernel/VTManager/VirtualTerminal-kbd.class.cpp b/Source/Kernel/VTManager/VirtualTerminal-kbd.class.cpp index d40a9a7..7c784fe 100644 --- a/Source/Kernel/VTManager/VirtualTerminal-kbd.class.cpp +++ b/Source/Kernel/VTManager/VirtualTerminal-kbd.class.cpp @@ -4,6 +4,7 @@ using namespace Kbd; void VirtualTerminal::keyPress(keypress_t kp) { + m_kbdbuffMutex.waitLock(); m_kbdbuff.push(kp); if (!m_kbdMutex.locked()) { if (kp.haschar && !kp.hascmd) { @@ -16,6 +17,7 @@ void VirtualTerminal::keyPress(keypress_t kp) { put("\b"); } } + m_kbdbuffMutex.unlock(); } keypress_t VirtualTerminal::getKeypress(bool show, bool block) { @@ -29,12 +31,14 @@ keypress_t VirtualTerminal::getKeypress(bool show, bool block) { while (m_kbdbuff.empty()) Task::currentThread->sleep(10); + m_kbdbuffMutex.waitLock(); keypress_t ret = m_kbdbuff[0]; for (u32int i = 1; i < m_kbdbuff.size(); i++) { m_kbdbuff[i - 1] = m_kbdbuff[i]; } m_kbdbuff.pop(); + m_kbdbuffMutex.unlock(); if (show) { if (ret.haschar && !ret.hascmd) { diff --git a/Source/Kernel/VTManager/VirtualTerminal.class.cpp b/Source/Kernel/VTManager/VirtualTerminal.class.cpp index be1299c..7ee360b 100644 --- a/Source/Kernel/VTManager/VirtualTerminal.class.cpp +++ b/Source/Kernel/VTManager/VirtualTerminal.class.cpp @@ -136,12 +136,13 @@ void VirtualTerminal::write(const String& s, bool updatecsr) { if (updatecsr) updateCursor(); } -void VirtualTerminal::writeDec(s32int i, bool updatecsr) { +void VirtualTerminal::writeDec(s64int num, bool updatecsr) { + u64int i = num; if (i == 0) { put('0', false); - } else if (i < 0) { + } else if (num < 0) { put('-', false); - i = 0 - i; + i = 0 - num; } char c[32]; int n = 0; diff --git a/Source/Kernel/VTManager/VirtualTerminal.class.h b/Source/Kernel/VTManager/VirtualTerminal.class.h index 6bdcf84..d8d7104 100644 --- a/Source/Kernel/VTManager/VirtualTerminal.class.h +++ b/Source/Kernel/VTManager/VirtualTerminal.class.h @@ -23,7 +23,7 @@ class VirtualTerminal { u32int m_csrlin, m_csrcol; - Mutex m_kbdMutex; + Mutex m_kbdMutex, m_kbdbuffMutex; Vector m_kbdbuff; //Key press events buffer public: @@ -47,7 +47,7 @@ class VirtualTerminal { //Display functions void put(WChar c, bool updatecsr = true); void write(const String& s, bool updatecsr = true); - void writeDec(s32int i, bool updatecsr = true); + void writeDec(s64int num, bool updatecsr = true); void writeHex(u32int i, bool updatecsr = true); void hexDump(u8int* ptr, u32int sz); @@ -55,6 +55,7 @@ class VirtualTerminal { inline VirtualTerminal& operator<<(const String& s) { write(s); return *this; } //inline VirtualTerminal& operator<<(WChar c) { put(c); return *this; } inline VirtualTerminal& operator<<(s32int i) { writeDec(i); return *this; } + inline VirtualTerminal& operator<<(s64int i) { writeDec(i); return *this; } inline VirtualTerminal& operator<<(u32int i) { writeHex(i); return *this; } //Keyboard functions -- cgit v1.2.3