summaryrefslogtreecommitdiff
path: root/kernel/cpu/arch_inst.s
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-02-21 20:06:35 +0100
committerAnton Kling <anton@kling.gg>2024-02-21 20:06:35 +0100
commit9b475d3db3275d4c34f02161ae70ced5595a0fdb (patch)
tree0c50e4af3ce52017f295c44f6f4319e4a43de085 /kernel/cpu/arch_inst.s
parent6c9cb0bd8ceb039ce387c850e25adc6f99cfcd6f (diff)
Kernel: Remove all inline assembly.
Now the kernel does not rely upon inline assembly which is often very error prone. This also means that the kernel could probably be compiled with any c99 compiler which would help future bootstrapping.
Diffstat (limited to 'kernel/cpu/arch_inst.s')
-rw-r--r--kernel/cpu/arch_inst.s60
1 files changed, 60 insertions, 0 deletions
diff --git a/kernel/cpu/arch_inst.s b/kernel/cpu/arch_inst.s
new file mode 100644
index 0000000..aaf34b6
--- /dev/null
+++ b/kernel/cpu/arch_inst.s
@@ -0,0 +1,60 @@
+.intel_syntax noprefix
+.global get_current_sp
+.global get_current_sbp
+.global halt
+.global get_cr2
+.global set_sp
+.global set_sbp
+.global flush_tlb
+.global set_cr3
+.global get_cr3
+.global enable_paging
+
+get_current_sp:
+ mov eax, esp
+ sub eax, 4
+ ret
+
+get_current_sbp:
+ mov eax, ebp
+ ret
+
+set_sp:
+ mov ecx, [esp] # store the return address in ecx
+ mov eax, [esp + 4]
+ mov esp, eax
+ jmp ecx # jump to the return address instead of doing a ret as the stack values may have changed
+
+set_sbp:
+ mov eax, [esp + 4]
+ mov ebp, eax
+ ret
+
+halt:
+ hlt
+ jmp $
+ ret
+
+get_cr2:
+ mov eax, cr2
+ ret
+
+flush_tlb:
+ mov eax, cr3
+ mov cr3, eax
+ ret
+
+set_cr3:
+ mov eax, [esp + 4]
+ mov cr3, eax
+ ret
+
+get_cr3:
+ mov eax, cr3
+ ret
+
+enable_paging:
+ mov eax, cr0
+ or eax, 0b10000000000000000000000000000000
+ mov cr0, eax
+ ret