From 9b475d3db3275d4c34f02161ae70ced5595a0fdb Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Wed, 21 Feb 2024 20:06:35 +0100 Subject: 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. --- kernel/cpu/arch_inst.s | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 kernel/cpu/arch_inst.s (limited to 'kernel/cpu/arch_inst.s') 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 -- cgit v1.2.3