summaryrefslogtreecommitdiffhomepage
path: root/Private/HALKit/AMD64/HalProcessor.cpp
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-31 09:42:54 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-31 09:42:54 +0100
commitfc55f0d69d24fb4908cbd811681f2c3fac53614d (patch)
treeba09a2cdbb225df7ba1a9ec5a12bcbb90b673ead /Private/HALKit/AMD64/HalProcessor.cpp
parent7bed9287589293bd9d712d152539591dee0b28c0 (diff)
kernel: add GKit, improve AMD64 HAL.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/HALKit/AMD64/HalProcessor.cpp')
-rw-r--r--Private/HALKit/AMD64/HalProcessor.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/Private/HALKit/AMD64/HalProcessor.cpp b/Private/HALKit/AMD64/HalProcessor.cpp
new file mode 100644
index 00000000..3d509f79
--- /dev/null
+++ b/Private/HALKit/AMD64/HalProcessor.cpp
@@ -0,0 +1,58 @@
+/*
+ * ========================================================
+ *
+ * HCore
+ * Copyright 2024 Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <HALKit/AMD64/Processor.hpp>
+
+/**
+ * @file Processor.cpp
+ * @brief This file is about processor specific functions (in/out...)
+ */
+
+namespace HCore::HAL {
+void out8(UInt16 port, UInt8 value) {
+ asm volatile("outb %%al, %1" : : "a"(value), "Nd"(port) : "memory");
+}
+
+void out16(UInt16 port, UInt16 value) {
+ asm volatile("outw %%ax, %1" : : "a"(value), "Nd"(port) : "memory");
+}
+
+void out32(UInt16 port, UInt32 value) {
+ asm volatile("outl %%eax, %1" : : "a"(value), "Nd"(port) : "memory");
+}
+
+UInt8 in8(UInt16 port) {
+ UInt8 value = 0UL;
+ asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory");
+
+ return value;
+}
+
+UInt16 in16(UInt16 port) {
+ UInt16 value = 0UL;
+ asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory");
+
+ return value;
+}
+
+UInt32 in32(UInt16 port) {
+ UInt32 value = 0UL;
+ asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory");
+
+ return value;
+}
+
+void rt_halt() { asm volatile("hlt"); }
+
+void rt_cli() { asm volatile("cli"); }
+
+void rt_sti() { asm volatile("sti"); }
+
+void rt_cld() { asm volatile("cld"); }
+} // namespace HCore::HAL