diff --git a/src/kernel/console.cpp b/src/kernel/console.cpp index d3f600e..9b28fd6 100644 --- a/src/kernel/console.cpp +++ b/src/kernel/console.cpp @@ -1,4 +1,5 @@ #include "kutil/coord.h" +#include "kutil/guid.h" #include "kutil/memory.h" #include "console.h" #include "font.h" @@ -334,6 +335,23 @@ void console::vprintf(const char *fmt, va_list args) done = true; break; + case 'G': { + // Special: GUID type + kutil::guid g = va_arg(args, kutil::guid); + put_hex(g.a, 8, '0'); + putc('-'); + put_hex((g.a >> 32) & 0xffff, 4, '0'); + putc('-'); + put_hex((g.a >> 48) & 0xffff, 4, '0'); + putc('-'); + put_hex((kutil::byteswap(g.b) >> 16) & 0xffff, 4, '0'); + putc('-'); + put_hex(kutil::byteswap(g.b) & 0xffff, 4, '0'); + put_hex(kutil::byteswap(g.b >> 32), 8, '0'); + } + done = true; + break; + case 'l': switch (*r++) { case 'x': put_hex(va_arg(args, uint64_t), right ? width : -width, pad); done = true; break; diff --git a/src/modules/kutil/guid.h b/src/modules/kutil/guid.h new file mode 100644 index 0000000..c394913 --- /dev/null +++ b/src/modules/kutil/guid.h @@ -0,0 +1,38 @@ +#pragma once +/// \file guid.h +/// Definition of the guid type and related functions +#include +#include "kutil/misc.h" + +namespace kutil { + + +/// A GUID +struct guid +{ + uint64_t a, b; +}; + +/// Make a GUID by writing it naturally-ordered in code: +/// AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE becomes: +/// make_guid(0xAAAAAAAA, 0xBBBB, 0xCCCC, 0xDDDD, 0xEEEEEEEEEEEE); +/// \returns The guid object +inline constexpr guid make_guid(uint32_t a, uint16_t b, uint16_t c, uint16_t d, uint64_t e) +{ + const uint64_t h = + static_cast(c) << 48 | + static_cast(b) << 32 | + a; + + const uint64_t l = + static_cast(byteswap(e & 0xffffffff)) << 32 | + (byteswap(e >> 32) & 0xffff0000) | + ((d << 8) & 0xff00) | ((d >> 8) & 0xff); + + return {h, l}; +} + +} // namespace kutil + + +inline bool operator==(const kutil::guid &a, const kutil::guid &b) { return a.a == b.a && a.b == b.b; }