From 3870cac25e895dcca9535d03a79d5ae96b5b023e Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Sun, 28 Jul 2024 10:55:51 +0200 Subject: [IMP} Hal Utils API. Signed-off-by: Amlal EL Mahrouss --- Kernel/HALKit/AMD64/HalInstallTIB.asm | 43 ------------------------------ Kernel/HALKit/AMD64/HalUtils.asm | 49 +++++++++++++++++++++++++++++++++++ Kernel/amd64-efi.make | 2 +- 3 files changed, 50 insertions(+), 44 deletions(-) delete mode 100644 Kernel/HALKit/AMD64/HalInstallTIB.asm create mode 100644 Kernel/HALKit/AMD64/HalUtils.asm (limited to 'Kernel') diff --git a/Kernel/HALKit/AMD64/HalInstallTIB.asm b/Kernel/HALKit/AMD64/HalInstallTIB.asm deleted file mode 100644 index 00fe2ad8..00000000 --- a/Kernel/HALKit/AMD64/HalInstallTIB.asm +++ /dev/null @@ -1,43 +0,0 @@ -;; /* -;; * ======================================================== -;; * -;; * Kernel -;; * Copyright ZKA Technologies, all rights reserved. -;; * -;; * ======================================================== -;; */ - -[bits 64] - -[global rt_install_tib] - -section .text - -;; changed: rs, fs -;; expected: rcx, rdx - -rt_install_tib: - mov rcx, gs ;; TIB -> Thread Information Block - mov rdx, fs ;; PIB -> Process Information Block - ret - -;; //////////////////////////////////////////////////// ;; - -[global rt_jump_user_mode] - -;; @used rcx, address to jump on. -;; @note adjusted for long mode. -rt_jump_user_mode: - mov ax, (6 * 8) | 3 ; user data segment with RPL 3 - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax ; SS is handled by iret - - mov rax, rsp - push (6 * 8) | 3 - push rax - pushf - push (5 * 8) | 3 - push rcx - iretq diff --git a/Kernel/HALKit/AMD64/HalUtils.asm b/Kernel/HALKit/AMD64/HalUtils.asm new file mode 100644 index 00000000..6681a692 --- /dev/null +++ b/Kernel/HALKit/AMD64/HalUtils.asm @@ -0,0 +1,49 @@ +;; /* +;; * ======================================================== +;; * +;; * Kernel +;; * Copyright ZKA Technologies, all rights reserved. +;; * +;; * ======================================================== +;; */ + +[bits 64] + +[global rt_install_tib] + +section .text + +;; changed: rs, fs +;; expected: rcx, rdx + +rt_install_tib: + mov rcx, gs ;; TIB -> Thread Information Block + mov rdx, fs ;; PIB -> Process Information Block + ret + +;; //////////////////////////////////////////////////// ;; + +[global rt_jump_user_mode] + +;; @used rcx, address to jump on. +;; @note adjusted for long mode. +rt_jump_user_mode: + cmp rcx, 0 + je rt_jump_user_mode_failed + + mov ax, (6 * 8) | 3 ; user data segment with RPL 3 + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax ; SS is handled by iret + + mov rax, rsp + push (6 * 8) | 3 + push rax + pushf + push (5 * 8) | 3 ; user code segment with RPL 3 + push rcx + iretq + ;; we just failed to validate the rcx, fallback and return to previous pc. +rt_jump_user_mode_failed: + ret \ No newline at end of file diff --git a/Kernel/amd64-efi.make b/Kernel/amd64-efi.make index e59034c9..a6bd3772 100644 --- a/Kernel/amd64-efi.make +++ b/Kernel/amd64-efi.make @@ -60,7 +60,7 @@ newos-amd64-epm: clean $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptAPI.asm $(ASM) $(ASMFLAGS) HALKit/AMD64/HalSMPCoreManager.asm $(ASM) $(ASMFLAGS) HALKit/AMD64/HalBoot.asm - $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInstallTIB.asm + $(ASM) $(ASMFLAGS) HALKit/AMD64/HalUtils.asm $(MOVEALL) OBJCOPY=x86_64-w64-mingw32-objcopy -- cgit v1.2.3