1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:47:45 +00:00

Kernel: Push ARCH specific ifdef's down into RegisterState functions

The non CPU specific code of the kernel shouldn't need to deal with
architecture specific registers, and should instead deal with an
abstract view of the machine. This allows us to remove a variety of
architecture specific ifdefs and helps keep the code slightly more
portable.

We do this by exposing the abstract representation of instruction
pointer, stack pointer, base pointer, return register, etc on the
RegisterState struct.
This commit is contained in:
Brian Gianforcaro 2021-07-18 16:50:08 -07:00 committed by Gunnar Beutner
parent ff8429a749
commit 1cffecbe8d
9 changed files with 119 additions and 97 deletions

View file

@ -67,6 +67,75 @@ struct [[gnu::packed]] RegisterState {
FlatPtr userspace_rsp;
FlatPtr userspace_ss;
#endif
FlatPtr userspace_sp() const
{
#if ARCH(I386)
return userspace_esp;
#else
return userspace_rsp;
#endif
}
FlatPtr ip() const
{
#if ARCH(I386)
return eip;
#else
return rip;
#endif
}
FlatPtr bp() const
{
#if ARCH(I386)
return ebp;
#else
return rbp;
#endif
}
FlatPtr flags() const
{
#if ARCH(I386)
return eflags;
#else
return rflags;
#endif
}
void capture_syscall_params(FlatPtr& function, FlatPtr& arg1, FlatPtr& arg2, FlatPtr& arg3) const
{
#if ARCH(I386)
function = eax;
arg1 = edx;
arg2 = ecx;
arg3 = ebx;
#else
function = rax;
arg1 = rdx;
arg2 = rcx;
arg3 = rbx;
#endif
}
void set_ip_reg(FlatPtr value)
{
#if ARCH(I386)
eip = value;
#else
rip = value;
#endif
}
void set_return_reg(FlatPtr value)
{
#if ARCH(I386)
eax = value;
#else
rax = value;
#endif
}
};
#if ARCH(I386)