1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 06:38:10 +00:00

Kernel: Implement and use the syscall/sysret instruction pair on x86_64

This commit is contained in:
Owen Smith 2021-07-23 21:52:25 +01:00 committed by Andreas Kling
parent d36c84c331
commit e6df1c9988
6 changed files with 169 additions and 1 deletions

View file

@ -30,6 +30,10 @@ struct ProcessorMessage;
struct ProcessorMessageEntry;
#if ARCH(X86_64)
# define MSR_EFER 0xc0000080
# define MSR_STAR 0xc0000081
# define MSR_LSTAR 0xc0000082
# define MSR_SFMASK 0xc0000084
# define MSR_FS_BASE 0xc0000100
# define MSR_GS_BASE 0xc0000101
#endif
@ -58,6 +62,11 @@ class Processor {
Processor* m_self;
#if ARCH(X86_64)
// Saved user stack for the syscall instruction.
void* m_user_stack;
#endif
DescriptorTablePointer m_gdtr;
Descriptor m_gdt[256];
u32 m_gdt_length;
@ -205,6 +214,17 @@ public:
static bool is_smp_enabled();
#if ARCH(X86_64)
static constexpr u64 user_stack_offset()
{
return __builtin_offsetof(Processor, m_user_stack);
}
static constexpr u64 kernel_stack_offset()
{
return __builtin_offsetof(Processor, m_tss) + __builtin_offsetof(TSS, rsp0l);
}
#endif
ALWAYS_INLINE static Processor& current()
{
return *(Processor*)read_gs_ptr(__builtin_offsetof(Processor, m_self));