aboutsummaryrefslogtreecommitdiff
path: root/libk
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-02-02 22:27:27 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2021-02-02 22:27:27 +0200
commit36e8ee0cdaa904ee00710b1d2df16691729cc93d (patch)
tree16e3836af7ef9efa6da1bbde4248ae5ad956bf58 /libk
parentlibk: add its own makefile (diff)
downloadkernel.cpp-36e8ee0cdaa904ee00710b1d2df16691729cc93d.tar.xz
Print some multiboot2 information
Diffstat (limited to 'libk')
-rw-r--r--libk/stdlib.h22
-rw-r--r--libk/stdlib/console.cc9
-rw-r--r--libk/type_traits.h10
-rw-r--r--libk/types.h9
4 files changed, 36 insertions, 14 deletions
diff --git a/libk/stdlib.h b/libk/stdlib.h
index 3e6619d..44bacf4 100644
--- a/libk/stdlib.h
+++ b/libk/stdlib.h
@@ -1,14 +1,32 @@
#pragma once
#include <string.h>
+#include <type_traits.h>
class Console {
public:
+ virtual void write(char c) = 0;
virtual void write(const String &msg) = 0;
+ virtual void write(int n) = 0;
+ virtual void write(unsigned int n) = 0;
+
+ static void set(Console *ptr);
+ static Console *get();
};
-void console_set(Console *ptr);
+template <typename T> void printk(const T &a) {
+ if (auto *c = Console::get()) {
+ if constexpr (is_same<T, const char *>())
+ c->write(String(a));
+ else
+ c->write(a);
+ }
+}
-void printk(const String &msg);
+template <typename T, typename... Args>
+void printk(const T &a, const Args &...x) {
+ printk(a);
+ printk(x...);
+}
__attribute__((__noreturn__)) void abort();
diff --git a/libk/stdlib/console.cc b/libk/stdlib/console.cc
index dbc9b86..dee6a8f 100644
--- a/libk/stdlib/console.cc
+++ b/libk/stdlib/console.cc
@@ -2,18 +2,13 @@
static Console *global_console = nullptr;
-void console_set(Console *ptr) {
+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);
-}
+Console *Console::get() { return global_console; }
void abort() {
/*
diff --git a/libk/type_traits.h b/libk/type_traits.h
new file mode 100644
index 0000000..cef30c1
--- /dev/null
+++ b/libk/type_traits.h
@@ -0,0 +1,10 @@
+#pragma once
+
+template <class T, T v> struct integral_constant {
+ constexpr T operator()() const { return v; }
+ constexpr operator T() const { return v; }
+};
+
+template <class T, class U> struct is_same : integral_constant<bool, false> {};
+
+template <class T> struct is_same<T, T> : integral_constant<bool, true> {};
diff --git a/libk/types.h b/libk/types.h
index 0818342..be38cb0 100644
--- a/libk/types.h
+++ b/libk/types.h
@@ -13,9 +13,8 @@ static_assert(sizeof(uint16_t) == 2);
typedef unsigned int uint32_t;
static_assert(sizeof(uint32_t) == 4);
-//typedef unsigned long uint64_t;
-//static_assert(sizeof(uint64_t) == 8);
-
+typedef unsigned long long int uint64_t;
+static_assert(sizeof(uint64_t) == 8);
typedef char int8_t;
static_assert(sizeof(int8_t) == 1);
@@ -26,5 +25,5 @@ static_assert(sizeof(int16_t) == 2);
typedef int int32_t;
static_assert(sizeof(int32_t) == 4);
-//typedef long int64_t;
-//static_assert(sizeof(int64_t) == 8);
+typedef long long int int64_t;
+static_assert(sizeof(int64_t) == 8);