Compare commits

...

2 Commits

Author SHA1 Message Date
a43550fb9a
apps: Add date
All checks were successful
continuous-integration/drone/push Build is passing
2023-03-24 21:48:43 +01:00
1635eaf992
kernel: Eliminate the splash screen
Userspace is free to show a splash if it wants, but the kernel shouldn't force it upon us.
2023-03-24 21:48:32 +01:00
3 changed files with 21 additions and 98 deletions

View File

@ -10,3 +10,4 @@ luna_app(init.c init)
luna_app(cat.c cat) luna_app(cat.c cat)
luna_app(edit.c edit) luna_app(edit.c edit)
luna_app(sh.c sh) luna_app(sh.c sh)
luna_app(date.c date)

10
apps/date.c Normal file
View File

@ -0,0 +1,10 @@
#include <stddef.h>
#include <stdio.h>
#include <time.h>
int main()
{
time_t now = time(NULL);
fputs(ctime(&now), stdout);
}

View File

@ -33,133 +33,45 @@ void reap_thread()
} }
} }
static void identify_processor() Result<void> init()
{ {
kinfoln("Starting Moon %s, built on %s at %s", MOON_VERSION, __DATE__, __TIME__);
kinfoln("Current platform: %s", CPU::platform_string()); kinfoln("Current platform: %s", CPU::platform_string());
kinfoln("Current processor: %s", CPU::identify().value_or("(unknown)")); kinfoln("Current processor: %s", CPU::identify().value_or("(unknown)"));
}
static void identify_memory() Timer::init();
{
kinfoln("Total memory: %s", to_dynamic_unit(MemoryManager::total()).release_value().chars()); kinfoln("Total memory: %s", to_dynamic_unit(MemoryManager::total()).release_value().chars());
kinfoln("Free memory: %s", to_dynamic_unit(MemoryManager::free()).release_value().chars()); kinfoln("Free memory: %s", to_dynamic_unit(MemoryManager::free()).release_value().chars());
kinfoln("Used memory: %s", to_dynamic_unit(MemoryManager::used()).release_value().chars()); kinfoln("Used memory: %s", to_dynamic_unit(MemoryManager::used()).release_value().chars());
kinfoln("Reserved memory: %s", to_dynamic_unit(MemoryManager::reserved()).release_value().chars()); kinfoln("Reserved memory: %s", to_dynamic_unit(MemoryManager::reserved()).release_value().chars());
}
static Result<void> try_init_vfs() Thread::init();
{ Scheduler::init();
VFS::root_fs = TRY(TmpFS::FileSystem::create()); VFS::root_fs = TRY(TmpFS::FileSystem::create());
TRY(DeviceRegistry::init()); TRY(DeviceRegistry::init());
InitRD::populate_vfs(); InitRD::populate_vfs();
return {};
}
static void init_vfs()
{
try_init_vfs().release_value();
}
static Result<void> try_init_userspace()
{
auto init = TRY(VFS::resolve_path("/bin/init")); auto init = TRY(VFS::resolve_path("/bin/init"));
TRY(Scheduler::new_userspace_thread(init, "/bin/init")); TRY(Scheduler::new_userspace_thread(init, "/bin/init"));
return {};
}
static void init_userspace()
{
try_init_userspace().release_value();
}
static void create_reaper()
{
Scheduler::new_kernel_thread(reap_thread, "[reap]").release_value(); Scheduler::new_kernel_thread(reap_thread, "[reap]").release_value();
}
static void scan_pci()
{
PCI::scan( PCI::scan(
[](const PCI::Device& device) { [](const PCI::Device& device) {
kinfoln("Found PCI mass storage device %.4x:%.4x, at address %u:%u:%u", device.id.vendor, device.id.device, kinfoln("Found PCI mass storage device %.4x:%.4x, at address %u:%u:%u", device.id.vendor, device.id.device,
device.address.bus, device.address.slot, device.address.function); device.address.bus, device.address.slot, device.address.function);
}, },
{ .klass = 1 }); { .klass = 1 });
}
static void transfer_control() CPU::platform_finish_init();
{
// Disable console logging before transferring control to userspace. // Disable console logging before transferring control to userspace.
setup_log(log_debug_enabled(), log_serial_enabled(), false); setup_log(log_debug_enabled(), log_serial_enabled(), false);
CPU::enable_interrupts(); CPU::enable_interrupts();
}
struct SplashAction
{
const char* message;
void (*action)(void);
};
constexpr SplashAction actions[] = {
{ "Identify Processor", identify_processor }, { "Initialize Timer", Timer::init },
{ "Identify System Memory", identify_memory }, { "Initialize Threads", Thread::init },
{ "Initialize Scheduler", Scheduler::init }, { "Initialize File System", init_vfs },
{ "Initialize Userspace", init_userspace }, { "Create Reaper Thread", create_reaper },
{ "Find Available Devices", scan_pci }, { "Final CPU Initialization", CPU::platform_finish_init },
{ "Start Userspace", transfer_control },
};
static constexpr u32 WHITE = 0xffffffff;
static constexpr u32 RED = 0xffff0000;
static constexpr u32 BLACK = 0xff000000;
static void update_splash(const char* message, u32 current, u32 total)
{
const u32 line_height = Framebuffer::height() / 2;
const u32 line_begin = 100;
const u32 line_length = Framebuffer::width() - 200;
if (current != total)
{
const u32 line_completed = (line_length / total) * current;
Framebuffer::rect(line_begin, line_height, line_completed, 2, WHITE);
Framebuffer::rect(line_begin + line_completed, line_height, line_length - line_completed, 2, RED);
}
else { Framebuffer::rect(line_begin, line_height, line_length, 2, WHITE); }
Framebuffer::rect(line_begin, line_height + 20, line_length, 16, BLACK);
TextConsole::move_to(Framebuffer::width() / 2 - 100, line_height + 20);
TextConsole::printf("%s (%d%%)", message, (100 / total) * current).release_value();
TextConsole::move_to(0, 0);
for (int i = 0; i < 3000000; i++) CPU::pause();
}
Result<void> init()
{
kinfoln("Starting Moon %s, built on %s at %s", MOON_VERSION, __DATE__, __TIME__);
constexpr usize total_actions = sizeof(actions) / sizeof(actions[0]);
for (usize i = 0; i < total_actions; i++)
{
#ifndef DEBUG_MODE
update_splash(actions[i].message, (u32)i, (u32)(total_actions - 1));
#else
(void)update_splash;
#endif
actions[i].action();
}
return {}; return {};
} }