diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/Kernel/Core/Log.ns.cpp | 35 | ||||
-rw-r--r-- | Source/Kernel/Core/Log.ns.h | 20 | ||||
-rw-r--r-- | Source/Kernel/Core/kmain.wtf.cpp | 31 | ||||
-rw-r--r-- | Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp | 37 | ||||
-rw-r--r-- | Source/Kernel/Library/ByteArray.class.cpp | 4 | ||||
-rw-r--r-- | Source/Kernel/Library/ByteArray.class.h | 8 | ||||
-rw-r--r-- | Source/Kernel/Library/WChar.class.cpp | 29 | ||||
-rw-r--r-- | Source/Kernel/Library/WChar.class.h | 1 | ||||
-rw-r--r-- | Source/Kernel/Makefile | 2 | ||||
-rwxr-xr-x | Source/Kernel/Melon.ke | bin | 162952 -> 168414 bytes | |||
-rw-r--r-- | Source/Kernel/Ressources/Info.txt | 5 | ||||
-rw-r--r-- | Source/Kernel/VFS/File.class.cpp | 4 | ||||
-rw-r--r-- | Source/Kernel/VFS/File.class.h | 7 |
13 files changed, 135 insertions, 48 deletions
diff --git a/Source/Kernel/Core/Log.ns.cpp b/Source/Kernel/Core/Log.ns.cpp new file mode 100644 index 0000000..fbdb7f2 --- /dev/null +++ b/Source/Kernel/Core/Log.ns.cpp @@ -0,0 +1,35 @@ +#include "Log.ns.h" +#include <VFS/VFS.ns.h> + +namespace Log { + +TextFile *logs[7] = {0, 0, 0, 0, 0, 0, 0}; + +void init(u8int loglevel) { + //Create directories + if (VFS::find("/System") == 0) VFS::createDirectory("/System"); + if (VFS::find("/System/Logs") == 0) VFS::createDirectory("/System/Logs"); + + if (KL_PANIC <= loglevel) logs[KL_PANIC] = new TextFile("/System/Logs/Panic.log", FM_APPEND); + if (KL_CRITICAL <= loglevel) logs[KL_CRITICAL] = new TextFile("/System/Logs/Critical.log", FM_APPEND); + if (KL_ERROR <= loglevel) logs[KL_ERROR] = new TextFile("/System/Logs/Error.log", FM_APPEND); + if (KL_WARNING <= loglevel) logs[KL_WARNING] = new TextFile("/System/Logs/Warning.log", FM_APPEND); + if (KL_NOTICE <= loglevel) logs[KL_NOTICE] = new TextFile("/System/Logs/Notice.log", FM_APPEND); + if (KL_STATUS <= loglevel) logs[KL_STATUS] = new TextFile("/System/Logs/Status.log", FM_APPEND); + if (KL_DEBUG <= loglevel) logs[KL_DEBUG] = new TextFile("/System/Logs/Debug.log", FM_APPEND); +} + +void close() { + for (u32int i = 0; i < 7; i++) { + if (logs[i] != 0) { + delete logs[i]; + logs[i] = 0; + } + } +} + +void log(u8int level, String event) { + if (logs[level] != 0 and logs[level]->valid()) logs[level]->write(event, true); +} + +} diff --git a/Source/Kernel/Core/Log.ns.h b/Source/Kernel/Core/Log.ns.h new file mode 100644 index 0000000..d825f62 --- /dev/null +++ b/Source/Kernel/Core/Log.ns.h @@ -0,0 +1,20 @@ +#ifndef DEF_LOG_NS_H +#define DEF_LOG_NS_H + +#include <VFS/TextFile.class.h> + +#define KL_PANIC 0 +#define KL_CRITICAL 1 +#define KL_ERROR 2 +#define KL_WARNING 3 +#define KL_NOTICE 4 +#define KL_STATUS 5 +#define KL_DEBUG 6 + +namespace Log { + void init(u8int loglevel); + void close(); + void log(u8int level, String event); +} + +#endif diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp index 11fbbea..e3ef2fd 100644 --- a/Source/Kernel/Core/kmain.wtf.cpp +++ b/Source/Kernel/Core/kmain.wtf.cpp @@ -24,7 +24,8 @@ #include <VFS/FileNode.class.h> #include <VFS/VFS.ns.h> #include <VFS/DirectoryNode.class.h> -#include <VFS/File.class.h> +#include <VFS/TextFile.class.h> +#include <Core/Log.ns.h> #include <Ressources/logo.cxd> #include <Ressources/keymap-fr.wtf.cxd> @@ -95,30 +96,33 @@ void kmain(multiboot_info_t* mbd, u32int magic) { Mem::createHeap(); OK(kvt); INFO(kvt); *kvt << "Free frames : " << (s32int)PhysMem::free() << "/" << (s32int)PhysMem::total() << "\n"; - PROCESSING(kvt, "Registering textual VGA output..."); - Dev::registerDevice(vgaout); OK(kvt); - PROCESSING(kvt,"Initializing PIT..."); Dev::registerDevice(new Timer()); OK(kvt); PROCESSING(kvt, "Initializing multitasking..."); Task::initialize(String((char*)mbd->cmdline), kvt); OK(kvt); - PROCESSING(kvt, "Setting up keyboard..."); - Dev::registerDevice(new PS2Keyboard()); //Initialize keyboard driver - Kbd::setKeymap(keymapFR_normal, keymapFR_shift, keymapFR_caps, keymapFR_altgr, keymapFR_shiftaltgr); //Load keymap - Kbd::setFocus(kvt); //Set focus to virtual terminal - OK(kvt); - - PROCESSING(kvt, "Detecting floppy drives..."); - FloppyController::detect(); OK(kvt); - PROCESSING(kvt, "Mounting first module as ramfs on root directory..."); FileSystem* fs = new RamFS((u8int*)mods[0].mod_start, 1024 * 1024); DirectoryNode* cwd; cwd = fs->getRootNode(); VFS::setRootNode(cwd); OK(kvt); + PROCESSING(kvt, "Setting up logs..."); + Log::init(KL_STATUS); OK(kvt); + INFO(kvt); *kvt << "Logs are now going to files in /System/Logs/\n"; + + Dev::registerDevice(vgaout); + Log::log(KL_STATUS, "kmain : Registered textual VGA output"); + + Dev::registerDevice(new PS2Keyboard()); //Initialize keyboard driver + Kbd::setKeymap(keymapFR_normal, keymapFR_shift, keymapFR_caps, keymapFR_altgr, keymapFR_shiftaltgr); //Load keymap + Kbd::setFocus(kvt); //Set focus to virtual terminal + Log::log(KL_STATUS, "kmain : Keyboard set up"); + + FloppyController::detect(); + Log::log(KL_STATUS, "kmain : Floppy drives detected"); + asm volatile("sti"); while(1) { @@ -212,7 +216,6 @@ void kmain(multiboot_info_t* mbd, u32int magic) { *kvt << "No argument specified.\n"; } } else if (tokens[0] == "wf") { - //*kvt << "Sorry, this command isn't implemented yet.\n"; if (tokens.size() == 1) { *kvt << "No file to write !\n"; } else { diff --git a/Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp b/Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp index 0d1b5fc..beaaf19 100644 --- a/Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp +++ b/Source/Kernel/Devices/Floppy/FloppyDrive.class.cpp @@ -2,6 +2,7 @@ #include "FloppyController.class.h" #include <TaskManager/Task.ns.h> #include <DeviceManager/Time.ns.h> +#include <Core/Log.ns.h> using namespace Sys; @@ -228,19 +229,29 @@ bool FloppyDrive::doTrack(u32int cyl, u8int dir) { int error = 0; if (st0 & 0xC0) error = 1; - if (st1 & 0x80) error = 1; //End of cylinder - if (st0 & 0x08) error = 1; //Drive not ready - if (st1 & 0x20) error = 1; //CRC error - if (st1 & 0x10) error = 1; //Controller timeout - if (st1 & 0x04) error = 1; //No data found - if ((st2|st1) & 0x01) error=1; //No address mark found - if (st2 & 0x40) error = 1; //Deleted address mark - if (st2 & 0x20) error = 1; //CRC error in data - if (st2 & 0x10) error = 1; //Wrong cylinder - if (st2 & 0x04) error = 1; //uPD765 sector not found - if (st2 & 0x02) error = 1; //Bad cylinder - if (bps != 0x2) error = 1; //Wanted 512 bytes/sector, got (1<<(bps+7)) - if (st1 & 0x02) error = 2; //Not writable + if (st1 & 0x80) { Log::log(KL_ERROR, "FloppyDrive.class : error while I/O : end of cyilnder."); error = 1; } + if (st0 & 0x08) { Log::log(KL_ERROR, "FloppyDrive.class : error while I/O : drive not ready."); error = 1; } + if (st1 & 0x20) { Log::log(KL_ERROR, "FloppyDrive.class : error while I/O : CRC error."); error = 1; } + if (st1 & 0x10) { Log::log(KL_ERROR, "FloppyDrive.class : error while I/O : controller timeout."); error = 1; } + if (st1 & 0x04) { Log::log(KL_ERROR, "FloppyDrive.class : error while I/O : no data found."); error = 1; } + if ((st2|st1) & 0x01) { + Log::log(KL_ERROR, "FloppyDrive.class : error while I/O : no address mark found."); + error=1; + } + if (st2 & 0x40) { Log::log(KL_ERROR, "FloppyDrive.class : error while I/O : deleted address mark."); error = 1; } + if (st2 & 0x20) { Log::log(KL_ERROR, "FloppyDrive.class : error while I/O : CRC error in data."); error = 1; } + if (st2 & 0x10) { Log::log(KL_ERROR, "FloppyDrive.class : error while I/O : wrong cylinder."); error = 1; } + if (st2 & 0x04) { + Log::log(KL_ERROR, "FloppyDrive.class : error while I/O : uPD765 sector not found."); + error = 1; + } + if (st2 & 0x02) { Log::log(KL_ERROR, "FloppyDrive.class : error while I/O : bad cylinder."); error = 1; } + if (bps != 0x2) { + Log::log(KL_ERROR, String("FloppyDrive.class : error while I/O : wanted 512 bytes/sector, got ") + += String::number(1 << (bps + 7))); + error = 1; + } + if (st1 & 0x02) { Log::log(KL_ERROR, "FloppyDrive.class : error while I/O : not writable."); error = 2; } if (!error) CMem::memcpy(m_buffer, FloppyController::dmabuff, FLOPPY_DMALEN); //Copy data to internal buffer FloppyController::dmaRelease(); diff --git a/Source/Kernel/Library/ByteArray.class.cpp b/Source/Kernel/Library/ByteArray.class.cpp index b987817..9972493 100644 --- a/Source/Kernel/Library/ByteArray.class.cpp +++ b/Source/Kernel/Library/ByteArray.class.cpp @@ -53,11 +53,11 @@ void ByteArray::dump(VirtualTerminal *vt) { vt->hexDump(m_string, m_length); } -ByteArray::operator String () { +String ByteArray::toString (u8int encoding) { char* c = new char[m_length + 1]; memcpy((u8int*)c, m_string, m_length); c[m_length] = 0; //Add NULL terminator - String r(c); + String r(c, encoding); delete c; return r; } diff --git a/Source/Kernel/Library/ByteArray.class.h b/Source/Kernel/Library/ByteArray.class.h index 4b2dbed..f5214b3 100644 --- a/Source/Kernel/Library/ByteArray.class.h +++ b/Source/Kernel/Library/ByteArray.class.h @@ -7,6 +7,12 @@ class ByteArray : public BasicString<u8int> { public: ByteArray() : BasicString<u8int>() {} + ByteArray(const BasicString<u8int> &bs) : BasicString<u8int>() { + m_length = bs.size(); + m_string = new u8int[m_length]; + for (u32int i = 0; i < m_length; i++) + m_string[i] = bs[i]; + } ByteArray(const ByteArray& other) : BasicString<u8int>(other) {} ByteArray(const char* c); ByteArray(u32int size) : BasicString<u8int>((u8int)0, size) {} @@ -17,7 +23,7 @@ class ByteArray : public BasicString<u8int> { void dump(VirtualTerminal *vt); - operator String (); + String toString(u8int encoding = UE_UTF8); operator u8int* () { return m_string; } }; diff --git a/Source/Kernel/Library/WChar.class.cpp b/Source/Kernel/Library/WChar.class.cpp index 8b8b2e8..a6ecf3f 100644 --- a/Source/Kernel/Library/WChar.class.cpp +++ b/Source/Kernel/Library/WChar.class.cpp @@ -25,21 +25,26 @@ WChar::WChar(const char* c, u8int encoding) { if (encoding == UE_UTF32) affectUtf32(c); } +u32int WChar::ucharLen(const char* c, u8int encoding) { + if (encoding == UE_UTF8) { + if ((c[0] & 0x80) == 0) return 1; + else if ((c[0] & 0xE0) == 0xC0) return 2; + else if ((c[0] & 0xF0) == 0xE0) return 3; + else if ((c[0] & 0xF8) == 0xF0) return 4; + else return 1; + } else if (encoding == UE_UTF16) { + if ((c[0] & 0xFC) == 0xD8 and (c[2] & 0xFC) == 0xDC) return 4; + else return 2; + } else if (encoding == UE_UTF32) { + return 4; + } + return 1; +} + u32int WChar::utfLen(const char* c, u8int encoding) { int i = 0, l = CMem::strlen(c), co = 0; while (i < l) { - if (encoding == UE_UTF8) { - if ((c[i] & 0x80) == 0) i += 1; - else if ((c[i] & 0xE0) == 0xC0) i += 2; - else if ((c[i] & 0xF0) == 0xE0) i += 3; - else if ((c[i] & 0xF8) == 0xF0) i += 4; - else i += 1; - } else if (encoding == UE_UTF16) { - if ((c[i] & 0xFC) == 0xD8 and (c[i + 2] & 0xFC) == 0xDC) i += 4; - else i += 2; - } else if (encoding == UE_UTF32) { - i += 4; - } + i += ucharLen(c + i, encoding); co++; } return co; diff --git a/Source/Kernel/Library/WChar.class.h b/Source/Kernel/Library/WChar.class.h index 62226f5..ba94a23 100644 --- a/Source/Kernel/Library/WChar.class.h +++ b/Source/Kernel/Library/WChar.class.h @@ -22,6 +22,7 @@ struct WChar { WChar(char c); //From ascii character WChar(const char* c, u8int encoding = UE_UTF8); //From utf8 string + static u32int ucharLen(const char* c, u8int encoding = UE_UTF8); //Returns count of bytes in one unicode character static u32int utfLen(const char* c, u8int encoding = UE_UTF8); //Returns count of utf8 characters in string void affectAscii(char c); diff --git a/Source/Kernel/Makefile b/Source/Kernel/Makefile index 67e9e39..e68d12b 100644 --- a/Source/Kernel/Makefile +++ b/Source/Kernel/Makefile @@ -15,6 +15,7 @@ Objects = Core/loader.wtf.o \ Core/cppsupport.wtf.o \ Core/Sys.ns.o \ Core/CMem.ns.o \ + Core/Log.ns.o \ MemoryManager/Mem.ns.o \ MemoryManager/PhysMem.ns.o \ MemoryManager/GDT.wtf.o \ @@ -41,6 +42,7 @@ Objects = Core/loader.wtf.o \ VFS/Part.ns.o \ VFS/VFS.ns.o \ VFS/File.class.o \ + VFS/TextFile.class.o \ VFS/DirectoryNode.class.o \ FileSystems/RamFS/RamFS.class.o \ SyscallManager/IDT.ns.o \ diff --git a/Source/Kernel/Melon.ke b/Source/Kernel/Melon.ke Binary files differindex 605b45a..de3493a 100755 --- a/Source/Kernel/Melon.ke +++ b/Source/Kernel/Melon.ke diff --git a/Source/Kernel/Ressources/Info.txt b/Source/Kernel/Ressources/Info.txt index 2b86198..1a57fc9 100644 --- a/Source/Kernel/Ressources/Info.txt +++ b/Source/Kernel/Ressources/Info.txt @@ -1,6 +1,5 @@ These files were just added here for fun. Oh, you wanted to know what the wf command meant ? -Simple : it means Write File. When it will exist, it will prompt you for -the textual contents of the file given as an argument. Not very exciting, -but it might be useful one day. +Simple : it means Write File. Type 'wf filename' and then enter the +file's contents, ending with <CRLF>.<CRLF> diff --git a/Source/Kernel/VFS/File.class.cpp b/Source/Kernel/VFS/File.class.cpp index f3c7d54..69b08de 100644 --- a/Source/Kernel/VFS/File.class.cpp +++ b/Source/Kernel/VFS/File.class.cpp @@ -121,6 +121,10 @@ bool File::seek(u64int count, u8int mode) { return false; } +bool File::eof() { + return m_position == m_file->getLength(); +} + void File::close(bool unregisterFD) { if (!m_valid) return; if (m_writable) diff --git a/Source/Kernel/VFS/File.class.h b/Source/Kernel/VFS/File.class.h index 460036c..ef82a70 100644 --- a/Source/Kernel/VFS/File.class.h +++ b/Source/Kernel/VFS/File.class.h @@ -19,7 +19,7 @@ enum { }; class File { - private: + protected: FileNode* m_file; bool m_valid; //Is a file opened and valid ? bool m_writable; //Is file opened for write ? @@ -28,19 +28,20 @@ class File { public: File(); File(String filename, u8int mode = FM_READ, FSNode* start = 0); - ~File(); + virtual ~File(); bool open(String filename, u8int mode = FM_READ, FSNode* start = 0); void close(bool unregisterFD = true); //unregisterFD = whether or not we must unregister the file descriptor from process u32int read(u32int max_length, u8int *data); bool write(u32int length, u8int *data); - u32int read(ByteArray &data); //Fills ByteArray at its current length or shrinks it if necessary + u32int read(ByteArray &data); //Fills ByteArray at its current length or shrinks it if we can't read enough bool write(ByteArray &data); bool seek(u64int count, u8int mode); u64int position() { return m_position; } u64int length() { return m_file->getLength(); } + bool eof(); bool valid() { return m_valid; } }; |