summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/HALKit/AMD64/HalSMPCoreManager.asm
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-15 18:35:34 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-15 18:35:34 +0200
commitf3d931aa7cfaf96baef8383b59a8938779541ee7 (patch)
treefdb9fc51badb3dbd03e46ab0766a49d9522e13e2 /dev/Kernel/HALKit/AMD64/HalSMPCoreManager.asm
parent86640816e8b1d3595365f1fcc8a2a9e61fb40ff1 (diff)
[IMP] Moved source code into dev/ folder.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/HALKit/AMD64/HalSMPCoreManager.asm')
-rw-r--r--dev/Kernel/HALKit/AMD64/HalSMPCoreManager.asm81
1 files changed, 81 insertions, 0 deletions
diff --git a/dev/Kernel/HALKit/AMD64/HalSMPCoreManager.asm b/dev/Kernel/HALKit/AMD64/HalSMPCoreManager.asm
new file mode 100644
index 00000000..3c53d49d
--- /dev/null
+++ b/dev/Kernel/HALKit/AMD64/HalSMPCoreManager.asm
@@ -0,0 +1,81 @@
+;; /*
+;; * ========================================================
+;; *
+;; * Kernel
+;; * Copyright ZKA Technologies., all rights reserved.
+;; *
+;; * ========================================================
+;; */
+
+[bits 64]
+
+[global rt_get_current_context]
+[global rt_do_context_switch]
+[global _hal_spin_core]
+[extern _hal_switch_context]
+[extern _hal_leak_current_context]
+
+section .text
+
+;; writes to rdx the stackframe inside rcx.
+;; rcx: Stack Pointer
+;; rdx: SMP core address.
+rt_do_context_switch:
+ push rax
+ call _hal_switch_context
+ pop rax
+
+ ;; Now grab newly allocated process's stack frame.
+
+ push rax
+ call _hal_leak_current_context
+ mov rax, r9
+ pop rax
+
+ ;; Take care of context switching within AP.
+
+ mov r9, rax
+
+ mov rbp, [r9 + (8 * 5)]
+ mov rsp, [r9 + (8 * 6)]
+
+ mov gs, [r9 + (8 * 19)]
+ mov fs, [r9 + (8 * 20)]
+
+ mov rcx, [r9 + (8 * 3)]
+ mov rdx, [r9 + (8 * 4)]
+ mov rbx, [r9 + (8 * 7)]
+ mov rax, [r9 + (8 * 8)]
+ movq xmm0, [r9 + (8 * 9)]
+ movq xmm1, [r9 + (8 * 10)]
+
+ mov r8, [r9 + (8 * 11)]
+ mov r10, [r9 + (8 * 13)]
+ mov r11, [r9 + (8 * 14)]
+ mov r12, [r9 + (8 * 15)]
+ mov r13, [r9 + (8 * 16)]
+ mov r14, [r9 + (8 * 17)]
+ mov r15, [r9 + (8 * 18)]
+
+ fldcw word [r9 + (8 * 21)]
+
+ mov r9, [r9 + (8 * 12)]
+
+ retfq
+
+;; gets the current stack frame.
+rt_get_current_context:
+ push rax
+
+ call _hal_leak_current_context
+
+ mov rax, r9
+ pop rax
+
+ mov r9, rax
+
+ retfq
+
+_hal_spin_core:
+ jmp $
+ ret