diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-09-01 09:23:10 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-09-01 09:23:10 +0200 |
| commit | e757bb6a90c98f53995e4828d68eba26a2327540 (patch) | |
| tree | feabdd3047b67f21ee0e6f76ccd89f8458493e77 /dev/ZKA/HALKit | |
| parent | 21a0081ac9d9a8abe66cc6a248b5363768de1dc9 (diff) | |
[ IMP ] Found out the issue of ring 3 switch.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA/HALKit')
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm | 9 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm | 2 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx | 18 | ||||
| -rw-r--r-- | dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx | 3 |
4 files changed, 28 insertions, 4 deletions
diff --git a/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm b/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm index 847c609e..89cb4078 100644 --- a/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm +++ b/dev/ZKA/HALKit/AMD64/HalInterruptAPI.asm @@ -267,7 +267,7 @@ hal_switch_to_user_code: mov rbx, 0x28 mov es, rbx - mov rsp, [hal_user_code_stack_end] + mov rsp, hal_user_code_stack_end mov rcx, hal_user_code_start mov r11, 0x0202 @@ -275,9 +275,14 @@ hal_switch_to_user_code: o64 sysret hal_user_code_start: -L0: + hlt nop jmp $ +hal_user_code_end: + +section .data + +hal_user_code_sz: dq hal_user_code_end - hal_user_code_start section .bss diff --git a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm index f20ffcee..f5f36b27 100644 --- a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm +++ b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm @@ -50,7 +50,7 @@ mp_do_context_switch: ;; Swap registers, since it's the other way around. mov rcx, r12 ;; code ptr - mov rsp, [r11] ;; stack ptr + mov rsp, r11 ;; stack ptr mov r11, 0x0202 ;; rcx and rdx already set. diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx index 4e1b500c..82eea45e 100644 --- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx +++ b/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx @@ -135,5 +135,23 @@ namespace Kernel // Now allocate the page. return hal_try_alloc_new_page(rw, user, size); } + + auto hal_free_page(VoidPtr page_ptr) -> Bool + { + if (!page_ptr) + return false; + + Detail::VIRTUAL_MEMORY_HEADER* result = reinterpret_cast<Detail::VIRTUAL_MEMORY_HEADER*>((UIntPtr)page_ptr - sizeof(Detail::VIRTUAL_MEMORY_HEADER)); + + if (result->Magic != cVMHMagic) + return false; + + if (result->Present != true) + return true; + + result->Present = false; + + return true; + } } // namespace HAL } // namespace Kernel diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx index 30cb7911..38666e7e 100644 --- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx +++ b/dev/ZKA/HALKit/AMD64/HalPageAlloc.hxx @@ -82,7 +82,8 @@ namespace Kernel::HAL PageTable64 ALIGN(kPTEAlign) Pte[kPTEMax]; }; - VoidPtr hal_alloc_page(Boolean rw, Boolean user, SizeT size); + auto hal_alloc_page(Boolean rw, Boolean user, SizeT size) -> VoidPtr; + auto hal_free_page(VoidPtr page_ptr) -> Bool; } // namespace Kernel::HAL namespace Kernel |
