aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src/boot
diff options
context:
space:
mode:
authorFabian Imhof <fabian.imhof@ost.ch>2025-04-06 07:47:27 +0000
committerFabian Imhof <fabian.imhof@ost.ch>2025-04-06 07:47:27 +0000
commit350aedae0e50749f9821ac7dc6b8316cf35f24bb (patch)
tree21f3c67a1648d5950718dc5b0db32e45b870641f /arch/x86_64/src/boot
parenta8852f91967a7e55e62e30f5cc07d076092b8b78 (diff)
downloadteachos-350aedae0e50749f9821ac7dc6b8316cf35f24bb.tar.xz
teachos-350aedae0e50749f9821ac7dc6b8316cf35f24bb.zip
wip context switch in asm
Diffstat (limited to 'arch/x86_64/src/boot')
-rw-r--r--arch/x86_64/src/boot/boot.s29
1 files changed, 29 insertions, 0 deletions
diff --git a/arch/x86_64/src/boot/boot.s b/arch/x86_64/src/boot/boot.s
index 7932045..85ae1a1 100644
--- a/arch/x86_64/src/boot/boot.s
+++ b/arch/x86_64/src/boot/boot.s
@@ -352,6 +352,35 @@ prepare_page_maps:
.section .boot_text, "ax", @progbits
.code64
+.global context_switch
+context_switch:
+ // ring 3 data with bottom 2 bits set for ring 3
+ mov $((4 * 16) | 3), %rax
+ mov %rax, %ds
+ mov %rax, %es
+ mov %rax, %fs
+ mov %rax, %gs
+ // SS is handled by iret https://wiki.osdev.org/Getting_to_Ring_3
+
+ // set up the stack frame iret expects
+ mov %rsp, %rax
+ // user data selector
+ push $((4 * 16) | 3)
+ // current exp
+ push %rax
+ // push eflags
+ pushf
+ // push code selector (ring 3 code with bottom 2 bits set for ring 3)
+ push $((3 * 16) | 3)
+ // instruction address to return to
+ push test_function
+
+ iret
+
+test_function:
+ cli
+ ret
+
_transition_to_long_mode:
xor %rax, %rax
mov %rax, %ss