From 950f164a2eb851dbab0aacb44334f0b687d123e8 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 31 Jan 2021 23:24:42 +0200 Subject: libk: add its own makefile --- libk/stdlib/console.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 libk/stdlib/console.cc (limited to 'libk/stdlib') diff --git a/libk/stdlib/console.cc b/libk/stdlib/console.cc new file mode 100644 index 0000000..dbc9b86 --- /dev/null +++ b/libk/stdlib/console.cc @@ -0,0 +1,28 @@ +#include "stdlib.h" + +static Console *global_console = nullptr; + +void console_set(Console *ptr) { + if (ptr != nullptr) { + global_console = ptr; + } +} + +void printk(const String &msg) { + if (global_console == nullptr) + return; + + global_console->write(msg); +} + +void abort() { + /* + * On gcc, a 'while(true) {}' will infinitely loop + * but clang will optimize it away on -O2 if it's empty + * therefore, add no-op + */ + while (true) { + asm volatile("nop"); + } + __builtin_unreachable(); +} -- cgit v1.2.1