summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/KernelKit/DebugOutput.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-05-02 19:38:46 +0200
committerGitHub <noreply@github.com>2025-05-02 19:38:46 +0200
commit997be16e5ac9a68d54882ab69529815860d62955 (patch)
tree19d6129c2d776bb1edc5d4a7325e39ca176c3403 /dev/kernel/KernelKit/DebugOutput.h
parent618104e74c195d7508a18450524f8ed7f9af8cc6 (diff)
parentb3b4b1ebdcd6adeac914869017c86d892b7a8ced (diff)
Merge pull request #28 from nekernel-org/dev
0.0.2
Diffstat (limited to 'dev/kernel/KernelKit/DebugOutput.h')
-rw-r--r--dev/kernel/KernelKit/DebugOutput.h311
1 files changed, 164 insertions, 147 deletions
diff --git a/dev/kernel/KernelKit/DebugOutput.h b/dev/kernel/KernelKit/DebugOutput.h
index f0506133..f6cfa027 100644
--- a/dev/kernel/KernelKit/DebugOutput.h
+++ b/dev/kernel/KernelKit/DebugOutput.h
@@ -1,204 +1,221 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
#pragma once
-#include <KernelKit/DeviceMgr.h>
#include <CompilerKit/CompilerKit.h>
+#include <KernelKit/DeviceMgr.h>
#include <NewKit/OwnPtr.h>
#include <NewKit/Stream.h>
-
-#define kDebugMaxPorts 56
+#include <NewKit/Utils.h>
#define kDebugUnboundPort 0x0FEED
-#define kDebugMag0 'Z'
+#define kDebugMag0 'K'
#define kDebugMag1 'D'
#define kDebugMag2 'B'
#define kDebugMag3 'G'
-#define kDebugSourceFile 0
-#define kDebugLine 33
-#define kDebugTeam 43
-#define kDebugEOP 49
-
-namespace Kernel
-{
- class TerminalDevice;
- class DTraceDevice;
-
- inline TerminalDevice end_line();
- inline TerminalDevice number(const Long& x);
- inline TerminalDevice hex_number(const Long& x);
-
- // @brief Emulates a VT100 terminal.
- class TerminalDevice final NE_DEVICE<const Char*>
- {
- public:
- TerminalDevice(void (*print)(IDeviceObject*, const Char*), void (*gets)(IDeviceObject*, const Char*))
- : IDeviceObject<const Char*>(print, gets)
- {
- }
-
- ~TerminalDevice() override;
-
- /// @brief returns device name (terminal name)
- /// @return string type (const Char*)
- const Char* Name() const override
- {
- return ("TerminalDevice");
- }
-
- NE_COPY_DEFAULT(TerminalDevice)
-
- STATIC TerminalDevice The() noexcept;
- };
-
- inline TerminalDevice end_line()
- {
- TerminalDevice self = TerminalDevice::The();
-
- self.operator<<("\r");
- return self;
- }
+#define kDebugSourceFile 23
+#define kDebugLine 33
+#define kDebugTeam 43
+#define kDebugEOP 49
+
+namespace Kernel {
+class TerminalDevice;
+class DTraceDevice;
+class DebugDevice;
+class Utf8TerminalDevice;
+
+inline TerminalDevice end_line();
+inline TerminalDevice number(const Long& x);
+inline TerminalDevice hex_number(const Long& x);
+
+// @brief Emulates a VT100 terminal.
+class TerminalDevice final NE_DEVICE<const Char*> {
+ public:
+ TerminalDevice(void (*print)(IDeviceObject*, const Char*),
+ void (*gets)(IDeviceObject*, const Char*))
+ : IDeviceObject<const Char*>(print, gets) {}
+
+ ~TerminalDevice() override;
+
+ /// @brief returns device name (terminal name)
+ /// @return string type (const Char*)
+ const Char* Name() const override { return ("TerminalDevice"); }
+
+ NE_COPY_DEFAULT(TerminalDevice)
+
+ STATIC TerminalDevice The() noexcept;
+};
+
+class Utf8TerminalDevice final NE_DEVICE<const Utf8Char*> {
+ public:
+ Utf8TerminalDevice(void (*print)(IDeviceObject*, const Utf8Char*),
+ void (*gets)(IDeviceObject*, const Utf8Char*))
+ : IDeviceObject<const Utf8Char*>(print, gets) {}
+
+ ~Utf8TerminalDevice() override;
- inline TerminalDevice carriage_return()
- {
- TerminalDevice self = TerminalDevice::The();
+ /// @brief returns device name (terminal name)
+ /// @return string type (const Char*)
+ const Char* Name() const override { return ("Utf8TerminalDevice"); }
- self.operator<<("\r");
- return self;
- }
+ NE_COPY_DEFAULT(Utf8TerminalDevice)
- inline TerminalDevice tabulate()
- {
- TerminalDevice self = TerminalDevice::The();
+ STATIC Utf8TerminalDevice The() noexcept;
+};
- self.operator<<("\t");
- return self;
- }
+inline TerminalDevice end_line() {
+ TerminalDevice self = TerminalDevice::The();
- /// @brief emulate a terminal bell, like the VT100 does.
- inline TerminalDevice bell()
- {
- TerminalDevice self = TerminalDevice::The();
+ self.operator<<("\r");
+ return self;
+}
- self.operator<<("\a");
- return self;
- }
+inline Utf8TerminalDevice utf_end_line() {
+ Utf8TerminalDevice self = Utf8TerminalDevice::The();
- namespace Detail
- {
- inline TerminalDevice _write_number(const Long& x, TerminalDevice& term)
- {
- UInt64 y = (x > 0 ? x : -x) / 10;
- UInt64 h = (x > 0 ? x : -x) % 10;
+ self.operator<<(u8"\r");
+ return self;
+}
- if (y)
- _write_number(y, term);
+inline TerminalDevice carriage_return() {
+ TerminalDevice self = TerminalDevice::The();
- /* fail if the number is not base-10 */
- if (h > 10)
- {
- _write_number('?', term);
- return term;
- }
+ self.operator<<("\r");
+ return self;
+}
- if (y == ~0UL)
- y = -y;
+inline TerminalDevice tabulate() {
+ TerminalDevice self = TerminalDevice::The();
- const Char kNumbers[11] = "0123456789";
+ self.operator<<("\t");
+ return self;
+}
- Char buf[2];
- buf[0] = kNumbers[h];
- buf[1] = 0;
+/// @brief emulate a terminal bell, like the VT100 does.
+inline TerminalDevice bell() {
+ TerminalDevice self = TerminalDevice::The();
- term.operator<<(buf);
- return term;
- }
+ self.operator<<("\a");
+ return self;
+}
- inline TerminalDevice _write_number_hex(const Long& x, TerminalDevice& term)
- {
- UInt64 y = (x > 0 ? x : -x) / 16;
- UInt64 h = (x > 0 ? x : -x) % 16;
+namespace Detail {
+ inline TerminalDevice _write_number(const Long& x, TerminalDevice& term) {
+ UInt64 y = (x > 0 ? x : -x) / 10;
+ UInt64 h = (x > 0 ? x : -x) % 10;
- if (y)
- _write_number_hex(y, term);
+ if (y) _write_number(y, term);
- /* fail if the hex number is not base-16 */
- if (h > 16)
- {
- _write_number_hex('?', term);
- return term;
- }
+ /* fail if the number is not base-10 */
+ if (h > 10) {
+ _write_number('?', term);
+ return term;
+ }
- if (y == ~0UL)
- y = -y;
+ if (y == ~0UL) y = -y;
- const Char kNumbers[17] = "0123456789ABCDEF";
+ const Char kNumbers[11] = "0123456789";
- Char buf[2];
- buf[0] = kNumbers[h];
- buf[1] = 0;
+ Char buf[2];
+ buf[0] = kNumbers[h];
+ buf[1] = 0;
- term.operator<<(buf);
- return term;
- }
- } // namespace Detail
+ term.operator<<(buf);
+ return term;
+ }
- inline TerminalDevice hex_number(const Long& x)
- {
- TerminalDevice self = TerminalDevice::The();
+ inline TerminalDevice _write_number_hex(const Long& x, TerminalDevice& term) {
+ UInt64 y = (x > 0 ? x : -x) / 16;
+ UInt64 h = (x > 0 ? x : -x) % 16;
- Detail::_write_number_hex(x, self);
- self.operator<<("h");
+ if (y) _write_number_hex(y, term);
- return self;
- }
+ /* fail if the hex number is not base-16 */
+ if (h > 16) {
+ _write_number_hex('?', term);
+ return term;
+ }
- inline TerminalDevice number(const Long& x)
- {
- TerminalDevice self = TerminalDevice::The();
+ if (y == ~0UL) y = -y;
- Detail::_write_number(x, self);
+ const Char kNumbers[17] = "0123456789ABCDEF";
- return self;
- }
+ Char buf[2];
+ buf[0] = kNumbers[h];
+ buf[1] = 0;
- inline TerminalDevice get_console_in(Char* buf)
- {
- TerminalDevice self = TerminalDevice::The();
+ term.operator<<(buf);
+ return term;
+ }
+} // namespace Detail
- self >> buf;
+inline TerminalDevice hex_number(const Long& x) {
+ TerminalDevice self = TerminalDevice::The();
- return self;
- }
+ Detail::_write_number_hex(x, self);
+ self.operator<<("h");
- constexpr SizeT kDebugTypeLen = 256U;
+ return self;
+}
- typedef Char rt_debug_type[kDebugTypeLen];
+inline TerminalDevice number(const Long& x) {
+ TerminalDevice self = TerminalDevice::The();
- class DebuggerPortHeader final
- {
- public:
- Int16 fPort[kDebugMaxPorts];
- Int16 fPortCnt;
- };
+ Detail::_write_number(x, self);
- inline TerminalDevice& operator<<(TerminalDevice& src, const Long& num)
- {
- src = number(num);
- return src;
- }
-} // namespace Kernel
+ return self;
+}
+
+inline TerminalDevice get_console_in(Char* buf) {
+ TerminalDevice self = TerminalDevice::The();
+
+ self >> buf;
+
+ return self;
+}
+
+inline constexpr SizeT kDebugTypeLen = 256U;
+
+typedef Char rt_debug_type[kDebugTypeLen];
+
+class DebuggerPortHeader final {
+ public:
+ Int16 fPort;
+ Int16 fPortBsy;
+};
+
+inline TerminalDevice& operator<<(TerminalDevice& src, const Long& num) {
+ src = number(num);
+ return src;
+}
+} // namespace Kernel
#ifdef kout
#undef kout
-#endif // ifdef kout
+#endif // ifdef kout
#define kout TerminalDevice::The()
+#ifdef kendl
+#undef kendl
+#endif // ifdef kendl
+
#define kendl end_line()
+
+#ifdef kout8
+#undef kout8
+#endif // ifdef kout8
+
+#define kout8 Utf8TerminalDevice::The()
+
+#ifdef kendl8
+#undef kendl8
+#endif // ifdef kendl8
+
+#define kendl8 utf_end_line()