diff options
author | Alexis211 <alexis211@gmail.com> | 2009-10-02 22:51:28 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-10-02 22:51:28 +0200 |
commit | 92abedffec913fe7337117403c5e07185356c81b (patch) | |
tree | 1527937c1a1a7ab8168891f6465e198b88bbfea2 /Source/Kernel/Core | |
parent | 021831ab981b9df22cd1ac5e5ac51f0f84ef49a7 (diff) | |
download | Melon-92abedffec913fe7337117403c5e07185356c81b.tar.gz Melon-92abedffec913fe7337117403c5e07185356c81b.zip |
The kernel shell is now in an independent class, KernelShell::
Diffstat (limited to 'Source/Kernel/Core')
-rw-r--r-- | Source/Kernel/Core/kmain.wtf.cpp | 173 |
1 files changed, 13 insertions, 160 deletions
diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp index 0f22189..924cfc2 100644 --- a/Source/Kernel/Core/kmain.wtf.cpp +++ b/Source/Kernel/Core/kmain.wtf.cpp @@ -27,6 +27,7 @@ #include <VFS/DirectoryNode.class.h> #include <VFS/TextFile.class.h> #include <Core/Log.ns.h> +#include <Shell/KernelShell.class.h> #include <Ressources/Graphics/logo.text.cxd> @@ -74,8 +75,8 @@ void kmain(multiboot_info_t* mbd, u32int magic) { melonLogoVT->map(1); //Create a VT for logging what kernel does - SimpleVT *kvt = new ScrollableVT(15, 76, 200, KVT_FGCOLOR, KVT_BGCOLOR); - kvt->map(melonLogoLines + 2); + SimpleVT *kvt = new ScrollableVT(5, 69, 10, KVT_FGCOLOR, KVT_BGCOLOR); + kvt->map(20); INFO(kvt); *kvt << "Lower ram : " << (s32int)mbd->mem_lower << "k, upper : " << (s32int)mbd->mem_upper << "k.\n"; INFO(kvt); *kvt << "Placement address : " << (u32int)Mem::placementAddress << "\n"; @@ -124,165 +125,17 @@ void kmain(multiboot_info_t* mbd, u32int magic) { Log::log(KL_STATUS, "kmain : Floppy drives detected"); asm volatile("sti"); + Log::log(KL_STATUS, "kmain : Interrupts enabled."); - while(1) { - kvt->setColor(KVT_LIGHTCOLOR); - *kvt << "[" << cwd->getName() << "]# "; - kvt->setColor(KVT_ENTRYCOLOR); - Vector<String> tokens = kvt->readLine().split(" "); - kvt->setColor(KVT_FGCOLOR); - if (tokens[0] == "help") { - *kvt << " - Command list for integrated kernel shell:\n"; - *kvt << " - help shows this help screen\n"; - *kvt << " - reboot reboots your computer\n"; - *kvt << " - halt shuts down your computer\n"; - *kvt << " - panic causes a kernel panic\n"; - *kvt << " - devices shows all detected devices on your computer\n"; - *kvt << " - loadkeys loads specified kekymap\n"; - *kvt << " - free shows memory usage (physical frames and kernel heap)\n"; - *kvt << " - uptime shows seconds since boot\n"; - *kvt << " - part shows all detected block devices and partitions\n"; - *kvt << " - Commands you should know how to use : ls, cd, cat, pwd, rm, mkdir, wf\n"; - } else if (tokens[0] == "reboot") { - Sys::reboot(); - } else if (tokens[0] == "halt") { - Sys::halt(); - } else if (tokens[0] == "panic") { - PANIC("This is what happens when you say 'panic'."); - } else if (tokens[0] == "ls") { - DirectoryNode* d = cwd; - if (tokens.size() == 2) { - FSNode* n = VFS::find(tokens[1], cwd); - d = NULL; - if (n == NULL) - *kvt << "No such directory : " << tokens[1] << "\n"; - else if (n->type() != NT_DIRECTORY) - *kvt << "Not a directory : " << tokens[1] << "\n"; - else - d = (DirectoryNode*)n; - } - if (d != NULL) *kvt << "Contents of directory " << VFS::path(d) << " :\n"; - for (u32int i = 0; d != NULL && i < d->getLength(); i++) { - FSNode* n = d->getChild(i); - if (n->type() == NT_FILE) { - FileNode* f = (FileNode*)n; - *kvt << " - FILE\t" << f->getName(); - kvt->setCursorCol(30); - *kvt << (s32int)f->getLength() << " bytes.\n"; - } else if (n->type() == NT_DIRECTORY) { - *kvt << " - DIR\t" << n->getName() << "/"; - kvt->setCursorCol(30); - *kvt << (s32int)n->getLength() << " items.\n"; - } - } - } else if (tokens[0] == "cd") { - if (tokens.size() == 1) { - *kvt << "Error : no argument given.\n"; - } else { - FSNode* n = VFS::find(tokens[1], cwd); - if (n == NULL) - *kvt << "No such directory : " << tokens[1] << "\n"; - else if (n->type() != NT_DIRECTORY) - *kvt << "Not a directory : " << tokens[1] << "\n"; - else - cwd = (DirectoryNode*)n; - } - } else if (tokens[0] == "cat") { - if (tokens.size() == 1) *kvt << "Meow.\n"; - for (u32int i = 1; i < tokens.size(); i++) { - File f(tokens[i], FM_READ, cwd); - if (f.valid()) { - u8int *buff = (u8int*)Mem::kalloc(f.length() + 1); - f.read(f.length(), buff); - buff[f.length()] = 0; - *kvt << String((const char*) buff); - Mem::kfree(buff); - } else { - *kvt << "Error reading from file " << tokens[i] << "\n"; - } - } - } else if (tokens[0] == "pwd") { - *kvt << "Current location : " << VFS::path(cwd) << "\n"; - } else if (tokens[0] == "rm") { - if (tokens.size() == 1) *kvt << "Error : no argument specified.\n"; - for (u32int i = 1; i < tokens.size(); i++) { - if (!VFS::remove(tokens[i], cwd)) { - *kvt << "Error while removing file " << tokens[i] << "\n"; - } - } - } else if (tokens[0] == "mkdir") { - if (tokens.size() > 1) { - for (u32int i = 1; i < tokens.size(); i++) { - if (VFS::createDirectory(tokens[i], cwd) == NULL) - *kvt << "Error while creating directory " << tokens[i] << "\n"; - } - } else { - *kvt << "No argument specified.\n"; - } - } else if (tokens[0] == "wf") { - if (tokens.size() == 1) { - *kvt << "No file to write !\n"; - } else { - File f(tokens[1], FM_TRUNCATE, cwd); - if (f.valid()) { - String t = kvt->readLine(); - while (t != ".") { - t += "\n"; - ByteArray temp(t); - f.write(temp); - t = kvt->readLine(); - } - } else { - *kvt << "Error openning file.\n"; - } - } - } else if (tokens[0] == "devices") { - Vector<Device*> dev = Dev::findDevices(); - *kvt << " - Detected devices :\n"; - for (u32int i = 0; i < dev.size(); i++) { - *kvt << " - " << dev[i]->getClass(); - kvt->setCursorCol(25); - *kvt << dev[i]->getName() << "\n"; - } - } else if (tokens[0] == "loadkeys") { - if (tokens.size() == 1) { - *kvt << "Error : no argument specified.\n"; - } else { - if (!Kbd::loadKeymap(tokens[1])) { - *kvt << "Error while loading keymap " << tokens[1] << ".\n"; - } - } - } else if (tokens[0] == "free") { - u32int frames = PhysMem::total(), freef = PhysMem::free(); - *kvt << " - Free frames : " << (s32int)freef << " (" << (s32int)(freef * 4 / 1024) << "Mo) of " - << (s32int)frames << " (" << (s32int)(frames * 4 / 1024) << "Mo).\n"; - u32int kh = Mem::kheapSize(), freek = Mem::kheapFree; - *kvt << " - Kernel heap free : " << (s32int)(freek / 1024 / 1024) << "Mo (" << (s32int)(freek / 1024) << - "Ko) of " << (s32int)(kh / 1024 / 1024) << "Mo (" << (s32int)(kh / 1024) << "Ko).\n"; - } else if (tokens[0] == "uptime") { - *kvt << " - Uptime : " << (s32int)(Time::uptime()) << "s.\n"; - } else if (tokens[0] == "part") { - *kvt << " * ID\tClass Name\n"; - for (u32int i = 0; i < Part::devices.size(); i++) { - *kvt << " - " << (s32int)i << "\t"; - if (Part::devices[i] == 0) { - *kvt << "[none]\n"; - } else { - *kvt << Part::devices[i]->getClass(); - kvt->setCursorCol(33); - *kvt << Part::devices[i]->getName() << "\n"; - for (u32int j = 0; j < Part::partitions.size(); j++) { - if (Part::partitions[j]->getDevice() == Part::devices[i]) { - *kvt << "\t - Partition " << (s32int)Part::partitions[j]->getPartNumber() << - ", start at " << (s32int)Part::partitions[j]->getStartBlock() << - ", size " << (s32int)Part::partitions[j]->getBlockCount() << "\n"; - } - } - } - } - } else if (tokens.size() > 1 or tokens[0] != "") { - *kvt << " - Unrecognized command: " << tokens[0] << "\n"; - } + new KernelShell(cwd); //No need to save that in a var, it is automatically destroyed anyways + Log::log(KL_STATUS, "kmain : Kernel shell launched"); + + while (KernelShell::getInstances() > 0) { + Task::currentThread->sleep(10); } + + Log::log(KL_STATUS, "kmain : All kernel shells finished. Halting."); + Sys::halt(); + PANIC("END OF KMAIN"); } |