summaryrefslogtreecommitdiffhomepage
path: root/Kernel/HALKit/AMD64/Processor.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel/HALKit/AMD64/Processor.hpp')
-rw-r--r--Kernel/HALKit/AMD64/Processor.hpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/Kernel/HALKit/AMD64/Processor.hpp b/Kernel/HALKit/AMD64/Processor.hpp
index 235e425d..4916d845 100644
--- a/Kernel/HALKit/AMD64/Processor.hpp
+++ b/Kernel/HALKit/AMD64/Processor.hpp
@@ -17,6 +17,7 @@
#include <NewKit/Defines.hpp>
#include <NewKit/Utils.hpp>
#include <FirmwareKit/Handover.hxx>
+#include <HALKit/AMD64/HalPageAlloc.hpp>
#ifdef kCPUBackendName
#undef kCPUBackendName
@@ -53,6 +54,68 @@ namespace NewOS
namespace NewOS::HAL
{
+
+ enum
+ {
+ eFlagsUser,
+ eFlagsRw,
+ eFlagsExecDisable
+ };
+
+ /// @brief Map address to PDE.
+ /// @param pde a valid page directory.
+ /// @param phys_addr a valid phyiscal address.
+ /// @param virt_addr a valid virtual address.
+ /// @param flags the flags to put on the page.
+ inline Int32 ke_map_address(PDE* pde, UIntPtr phys_addr, UIntPtr virt_addr, UInt32 flags)
+ {
+ UInt16 pml4_index = (virt_addr >> 39) & 0x1FF;
+
+ if (!pde->Pte[pml4_index].Present)
+ {
+ pde->Pte[pml4_index].Present = true;
+ kcout << "PM is present now.\r";
+
+ pde->Pte[pml4_index].PhysicalAddress = phys_addr;
+ pde->Pte[pml4_index].Rw = flags & eFlagsRw;
+ pde->Pte[pml4_index].User = flags & eFlagsUser;
+ pde->Pte[pml4_index].ExecDisable = flags & eFlagsExecDisable;
+
+ return 0;
+ }
+ else
+ {
+ kcout << "PM is already present.\r";
+
+ kcout << "PhysicalAddress: " << hex_number(pde->Pte[pml4_index].PhysicalAddress) << endl;
+ kcout << "User: " << (pde->Pte[pml4_index].User ? "yes" : "no") << "\r";
+ kcout << "RW: " << (pde->Pte[pml4_index].Rw ? "yes" : "no") << "\r";
+
+ return 1;
+ }
+
+ return 0;
+ }
+
+ /// @brief Map address to PDE.
+ /// @param pde
+ /// @param phys_addr
+ /// @param virt_addr
+ /// @param flags
+ inline void ke_unmap_address(PDE* pde, UIntPtr phys_addr, UIntPtr virt_addr, UInt32 flags)
+ {
+ UInt16 pml4_index = (virt_addr >> 39) & 0x1FF;
+
+ if (pde->Pte[pml4_index].Present)
+ {
+ pde->Pte[pml4_index].Present = false;
+ pde->Pte[pml4_index].PhysicalAddress = 0;
+ pde->Pte[pml4_index].Rw = 0;
+ pde->Pte[pml4_index].User = 0;
+ pde->Pte[pml4_index].ExecDisable = 0;
+ }
+ }
+
EXTERN_C UChar In8(UInt16 port);
EXTERN_C UShort In16(UInt16 port);
EXTERN_C UInt In32(UInt16 port);
@@ -162,6 +225,8 @@ namespace NewOS::HAL
};
Void hal_system_get_cores(VoidPtr rsdPtr);
+ Void hal_send_start_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress);
+ Void hal_send_end_ipi(UInt32 apicId, UInt8 vector, UInt32 targetAddress);
/// @brief Processor specific structures.
namespace Detail