summaryrefslogtreecommitdiffhomepage
path: root/Kernel/HALKit/AMD64/HalProcessor.cpp
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-09 00:42:44 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-09 00:42:44 +0200
commitaf8a516fc22865abd80d6e26f1541fa3d6bebfdc (patch)
tree96d42a10945fc03df022389aef54708383c1d616 /Kernel/HALKit/AMD64/HalProcessor.cpp
parenta874e9cc98df994178d55996943fe81799c61d2f (diff)
MHR-23: :boom:, refactors.
- Move NewBoot to /Boot, thus making Kernel directory only containing the kernel. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/HALKit/AMD64/HalProcessor.cpp')
-rw-r--r--Kernel/HALKit/AMD64/HalProcessor.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/Kernel/HALKit/AMD64/HalProcessor.cpp b/Kernel/HALKit/AMD64/HalProcessor.cpp
new file mode 100644
index 00000000..31cee72c
--- /dev/null
+++ b/Kernel/HALKit/AMD64/HalProcessor.cpp
@@ -0,0 +1,97 @@
+/* -------------------------------------------
+
+ Copyright SoftwareLabs
+
+------------------------------------------- */
+
+#include <HALKit/AMD64/Processor.hpp>
+
+/**
+ * @file Processor.cpp
+ * @brief This file is about processor specific functions (in/out/cli/std...)
+ */
+
+namespace NewOS::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");
+ }
+
+ void rt_std()
+ {
+ asm volatile("std");
+ }
+} // namespace NewOS::HAL