summaryrefslogtreecommitdiffhomepage
path: root/Private/DriverKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-18 23:10:15 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-18 23:10:15 +0200
commit0ae4062bfe9936cc9fd2c7bb924442480b067d93 (patch)
tree491b3cfc9c751557c37213ff437e56f66d100a4d /Private/DriverKit
parent706c58b9b9fa74c63180f490a1f48652d0408944 (diff)
MHR-5: initial commit.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/DriverKit')
-rw-r--r--Private/DriverKit/KernelPrint.c19
-rw-r--r--Private/DriverKit/KernelPrint.h45
2 files changed, 64 insertions, 0 deletions
diff --git a/Private/DriverKit/KernelPrint.c b/Private/DriverKit/KernelPrint.c
new file mode 100644
index 00000000..32e20f4f
--- /dev/null
+++ b/Private/DriverKit/KernelPrint.c
@@ -0,0 +1,19 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+ Purpose: Kernel Text I/O.
+
+------------------------------------------- */
+
+#include "DriverKit/KernelPrint.h"
+
+#ifdef __x86_64__
+static void kernelPrintCharAMD64(const char ch) {
+ __asm__ volatile("outb %%al, %1" : : "a"(ch), "Nd"(0x3F8) : "memory");
+}
+#endif // if __x86_64__
+
+DK_EXTERN void kernelPrintChar(const char ch) {
+ kernelPrintChar(ch);
+}
diff --git a/Private/DriverKit/KernelPrint.h b/Private/DriverKit/KernelPrint.h
new file mode 100644
index 00000000..7e25e304
--- /dev/null
+++ b/Private/DriverKit/KernelPrint.h
@@ -0,0 +1,45 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+ Purpose: Kernel Text I/O.
+
+------------------------------------------- */
+
+#pragma once
+
+#if defined(__cplusplus)
+#define DK_EXTERN extern "C"
+#else
+#define DK_EXTERN extern
+#endif // defined(__cplusplus)
+
+#include <stdint.h>
+#include <stddef.h>
+
+/// @brief print character into UART.
+DK_EXTERN void kernelPrintChar(const char ch);
+
+static inline size_t kernelStringLength(const char* str) {
+ size_t index = 0;
+
+ while (str[index] != 0) {
+ ++index;
+ }
+
+ return index;
+}
+
+/// @brief print string to UART.
+static inline void kernelPrintStr(const char* message) {
+ if (!message) return;
+ if (*message == 0) return;
+
+ size_t index = 0;
+ size_t len = kernelStringLength(message);
+
+ while (index < len) {
+ kernelPrintChar(message[index]);
+ ++index;
+ }
+}