diff options
author | Andreas Kling <kling@serenityos.org> | 2021-08-19 21:53:53 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-19 23:22:02 +0200 |
commit | 961f727448019047433ac1b045f8075f269ba9f7 (patch) | |
tree | 25f3972636525b96df35941cb72fc7a03e6f78e5 /Kernel/Arch/x86 | |
parent | 3f5a42b3dd05e56794e5a1394c6e008c15b3f58e (diff) | |
download | serenity-961f727448019047433ac1b045f8075f269ba9f7.zip |
Kernel: Consolidate a bunch of i386/x86_64 code paths
Add some arch-specific getters and setters that allow us to merge blocks
that were previously specific to either ARCH(I386) or ARCH(X86_64).
Diffstat (limited to 'Kernel/Arch/x86')
-rw-r--r-- | Kernel/Arch/x86/RegisterState.h | 68 | ||||
-rw-r--r-- | Kernel/Arch/x86/common/SafeMem.cpp | 18 |
2 files changed, 26 insertions, 60 deletions
diff --git a/Kernel/Arch/x86/RegisterState.h b/Kernel/Arch/x86/RegisterState.h index 21e9fe13cd..cefd54209b 100644 --- a/Kernel/Arch/x86/RegisterState.h +++ b/Kernel/Arch/x86/RegisterState.h @@ -68,41 +68,35 @@ struct [[gnu::packed]] RegisterState { FlatPtr userspace_ss; #endif +#if ARCH(I386) 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 + void set_userspace_sp(FlatPtr value) { userspace_esp = value; } + FlatPtr ip() const { return eip; } + void set_ip(FlatPtr value) { eip = value; } + void set_dx(FlatPtr value) { edx = value; } + FlatPtr bp() const { return ebp; } + void set_bp(FlatPtr value) { ebp = value; } + FlatPtr flags() const { return eflags; } + void set_flags(FlatPtr value) { eflags = value; } + void set_return_reg(FlatPtr value) { eax = value; } +#elif ARCH(X86_64) + FlatPtr userspace_sp() const { -#if ARCH(I386) - return ebp; -#else - return rbp; -#endif + return userspace_rsp; } - - FlatPtr flags() const - { -#if ARCH(I386) - return eflags; -#else - return rflags; + void set_userspace_sp(FlatPtr value) { userspace_rsp = value; } + FlatPtr ip() const { return rip; } + void set_ip(FlatPtr value) { rip = value; } + void set_dx(FlatPtr value) { rdx = value; } + FlatPtr bp() const { return rbp; } + void set_bp(FlatPtr value) { rbp = value; } + FlatPtr flags() const { return rflags; } + void set_flags(FlatPtr value) { rflags = value; } + void set_return_reg(FlatPtr value) { rax = value; } #endif - } void capture_syscall_params(FlatPtr& function, FlatPtr& arg1, FlatPtr& arg2, FlatPtr& arg3, FlatPtr& arg4) const { @@ -120,24 +114,6 @@ struct [[gnu::packed]] RegisterState { arg4 = rsi; #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) diff --git a/Kernel/Arch/x86/common/SafeMem.cpp b/Kernel/Arch/x86/common/SafeMem.cpp index 9fb7208ad3..36824714f8 100644 --- a/Kernel/Arch/x86/common/SafeMem.cpp +++ b/Kernel/Arch/x86/common/SafeMem.cpp @@ -299,13 +299,8 @@ bool handle_safe_access_fault(RegisterState& regs, FlatPtr fault_address) else return false; -#if ARCH(I386) - regs.eip = ip; - regs.edx = fault_address; -#else - regs.rip = ip; - regs.rdx = fault_address; -#endif + regs.set_ip(ip); + regs.set_dx(fault_address); return true; } if (ip >= (FlatPtr)&start_of_safemem_atomic_text && ip < (FlatPtr)&end_of_safemem_atomic_text) { @@ -325,13 +320,8 @@ bool handle_safe_access_fault(RegisterState& regs, FlatPtr fault_address) else return false; -#if ARCH(I386) - regs.eip = ip; - regs.edx = 1; -#else - regs.rip = ip; - regs.rdx = 1; -#endif + regs.set_ip(ip); + regs.set_dx(1); return true; } return false; |