From f9eb40dbfbc9efcc197b0566f371dc5a880d7a9f Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 19 Sep 2020 17:18:39 +0300 Subject: [PATCH] cpu: properly reload segment registers after lgdt --- arch/amd64/hw/gdt_s.S | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/arch/amd64/hw/gdt_s.S b/arch/amd64/hw/gdt_s.S index e8c030d..d451540 100644 --- a/arch/amd64/hw/gdt_s.S +++ b/arch/amd64/hw/gdt_s.S @@ -2,7 +2,27 @@ .global amd64_gdt_load amd64_gdt_load: lgdt (%rdi) - // Not sure if CS reload is needed movw $0x28, %ax ltr %ax - retq + + mov %rsp, %rdx + mov $0x10, %rax + push %rax + push %rdx + + pushf + + mov $0x08, %rax + push %rax + lea 1f(%rip), %rax + push %rax + + iretq + +1: + mov $0x10, %rax + mov %rax, %ds + mov %rax, %es + mov %rax, %fs + mov %rax, %gs + ret