diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-09-02 00:03:03 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-09-02 00:05:22 +0200 |
| commit | ab69a596a336d9874555672a154c4f48e0ed1020 (patch) | |
| tree | 5cb4abec909c1b2a63e016d60b1a83d471be1d6a /dev/ZKA/HALKit | |
| parent | a65b375680f63f5d4621941f49834255b9a567fb (diff) | |
[ IMP ] Reserve system call interrupt for user code only.
[ FIX ] Fix mm_update_page function, which pde index instead of pte
index.
[ IMP ] New .drawio files.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA/HALKit')
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx | 22 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm | 17 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm | 1 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx | 35 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalProcessor.cxx | 28 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalSchedulerCore.cxx | 2 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalUtils.asm | 2 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/Processor.hxx | 2 |
8 files changed, 68 insertions, 41 deletions
diff --git a/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx b/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx index 2e61b249..adf8de2e 100644 --- a/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx +++ b/dev/ZKA/HALKit/AMD64/HalDescriptorLoader.cxx @@ -49,21 +49,21 @@ namespace Kernel::HAL Void IDTLoader::Load(Register64& idt) { - volatile ::Kernel::UIntPtr** baseIdt = (volatile ::Kernel::UIntPtr**)idt.Base; + volatile ::Kernel::UIntPtr** ptr_ivt = (volatile ::Kernel::UIntPtr**)idt.Base; - for (UInt16 i = 0; i < kKernelIdtSize; ++i) + for (UInt16 idt_indx = 0; idt_indx < kKernelIdtSize; ++idt_indx) { - MUST_PASS(baseIdt[i]); + MUST_PASS(ptr_ivt[idt_indx]); - Detail::kInterruptVectorTable[i].Selector = kGdtCodeSelector; - Detail::kInterruptVectorTable[i].Ist = 0x0; - Detail::kInterruptVectorTable[i].TypeAttributes = kInterruptGate; - Detail::kInterruptVectorTable[i].OffsetLow = ((UIntPtr)baseIdt[i] & __INT16_MAX__); - Detail::kInterruptVectorTable[i].OffsetMid = (((UIntPtr)baseIdt[i] >> 16) & __INT16_MAX__); - Detail::kInterruptVectorTable[i].OffsetHigh = - (((UIntPtr)baseIdt[i] >> 32) & __INT32_MAX__); + Detail::kInterruptVectorTable[idt_indx].Selector = idt_indx == kSyscallRoute ? kGdtUserCodeSelector : kGdtCodeSelector; + Detail::kInterruptVectorTable[idt_indx].Ist = 0; + Detail::kInterruptVectorTable[idt_indx].TypeAttributes = kInterruptGate; + Detail::kInterruptVectorTable[idt_indx].OffsetLow = ((UIntPtr)ptr_ivt[idt_indx] & __INT16_MAX__); + Detail::kInterruptVectorTable[idt_indx].OffsetMid = (((UIntPtr)ptr_ivt[idt_indx] >> 16) & __INT16_MAX__); + Detail::kInterruptVectorTable[idt_indx].OffsetHigh = + (((UIntPtr)ptr_ivt[idt_indx] >> 32) & __INT32_MAX__); - Detail::kInterruptVectorTable[i].Zero = 0x0; + Detail::kInterruptVectorTable[idt_indx].Zero = 0x0; } Detail::kRegIdt.Base = reinterpret_cast<UIntPtr>(Detail::kInterruptVectorTable); diff --git a/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm b/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm index 2eae172a..5fe8b1aa 100644 --- a/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm +++ b/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm @@ -37,6 +37,7 @@ extern idt_handle_gpf extern idt_handle_pf extern ke_io_write extern idt_handle_ud +extern idt_handle_generic section .text @@ -64,7 +65,21 @@ __ZKA_INT_6: iretq IntNormal 7 -IntExp 8 + +;; Invalid opcode interrupt +__ZKA_INT_8: + cli + + push rax + + mov rcx, rsp + call idt_handle_generic + + pop rax + + sti + iretq + IntNormal 9 IntExp 10 IntExp 11 diff --git a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm index b9892d74..42d5ffe5 100644 --- a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm +++ b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm @@ -22,6 +22,7 @@ section .text ;; rdx: stack ptr. mp_do_context_switch: mov r11, 0x0202 + mov rsp, rdx o64 sysret ;; @brief Gets the current stack frame. diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx index 81ea2bd8..0cfa5ed8 100644 --- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx +++ b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx @@ -40,18 +40,23 @@ EXTERN_C Kernel::VoidPtr hal_read_cr3(); // @brief Page table. namespace Kernel::HAL { - struct PACKED PageTable64 final + struct PACKED ZKA_PTE final { - bool Present : 1; - bool Rw : 1; - bool User : 1; - bool Wt : 1; - bool Cache : 1; - bool Accessed : 1; - Kernel::Int32 Reserved : 6; - Kernel::UInt64 PhysicalAddress : 36; - Kernel::Int32 Reserved1 : 15; - bool ExecDisable : 1; + UInt8 Present : 1; + UInt8 Rw : 1; + UInt8 User : 1; + UInt8 Wt : 1; + UInt8 Cache : 1; + UInt8 Accessed : 1; + UInt8 Dirty : 1; + UInt8 PageSize : 1; + UInt8 Global : 1; + UInt8 Available : 3; + UInt64 PhysicalAddress : 39; + UInt8 Reserved : 6; + UInt8 ProtectionKey : 1; + UInt8 ExecDisable : 1; + UInt8 ReservedEx : 3; }; namespace Detail @@ -77,9 +82,9 @@ namespace Kernel::HAL } } // namespace Detail - struct PageDirectory64 final + struct ZKA_PDE final { - PageTable64 ALIGN(kPTEAlign) Pte[kPTEMax]; + ZKA_PTE ALIGN(kPTEAlign) Pte[kPTEMax]; }; auto hal_alloc_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr; @@ -88,6 +93,6 @@ namespace Kernel::HAL namespace Kernel { - typedef HAL::PageTable64 PTE; - typedef HAL::PageDirectory64 PDE; + typedef HAL::ZKA_PTE PTE; + typedef HAL::ZKA_PDE PDE; } // namespace Kernel diff --git a/dev/ZKA/HALKit/AMD64/HalProcessor.cxx b/dev/ZKA/HALKit/AMD64/HalProcessor.cxx index dffaed3e..457752b7 100644 --- a/dev/ZKA/HALKit/AMD64/HalProcessor.cxx +++ b/dev/ZKA/HALKit/AMD64/HalProcessor.cxx @@ -18,25 +18,31 @@ namespace Kernel::HAL { EXTERN_C Int32 mm_update_page(VoidPtr pd_base, VoidPtr phys_addr, VoidPtr virt_addr, UInt32 flags) { - UIntPtr pde_idx = (UIntPtr)virt_addr >> 22; - UIntPtr pte_idx = (UIntPtr)virt_addr >> 12 & 0x03FF; + UIntPtr pte_idx = (UIntPtr)virt_addr >> 12; - volatile PTE* pte = (volatile PTE*)((UIntPtr)pd_base + (kPTEAlign * pde_idx)); + volatile PTE* pte = (volatile PTE*)((UIntPtr)pd_base + (kPTEAlign * pte_idx)); if (pte) { - if ((flags & eFlagsSetPhysAddress)) - pte->PhysicalAddress = (UInt32)(UIntPtr)phys_addr; + if (flags & eFlagsSetPhysAddress) + pte->PhysicalAddress = (UIntPtr)phys_addr >> 12; - pte->Present = flags & eFlagsPresent; - pte->Rw = flags & eFlagsRw; - pte->User = flags & eFlagsUser; - pte->ExecDisable = flags & eFlagsExecDisable; + if (flags & eFlagsPresent) + pte->Present = flags & eFlagsPresent; - return 0; + if (flags & eFlagsRw) + pte->Rw = flags & eFlagsRw; + + if (flags & eFlagsUser) + pte->User = flags & eFlagsUser; + + if (flags & eFlagsExecDisable) + pte->ExecDisable = flags & eFlagsExecDisable; + + return Yes; } - return 1; + return No; } Void Out8(UInt16 port, UInt8 value) diff --git a/dev/ZKA/HALKit/AMD64/HalSchedulerCore.cxx b/dev/ZKA/HALKit/AMD64/HalSchedulerCore.cxx index b3449026..e8a89f85 100644 --- a/dev/ZKA/HALKit/AMD64/HalSchedulerCore.cxx +++ b/dev/ZKA/HALKit/AMD64/HalSchedulerCore.cxx @@ -14,7 +14,7 @@ Void UserProcess::SetEntrypoint(VoidPtr imageStart) noexcept if (imageStart == nullptr) this->Crash(); - HAL::mm_update_page(hal_read_cr3(), 0, imageStart, HAL::eFlagsPresent | HAL::eFlagsRw | HAL::eFlagsUser); + HAL::mm_update_page(hal_read_cr3(), 0, imageStart, HAL::eFlagsPresent | HAL::eFlagsUser); this->Image = imageStart; } diff --git a/dev/ZKA/HALKit/AMD64/HalUtils.asm b/dev/ZKA/HALKit/AMD64/HalUtils.asm index 91bf216e..0e4caf2b 100644 --- a/dev/ZKA/HALKit/AMD64/HalUtils.asm +++ b/dev/ZKA/HALKit/AMD64/HalUtils.asm @@ -18,7 +18,7 @@ section .text rt_install_tib: mov rcx, gs ;; TIB -> Thread Information Block - mov rdx, fs ;; PIB -> UserProcess Information Block + mov rdx, fs ;; PIB -> Process Information Block ret ;; //////////////////////////////////////////////////// ;; diff --git a/dev/ZKA/HALKit/AMD64/Processor.hxx b/dev/ZKA/HALKit/AMD64/Processor.hxx index ee68a7ed..570346c1 100644 --- a/dev/ZKA/HALKit/AMD64/Processor.hxx +++ b/dev/ZKA/HALKit/AMD64/Processor.hxx @@ -33,7 +33,7 @@ EXTERN_C #define kTrapGate (0xEF) #define kTaskGate (0b10001100) #define kGdtCodeSelector (0x08) -#define kGdtUserCodeSelector (0x10) +#define kGdtUserCodeSelector (0x2b) namespace Kernel { |
