Center ascii cat on boot.

This commit is contained in:
Jonas 'Sortie' Termansen 2015-10-26 00:09:54 +01:00
parent f58c70d081
commit 8c7c6fa59f
6 changed files with 75 additions and 66 deletions

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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();
}

View File

@ -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 \