From 6f9a740edf47298b2d7eb40008473f646c148d7f Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Thu, 2 Nov 2023 10:30:52 +0100 Subject: [PATCH] arch,traps: set default stack segment selector Signed-off-by: Pawel Wieczorkiewicz --- arch/x86/traps.c | 1 + include/lib.h | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/arch/x86/traps.c b/arch/x86/traps.c index a44d2609..0429edbc 100644 --- a/arch/x86/traps.c +++ b/arch/x86/traps.c @@ -112,6 +112,7 @@ static void init_gdt(percpu_t *percpu) { barrier(); lgdt(&percpu->gdt_ptr); + write_ss(__KERN_DS); write_gs(GDT_PERCPU << 3); wrmsr(MSR_KERNEL_GS_BASE, 0x0); diff --git a/include/lib.h b/include/lib.h index bce6f233..d4bef3d8 100644 --- a/include/lib.h +++ b/include/lib.h @@ -239,6 +239,10 @@ static inline unsigned long read_gs(void) { return gs; } +static inline void write_ss(unsigned long ss) { + asm volatile("mov %0, %%ss" ::"r"(ss)); +} + static inline void write_gs(unsigned long gs) { asm volatile("mov %0, %%gs" ::"r"(gs)); }