Skip to content

Commit

Permalink
arch,traps: set default stack segment selector
Browse files Browse the repository at this point in the history
Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Nov 7, 2023
1 parent a4be3d2 commit 6f9a740
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions arch/x86/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions include/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit 6f9a740

Please sign in to comment.