summaryrefslogtreecommitdiff
path: root/src/kernel/arch/amd64/sysenter.s
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/arch/amd64/sysenter.s')
-rw-r--r--src/kernel/arch/amd64/sysenter.s46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/kernel/arch/amd64/sysenter.s b/src/kernel/arch/amd64/sysenter.s
index 8d91c4a..8e07dbb 100644
--- a/src/kernel/arch/amd64/sysenter.s
+++ b/src/kernel/arch/amd64/sysenter.s
@@ -41,13 +41,19 @@ stored_rsp:
pagedir_current:
.skip 8
-// temporarily used for IRET
+/* fake stack used for IRET */
+.align 8
+iret_stack:
+iret_ip:
.skip 8
+iret_cs:
+ .quad SEG_r3code << 3 | 3
+iret_flags:
.skip 8
+iret_sp:
.skip 8
- .skip 8
- .skip 8
-dumb_stack:
+iret_ss:
+ .quad SEG_r3data << 3 | 3
.global _sysexit_real
.type _sysexit_real, @function
@@ -58,12 +64,6 @@ _sysexit_real:
mov %ax, %fs
mov %ax, %gs
- /* The state image referenced with an FXRSTOR instruction must have
- * been saved using an FXSAVE instruction or be in the same format
- * as required [...] will result in an incorrect state restoration. */
- // TODO will probably end up fucking something up in a hard to debug way
- // sorry, future me. hopefully you have learned something from this
- fxrstor (_sysexit_regs + 128)
mov $_sysexit_regs, %rsp
pop %r15
pop %r14
@@ -78,23 +78,25 @@ _sysexit_real:
pop %rdi
pop %rsi
pop %rbp
- pop (stored_rsp)
+ pop (iret_sp)
pop %rbx
pop %rdx
pop %rcx
pop %rax
- // enable paging
+ pop (iret_ip)
+ pop (iret_flags)
+
+ /* The state image referenced with an FXRSTOR instruction must have
+ * been saved using an FXSAVE instruction or be in the same format
+ * as required [...] will result in an incorrect state restoration. */
+ fxrstor (%rsp)
+
mov (pagedir_current), %rsp
mov %rsp, %cr3
- mov $dumb_stack, %rsp
- push $(SEG_r3data << 3 | 3) /* SS */
- push (stored_rsp) /* SP */
- push %r11 /* FLAGS */
- push $(SEG_r3code << 3 | 3) /* CS */
- push %rcx /* IP */
+ mov $iret_stack, %rsp
iretq
sysenter_stage1:
@@ -105,8 +107,12 @@ sysenter_stage1:
mov $pml4_identity, %rsp
mov %rsp, %cr3
- fxsave (_sysexit_regs + 128)
- mov $(_sysexit_regs + 128), %rsp
+ mov $(_sysexit_regs + 144), %rsp
+ fxsave (%rsp)
+
+ push %r11 /* flags */
+ push %rcx /* ip */
+
push %rax
push %rcx
push %rdx