From b163fa4521c4ee1c37de53fb1ad30bc48890ff33 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 20 Aug 2017 10:19:25 +0200 Subject: [PATCH 1/3] reload the segment descriptors after loading GDT --- arch/x86/kernel/entry.asm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kernel/entry.asm b/arch/x86/kernel/entry.asm index fadc21c3d..28d49943b 100644 --- a/arch/x86/kernel/entry.asm +++ b/arch/x86/kernel/entry.asm @@ -264,6 +264,16 @@ extern gp ; C as 'extern void gdt_flush();' gdt_flush: lgdt [gp] + ; reload the segment descriptors + mov eax, 0x10 + mov ds, eax + mov es, eax + mov ss, eax + xor eax, eax + mov fs, eax + mov gs, eax + jmp 0x08:flush2 +flush2: ret ; The first 32 interrupt service routines (ISR) entries correspond to exceptions. From e38722c7f4d7dddf8a86826fb14e7b77a99fbdf2 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 20 Aug 2017 10:36:49 +0200 Subject: [PATCH 2/3] remove 32bit code --- arch/x86/kernel/entry.asm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/entry.asm b/arch/x86/kernel/entry.asm index 28d49943b..022f0209c 100644 --- a/arch/x86/kernel/entry.asm +++ b/arch/x86/kernel/entry.asm @@ -272,7 +272,10 @@ gdt_flush: xor eax, eax mov fs, eax mov gs, eax - jmp 0x08:flush2 + ; create pseudo interrupt to set cs + push 0x08 + push flush2 + iretq flush2: ret From 3b8e6791ee47d6210870515de58b95ca87e700d5 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 20 Aug 2017 10:51:52 +0200 Subject: [PATCH 3/3] create valid pseudo interrupt to set cs --- arch/x86/kernel/entry.asm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/entry.asm b/arch/x86/kernel/entry.asm index 022f0209c..5775dfbcc 100644 --- a/arch/x86/kernel/entry.asm +++ b/arch/x86/kernel/entry.asm @@ -273,11 +273,13 @@ gdt_flush: mov fs, eax mov gs, eax ; create pseudo interrupt to set cs - push 0x08 - push flush2 + push QWORD 0x10 ; SS + push rsp ; RSP + add QWORD [rsp], 0x08 ; => value of rsp before the creation of a pseudo interrupt + pushfq ; RFLAGS + push QWORD 0x08 ; CS + push QWORD rollback ; RIP iretq -flush2: - ret ; The first 32 interrupt service routines (ISR) entries correspond to exceptions. ; Some exceptions will push an error code onto the stack which is specific to