summaryrefslogtreecommitdiff
path: root/kc/core/cpu/cpu_thread.S
diff options
context:
space:
mode:
authorAda Christine <adachristine18@gmail.com>2026-05-20 23:04:06 +0000
committerAda Christine <adachristine18@gmail.com>2026-05-20 23:04:06 +0000
commitedc42358664e9d70227e274273321ab032394a7e (patch)
tree54fd2de509c9c3cae911cad04328308f28afb0cc /kc/core/cpu/cpu_thread.S
parent0e61096ab498c12ffd0fd2eb993deb31a0a50b09 (diff)
new thread code works fine
Diffstat (limited to 'kc/core/cpu/cpu_thread.S')
-rw-r--r--kc/core/cpu/cpu_thread.S57
1 files changed, 57 insertions, 0 deletions
diff --git a/kc/core/cpu/cpu_thread.S b/kc/core/cpu/cpu_thread.S
new file mode 100644
index 0000000..c4d04e1
--- /dev/null
+++ b/kc/core/cpu/cpu_thread.S
@@ -0,0 +1,57 @@
+.section .text
+
+.extern arch_terminate_thread
+
+.global arch_begin_thread
+arch_begin_thread:
+ movq %rdi, %rax
+ movq %rsi, %rdi
+ pushq %rdx
+ pushq %rbp
+ movq %rsp, %rbp
+ andq $-16, %rsp
+ callq *%rax
+ movq %rax, %rdi
+ movq 8(%rbp), %rsi
+ callq arch_terminate_thread
+
+.global arch_swap_thread_stack
+arch_swap_thread_stack:
+ pushq %rsp
+ pushq %rbp
+ pushq %rax
+ pushq %rbx
+ pushq %rcx
+ pushq %rdx
+ pushq %rdi
+ pushq %rsi
+ pushq %r8
+ pushq %r9
+ pushq %r10
+ pushq %r11
+ pushq %r12
+ pushq %r13
+ pushq %r14
+ pushq %r15
+ movq %rsp, (%rdi)
+ .Lenter_thread:
+ movq %rsi, %rsp
+ popq %r15
+ popq %r14
+ popq %r13
+ popq %r12
+ popq %r11
+ popq %r10
+ popq %r9
+ popq %r8
+ popq %rsi
+ popq %rdi
+ popq %rdx
+ popq %rcx
+ popq %rbx
+ popq %rax
+ popq %rbp
+ popq %rsp
+ retq
+
+