diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-06-06 10:27:55 +0000 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-06-06 10:27:55 +0000 |
| commit | 4e75e05a20ddd0dbca982e8f3bc2ea8043ed3a3f (patch) | |
| tree | 95409c0e32b644578b94a5c230417da684d79dc9 /Kernel/HALKit/AMD64/Processor.hpp | |
| parent | f5081a8f9a8537ad5be5d639955cd1d0e68a9e1d (diff) | |
| parent | 9994b8f3f88131f41be1061fb0947177e66dc7b0 (diff) | |
Merged in MHR-23 (pull request #14)
Draft: MHR-23
Diffstat (limited to 'Kernel/HALKit/AMD64/Processor.hpp')
| -rw-r--r-- | Kernel/HALKit/AMD64/Processor.hpp | 65 |
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 |
