1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 18:37:36 +00:00

Kernel: Use the GS segment for the per-CPU struct

Right now we're using the FS segment for our per-CPU struct. On x86_64
there's an instruction to switch between a kernel and usermode GS
segment (swapgs) which we could use.

This patch doesn't update the rest of the code to use swapgs but it
prepares for that by using the GS segment instead of the FS segment.
This commit is contained in:
Gunnar Beutner 2021-07-02 14:02:36 +02:00 committed by Andreas Kling
parent 42d197cde7
commit 52f9aaa823
8 changed files with 36 additions and 36 deletions

View file

@ -21,7 +21,7 @@ namespace Kernel {
#if ARCH(X86_64)
# define MSR_FS_BASE 0xc0000100
# define MSR_GS_BASE 0xc0000102
# define MSR_GS_BASE 0xc0000101
#endif
class Thread;
@ -241,16 +241,16 @@ public:
ALWAYS_INLINE static Processor& current()
{
return *(Processor*)read_fs_ptr(__builtin_offsetof(Processor, m_self));
return *(Processor*)read_gs_ptr(__builtin_offsetof(Processor, m_self));
}
ALWAYS_INLINE static bool is_initialized()
{
return
#if ARCH(I386)
get_fs() == GDT_SELECTOR_PROC &&
get_gs() == GDT_SELECTOR_PROC &&
#endif
read_fs_u32(__builtin_offsetof(Processor, m_self)) != 0;
read_gs_u32(__builtin_offsetof(Processor, m_self)) != 0;
}
ALWAYS_INLINE void set_scheduler_data(SchedulerPerProcessorData& scheduler_data)
@ -286,19 +286,19 @@ public:
// to another processor, which would lead us to get the wrong thread.
// To avoid having to disable interrupts, we can just read the field
// directly in an atomic fashion, similar to Processor::current.
return (Thread*)read_fs_ptr(__builtin_offsetof(Processor, m_current_thread));
return (Thread*)read_gs_ptr(__builtin_offsetof(Processor, m_current_thread));
}
ALWAYS_INLINE static void set_current_thread(Thread& current_thread)
{
// See comment in Processor::current_thread
write_fs_u32(__builtin_offsetof(Processor, m_current_thread), FlatPtr(&current_thread));
write_gs_u32(__builtin_offsetof(Processor, m_current_thread), FlatPtr(&current_thread));
}
ALWAYS_INLINE static Thread* idle_thread()
{
// See comment in Processor::current_thread
return (Thread*)read_fs_ptr(__builtin_offsetof(Processor, m_idle_thread));
return (Thread*)read_gs_ptr(__builtin_offsetof(Processor, m_idle_thread));
}
ALWAYS_INLINE u32 get_id() const
@ -314,7 +314,7 @@ public:
ALWAYS_INLINE static u32 id()
{
// See comment in Processor::current_thread
return read_fs_ptr(__builtin_offsetof(Processor, m_cpu));
return read_gs_ptr(__builtin_offsetof(Processor, m_cpu));
}
ALWAYS_INLINE static bool is_bootstrap_processor()