aboutsummaryrefslogtreecommitdiff
path: root/libk/stdlib/console.cc
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-01-31 23:24:42 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2021-01-31 23:24:42 +0200
commit950f164a2eb851dbab0aacb44334f0b687d123e8 (patch)
treea31c6e3140de2b208eca99e82535d740e9ca4039 /libk/stdlib/console.cc
parentInitial commit (diff)
downloadkernel.cpp-950f164a2eb851dbab0aacb44334f0b687d123e8.tar.xz
libk: add its own makefile
Diffstat (limited to 'libk/stdlib/console.cc')
-rw-r--r--libk/stdlib/console.cc28
1 files changed, 28 insertions, 0 deletions
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();
+}