summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA/HALKit
diff options
context:
space:
mode:
Diffstat (limited to 'dev/ZKA/HALKit')
-rw-r--r--dev/ZKA/HALKit/AMD64/HalTimer.cxx3
-rw-r--r--dev/ZKA/HALKit/AMD64/Processor.hxx70
2 files changed, 23 insertions, 50 deletions
diff --git a/dev/ZKA/HALKit/AMD64/HalTimer.cxx b/dev/ZKA/HALKit/AMD64/HalTimer.cxx
index 33b0e00f..f88d1143 100644
--- a/dev/ZKA/HALKit/AMD64/HalTimer.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalTimer.cxx
@@ -79,8 +79,7 @@ Int32 HardwareTimer::Wait() noexcept
*(fDigitalTimer + cHPETCompValue) = prev + ticks;
- while (*(fDigitalTimer + cHPETCounterValue) < (ticks))
- kcout << "MS: " << number(*(fDigitalTimer + cHPETCounterValue)) << endl;
+ while (*(fDigitalTimer + cHPETCounterValue) < (ticks));
return 0;
}
diff --git a/dev/ZKA/HALKit/AMD64/Processor.hxx b/dev/ZKA/HALKit/AMD64/Processor.hxx
index d1bda9ef..93540c34 100644
--- a/dev/ZKA/HALKit/AMD64/Processor.hxx
+++ b/dev/ZKA/HALKit/AMD64/Processor.hxx
@@ -35,10 +35,10 @@ EXTERN_C
#define IsActiveLow(FLG) (FLG & 2)
#define IsLevelTriggered(FLG) (FLG & 8)
-#define kInterruptGate (0x8E)
-#define kTrapGate (0xEF)
-#define kTaskGate (0b10001100)
-#define kGdtCodeSelector (0x08)
+#define kInterruptGate (0x8E)
+#define kTrapGate (0xEF)
+#define kTaskGate (0b10001100)
+#define kGdtCodeSelector (0x08)
#define kGdtUserCodeSelector (0x10)
namespace Kernel
@@ -64,42 +64,35 @@ namespace Kernel::HAL
/// @brief Virtual memory flags.
enum
{
+ eFlagsPresent,
eFlagsUser,
eFlagsRw,
- eFlagsExecDisable
+ eFlagsExecDisable,
+ eFlagsSetPhysAddress,
+ eFlagsCount,
};
- /// @brief Map address to PDE.
- /// @param pde a valid page directory.
+ /// @brief Updates a PTE from pd_base.
+ /// @param pd_base a valid PDE address.
/// @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)
+ inline Int32 mm_update_page(VoidPtr pd_base, UIntPtr phys_addr, UIntPtr virt_addr, UInt32 flags)
{
- UInt16 pml4_index = (virt_addr >> 39) & 0x1FF;
+ UIntPtr pde_idx = (UIntPtr)virt_addr >> 22;
+ UIntPtr pte_idx = (UIntPtr)virt_addr >> 12 & 0x03FF;
- if (pde && !pde->Pte[pml4_index].Present)
- {
- pde->Pte[pml4_index].Present = true;
-
- 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;
-
- kcout << "newoskrnl: PTE is present now.\r";
+ volatile PTE* pte = (volatile PTE*)((UIntPtr)pd_base + (kPTEAlign * pde_idx));
- return 0;
- }
- else
+ if (pte)
{
- kcout << "newoskrnl: PM is already present.\r";
-
- kcout << "PhysicalAddress: " << hex_number(pde->Pte[pml4_index].PhysicalAddress);
- kcout << "\r";
+ if ((flags & eFlagsSetPhysAddress))
+ pte->PhysicalAddress = phys_addr;
- kcout << "User: " << (pde->Pte[pml4_index].User ? "true" : "false") << "\r";
- kcout << "RW: " << (pde->Pte[pml4_index].Rw ? "true" : "false") << "\r";
+ pte->Present = flags & eFlagsPresent;
+ pte->Rw = flags & eFlagsRw;
+ pte->User = flags & eFlagsUser;
+ pte->ExecDisable = flags & eFlagsExecDisable;
return 0;
}
@@ -107,25 +100,6 @@ namespace Kernel::HAL
return 1;
}
- /// @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);
@@ -340,7 +314,7 @@ EXTERN_C Kernel::Void hal_load_gdt(Kernel::HAL::RegisterGDT ptr);
#define kKernelIdtSize 0x100
#define kKernelInterruptId 0x32
-inline Kernel::VoidPtr kKernelVMHStart = nullptr;
+inline Kernel::VoidPtr kKernelVMHStart = nullptr;
inline Kernel::VoidPtr kKernelVirtualStart = nullptr;
inline Kernel::UIntPtr kKernelVirtualSize = 0UL;