summaryrefslogtreecommitdiff
path: root/Source/Kernel/Core
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Kernel/Core')
-rw-r--r--Source/Kernel/Core/SB.ns.cpp136
-rw-r--r--Source/Kernel/Core/SB.ns.h17
-rw-r--r--Source/Kernel/Core/Sys.ns.cpp7
-rw-r--r--Source/Kernel/Core/kmain.wtf.cpp96
4 files changed, 201 insertions, 55 deletions
diff --git a/Source/Kernel/Core/SB.ns.cpp b/Source/Kernel/Core/SB.ns.cpp
new file mode 100644
index 0000000..f5b21ec
--- /dev/null
+++ b/Source/Kernel/Core/SB.ns.cpp
@@ -0,0 +1,136 @@
+#include "SB.ns.h"
+#include <Mutex.class.h>
+#include <TaskManager/Task.ns.h>
+#include <MemoryManager/PhysMem.ns.h>
+#include <DeviceManager/Disp.ns.h>
+
+#define BOOT_ITEMS 17
+
+namespace SB {
+
+SimpleVT *sb = NULL;
+
+String msg;
+
+u16int boot_progress = 0;
+u16int height;
+bool gone_multi = false;
+
+Mutex lock(MUTEX_FALSE);
+
+void init() {
+ sb = new SimpleVT(1, 80, STATUSBAR_FGCOLOR, STATUSBAR_BGCOLOR);
+ height = 1;
+ sb->map(0, 0);
+ sb->hideCursor();
+}
+
+void drawprogress(const String& s) {
+ sb->clear();
+ int d = (sb->width() / 2) - ((BOOT_ITEMS + 4) / 2);
+ if (height == 1) d -= 4;
+ sb->moveCursor(0, d);
+ *sb << "{";
+ for (u32int i = 0; i < boot_progress; i++) *sb << ":";
+ *sb << ".";
+ sb->moveCursor(0, BOOT_ITEMS + d + 3);
+ *sb << "}";
+ if (height > 1) {
+ *sb << "\n";
+ *sb << "Loading : [" << s;
+ sb->moveCursor(1, sb->width() - 2);
+ *sb << "]";
+ } else {
+ sb->moveCursor(0, 0);
+ *sb << "Melon is loading :";
+ sb->moveCursor(0, d + BOOT_ITEMS + 6);
+ *sb << "[" << s;
+ sb->moveCursor(0, sb->width() - 2);
+ *sb << "]";
+ }
+}
+
+void drawnormal() {
+ sb->clear();
+ sb->moveCursor(0, 0);
+ *sb << " [Up:" << (s64int)Time::uptime() << "s";
+ sb->moveCursor(0, 10);
+ *sb << "] [Mem:" << (s64int)PhysMem::free() << "/" << (s64int)PhysMem::total();
+ sb->moveCursor(0, 28);
+ *sb << "] [Proc.:" << (s64int)Task::processes->size();
+ sb->setCursorCol(39);
+ if (height > 1) {
+ *sb << "]";
+ sb->moveCursor(1, 0);
+ *sb << " [Threads:" << (s64int)Task::threads->size();
+ sb->setCursorCol(12);
+ *sb << "] [" << msg;
+ sb->setCursorCol(sb->width() - 2);
+ *sb << "]";
+ } else {
+ *sb << "] [Threads:" << (s64int)Task::threads->size();
+ sb->setCursorCol(52);
+ *sb << "] [" << msg;
+ sb->setCursorCol(sb->width() - 2);
+ *sb << "]";
+ }
+}
+
+void reinit() {
+ if (!gone_multi) return;
+ lock.waitLock();
+ delete sb;
+ height = (Disp::mode.textCols < 80 ? 2 : 1);
+ sb = new SimpleVT(height, Disp::mode.textCols, STATUSBAR_FGCOLOR, STATUSBAR_BGCOLOR);
+ sb->map(0, 0);
+ sb->hideCursor();
+ if (boot_progress != 0) {
+ drawprogress(msg);
+ } else {
+ drawnormal();
+ }
+ lock.unlock();
+}
+
+u32int thread(void*) {
+ while (!gone_multi); //Synchronize
+ while (1) {
+ lock.waitLock();
+ if (boot_progress != 0) {
+ drawprogress(msg);
+ } else {
+ drawnormal();
+ }
+ lock.unlock();
+ Task::currThread()->sleep(100);
+ }
+ return 0;
+}
+
+void gomulti() {
+ new Thread(thread, 0, true);
+ gone_multi = true;
+}
+
+void progress(const String& s) {
+ if (gone_multi) {
+ lock.waitLock();
+ boot_progress++;
+ msg = s;
+ lock.unlock();
+ } else {
+ boot_progress++;
+ drawprogress(s);
+ }
+}
+
+void message(const String& s) {
+ if (!gone_multi) return;
+ lock.waitLock();
+ boot_progress = 0;
+ msg = s;
+ drawnormal();
+ lock.unlock();
+}
+
+} //END NS
diff --git a/Source/Kernel/Core/SB.ns.h b/Source/Kernel/Core/SB.ns.h
new file mode 100644
index 0000000..7b3b65c
--- /dev/null
+++ b/Source/Kernel/Core/SB.ns.h
@@ -0,0 +1,17 @@
+#ifndef DEF_SB_NS_H
+#define DEF_SB_NS_H
+
+//StatusBar namespace :)
+#include <VTManager/SimpleVT.class.h>
+
+namespace SB {
+ extern u16int height;
+
+ void init(); //Setup status bar with default 80col configuration
+ void reinit(); //Setup status bar querying Disp:: for text screen width
+ void gomulti(); //Launch new thread for status bar
+ void progress(const String& s); //Update progress
+ void message(const String& s); //Set a message
+}
+
+#endif
diff --git a/Source/Kernel/Core/Sys.ns.cpp b/Source/Kernel/Core/Sys.ns.cpp
index 59da244..05e0d7d 100644
--- a/Source/Kernel/Core/Sys.ns.cpp
+++ b/Source/Kernel/Core/Sys.ns.cpp
@@ -7,6 +7,7 @@
#include <UserManager/Usr.ns.h>
#include <MemoryManager/PhysMem.ns.h>
#include <DeviceManager/Time.ns.h>
+#include <Core/SB.ns.h>
#define DEBUGVT(x) SimpleVT *x = new SimpleVT(4, 56, PANIC_FGCOLOR, PANIC_BGCOLOR); x->map(); x->put('\n');
@@ -95,6 +96,7 @@ void stackTrace(u32int ebp, VirtualTerminal& vt, u32int maxframes, bool isUser)
//Used by PANIC() macro (see common.wtf.h)
void panic(char *message, char *file, u32int line) {
+ SB::message("PANIC");
asm volatile("cli");
DEBUGVT(vt);
@@ -106,6 +108,7 @@ void panic(char *message, char *file, u32int line) {
}
void panic(char *message, registers_t *regs, char *file, u32int line) {
+ SB::message("PANIC");
asm volatile("cli");
SimpleVT vt(15, 70, BSOD_FGCOLOR, BSOD_BGCOLOR);
@@ -129,6 +132,7 @@ void panic(char *message, registers_t *regs, char *file, u32int line) {
//Used by ASSERT() macro (see common.wtf.h)
void panic_assert(char *file, u32int line, char *desc) {
+ SB::message("ASSERTION FAILED");
asm volatile("cli");
DEBUGVT(vt);
@@ -140,17 +144,20 @@ void panic_assert(char *file, u32int line, char *desc) {
}
void shutdown_cleanup() {
+ SB::message("Cleaning up system");
asm volatile("cli");
Log::close();
}
void reboot() {
shutdown_cleanup();
+ SB::message("Rebooting...");
outb(0x64, 0xFE);
}
void halt() {
shutdown_cleanup();
+ SB::message("Halting");
String message("MELON SEZ : KTHXBYE, U CAN NAOW TURNZ OFF UR COMPUTER.");
SimpleVT vt(3, message.size() + 16, HALT_FGCOLOR, HALT_BGCOLOR);
vt.map();
diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp
index 069bf5f..1760de8 100644
--- a/Source/Kernel/Core/kmain.wtf.cpp
+++ b/Source/Kernel/Core/kmain.wtf.cpp
@@ -31,6 +31,7 @@
#include <VFS/VFS.ns.h>
#include <VFS/DirectoryNode.class.h>
#include <Core/Log.ns.h>
+#include <Core/SB.ns.h>
#include <Shell/KernelShell.class.h>
#include <Map.class.h>
@@ -87,37 +88,6 @@ u32int logoAnimation(void* p) {
return 0;
}
-void selectVideoMode(SimpleVT& v) {
- Disp::getModes();
- v << "\nPlease select a graphic mode in the list below:\n";
-
- for (u32int i = 0; i < Disp::modes.size(); i++) {
- Disp::mode_t& m = Disp::modes[i];
- v << (s32int)i << ":\t" << "Text " << m.textRows << "x" << m.textCols << "\t";
- if (m.graphWidth != 0 and m.graphHeight != 0) {
- v << "Graphics " << m.graphWidth << "x" << m.graphHeight << "x" << m.graphDepth << "\t";
- } else {
- v << "No graphics";
- }
- v.setCursorCol(50);
- v << m.device->getName() << "\n";
- }
-
- while (1) {
- v << "\nYour selection: ";
- String answer = v.readLine();
- u32int n = answer.toInt();
- v.unmap();
- if (n >= 0 and n < Disp::modes.size() and Disp::setMode(Disp::modes[n])) {
- return;
- } else {
- Disp::setMode(Disp::modes[1]);
- v.map();
- v << "Error while switching video mode, please select another one.";
- }
- }
-}
-
void kmain(multiboot_info_t* mbd, u32int magic) {
DEBUG("Entering kmain.");
@@ -145,30 +115,46 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
VGATextOutput *vgaout = new VGATextOutput();
Disp::setText(vgaout);
+ SB::init();
+
//Create a VT for logging what kernel does
- kvt = new ScrollableVT(25, 80, 20, KVT_FGCOLOR, KVT_BGCOLOR);
- kvt->map(0, 0);
- *kvt << "Melon is loading...\n";
+ SB::progress("Create kernel VT");
+ kvt = new ScrollableVT(24, 80, 20, KVT_FGCOLOR, KVT_BGCOLOR);
+ kvt->map(1, 0);
+ kvt->setColor(TXTLOGO_FGCOLOR, TXTLOGO_BGCOLOR);
+ for (int i = 0; i < melonLogoLines; i++) {
+ kvt->setCursorCol(40 - (melonLogoCols / 2));
+ *kvt << melonLogo[i] << "\n";
+ }
+ kvt->setColor(KVT_FGCOLOR, KVT_BGCOLOR);
+ SB::progress("IDT");
IDT::init(); //Setup interrupts
+ SB::progress("Paging");
u32int totalRam = ((mbd->mem_upper + mbd->mem_lower) * 1024);
PhysMem::initPaging(totalRam); //Setup paging
+ SB::progress("GDT");
GDT::init(); //Initialize real GDT, not fake one from loader.wtf.asm
PhysMem::removeTemporaryPages(); //Remove useless page mapping
+ SB::progress("Heap");
Mem::createHeap(); //Create kernel heap
Dev::registerDevice(vgaout);
+ SB::progress("Timer");
Dev::registerDevice(new Timer()); //Initialize timer
String kcmdline((char*)mbd->cmdline);
+ SB::progress("Multitasking");
Task::initialize(kcmdline, kvt); //Initialize multitasking
+ SB::gomulti();
asm volatile("sti");
//*************************************** PARSE COMMAND LINE
+ SB::progress("Parse command line");
Vector<String> opts = kcmdline.split(" ");
String keymap = "builtin", init = "/System/Applications/PaperWork.app";
String root = "ramfs:0";
@@ -185,14 +171,15 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
//*************************************** DEVICE SETUP
- Dev::registerDevice(new PS2Keyboard()); //Initialize keyboard driver
+ SB::progress("Keyboard"); Dev::registerDevice(new PS2Keyboard()); //Initialize keyboard driver
Kbd::setFocus(kvt); //Set focus to virtual terminal
- if (enableVESA) Dev::registerDevice(new VESADisplay());
- FloppyController::detect();
- ATAController::detect();
+ SB::progress("VESA"); if (enableVESA) Dev::registerDevice(new VESADisplay());
+ SB::progress("Floppy"); FloppyController::detect();
+ SB::progress("Hard disk drives"); ATAController::detect();
//*************************************** MOUNT FILESYSTEMS
+ SB::progress("Root filesystem");
{ // mount root filesystem
if (!VFS::mount(String("/:") += root, kvt, mbd)) PANIC("Cannot mount root filesystem.");
}
@@ -200,6 +187,7 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
cwd = VFS::getRootNode();
Task::currProcess()->setCwd(cwd);
+ SB::progress("File systems");
// mount other filesystems
for (u32int i = 0; i < mount.size(); i++) {
VFS::mount(mount[i], kvt, mbd);
@@ -212,46 +200,44 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
if (!m.empty() && m[0] != WChar("#")) VFS::mount(m, kvt, mbd);
}
}
-
//*************************************** LOAD SYSTEM STUFF
- if (keymap != "builtin") {
- if (!Kbd::loadKeymap(keymap)) *kvt << "WARNING : Could not load keymap " << keymap << ", using built-in keymap instead.";
- }
-
+ SB::progress("Logging");
Log::init(KL_STATUS); //Setup logging
Log::log(KL_STATUS, "kmain : Melon booting.");
+ if (keymap != "builtin") {
+ SB::progress("Keymap");
+ if (!Kbd::loadKeymap(keymap)) Log::log(KL_WARNING, String("WARNING : Could not load keymap ") += keymap += ", using built-in keymap instead.");
+ }
+
+ SB::progress("Users");
Usr::load(); //Setup user managment
Log::log(KL_STATUS, "kmain : User list loaded");
+ SB::progress("Video mode selection");
+ Disp::selectMode();
if (init.empty()) {
+ SB::progress("Start kernel shell");
*kvt << "\n";
new KernelShell(cwd, kvt);
+ SB::message("Melon is running");
while (KernelShell::getInstances() > 0) {
Task::currThread()->sleep(100);
}
Sys::halt();
} else {
- selectVideoMode(*kvt);
- //Create a VT for handling the Melon bootup logo
- SimpleVT *melonLogoVT = new SimpleVT(melonLogoLines, melonLogoCols, TXTLOGO_FGCOLOR, TXTLOGO_BGCOLOR);
- melonLogoVT->map(1);
- new Thread(logoAnimation, (void*)melonLogoVT, true);
-
+ SB::progress("Launch INIT");
Process* p = Process::run(init, 0);
if (p == 0) {
PANIC((char*)(u8int*)ByteArray(String("Could not launch init : ") += init));
} else {
Log::log(KL_STATUS, String("kmain : Starting init : ") += init);
- VirtualTerminal* vt = new ScrollableVT(Disp::textRows() - 10, Disp::textCols() - 4,
- 200, SHELL_FGCOLOR, SHELL_BGCOLOR);
- Kbd::setFocus(vt);
- ((ScrollableVT*)vt)->map(9);
- p->setInVT(vt);
- p->setOutVT(vt);
+ p->setInVT(kvt);
+ p->setOutVT(kvt);
p->start();
+ SB::message("Init started");
while (p->getState() != P_FINISHED) Task::currThread()->sleep(100);
PANIC("Init has terminated");
}