From 8c7c6fa59f7fbd8366e13c22eb0dbfc2b256d54d Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Mon, 26 Oct 2015 00:09:54 +0100 Subject: [PATCH] Center ascii cat on boot. --- init/init.c++ | 4 -- kernel/include/sortix/kernel/log.h | 1 + kernel/kernel.cpp | 7 ++- kernel/log.cpp | 20 +++++++++ kernel/panic.cpp | 39 ++++++++--------- libc/include/brand.h | 70 +++++++++++++----------------- 6 files changed, 75 insertions(+), 66 deletions(-) diff --git a/init/init.c++ b/init/init.c++ index db24ec03..40c392ea 100644 --- a/init/init.c++ +++ b/init/init.c++ @@ -516,10 +516,6 @@ int main(int argc, char* argv[]) if ( 3 <= argc && !strcmp(argv[1], "--chain") ) return chain_boot_device(argv[2]); - // Reset the terminal's color and the rest of it. - printf(BRAND_INIT_BOOT_MESSAGE); - fflush(stdout); - // Set the default file creation mask. umask(022); diff --git a/kernel/include/sortix/kernel/log.h b/kernel/include/sortix/kernel/log.h index 481f9d0b..dd93413f 100644 --- a/kernel/include/sortix/kernel/log.h +++ b/kernel/include/sortix/kernel/log.h @@ -116,6 +116,7 @@ inline size_t PrintFV(const char* format, va_list list) } void Init(multiboot_info_t* bootinfo); +void Center(const char* string); } // namespace Log } // namespace Sortix diff --git a/kernel/kernel.cpp b/kernel/kernel.cpp index 0175eb7d..6da63e3d 100644 --- a/kernel/kernel.cpp +++ b/kernel/kernel.cpp @@ -173,8 +173,9 @@ extern "C" void KernelInit(unsigned long magic, multiboot_info_t* bootinfo) // Initialize the kernel log. Log::Init(bootinfo); - // Display the boot welcome screen. - Log::Print(BRAND_KERNEL_BOOT_MESSAGE); + // Display the logo. + Log::PrintF("\e[37;41m\e[2J"); + Log::Center(BRAND_MAXSI); #if defined(__x86_64__) // TODO: Remove this hack when qemu 1.4.x and 1.5.0 are obsolete. @@ -750,6 +751,8 @@ static void InitThread(void* /*user*/) init.Reset(); + Log::PrintF("\r\e[m\e[J"); + int envc = 0; const char* envp[] = { NULL }; struct thread_registers regs; diff --git a/kernel/log.cpp b/kernel/log.cpp index d3b8d9c1..8671b3f1 100644 --- a/kernel/log.cpp +++ b/kernel/log.cpp @@ -171,5 +171,25 @@ void Init(multiboot_info_t* bootinfo) Log::emergency_device_pointer = textterm; } +void Center(const char* string) +{ + size_t log_width = Log::Width(); + while ( *string ) + { + size_t string_width = strcspn(string, "\n"); + size_t leading = string_width <= log_width ? + (log_width - string_width) / 2 : 0; + for ( size_t i = 0; i < leading; i++ ) + Log::Print(" "); + Log::PrintData(string, string_width); + string += string_width; + if ( *string == '\n' ) + { + string++; + Log::Print("\n"); + } + } +} + } // namespace Log } // namespace Sortix diff --git a/kernel/panic.cpp b/kernel/panic.cpp index 2459b7a0..89b6a42a 100644 --- a/kernel/panic.cpp +++ b/kernel/panic.cpp @@ -42,18 +42,14 @@ static bool panicing = false; static bool doublepanic = false; static bool logrecovering = false; -static void PanicLogoLong() -{ - Log::PrintF(BRAND_PANIC_LONG); -} - -static void PanicLogoShort() -{ - Log::Print(BRAND_PANIC_SHORT); -} - void PanicInit() { + // TODO: Some panics are soft the console rendering and core features are + // perfectly online, they do not need too paranoid handling here, + // while others (like a real kernel crash) is critical and this is + // needed. Supply multiple kernel panicing interfaces and switch code + // to using them instead. + // This is a kernel emergency. We will need to disable preemption, such that // this is the only thread running. This means that we cannot acquire locks // and the data protected by them may be inconsistent. @@ -109,27 +105,31 @@ void PanicInit() // Handle the case where the panic code caused another system crash. if ( panicing ) { - Log::PrintF("Panic while panicing:\n"); + Log::Print("Panic while panicing:\n"); doublepanic = true; return; } panicing = true; // Render a notice that the system has crashed and forcefully shut down. - longpanic ? PanicLogoLong() : PanicLogoShort(); -} - -static void PanicHooks() -{ - if ( doublepanic ) - return; + if ( longpanic ) + { + Log::Print("\e[m\e[31;40m\e[2J\e[H"); + Log::Center(BRAND_MAXSI_DEAD); + Log::Center("KERNEL PANIC"); + Log::Print("\n\nThe operating system encountered an unrecoverable " + "error.\n\nTechincal information:\n"); + } + else + { + Log::Print("\e[m\e[31m\e[0Jkernel: panic: "); + } } extern "C" __attribute__((noreturn)) void Panic(const char* error) { PanicInit(); Log::Print(error); - PanicHooks(); HaltKernel(); } @@ -140,7 +140,6 @@ extern "C" __attribute__((noreturn)) void PanicF(const char* format, ...) va_start(list, format); Log::PrintFV(format, list); va_end(list); - PanicHooks(); HaltKernel(); } diff --git a/libc/include/brand.h b/libc/include/brand.h index 55427051..14a7d865 100644 --- a/libc/include/brand.h +++ b/libc/include/brand.h @@ -39,49 +39,39 @@ /* Ascii version of the maxsi logo. */ #define BRAND_MAXSI \ -" _ \n" \ -" / \\ \n" \ -" /\\ /\\ / \\ \n" \ -" / \\ / \\ | | \n" \ -" / \\/ \\ | | \n" \ -" | O O \\_______________________ / | \n" \ -" | | \n" \ -" | \\_______/ / \n" \ -" \\ / \n" \ -" ------ --------------- ---/ \n" \ -" / \\ / \\ \n" \ -" / \\ / \\ \n" \ -" / \\ / \\ \n" \ -" /_____________\\ /____________\\ \n" \ -" \n" \ +" _ \n" \ +" / \\ \n" \ +" /\\ /\\ / \\\n" \ +" / \\ / \\ | |\n" \ +" / \\/ \\ | |\n" \ +"| O O \\_______________________ / |\n" \ +"| |\n" \ +"| \\_______/ /\n" \ +" \\ / \n" \ +" ------ --------------- ---/ \n" \ +" / \\ / \\ \n" \ +" / \\ / \\ \n" \ +" / \\ / \\ \n" \ +" /_____________\\ /____________\\ \n" \ +" \n" \ /* Dead version of the maxsi logo, used for panic screens and such. */ #define BRAND_MAXSI_DEAD \ -" _ \n" \ -" / \\ \n" \ -" /\\ /\\ / \\ \n" \ -" / \\ / \\ | | \n" \ -" / \\/ \\ | | \n" \ -" | X X \\_______________________ / | \n" \ -" | | \n" \ -" | _________ / \n" \ -" \\ / \n" \ -" ------ --------------- ---/ \n" \ -" / \\ / \\ \n" \ -" / \\ / \\ \n" \ -" / \\ / \\ \n" \ -" /_____________\\ /____________\\ \n" \ -" \n" \ - -/* Message printed by the kernel just after boot. */ -#define BRAND_KERNEL_BOOT_MESSAGE \ -"\e[37;41m\e[2J" \ -BRAND_MAXSI \ -" BOOTING OPERATING SYSTEM... " - -/* Message printed by init after it takes control. */ -#define BRAND_INIT_BOOT_MESSAGE \ -"\r\e[m\e[J" +" _ \n" \ +" / \\ \n" \ +" /\\ /\\ / \\\n" \ +" / \\ / \\ | |\n" \ +" / \\/ \\ | |\n" \ +"| X X \\_______________________ / |\n" \ +"| |\n" \ +"| _________ /\n" \ +" \\ / \n" \ +" ------ --------------- ---/ \n" \ +" / \\ / \\ \n" \ +" / \\ / \\ \n" \ +" / \\ / \\ \n" \ +" /_____________\\ /____________\\ \n" \ +" \n" \ /* Message printed when a critical error occurs and the system panics. */ #define BRAND_PANIC_LONG \