summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kernel/Arch/CPU.h2
-rw-r--r--Kernel/Arch/IRQController.h2
-rw-r--r--Kernel/Arch/InterruptManagement.h2
-rw-r--r--Kernel/Arch/Interrupts.h2
-rw-r--r--Kernel/Arch/PageDirectory.h2
-rw-r--r--Kernel/Arch/Processor.h2
-rw-r--r--Kernel/Arch/RegisterState.h2
-rw-r--r--Kernel/Arch/TrapFrame.h2
-rw-r--r--Kernel/Arch/aarch64/Interrupts.cpp2
-rw-r--r--Kernel/Arch/mcontext.h2
-rw-r--r--Kernel/Arch/x86/common/ASM_wrapper.cpp49
-rw-r--r--Kernel/Arch/x86/i386/ASM_wrapper.cpp82
-rw-r--r--Kernel/Arch/x86/i386/Boot/ap_setup.S179
-rw-r--r--Kernel/Arch/x86/i386/InterruptEntry.cpp52
-rw-r--r--Kernel/Arch/x86/i386/Processor.cpp277
-rw-r--r--Kernel/Arch/x86/x86_64/Processor.cpp283
-rw-r--r--Kernel/Arch/x86_64/ASM_wrapper.cpp (renamed from Kernel/Arch/x86/x86_64/ASM_wrapper.cpp)37
-rw-r--r--Kernel/Arch/x86_64/ASM_wrapper.h (renamed from Kernel/Arch/x86/ASM_wrapper.h)0
-rw-r--r--Kernel/Arch/x86_64/BochsDebugOutput.h (renamed from Kernel/Arch/x86/common/BochsDebugOutput.h)0
-rw-r--r--Kernel/Arch/x86_64/Boot/ap_setup.S (renamed from Kernel/Arch/x86/x86_64/Boot/ap_setup.S)0
-rw-r--r--Kernel/Arch/x86_64/CMOS.cpp (renamed from Kernel/Arch/x86/common/CMOS.cpp)4
-rw-r--r--Kernel/Arch/x86_64/CMOS.h (renamed from Kernel/Arch/x86/common/CMOS.h)0
-rw-r--r--Kernel/Arch/x86_64/CPU.cpp (renamed from Kernel/Arch/x86/common/CPU.cpp)0
-rw-r--r--Kernel/Arch/x86_64/CPU.h (renamed from Kernel/Arch/x86/CPU.h)2
-rw-r--r--Kernel/Arch/x86_64/CPUID.cpp (renamed from Kernel/Arch/x86/common/CPUID.cpp)2
-rw-r--r--Kernel/Arch/x86_64/CPUID.h (renamed from Kernel/Arch/x86/CPUID.h)0
-rw-r--r--Kernel/Arch/x86_64/CrashHandler.cpp (renamed from Kernel/Arch/x86/common/CrashHandler.cpp)0
-rw-r--r--Kernel/Arch/x86_64/CurrentTime.cpp (renamed from Kernel/Arch/x86/CurrentTime.cpp)4
-rw-r--r--Kernel/Arch/x86_64/DebugOutput.cpp (renamed from Kernel/Arch/x86/common/DebugOutput.cpp)4
-rw-r--r--Kernel/Arch/x86_64/Delay.cpp (renamed from Kernel/Arch/x86/common/Delay.cpp)2
-rw-r--r--Kernel/Arch/x86_64/DescriptorTable.h (renamed from Kernel/Arch/x86/DescriptorTable.h)0
-rw-r--r--Kernel/Arch/x86_64/Hypervisor/BochsDisplayConnector.cpp (renamed from Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.cpp)4
-rw-r--r--Kernel/Arch/x86_64/Hypervisor/BochsDisplayConnector.h (renamed from Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.h)0
-rw-r--r--Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.cpp (renamed from Kernel/Arch/x86/Hypervisor/VMWareBackdoor.cpp)2
-rw-r--r--Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.h (renamed from Kernel/Arch/x86/Hypervisor/VMWareBackdoor.h)0
-rw-r--r--Kernel/Arch/x86_64/I8042Reboot.cpp (renamed from Kernel/Arch/x86/common/I8042Reboot.cpp)4
-rw-r--r--Kernel/Arch/x86_64/I8042Reboot.h (renamed from Kernel/Arch/x86/common/I8042Reboot.h)0
-rw-r--r--Kernel/Arch/x86_64/IO.h (renamed from Kernel/Arch/x86/IO.h)0
-rw-r--r--Kernel/Arch/x86_64/IRQController.h (renamed from Kernel/Arch/x86/IRQController.h)0
-rw-r--r--Kernel/Arch/x86_64/ISABus/HID/PS2KeyboardDevice.cpp (renamed from Kernel/Arch/x86/ISABus/HID/PS2KeyboardDevice.cpp)2
-rw-r--r--Kernel/Arch/x86_64/ISABus/HID/PS2KeyboardDevice.h (renamed from Kernel/Arch/x86/ISABus/HID/PS2KeyboardDevice.h)2
-rw-r--r--Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.cpp (renamed from Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.cpp)4
-rw-r--r--Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.h (renamed from Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.h)2
-rw-r--r--Kernel/Arch/x86_64/ISABus/HID/VMWareMouseDevice.cpp (renamed from Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.cpp)4
-rw-r--r--Kernel/Arch/x86_64/ISABus/HID/VMWareMouseDevice.h (renamed from Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.h)4
-rw-r--r--Kernel/Arch/x86_64/ISABus/I8042Controller.cpp (renamed from Kernel/Arch/x86/ISABus/I8042Controller.cpp)10
-rw-r--r--Kernel/Arch/x86_64/ISABus/I8042Controller.h (renamed from Kernel/Arch/x86/ISABus/I8042Controller.h)0
-rw-r--r--Kernel/Arch/x86_64/ISABus/IDEController.cpp (renamed from Kernel/Arch/x86/ISABus/IDEController.cpp)2
-rw-r--r--Kernel/Arch/x86_64/ISABus/IDEController.h (renamed from Kernel/Arch/x86/ISABus/IDEController.h)0
-rw-r--r--Kernel/Arch/x86_64/ISABus/SerialDevice.cpp (renamed from Kernel/Arch/x86/ISABus/SerialDevice.cpp)0
-rw-r--r--Kernel/Arch/x86_64/ISRStubs.h (renamed from Kernel/Arch/x86/ISRStubs.h)2
-rw-r--r--Kernel/Arch/x86_64/InterruptEntry.cpp (renamed from Kernel/Arch/x86/x86_64/InterruptEntry.cpp)4
-rw-r--r--Kernel/Arch/x86_64/InterruptManagement.cpp (renamed from Kernel/Arch/x86/common/InterruptManagement.cpp)8
-rw-r--r--Kernel/Arch/x86_64/InterruptManagement.h (renamed from Kernel/Arch/x86/InterruptManagement.h)4
-rw-r--r--Kernel/Arch/x86_64/Interrupts.cpp (renamed from Kernel/Arch/x86/common/Interrupts.cpp)4
-rw-r--r--Kernel/Arch/x86_64/Interrupts.h (renamed from Kernel/Arch/x86/Interrupts.h)0
-rw-r--r--Kernel/Arch/x86_64/Interrupts/APIC.cpp (renamed from Kernel/Arch/x86/common/Interrupts/APIC.cpp)8
-rw-r--r--Kernel/Arch/x86_64/Interrupts/APIC.h (renamed from Kernel/Arch/x86/common/Interrupts/APIC.h)0
-rw-r--r--Kernel/Arch/x86_64/Interrupts/IOAPIC.cpp (renamed from Kernel/Arch/x86/common/Interrupts/IOAPIC.cpp)6
-rw-r--r--Kernel/Arch/x86_64/Interrupts/IOAPIC.h (renamed from Kernel/Arch/x86/common/Interrupts/IOAPIC.h)2
-rw-r--r--Kernel/Arch/x86_64/Interrupts/PIC.cpp (renamed from Kernel/Arch/x86/common/Interrupts/PIC.cpp)4
-rw-r--r--Kernel/Arch/x86_64/Interrupts/PIC.h (renamed from Kernel/Arch/x86/common/Interrupts/PIC.h)2
-rw-r--r--Kernel/Arch/x86_64/MSR.h (renamed from Kernel/Arch/x86/MSR.h)2
-rw-r--r--Kernel/Arch/x86_64/NonMaskableInterruptDisabler.h (renamed from Kernel/Arch/x86/NonMaskableInterruptDisabler.h)2
-rw-r--r--Kernel/Arch/x86_64/PCI/Controller/HostBridge.cpp (renamed from Kernel/Arch/x86/PCI/Controller/HostBridge.cpp)4
-rw-r--r--Kernel/Arch/x86_64/PCI/Controller/HostBridge.h (renamed from Kernel/Arch/x86/PCI/Controller/HostBridge.h)0
-rw-r--r--Kernel/Arch/x86_64/PCI/IDELegacyModeController.cpp (renamed from Kernel/Arch/x86/PCI/IDELegacyModeController.cpp)2
-rw-r--r--Kernel/Arch/x86_64/PCI/IDELegacyModeController.h (renamed from Kernel/Arch/x86/PCI/IDELegacyModeController.h)0
-rw-r--r--Kernel/Arch/x86_64/PCI/Initializer.cpp (renamed from Kernel/Arch/x86/PCI/Initializer.cpp)2
-rw-r--r--Kernel/Arch/x86_64/PCSpeaker.cpp (renamed from Kernel/Arch/x86/common/PCSpeaker.cpp)6
-rw-r--r--Kernel/Arch/x86_64/PCSpeaker.h (renamed from Kernel/Arch/x86/common/PCSpeaker.h)0
-rw-r--r--Kernel/Arch/x86_64/PageDirectory.cpp (renamed from Kernel/Arch/x86/common/PageDirectory.cpp)0
-rw-r--r--Kernel/Arch/x86_64/PageDirectory.h (renamed from Kernel/Arch/x86/PageDirectory.h)0
-rw-r--r--Kernel/Arch/x86_64/Processor.cpp (renamed from Kernel/Arch/x86/common/Processor.cpp)272
-rw-r--r--Kernel/Arch/x86_64/Processor.h (renamed from Kernel/Arch/x86/Processor.h)10
-rw-r--r--Kernel/Arch/x86_64/ProcessorInfo.cpp (renamed from Kernel/Arch/x86/common/ProcessorInfo.cpp)4
-rw-r--r--Kernel/Arch/x86_64/ProcessorInfo.h (renamed from Kernel/Arch/x86/ProcessorInfo.h)0
-rw-r--r--Kernel/Arch/x86_64/RTC.cpp (renamed from Kernel/Arch/x86/common/RTC.cpp)4
-rw-r--r--Kernel/Arch/x86_64/RTC.h (renamed from Kernel/Arch/x86/common/RTC.h)0
-rw-r--r--Kernel/Arch/x86_64/RegisterState.h (renamed from Kernel/Arch/x86/RegisterState.h)2
-rw-r--r--Kernel/Arch/x86_64/SIMDState.h (renamed from Kernel/Arch/x86/SIMDState.h)0
-rw-r--r--Kernel/Arch/x86_64/SafeMem.cpp (renamed from Kernel/Arch/x86/common/SafeMem.cpp)0
-rw-r--r--Kernel/Arch/x86_64/ScopedCritical.cpp (renamed from Kernel/Arch/x86/common/ScopedCritical.cpp)0
-rw-r--r--Kernel/Arch/x86_64/Shutdown.cpp (renamed from Kernel/Arch/x86/common/Shutdown.cpp)4
-rw-r--r--Kernel/Arch/x86_64/Shutdown.h (renamed from Kernel/Arch/x86/common/Shutdown.h)0
-rw-r--r--Kernel/Arch/x86_64/SmapDisabler.cpp (renamed from Kernel/Arch/x86/common/SmapDisabler.cpp)2
-rw-r--r--Kernel/Arch/x86_64/SyscallEntry.cpp (renamed from Kernel/Arch/x86/x86_64/SyscallEntry.cpp)4
-rw-r--r--Kernel/Arch/x86_64/TSS.h (renamed from Kernel/Arch/x86/TSS.h)0
-rw-r--r--Kernel/Arch/x86_64/Time/APICTimer.cpp (renamed from Kernel/Arch/x86/Time/APICTimer.cpp)4
-rw-r--r--Kernel/Arch/x86_64/Time/APICTimer.h (renamed from Kernel/Arch/x86/Time/APICTimer.h)2
-rw-r--r--Kernel/Arch/x86_64/Time/HPET.cpp (renamed from Kernel/Arch/x86/Time/HPET.cpp)4
-rw-r--r--Kernel/Arch/x86_64/Time/HPET.h (renamed from Kernel/Arch/x86/Time/HPET.h)0
-rw-r--r--Kernel/Arch/x86_64/Time/HPETComparator.cpp (renamed from Kernel/Arch/x86/Time/HPETComparator.cpp)2
-rw-r--r--Kernel/Arch/x86_64/Time/HPETComparator.h (renamed from Kernel/Arch/x86/Time/HPETComparator.h)2
-rw-r--r--Kernel/Arch/x86_64/Time/PIT.cpp (renamed from Kernel/Arch/x86/Time/PIT.cpp)4
-rw-r--r--Kernel/Arch/x86_64/Time/PIT.h (renamed from Kernel/Arch/x86/Time/PIT.h)0
-rw-r--r--Kernel/Arch/x86_64/Time/RTC.cpp (renamed from Kernel/Arch/x86/Time/RTC.cpp)8
-rw-r--r--Kernel/Arch/x86_64/Time/RTC.h (renamed from Kernel/Arch/x86/Time/RTC.h)2
-rw-r--r--Kernel/Arch/x86_64/TrapFrame.cpp (renamed from Kernel/Arch/x86/common/TrapFrame.cpp)2
-rw-r--r--Kernel/Arch/x86_64/TrapFrame.h (renamed from Kernel/Arch/x86/TrapFrame.h)0
-rw-r--r--Kernel/Arch/x86_64/VGA/IOArbiter.cpp (renamed from Kernel/Arch/x86/VGA/IOArbiter.cpp)4
-rw-r--r--Kernel/Arch/x86_64/VGA/IOArbiter.h (renamed from Kernel/Arch/x86/VGA/IOArbiter.h)0
-rw-r--r--Kernel/Arch/x86_64/init.cpp (renamed from Kernel/Arch/x86/init.cpp)6
-rw-r--r--Kernel/Arch/x86_64/linker.ld (renamed from Kernel/Arch/x86/linker.ld)0
-rw-r--r--Kernel/Arch/x86_64/mcontext.h (renamed from Kernel/Arch/x86/mcontext.h)0
-rw-r--r--Kernel/Bus/PCI/Access.cpp2
-rw-r--r--Kernel/CMakeLists.txt103
-rw-r--r--Kernel/Devices/ConsoleDevice.cpp2
-rw-r--r--Kernel/Devices/HID/HIDManagement.cpp2
-rw-r--r--Kernel/FileSystem/SysFS/Subsystems/Kernel/CPUInfo.cpp2
-rw-r--r--Kernel/FileSystem/SysFS/Subsystems/Kernel/PowerStateSwitch.cpp4
-rw-r--r--Kernel/Firmware/ACPI/Parser.cpp2
-rw-r--r--Kernel/Firmware/MultiProcessor/Parser.cpp2
-rw-r--r--Kernel/Graphics/Bochs/GraphicsAdapter.cpp2
-rw-r--r--Kernel/Graphics/GraphicsManagement.cpp2
-rw-r--r--Kernel/Graphics/GraphicsManagement.h2
-rw-r--r--Kernel/IOWindow.h2
-rw-r--r--Kernel/Interrupts/SpuriousInterruptHandler.cpp2
-rw-r--r--Kernel/Panic.cpp2
-rw-r--r--Kernel/Prekernel/init.cpp4
-rw-r--r--Kernel/Random.cpp4
-rw-r--r--Kernel/Storage/StorageManagement.cpp4
-rw-r--r--Kernel/Syscall.cpp2
-rw-r--r--Kernel/Syscalls/beep.cpp2
-rw-r--r--Kernel/Syscalls/mmap.cpp2
-rw-r--r--Kernel/TTY/VirtualConsole.cpp2
-rw-r--r--Kernel/Time/TimeManagement.cpp14
-rw-r--r--Kernel/kprintf.cpp2
-rw-r--r--Tests/Kernel/crash.cpp2
129 files changed, 488 insertions, 1122 deletions
diff --git a/Kernel/Arch/CPU.h b/Kernel/Arch/CPU.h
index 24f2fcb640..f6a61bb9b5 100644
--- a/Kernel/Arch/CPU.h
+++ b/Kernel/Arch/CPU.h
@@ -17,7 +17,7 @@
#define MSB(x) (((x) >> 8) & 0xFF)
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/CPU.h>
+# include <Kernel/Arch/x86_64/CPU.h>
#elif ARCH(AARCH64)
# include <Kernel/Arch/aarch64/CPU.h>
#else
diff --git a/Kernel/Arch/IRQController.h b/Kernel/Arch/IRQController.h
index 57fc2ad441..5b58bfca75 100644
--- a/Kernel/Arch/IRQController.h
+++ b/Kernel/Arch/IRQController.h
@@ -9,7 +9,7 @@
#include <AK/Platform.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/IRQController.h>
+# include <Kernel/Arch/x86_64/IRQController.h>
#elif ARCH(AARCH64)
# include <Kernel/Arch/aarch64/IRQController.h>
#else
diff --git a/Kernel/Arch/InterruptManagement.h b/Kernel/Arch/InterruptManagement.h
index 1fa182015e..f9e3b4908f 100644
--- a/Kernel/Arch/InterruptManagement.h
+++ b/Kernel/Arch/InterruptManagement.h
@@ -9,7 +9,7 @@
#include <AK/Platform.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/InterruptManagement.h>
+# include <Kernel/Arch/x86_64/InterruptManagement.h>
#elif ARCH(AARCH64)
# include <Kernel/Arch/aarch64/InterruptManagement.h>
#else
diff --git a/Kernel/Arch/Interrupts.h b/Kernel/Arch/Interrupts.h
index ba39657b20..14e11147ad 100644
--- a/Kernel/Arch/Interrupts.h
+++ b/Kernel/Arch/Interrupts.h
@@ -10,7 +10,7 @@
#include <AK/Types.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/Interrupts.h>
+# include <Kernel/Arch/x86_64/Interrupts.h>
#endif
namespace Kernel {
diff --git a/Kernel/Arch/PageDirectory.h b/Kernel/Arch/PageDirectory.h
index e8c989cc01..e6c8e14b76 100644
--- a/Kernel/Arch/PageDirectory.h
+++ b/Kernel/Arch/PageDirectory.h
@@ -10,7 +10,7 @@
#include <AK/Platform.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/PageDirectory.h>
+# include <Kernel/Arch/x86_64/PageDirectory.h>
#elif ARCH(AARCH64)
# include <Kernel/Arch/aarch64/PageDirectory.h>
#else
diff --git a/Kernel/Arch/Processor.h b/Kernel/Arch/Processor.h
index 8ee7d6fc81..598be46915 100644
--- a/Kernel/Arch/Processor.h
+++ b/Kernel/Arch/Processor.h
@@ -24,7 +24,7 @@ void restore_processor_interrupts_state(InterruptsState);
}
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/Processor.h>
+# include <Kernel/Arch/x86_64/Processor.h>
#elif ARCH(AARCH64)
# include <Kernel/Arch/aarch64/Processor.h>
#else
diff --git a/Kernel/Arch/RegisterState.h b/Kernel/Arch/RegisterState.h
index f7a2928ac2..bb2d117c98 100644
--- a/Kernel/Arch/RegisterState.h
+++ b/Kernel/Arch/RegisterState.h
@@ -9,7 +9,7 @@
#include <AK/Platform.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/RegisterState.h>
+# include <Kernel/Arch/x86_64/RegisterState.h>
#elif ARCH(AARCH64)
# include <Kernel/Arch/aarch64/RegisterState.h>
#else
diff --git a/Kernel/Arch/TrapFrame.h b/Kernel/Arch/TrapFrame.h
index 9bfe840747..33ddf4ca87 100644
--- a/Kernel/Arch/TrapFrame.h
+++ b/Kernel/Arch/TrapFrame.h
@@ -9,7 +9,7 @@
#include <AK/Platform.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/TrapFrame.h>
+# include <Kernel/Arch/x86_64/TrapFrame.h>
#elif ARCH(AARCH64)
# include <Kernel/Arch/aarch64/TrapFrame.h>
#else
diff --git a/Kernel/Arch/aarch64/Interrupts.cpp b/Kernel/Arch/aarch64/Interrupts.cpp
index 8a49bfb120..b319fb123d 100644
--- a/Kernel/Arch/aarch64/Interrupts.cpp
+++ b/Kernel/Arch/aarch64/Interrupts.cpp
@@ -47,7 +47,7 @@ extern "C" void handle_interrupt(TrapFrame const* const)
}
}
-// FIXME: Share the code below with Arch/x86/common/Interrupts.cpp
+// FIXME: Share the code below with Arch/x86_64/Interrupts.cpp
// While refactoring, the interrupt handlers can also be moved into the InterruptManagement class.
GenericInterruptHandler& get_interrupt_handler(u8 interrupt_number)
{
diff --git a/Kernel/Arch/mcontext.h b/Kernel/Arch/mcontext.h
index 95d35a0d7e..1da7496634 100644
--- a/Kernel/Arch/mcontext.h
+++ b/Kernel/Arch/mcontext.h
@@ -7,7 +7,7 @@
#pragma once
#if defined(__i386__) || defined(__x86_64__)
-# include <Kernel/Arch/x86/mcontext.h>
+# include <Kernel/Arch/x86_64/mcontext.h>
#elif defined(__aarch64__)
# include <Kernel/Arch/aarch64/mcontext.h>
#endif
diff --git a/Kernel/Arch/x86/common/ASM_wrapper.cpp b/Kernel/Arch/x86/common/ASM_wrapper.cpp
deleted file mode 100644
index e19f9dc5d3..0000000000
--- a/Kernel/Arch/x86/common/ASM_wrapper.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <AK/Types.h>
-
-#include <Kernel/Arch/Processor.h>
-#include <Kernel/Arch/x86/ASM_wrapper.h>
-#include <Kernel/Sections.h>
-
-namespace Kernel {
-
-#define XCR_XFEATURE_ENABLED_MASK 0
-
-UNMAP_AFTER_INIT u64 read_xcr0()
-{
- u32 eax, edx;
- asm volatile("xgetbv"
- : "=a"(eax), "=d"(edx)
- : "c"(XCR_XFEATURE_ENABLED_MASK));
- return eax + ((u64)edx << 32);
-}
-
-UNMAP_AFTER_INIT void write_xcr0(u64 value)
-{
- u32 eax = value;
- u32 edx = value >> 32;
- asm volatile("xsetbv" ::"a"(eax), "d"(edx), "c"(XCR_XFEATURE_ENABLED_MASK));
-}
-
-void stac()
-{
- if (!Processor::current().has_feature(CPUFeature::SMAP))
- return;
- asm volatile("stac" ::
- : "cc");
-}
-
-void clac()
-{
- if (!Processor::current().has_feature(CPUFeature::SMAP))
- return;
- asm volatile("clac" ::
- : "cc");
-}
-
-}
diff --git a/Kernel/Arch/x86/i386/ASM_wrapper.cpp b/Kernel/Arch/x86/i386/ASM_wrapper.cpp
deleted file mode 100644
index 81490562f7..0000000000
--- a/Kernel/Arch/x86/i386/ASM_wrapper.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <AK/Types.h>
-
-#include <Kernel/Arch/x86/ASM_wrapper.h>
-#include <Kernel/Sections.h>
-
-namespace Kernel {
-
-UNMAP_AFTER_INIT void write_cr0(FlatPtr value)
-{
- asm volatile("mov %%eax, %%cr0" ::"a"(value));
-}
-
-UNMAP_AFTER_INIT void write_cr4(FlatPtr value)
-{
- asm volatile("mov %%eax, %%cr4" ::"a"(value));
-}
-FlatPtr read_cr0()
-{
- FlatPtr cr0;
- asm("mov %%cr0, %%eax"
- : "=a"(cr0));
- return cr0;
-}
-
-FlatPtr read_cr2()
-{
- FlatPtr cr2;
- asm("mov %%cr2, %%eax"
- : "=a"(cr2));
- return cr2;
-}
-
-FlatPtr read_cr3()
-{
- FlatPtr cr3;
- asm("mov %%cr3, %%eax"
- : "=a"(cr3));
- return cr3;
-}
-
-void write_cr3(FlatPtr cr3)
-{
- // NOTE: If you're here from a GPF crash, it's very likely that a PDPT entry is incorrect, not this!
- asm volatile("mov %%eax, %%cr3" ::"a"(cr3)
- : "memory");
-}
-
-FlatPtr read_cr4()
-{
- FlatPtr cr4;
- asm("mov %%cr4, %%eax"
- : "=a"(cr4));
- return cr4;
-}
-
-#define DEFINE_DEBUG_REGISTER(index) \
- FlatPtr read_dr##index() \
- { \
- FlatPtr value; \
- asm("mov %%dr" #index ", %%eax" \
- : "=a"(value)); \
- return value; \
- } \
- void write_dr##index(FlatPtr value) \
- { \
- asm volatile("mov %%eax, %%dr" #index ::"a"(value)); \
- }
-
-DEFINE_DEBUG_REGISTER(0);
-DEFINE_DEBUG_REGISTER(1);
-DEFINE_DEBUG_REGISTER(2);
-DEFINE_DEBUG_REGISTER(3);
-DEFINE_DEBUG_REGISTER(6);
-DEFINE_DEBUG_REGISTER(7);
-
-}
diff --git a/Kernel/Arch/x86/i386/Boot/ap_setup.S b/Kernel/Arch/x86/i386/Boot/ap_setup.S
deleted file mode 100644
index 915a1ad4c2..0000000000
--- a/Kernel/Arch/x86/i386/Boot/ap_setup.S
+++ /dev/null
@@ -1,179 +0,0 @@
-#include <Kernel/Sections.h>
-
-.extern init_ap
-.type init_ap, @function
-
-/*
- The apic_ap_start function will be loaded to P0x00008000 where the APIC
- will boot the AP from in real mode. This code also contains space for
- special variables that *must* remain here. When initializing the APIC,
- the code here gets copied to P0x00008000, the variables in here get
- populated and then the boot of the APs will be triggered.
- Having the variables here allows us to access them from real mode. Also, the
- code here avoids the need for relocation entries.
-
- Basically, the variables between apic_ap_start and end_apic_ap_start
- *MUST* remain here and cannot be moved into a .bss or any other location.
-*/
-.global apic_ap_start
-.type apic_ap_start, @function
-apic_ap_start:
-.code16
- cli
- jmp $0x800, $(1f - apic_ap_start) /* avoid relocation entries */
-1:
- mov %cs, %ax
- mov %ax, %ds
-
- xor %ax, %ax
- mov %ax, %sp
-
- /* load the first temporary gdt */
- lgdt (ap_cpu_gdtr_initial - apic_ap_start)
-
- /* enable PM */
- movl %cr0, %eax
- orl $1, %eax
- movl %eax, %cr0
-
- ljmpl $8, $(apic_ap_start32 - apic_ap_start + 0x8000)
-apic_ap_start32:
-.code32
- mov $0x10, %ax
- mov %ax, %ss
- mov %ax, %ds
- mov %ax, %es
- mov %ax, %fs
- mov %ax, %gs
-
- movl $0x8000, %ebp
-
- /* generate a unique ap cpu id (0 means 1st ap, not bsp!) */
- xorl %eax, %eax
- incl %eax
- lock; xaddl %eax, (ap_cpu_id - apic_ap_start)(%ebp) /* avoid relocation entries */
- movl %eax, %esi
-
- /* find our allocated stack based on the generated id */
- movl (ap_cpu_init_stacks - apic_ap_start)(%ebp, %eax, 4), %esp
-
- /* check if we support NX and enable it if we do */
- movl $0x80000001, %eax
- cpuid
- testl $0x100000, %edx
- je (1f - apic_ap_start + 0x8000)
- /* turn on IA32_EFER.NXE */
- movl $0xc0000080, %ecx
- rdmsr
- orl $0x800, %eax
- wrmsr
-1:
-
- /* load the bsp's cr3 value */
- movl (ap_cpu_init_cr3 - apic_ap_start)(%ebp), %eax
- movl %eax, %cr3
-
- /* enable PAE + PSE */
- movl %cr4, %eax
- orl $0x60, %eax
- movl %eax, %cr4
-
- /* enable PG */
- movl %cr0, %eax
- orl $0x80000000, %eax
- movl %eax, %cr0
-
- /* load a second temporary gdt that points above 3GB */
- lgdt (ap_cpu_gdtr_initial2 - apic_ap_start + 0xc0008000)
-
- /* jump above 3GB into our identity mapped area now */
- ljmp $8, $(apic_ap_start32_2 - apic_ap_start + 0xc0008000)
-apic_ap_start32_2:
- /* flush the TLB */
- movl %cr3, %eax
- movl %eax, %cr3
-
- movl $0xc0008000, %ebp
-
- /* now load the final gdt and idt from the identity mapped area */
- movl (ap_cpu_gdtr - apic_ap_start)(%ebp), %eax
- lgdt (%eax)
- movl (ap_cpu_idtr - apic_ap_start)(%ebp), %eax
- lidt (%eax)
-
- /* set same cr0 and cr4 values as the BSP */
- movl (ap_cpu_init_cr0 - apic_ap_start)(%ebp), %eax
- movl %eax, %cr0
- movl (ap_cpu_init_cr4 - apic_ap_start)(%ebp), %eax
- movl %eax, %cr4
-
- /* push the Processor pointer this CPU is going to use */
- movl (ap_cpu_init_processor_info_array - apic_ap_start)(%ebp), %eax
- addl kernel_mapping_base, %eax
- movl 0(%eax, %esi, 4), %eax
- push %eax
-
- /* push the cpu id, 0 representing the bsp and call into c++ */
- incl %esi
- push %esi
-
- xor %ebp, %ebp
- cld
-
- /* We are in identity mapped P0x8000 and the BSP will unload this code
- once all APs are initialized, so call init_ap but return to our
- infinite loop */
- push $loop
- ljmp $8, $init_ap
-
-loop:
- hlt
- jmp loop
-
-.align 4
-.global apic_ap_start_size
-apic_ap_start_size:
- .2byte end_apic_ap_start - apic_ap_start
-.align 4
-ap_cpu_id:
- .4byte 0x0
-ap_cpu_gdt:
- /* null */
- .8byte 0x0
- /* code */
- .4byte 0x0000FFFF
- .4byte 0x00cf9a00
- /* data */
- .4byte 0x0000FFFF
- .4byte 0x00cf9200
-ap_cpu_gdt_end:
-ap_cpu_gdtr_initial:
- .2byte ap_cpu_gdt_end - ap_cpu_gdt - 1
- .4byte (ap_cpu_gdt - apic_ap_start) + 0x8000
-ap_cpu_gdtr_initial2:
- .2byte ap_cpu_gdt_end - ap_cpu_gdt - 1
- .4byte (ap_cpu_gdt - apic_ap_start) + 0xc0008000
-.global ap_cpu_gdtr
-ap_cpu_gdtr:
- .4byte 0x0 /* will be set at runtime */
-.global ap_cpu_idtr
-ap_cpu_idtr:
- .4byte 0x0 /* will be set at runtime */
-.global ap_cpu_init_cr0
-ap_cpu_init_cr0:
- .4byte 0x0 /* will be set at runtime */
-.global ap_cpu_init_cr3
-ap_cpu_init_cr3:
- .4byte 0x0 /* will be set at runtime */
-.global ap_cpu_init_cr4
-ap_cpu_init_cr4:
- .4byte 0x0 /* will be set at runtime */
-.global ap_cpu_init_processor_info_array
-ap_cpu_init_processor_info_array:
- .4byte 0x0 /* will be set at runtime */
-.global ap_cpu_init_stacks
-ap_cpu_init_stacks:
- /* array of allocated stack pointers */
- /* NOTE: ap_cpu_init_stacks must be the last variable before
- end_apic_ap_start! */
-.set end_apic_ap_start, .
diff --git a/Kernel/Arch/x86/i386/InterruptEntry.cpp b/Kernel/Arch/x86/i386/InterruptEntry.cpp
deleted file mode 100644
index be32d22c55..0000000000
--- a/Kernel/Arch/x86/i386/InterruptEntry.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <Kernel/Arch/TrapFrame.h>
-#include <Kernel/Arch/x86/DescriptorTable.h>
-
-// clang-format off
-asm(
- ".globl interrupt_common_asm_entry\n"
- "interrupt_common_asm_entry: \n"
- " pusha\n"
- " pushl %ds\n"
- " pushl %es\n"
- " pushl %fs\n"
- " pushl %gs\n"
- " pushl %ss\n"
- " mov $" __STRINGIFY(GDT_SELECTOR_DATA0) ", %ax\n"
- " mov %ax, %ds\n"
- " mov %ax, %es\n"
- " mov $" __STRINGIFY(GDT_SELECTOR_PROC) ", %ax\n"
- " mov %ax, %gs\n"
- " pushl %esp \n" // set TrapFrame::regs
- " subl $" __STRINGIFY(TRAP_FRAME_SIZE - 4) ", %esp \n"
- " movl %esp, %ebx \n" // save pointer to TrapFrame
- " pushl %ebx \n"
- " cld\n"
- " call enter_trap \n"
- " movl %ebx, 0(%esp) \n" // push pointer to TrapFrame
- " call handle_interrupt\n"
- " movl %ebx, 0(%esp) \n" // push pointer to TrapFrame
- ".globl common_trap_exit \n"
- "common_trap_exit: \n"
- // another thread may have handled this trap at this point, so don't
- // make assumptions about the stack other than there's a TrapFrame
- // and a pointer to it.
- " call exit_trap \n"
- " addl $" __STRINGIFY(TRAP_FRAME_SIZE + 4) ", %esp\n" // pop TrapFrame and pointer to it
- ".globl interrupt_common_asm_exit \n"
- "interrupt_common_asm_exit: \n"
- " addl $4, %esp\n" // pop %ss
- " popl %gs\n"
- " popl %fs\n"
- " popl %es\n"
- " popl %ds\n"
- " popa\n"
- " addl $0x4, %esp\n" // skip exception_code, isr_number
- " iret\n"
-);
-// clang-format on
diff --git a/Kernel/Arch/x86/i386/Processor.cpp b/Kernel/Arch/x86/i386/Processor.cpp
deleted file mode 100644
index 9a23a5d083..0000000000
--- a/Kernel/Arch/x86/i386/Processor.cpp
+++ /dev/null
@@ -1,277 +0,0 @@
-/*
- * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <AK/StdLibExtras.h>
-#include <Kernel/Arch/Processor.h>
-#include <Kernel/Arch/TrapFrame.h>
-#include <Kernel/Process.h>
-#include <Kernel/Random.h>
-#include <Kernel/Scheduler.h>
-#include <Kernel/Sections.h>
-#include <Kernel/Thread.h>
-
-namespace Kernel {
-
-#define ENTER_THREAD_CONTEXT_ARGS_SIZE (2 * 4) // to_thread, from_thread
-
-NAKED void thread_context_first_enter(void)
-{
- // clang-format off
- // enter_thread_context returns to here first time a thread is executing
- asm(
- // switch_context will have pushed from_thread and to_thread to our new
- // stack prior to thread_context_first_enter() being called, and the
- // pointer to TrapFrame was the top of the stack before that
- " movl 8(%esp), %ebx \n" // save pointer to TrapFrame
- " cld \n"
- " call context_first_init \n"
- " addl $" __STRINGIFY(ENTER_THREAD_CONTEXT_ARGS_SIZE) ", %esp \n"
- " movl %ebx, 0(%esp) \n" // push pointer to TrapFrame
- " jmp common_trap_exit \n"
- );
- // clang-format on
-}
-
-NAKED void do_assume_context(Thread*, u32)
-{
- // clang-format off
- // FIXME: I hope (Thread* thread, u32 flags) aren't compiled away
- asm(
- " movl 4(%esp), %ebx \n"
- " movl 8(%esp), %esi \n"
- // We're going to call Processor::init_context, so just make sure
- // we have enough stack space so we don't stomp over it
- " subl $(" __STRINGIFY(4 + REGISTER_STATE_SIZE + TRAP_FRAME_SIZE + 4) "), %esp \n"
- " pushl %esi \n"
- " pushl %ebx \n"
- " cld \n"
- " call do_init_context \n"
- " addl $8, %esp \n"
- " movl %eax, %esp \n" // move stack pointer to what Processor::init_context set up for us
- " pushl %ebx \n" // push to_thread
- " pushl %ebx \n" // push from_thread
- " pushl $thread_context_first_enter \n" // should be same as regs.eip
- " jmp enter_thread_context \n"
- );
- // clang-format on
-}
-
-StringView Processor::platform_string()
-{
- return "i386"sv;
-}
-
-FlatPtr Processor::init_context(Thread& thread, bool leave_crit)
-{
- VERIFY(is_kernel_mode());
- VERIFY(g_scheduler_lock.is_locked());
- if (leave_crit) {
- // Leave the critical section we set up in Process::exec,
- // but because we still have the scheduler lock we should end up with 1
- VERIFY(in_critical() == 2);
- m_in_critical = 1; // leave it without triggering anything or restoring flags
- }
-
- u32 kernel_stack_top = thread.kernel_stack_top();
-
- // Add a random offset between 0-256 (16-byte aligned)
- kernel_stack_top -= round_up_to_power_of_two(get_fast_random<u8>(), 16);
-
- u32 stack_top = kernel_stack_top;
-
- // TODO: handle NT?
- VERIFY((cpu_flags() & 0x24000) == 0); // Assume !(NT | VM)
-
- auto& regs = thread.regs();
- bool return_to_user = (regs.cs & 3) != 0;
-
- // make room for an interrupt frame
- if (!return_to_user) {
- // userspace_esp and userspace_ss are not popped off by iret
- // unless we're switching back to user mode
- stack_top -= sizeof(RegisterState) - 2 * sizeof(u32);
-
- // For kernel threads we'll push the thread function argument
- // which should be in regs.esp and exit_kernel_thread as return
- // address.
- stack_top -= 2 * sizeof(u32);
- *reinterpret_cast<u32*>(kernel_stack_top - 2 * sizeof(u32)) = regs.esp;
- *reinterpret_cast<u32*>(kernel_stack_top - 3 * sizeof(u32)) = FlatPtr(&exit_kernel_thread);
- } else {
- stack_top -= sizeof(RegisterState);
- }
-
- // we want to end up 16-byte aligned, %esp + 4 should be aligned
- stack_top -= sizeof(u32);
- *reinterpret_cast<u32*>(kernel_stack_top - sizeof(u32)) = 0;
-
- // set up the stack so that after returning from thread_context_first_enter()
- // we will end up either in kernel mode or user mode, depending on how the thread is set up
- // However, the first step is to always start in kernel mode with thread_context_first_enter
- RegisterState& iretframe = *reinterpret_cast<RegisterState*>(stack_top);
- iretframe.ss = regs.ss;
- iretframe.gs = regs.gs;
- iretframe.fs = regs.fs;
- iretframe.es = regs.es;
- iretframe.ds = regs.ds;
- iretframe.edi = regs.edi;
- iretframe.esi = regs.esi;
- iretframe.ebp = regs.ebp;
- iretframe.esp = 0;
- iretframe.ebx = regs.ebx;
- iretframe.edx = regs.edx;
- iretframe.ecx = regs.ecx;
- iretframe.eax = regs.eax;
- iretframe.eflags = regs.eflags;
- iretframe.eip = regs.eip;
- iretframe.cs = regs.cs;
- if (return_to_user) {
- iretframe.userspace_esp = regs.esp;
- iretframe.userspace_ss = regs.ss;
- }
-
- // make space for a trap frame
- stack_top -= sizeof(TrapFrame);
- TrapFrame& trap = *reinterpret_cast<TrapFrame*>(stack_top);
- trap.regs = &iretframe;
- trap.prev_irq_level = 0;
- trap.next_trap = nullptr;
-
- stack_top -= sizeof(u32); // pointer to TrapFrame
- *reinterpret_cast<u32*>(stack_top) = stack_top + 4;
-
- if constexpr (CONTEXT_SWITCH_DEBUG) {
- if (return_to_user) {
- dbgln("init_context {} ({}) set up to execute at eip={}:{}, esp={}, stack_top={}, user_top={}:{}",
- thread,
- VirtualAddress(&thread),
- iretframe.cs, regs.eip,
- VirtualAddress(regs.esp),
- VirtualAddress(stack_top),
- iretframe.userspace_ss,
- iretframe.userspace_esp);
- } else {
- dbgln("init_context {} ({}) set up to execute at eip={}:{}, esp={}, stack_top={}",
- thread,
- VirtualAddress(&thread),
- iretframe.cs, regs.eip,
- VirtualAddress(regs.esp),
- VirtualAddress(stack_top));
- }
- }
-
- // make switch_context() always first return to thread_context_first_enter()
- // in kernel mode, so set up these values so that we end up popping iretframe
- // off the stack right after the context switch completed, at which point
- // control is transferred to what iretframe is pointing to.
- regs.eip = FlatPtr(&thread_context_first_enter);
- regs.esp0 = kernel_stack_top;
- regs.esp = stack_top;
- regs.cs = GDT_SELECTOR_CODE0;
- regs.ds = GDT_SELECTOR_DATA0;
- regs.es = GDT_SELECTOR_DATA0;
- regs.fs = GDT_SELECTOR_DATA0;
- regs.ss = GDT_SELECTOR_DATA0;
- regs.gs = GDT_SELECTOR_PROC;
- return stack_top;
-}
-
-void Processor::switch_context(Thread*& from_thread, Thread*& to_thread)
-{
- VERIFY(!m_in_irq);
- VERIFY(m_in_critical == 1);
- VERIFY(is_kernel_mode());
-
- dbgln_if(CONTEXT_SWITCH_DEBUG, "switch_context --> switching out of: {} {}", VirtualAddress(from_thread), *from_thread);
-
- // m_in_critical is restored in enter_thread_context
- from_thread->save_critical(m_in_critical);
-
- // clang-format off
- // Switch to new thread context, passing from_thread and to_thread
- // through to the new context using registers edx and eax
- asm volatile(
- // NOTE: changing how much we push to the stack affects thread_context_first_enter()!
- "pushfl \n"
- "pushl %%ebx \n"
- "pushl %%esi \n"
- "pushl %%edi \n"
- "pushl %%ebp \n"
- "movl %%esp, %[from_esp] \n"
- "movl $1f, %[from_eip] \n"
- "movl %[to_esp0], %%ebx \n"
- "movl %%ebx, %[tss_esp0] \n"
- "movl %[to_esp], %%esp \n"
- "pushl %[to_thread] \n"
- "pushl %[from_thread] \n"
- "pushl %[to_eip] \n"
- "cld \n"
- "jmp enter_thread_context \n"
- "1: \n"
- "popl %%edx \n"
- "popl %%eax \n"
- "popl %%ebp \n"
- "popl %%edi \n"
- "popl %%esi \n"
- "popl %%ebx \n"
- "popfl \n"
- : [from_esp] "=m" (from_thread->regs().esp),
- [from_eip] "=m" (from_thread->regs().eip),
- [tss_esp0] "=m" (m_tss.esp0),
- "=d" (from_thread), // needed so that from_thread retains the correct value
- "=a" (to_thread) // needed so that to_thread retains the correct value
- : [to_esp] "g" (to_thread->regs().esp),
- [to_esp0] "g" (to_thread->regs().esp0),
- [to_eip] "c" (to_thread->regs().eip),
- [from_thread] "d" (from_thread),
- [to_thread] "a" (to_thread)
- : "memory"
- );
- // clang-format on
-
- dbgln_if(CONTEXT_SWITCH_DEBUG, "switch_context <-- from {} {} to {} {}", VirtualAddress(from_thread), *from_thread, VirtualAddress(to_thread), *to_thread);
-}
-
-UNMAP_AFTER_INIT void Processor::initialize_context_switching(Thread& initial_thread)
-{
- VERIFY(initial_thread.process().is_kernel_process());
-
- auto& regs = initial_thread.regs();
- m_tss.iomapbase = sizeof(m_tss);
- m_tss.esp0 = regs.esp0;
- m_tss.ss0 = GDT_SELECTOR_DATA0;
-
- m_scheduler_initialized = true;
-
- // clang-format off
- asm volatile(
- "movl %[new_esp], %%esp \n" // switch to new stack
- "pushl %[from_to_thread] \n" // to_thread
- "pushl %[from_to_thread] \n" // from_thread
- "pushl $" __STRINGIFY(GDT_SELECTOR_CODE0) " \n"
- "pushl %[new_eip] \n" // save the entry eip to the stack
- "movl %%esp, %%ebx \n"
- "addl $20, %%ebx \n" // calculate pointer to TrapFrame
- "pushl %%ebx \n"
- "cld \n"
- "pushl %[cpu] \n" // push argument for init_finished before register is clobbered
- "call pre_init_finished \n"
- "call init_finished \n"
- "addl $4, %%esp \n"
- "call post_init_finished \n"
- "call enter_trap_no_irq \n"
- "addl $4, %%esp \n"
- "lret \n"
- :: [new_esp] "g" (regs.esp),
- [new_eip] "a" (regs.eip),
- [from_to_thread] "b" (&initial_thread),
- [cpu] "c" (Processor::current_id())
- );
- // clang-format on
-
- VERIFY_NOT_REACHED();
-}
-}
diff --git a/Kernel/Arch/x86/x86_64/Processor.cpp b/Kernel/Arch/x86/x86_64/Processor.cpp
deleted file mode 100644
index 7925258e82..0000000000
--- a/Kernel/Arch/x86/x86_64/Processor.cpp
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <AK/StdLibExtras.h>
-#include <Kernel/Arch/Processor.h>
-#include <Kernel/Arch/x86/TrapFrame.h>
-#include <Kernel/Panic.h>
-#include <Kernel/Process.h>
-#include <Kernel/Random.h>
-#include <Kernel/Scheduler.h>
-#include <Kernel/Sections.h>
-#include <Kernel/Thread.h>
-
-namespace Kernel {
-
-NAKED void thread_context_first_enter(void)
-{
- // enter_thread_context returns to here first time a thread is executing
- asm(
- // switch_context will have pushed from_thread and to_thread to our news
- // stack prior to thread_context_first_enter() being called, and the
- // pointer to TrapFrame was the top of the stack before that
- " popq %rdi \n" // from_thread (argument 0)
- " popq %rsi \n" // to_thread (argument 1)
- " popq %rdx \n" // pointer to TrapFrame (argument 2)
- " cld \n"
- " call context_first_init \n"
- " jmp common_trap_exit \n");
-};
-
-NAKED void do_assume_context(Thread*, u32)
-{
- // clang-format off
- // FIXME: I hope (Thread* thread, u32 flags) aren't compiled away
- asm(
- " movq %rdi, %r12 \n" // save thread ptr
- " movq %rsi, %r13 \n" // save flags
- // We're going to call Processor::init_context, so just make sure
- // we have enough stack space so we don't stomp over it
- " subq $(" __STRINGIFY(16 + REGISTER_STATE_SIZE + TRAP_FRAME_SIZE + 8) "), %rsp \n"
- " cld \n"
- " call do_init_context \n"
- " movq %rax, %rsp \n" // move stack pointer to what Processor::init_context set up for us
- " movq %r12, %rdi \n" // to_thread
- " movq %r12, %rsi \n" // from_thread
- " pushq %r12 \n" // to_thread (for thread_context_first_enter)
- " pushq %r12 \n" // from_thread (for thread_context_first_enter)
- " leaq thread_context_first_enter(%rip), %r12 \n" // should be same as regs.rip
- " pushq %r12 \n"
- " jmp enter_thread_context \n");
- // clang-format on
-}
-
-StringView Processor::platform_string()
-{
- return "x86_64"sv;
-}
-
-// FIXME: For the most part this is a copy of the i386-specific function, get rid of the code duplication
-FlatPtr Processor::init_context(Thread& thread, bool leave_crit)
-{
- VERIFY(is_kernel_mode());
- VERIFY(g_scheduler_lock.is_locked());
- if (leave_crit) {
- // Leave the critical section we set up in Process::exec,
- // but because we still have the scheduler lock we should end up with 1
- VERIFY(in_critical() == 2);
- m_in_critical = 1; // leave it without triggering anything or restoring flags
- }
-
- u64 kernel_stack_top = thread.kernel_stack_top();
-
- // Add a random offset between 0-256 (16-byte aligned)
- kernel_stack_top -= round_up_to_power_of_two(get_fast_random<u8>(), 16);
-
- u64 stack_top = kernel_stack_top;
-
- // TODO: handle NT?
- VERIFY((cpu_flags() & 0x24000) == 0); // Assume !(NT | VM)
-
- auto& regs = thread.regs();
- bool return_to_user = (regs.cs & 3) != 0;
-
- stack_top -= 1 * sizeof(u64);
- *reinterpret_cast<u64*>(kernel_stack_top - 2 * sizeof(u64)) = FlatPtr(&exit_kernel_thread);
-
- stack_top -= sizeof(RegisterState);
-
- // we want to end up 16-byte aligned, %rsp + 8 should be aligned
- stack_top -= sizeof(u64);
- *reinterpret_cast<u64*>(kernel_stack_top - sizeof(u64)) = 0;
-
- // set up the stack so that after returning from thread_context_first_enter()
- // we will end up either in kernel mode or user mode, depending on how the thread is set up
- // However, the first step is to always start in kernel mode with thread_context_first_enter
- RegisterState& iretframe = *reinterpret_cast<RegisterState*>(stack_top);
- iretframe.rdi = regs.rdi;
- iretframe.rsi = regs.rsi;
- iretframe.rbp = regs.rbp;
- iretframe.rsp = 0;
- iretframe.rbx = regs.rbx;
- iretframe.rdx = regs.rdx;
- iretframe.rcx = regs.rcx;
- iretframe.rax = regs.rax;
- iretframe.r8 = regs.r8;
- iretframe.r9 = regs.r9;
- iretframe.r10 = regs.r10;
- iretframe.r11 = regs.r11;
- iretframe.r12 = regs.r12;
- iretframe.r13 = regs.r13;
- iretframe.r14 = regs.r14;
- iretframe.r15 = regs.r15;
- iretframe.rflags = regs.rflags;
- iretframe.rip = regs.rip;
- iretframe.cs = regs.cs;
- if (return_to_user) {
- iretframe.userspace_rsp = regs.rsp;
- iretframe.userspace_ss = GDT_SELECTOR_DATA3 | 3;
- } else {
- iretframe.userspace_rsp = kernel_stack_top;
- iretframe.userspace_ss = 0;
- }
-
- // make space for a trap frame
- stack_top -= sizeof(TrapFrame);
- TrapFrame& trap = *reinterpret_cast<TrapFrame*>(stack_top);
- trap.regs = &iretframe;
- trap.prev_irq_level = 0;
- trap.next_trap = nullptr;
-
- stack_top -= sizeof(u64); // pointer to TrapFrame
- *reinterpret_cast<u64*>(stack_top) = stack_top + 8;
-
- if constexpr (CONTEXT_SWITCH_DEBUG) {
- if (return_to_user) {
- dbgln("init_context {} ({}) set up to execute at rip={}:{}, rsp={}, stack_top={}, user_top={}",
- thread,
- VirtualAddress(&thread),
- iretframe.cs, regs.rip,
- VirtualAddress(regs.rsp),
- VirtualAddress(stack_top),
- iretframe.userspace_rsp);
- } else {
- dbgln("init_context {} ({}) set up to execute at rip={}:{}, rsp={}, stack_top={}",
- thread,
- VirtualAddress(&thread),
- iretframe.cs, regs.rip,
- VirtualAddress(regs.rsp),
- VirtualAddress(stack_top));
- }
- }
-
- // make switch_context() always first return to thread_context_first_enter()
- // in kernel mode, so set up these values so that we end up popping iretframe
- // off the stack right after the context switch completed, at which point
- // control is transferred to what iretframe is pointing to.
- regs.rip = FlatPtr(&thread_context_first_enter);
- regs.rsp0 = kernel_stack_top;
- regs.rsp = stack_top;
- regs.cs = GDT_SELECTOR_CODE0;
- return stack_top;
-}
-
-void Processor::switch_context(Thread*& from_thread, Thread*& to_thread)
-{
- VERIFY(!m_in_irq);
- VERIFY(m_in_critical == 1);
- VERIFY(is_kernel_mode());
-
- dbgln_if(CONTEXT_SWITCH_DEBUG, "switch_context --> switching out of: {} {}", VirtualAddress(from_thread), *from_thread);
-
- // m_in_critical is restored in enter_thread_context
- from_thread->save_critical(m_in_critical);
-
- // clang-format off
- // Switch to new thread context, passing from_thread and to_thread
- // through to the new context using registers rdx and rax
- asm volatile(
- // NOTE: changing how much we push to the stack affects thread_context_first_enter()!
- "pushfq \n"
- "pushq %%rbx \n"
- "pushq %%rcx \n"
- "pushq %%rbp \n"
- "pushq %%rsi \n"
- "pushq %%rdi \n"
- "pushq %%r8 \n"
- "pushq %%r9 \n"
- "pushq %%r10 \n"
- "pushq %%r11 \n"
- "pushq %%r12 \n"
- "pushq %%r13 \n"
- "pushq %%r14 \n"
- "pushq %%r15 \n"
- "movq %%rsp, %[from_rsp] \n"
- "leaq 1f(%%rip), %%rbx \n"
- "movq %%rbx, %[from_rip] \n"
- "movq %[to_rsp0], %%rbx \n"
- "movl %%ebx, %[tss_rsp0l] \n"
- "shrq $32, %%rbx \n"
- "movl %%ebx, %[tss_rsp0h] \n"
- "movq %[to_rsp], %%rsp \n"
- "pushq %[to_thread] \n"
- "pushq %[from_thread] \n"
- "pushq %[to_rip] \n"
- "cld \n"
- "movq 16(%%rsp), %%rsi \n"
- "movq 8(%%rsp), %%rdi \n"
- "jmp enter_thread_context \n"
- "1: \n"
- "popq %%rdx \n"
- "popq %%rax \n"
- "popq %%r15 \n"
- "popq %%r14 \n"
- "popq %%r13 \n"
- "popq %%r12 \n"
- "popq %%r11 \n"
- "popq %%r10 \n"
- "popq %%r9 \n"
- "popq %%r8 \n"
- "popq %%rdi \n"
- "popq %%rsi \n"
- "popq %%rbp \n"
- "popq %%rcx \n"
- "popq %%rbx \n"
- "popfq \n"
- : [from_rsp] "=m" (from_thread->regs().rsp),
- [from_rip] "=m" (from_thread->regs().rip),
- [tss_rsp0l] "=m" (m_tss.rsp0l),
- [tss_rsp0h] "=m" (m_tss.rsp0h),
- "=d" (from_thread), // needed so that from_thread retains the correct value
- "=a" (to_thread) // needed so that to_thread retains the correct value
- : [to_rsp] "g" (to_thread->regs().rsp),
- [to_rsp0] "g" (to_thread->regs().rsp0),
- [to_rip] "c" (to_thread->regs().rip),
- [from_thread] "d" (from_thread),
- [to_thread] "a" (to_thread)
- : "memory", "rbx"
- );
- // clang-format on
-
- dbgln_if(CONTEXT_SWITCH_DEBUG, "switch_context <-- from {} {} to {} {}", VirtualAddress(from_thread), *from_thread, VirtualAddress(to_thread), *to_thread);
-}
-
-UNMAP_AFTER_INIT void Processor::initialize_context_switching(Thread& initial_thread)
-{
- VERIFY(initial_thread.process().is_kernel_process());
-
- auto& regs = initial_thread.regs();
- m_tss.iomapbase = sizeof(m_tss);
- m_tss.rsp0l = regs.rsp0 & 0xffffffff;
- m_tss.rsp0h = regs.rsp0 >> 32;
-
- m_scheduler_initialized = true;
-
- // clang-format off
- asm volatile(
- "movq %[new_rsp], %%rsp \n" // switch to new stack
- "pushq %[from_to_thread] \n" // to_thread
- "pushq %[from_to_thread] \n" // from_thread
- "pushq %[new_rip] \n" // save the entry rip to the stack
- "cld \n"
- "pushq %[cpu] \n" // push argument for init_finished before register is clobbered
- "call pre_init_finished \n"
- "pop %%rdi \n" // move argument for init_finished into place
- "call init_finished \n"
- "call post_init_finished \n"
- "movq 24(%%rsp), %%rdi \n" // move pointer to TrapFrame into place
- "call enter_trap_no_irq \n"
- "retq \n"
- :: [new_rsp] "g" (regs.rsp),
- [new_rip] "a" (regs.rip),
- [from_to_thread] "b" (&initial_thread),
- [cpu] "c" ((u64)id())
- );
- // clang-format on
-
- VERIFY_NOT_REACHED();
-}
-
-}
diff --git a/Kernel/Arch/x86/x86_64/ASM_wrapper.cpp b/Kernel/Arch/x86_64/ASM_wrapper.cpp
index f92605572e..e406f9910f 100644
--- a/Kernel/Arch/x86/x86_64/ASM_wrapper.cpp
+++ b/Kernel/Arch/x86_64/ASM_wrapper.cpp
@@ -6,11 +6,46 @@
#include <AK/Types.h>
-#include <Kernel/Arch/x86/ASM_wrapper.h>
+#include <Kernel/Arch/Processor.h>
+#include <Kernel/Arch/x86_64/ASM_wrapper.h>
#include <Kernel/Sections.h>
namespace Kernel {
+#define XCR_XFEATURE_ENABLED_MASK 0
+
+UNMAP_AFTER_INIT u64 read_xcr0()
+{
+ u32 eax, edx;
+ asm volatile("xgetbv"
+ : "=a"(eax), "=d"(edx)
+ : "c"(XCR_XFEATURE_ENABLED_MASK));
+ return eax + ((u64)edx << 32);
+}
+
+UNMAP_AFTER_INIT void write_xcr0(u64 value)
+{
+ u32 eax = value;
+ u32 edx = value >> 32;
+ asm volatile("xsetbv" ::"a"(eax), "d"(edx), "c"(XCR_XFEATURE_ENABLED_MASK));
+}
+
+void stac()
+{
+ if (!Processor::current().has_feature(CPUFeature::SMAP))
+ return;
+ asm volatile("stac" ::
+ : "cc");
+}
+
+void clac()
+{
+ if (!Processor::current().has_feature(CPUFeature::SMAP))
+ return;
+ asm volatile("clac" ::
+ : "cc");
+}
+
UNMAP_AFTER_INIT void write_cr0(FlatPtr value)
{
asm volatile("mov %%rax, %%cr0" ::"a"(value));
diff --git a/Kernel/Arch/x86/ASM_wrapper.h b/Kernel/Arch/x86_64/ASM_wrapper.h
index 65fd94c7c9..65fd94c7c9 100644
--- a/Kernel/Arch/x86/ASM_wrapper.h
+++ b/Kernel/Arch/x86_64/ASM_wrapper.h
diff --git a/Kernel/Arch/x86/common/BochsDebugOutput.h b/Kernel/Arch/x86_64/BochsDebugOutput.h
index 624b26dcb4..624b26dcb4 100644
--- a/Kernel/Arch/x86/common/BochsDebugOutput.h
+++ b/Kernel/Arch/x86_64/BochsDebugOutput.h
diff --git a/Kernel/Arch/x86/x86_64/Boot/ap_setup.S b/Kernel/Arch/x86_64/Boot/ap_setup.S
index 3cb63554d4..3cb63554d4 100644
--- a/Kernel/Arch/x86/x86_64/Boot/ap_setup.S
+++ b/Kernel/Arch/x86_64/Boot/ap_setup.S
diff --git a/Kernel/Arch/x86/common/CMOS.cpp b/Kernel/Arch/x86_64/CMOS.cpp
index ad2b5ee015..310fd87e29 100644
--- a/Kernel/Arch/x86/common/CMOS.cpp
+++ b/Kernel/Arch/x86_64/CMOS.cpp
@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <Kernel/Arch/x86/IO.h>
-#include <Kernel/Arch/x86/common/CMOS.h>
+#include <Kernel/Arch/x86_64/CMOS.h>
+#include <Kernel/Arch/x86_64/IO.h>
namespace Kernel::CMOS {
diff --git a/Kernel/Arch/x86/common/CMOS.h b/Kernel/Arch/x86_64/CMOS.h
index fc3616da24..fc3616da24 100644
--- a/Kernel/Arch/x86/common/CMOS.h
+++ b/Kernel/Arch/x86_64/CMOS.h
diff --git a/Kernel/Arch/x86/common/CPU.cpp b/Kernel/Arch/x86_64/CPU.cpp
index 635613d5c6..635613d5c6 100644
--- a/Kernel/Arch/x86/common/CPU.cpp
+++ b/Kernel/Arch/x86_64/CPU.cpp
diff --git a/Kernel/Arch/x86/CPU.h b/Kernel/Arch/x86_64/CPU.h
index 4bc1a50490..3b3e0c4845 100644
--- a/Kernel/Arch/x86/CPU.h
+++ b/Kernel/Arch/x86_64/CPU.h
@@ -10,7 +10,7 @@
#include <AK/Concepts.h>
#include <AK/Vector.h>
-#include <Kernel/Arch/x86/DescriptorTable.h>
+#include <Kernel/Arch/x86_64/DescriptorTable.h>
#include <AK/Platform.h>
VALIDATE_IS_X86()
diff --git a/Kernel/Arch/x86/common/CPUID.cpp b/Kernel/Arch/x86_64/CPUID.cpp
index 835f697fc1..be39e2ae3c 100644
--- a/Kernel/Arch/x86/common/CPUID.cpp
+++ b/Kernel/Arch/x86_64/CPUID.cpp
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <Kernel/Arch/x86/CPUID.h>
+#include <Kernel/Arch/x86_64/CPUID.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/CPUID.h b/Kernel/Arch/x86_64/CPUID.h
index c19211a427..c19211a427 100644
--- a/Kernel/Arch/x86/CPUID.h
+++ b/Kernel/Arch/x86_64/CPUID.h
diff --git a/Kernel/Arch/x86/common/CrashHandler.cpp b/Kernel/Arch/x86_64/CrashHandler.cpp
index c33276717a..c33276717a 100644
--- a/Kernel/Arch/x86/common/CrashHandler.cpp
+++ b/Kernel/Arch/x86_64/CrashHandler.cpp
diff --git a/Kernel/Arch/x86/CurrentTime.cpp b/Kernel/Arch/x86_64/CurrentTime.cpp
index 3963263ab4..6204f0a10f 100644
--- a/Kernel/Arch/x86/CurrentTime.cpp
+++ b/Kernel/Arch/x86_64/CurrentTime.cpp
@@ -5,8 +5,8 @@
*/
#include <Kernel/Arch/CurrentTime.h>
-#include <Kernel/Arch/x86/ASM_wrapper.h>
-#include <Kernel/Arch/x86/Processor.h>
+#include <Kernel/Arch/x86_64/ASM_wrapper.h>
+#include <Kernel/Arch/x86_64/Processor.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/common/DebugOutput.cpp b/Kernel/Arch/x86_64/DebugOutput.cpp
index 22e5485e30..b2eef62296 100644
--- a/Kernel/Arch/x86/common/DebugOutput.cpp
+++ b/Kernel/Arch/x86_64/DebugOutput.cpp
@@ -5,8 +5,8 @@
*/
#include <Kernel/Arch/DebugOutput.h>
-#include <Kernel/Arch/x86/IO.h>
-#include <Kernel/Arch/x86/common/BochsDebugOutput.h>
+#include <Kernel/Arch/x86_64/BochsDebugOutput.h>
+#include <Kernel/Arch/x86_64/IO.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/common/Delay.cpp b/Kernel/Arch/x86_64/Delay.cpp
index 444d6604c0..9896abfd4f 100644
--- a/Kernel/Arch/x86/common/Delay.cpp
+++ b/Kernel/Arch/x86_64/Delay.cpp
@@ -5,7 +5,7 @@
*/
#include <Kernel/Arch/Delay.h>
-#include <Kernel/Arch/x86/IO.h>
+#include <Kernel/Arch/x86_64/IO.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/DescriptorTable.h b/Kernel/Arch/x86_64/DescriptorTable.h
index 8eefd85cfa..8eefd85cfa 100644
--- a/Kernel/Arch/x86/DescriptorTable.h
+++ b/Kernel/Arch/x86_64/DescriptorTable.h
diff --git a/Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.cpp b/Kernel/Arch/x86_64/Hypervisor/BochsDisplayConnector.cpp
index 74fb9b3338..0a43819004 100644
--- a/Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.cpp
+++ b/Kernel/Arch/x86_64/Hypervisor/BochsDisplayConnector.cpp
@@ -5,8 +5,8 @@
*/
#include <AK/Platform.h>
-#include <Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.h>
-#include <Kernel/Arch/x86/IO.h>
+#include <Kernel/Arch/x86_64/Hypervisor/BochsDisplayConnector.h>
+#include <Kernel/Arch/x86_64/IO.h>
#include <Kernel/Bus/PCI/Access.h>
#include <Kernel/Debug.h>
#include <Kernel/Devices/DeviceManagement.h>
diff --git a/Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.h b/Kernel/Arch/x86_64/Hypervisor/BochsDisplayConnector.h
index cf9f79f9a4..cf9f79f9a4 100644
--- a/Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.h
+++ b/Kernel/Arch/x86_64/Hypervisor/BochsDisplayConnector.h
diff --git a/Kernel/Arch/x86/Hypervisor/VMWareBackdoor.cpp b/Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.cpp
index 5c110a4896..013cad97d9 100644
--- a/Kernel/Arch/x86/Hypervisor/VMWareBackdoor.cpp
+++ b/Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.cpp
@@ -7,7 +7,7 @@
#include <AK/OwnPtr.h>
#include <AK/Singleton.h>
#include <Kernel/API/MousePacket.h>
-#include <Kernel/Arch/x86/Hypervisor/VMWareBackdoor.h>
+#include <Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.h>
#include <Kernel/CommandLine.h>
#include <Kernel/Debug.h>
#include <Kernel/InterruptDisabler.h>
diff --git a/Kernel/Arch/x86/Hypervisor/VMWareBackdoor.h b/Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.h
index a76aa8d8a2..a76aa8d8a2 100644
--- a/Kernel/Arch/x86/Hypervisor/VMWareBackdoor.h
+++ b/Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.h
diff --git a/Kernel/Arch/x86/common/I8042Reboot.cpp b/Kernel/Arch/x86_64/I8042Reboot.cpp
index 2eaf0a0df7..6f987d280f 100644
--- a/Kernel/Arch/x86/common/I8042Reboot.cpp
+++ b/Kernel/Arch/x86_64/I8042Reboot.cpp
@@ -5,8 +5,8 @@
*/
#include <AK/Format.h>
-#include <Kernel/Arch/x86/IO.h>
-#include <Kernel/Arch/x86/common/I8042Reboot.h>
+#include <Kernel/Arch/x86_64/I8042Reboot.h>
+#include <Kernel/Arch/x86_64/IO.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/common/I8042Reboot.h b/Kernel/Arch/x86_64/I8042Reboot.h
index 9c457a0f1a..9c457a0f1a 100644
--- a/Kernel/Arch/x86/common/I8042Reboot.h
+++ b/Kernel/Arch/x86_64/I8042Reboot.h
diff --git a/Kernel/Arch/x86/IO.h b/Kernel/Arch/x86_64/IO.h
index 79a7b92a4c..79a7b92a4c 100644
--- a/Kernel/Arch/x86/IO.h
+++ b/Kernel/Arch/x86_64/IO.h
diff --git a/Kernel/Arch/x86/IRQController.h b/Kernel/Arch/x86_64/IRQController.h
index 64e969033c..64e969033c 100644
--- a/Kernel/Arch/x86/IRQController.h
+++ b/Kernel/Arch/x86_64/IRQController.h
diff --git a/Kernel/Arch/x86/ISABus/HID/PS2KeyboardDevice.cpp b/Kernel/Arch/x86_64/ISABus/HID/PS2KeyboardDevice.cpp
index b569f16e48..02e1d3ab01 100644
--- a/Kernel/Arch/x86/ISABus/HID/PS2KeyboardDevice.cpp
+++ b/Kernel/Arch/x86_64/ISABus/HID/PS2KeyboardDevice.cpp
@@ -6,7 +6,7 @@
*/
#include <AK/Types.h>
-#include <Kernel/Arch/x86/ISABus/HID/PS2KeyboardDevice.h>
+#include <Kernel/Arch/x86_64/ISABus/HID/PS2KeyboardDevice.h>
#include <Kernel/Debug.h>
#include <Kernel/Devices/DeviceManagement.h>
#include <Kernel/Devices/HID/HIDManagement.h>
diff --git a/Kernel/Arch/x86/ISABus/HID/PS2KeyboardDevice.h b/Kernel/Arch/x86_64/ISABus/HID/PS2KeyboardDevice.h
index 89815f5a09..7faedbe921 100644
--- a/Kernel/Arch/x86/ISABus/HID/PS2KeyboardDevice.h
+++ b/Kernel/Arch/x86_64/ISABus/HID/PS2KeyboardDevice.h
@@ -9,7 +9,7 @@
#include <AK/CircularQueue.h>
#include <AK/Types.h>
#include <Kernel/API/KeyCode.h>
-#include <Kernel/Arch/x86/ISABus/I8042Controller.h>
+#include <Kernel/Arch/x86_64/ISABus/I8042Controller.h>
#include <Kernel/Devices/HID/KeyboardDevice.h>
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/Random.h>
diff --git a/Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.cpp b/Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.cpp
index e1bc3370c2..72b73cbba0 100644
--- a/Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.cpp
+++ b/Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.cpp
@@ -5,8 +5,8 @@
*/
#include <AK/Memory.h>
-#include <Kernel/Arch/x86/Hypervisor/VMWareBackdoor.h>
-#include <Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.h>
+#include <Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.h>
+#include <Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.h>
#include <Kernel/Debug.h>
#include <Kernel/Devices/DeviceManagement.h>
#include <Kernel/Sections.h>
diff --git a/Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.h b/Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.h
index e874ae42f4..177097f5f3 100644
--- a/Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.h
+++ b/Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.h
@@ -8,7 +8,7 @@
#include <AK/CircularQueue.h>
#include <Kernel/API/MousePacket.h>
-#include <Kernel/Arch/x86/ISABus/I8042Controller.h>
+#include <Kernel/Arch/x86_64/ISABus/I8042Controller.h>
#include <Kernel/Devices/HID/MouseDevice.h>
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/Random.h>
diff --git a/Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.cpp b/Kernel/Arch/x86_64/ISABus/HID/VMWareMouseDevice.cpp
index b2e9bc046a..ec6029b5b0 100644
--- a/Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.cpp
+++ b/Kernel/Arch/x86_64/ISABus/HID/VMWareMouseDevice.cpp
@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <Kernel/Arch/x86/Hypervisor/VMWareBackdoor.h>
-#include <Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.h>
+#include <Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.h>
+#include <Kernel/Arch/x86_64/ISABus/HID/VMWareMouseDevice.h>
#include <Kernel/Devices/DeviceManagement.h>
#include <Kernel/Sections.h>
diff --git a/Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.h b/Kernel/Arch/x86_64/ISABus/HID/VMWareMouseDevice.h
index 63711ab1e7..b0d753cc78 100644
--- a/Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.h
+++ b/Kernel/Arch/x86_64/ISABus/HID/VMWareMouseDevice.h
@@ -8,8 +8,8 @@
#include <AK/CircularQueue.h>
#include <Kernel/API/MousePacket.h>
-#include <Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.h>
-#include <Kernel/Arch/x86/ISABus/I8042Controller.h>
+#include <Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.h>
+#include <Kernel/Arch/x86_64/ISABus/I8042Controller.h>
#include <Kernel/Interrupts/IRQHandler.h>
#include <Kernel/Random.h>
diff --git a/Kernel/Arch/x86/ISABus/I8042Controller.cpp b/Kernel/Arch/x86_64/ISABus/I8042Controller.cpp
index c4ce6b62f1..096ba932b0 100644
--- a/Kernel/Arch/x86/ISABus/I8042Controller.cpp
+++ b/Kernel/Arch/x86_64/ISABus/I8042Controller.cpp
@@ -5,11 +5,11 @@
*/
#include <Kernel/Arch/Delay.h>
-#include <Kernel/Arch/x86/IO.h>
-#include <Kernel/Arch/x86/ISABus/HID/PS2KeyboardDevice.h>
-#include <Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.h>
-#include <Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.h>
-#include <Kernel/Arch/x86/ISABus/I8042Controller.h>
+#include <Kernel/Arch/x86_64/IO.h>
+#include <Kernel/Arch/x86_64/ISABus/HID/PS2KeyboardDevice.h>
+#include <Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.h>
+#include <Kernel/Arch/x86_64/ISABus/HID/VMWareMouseDevice.h>
+#include <Kernel/Arch/x86_64/ISABus/I8042Controller.h>
#include <Kernel/Sections.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/ISABus/I8042Controller.h b/Kernel/Arch/x86_64/ISABus/I8042Controller.h
index 997cf4517d..997cf4517d 100644
--- a/Kernel/Arch/x86/ISABus/I8042Controller.h
+++ b/Kernel/Arch/x86_64/ISABus/I8042Controller.h
diff --git a/Kernel/Arch/x86/ISABus/IDEController.cpp b/Kernel/Arch/x86_64/ISABus/IDEController.cpp
index 64831f5ebd..fc701d4a8e 100644
--- a/Kernel/Arch/x86/ISABus/IDEController.cpp
+++ b/Kernel/Arch/x86_64/ISABus/IDEController.cpp
@@ -6,7 +6,7 @@
#include <AK/OwnPtr.h>
#include <AK/Types.h>
-#include <Kernel/Arch/x86/ISABus/IDEController.h>
+#include <Kernel/Arch/x86_64/ISABus/IDEController.h>
#include <Kernel/Bus/PCI/API.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Sections.h>
diff --git a/Kernel/Arch/x86/ISABus/IDEController.h b/Kernel/Arch/x86_64/ISABus/IDEController.h
index 0fa83df194..0fa83df194 100644
--- a/Kernel/Arch/x86/ISABus/IDEController.h
+++ b/Kernel/Arch/x86_64/ISABus/IDEController.h
diff --git a/Kernel/Arch/x86/ISABus/SerialDevice.cpp b/Kernel/Arch/x86_64/ISABus/SerialDevice.cpp
index 22a50d9a3d..22a50d9a3d 100644
--- a/Kernel/Arch/x86/ISABus/SerialDevice.cpp
+++ b/Kernel/Arch/x86_64/ISABus/SerialDevice.cpp
diff --git a/Kernel/Arch/x86/ISRStubs.h b/Kernel/Arch/x86_64/ISRStubs.h
index 1108d8556a..6ffc1e24d7 100644
--- a/Kernel/Arch/x86/ISRStubs.h
+++ b/Kernel/Arch/x86_64/ISRStubs.h
@@ -6,7 +6,7 @@
#pragma once
-#include <Kernel/Arch/x86/Interrupts.h>
+#include <Kernel/Arch/x86_64/Interrupts.h>
#include <AK/Platform.h>
VALIDATE_IS_X86()
diff --git a/Kernel/Arch/x86/x86_64/InterruptEntry.cpp b/Kernel/Arch/x86_64/InterruptEntry.cpp
index cc1811106c..7c91ce38c5 100644
--- a/Kernel/Arch/x86/x86_64/InterruptEntry.cpp
+++ b/Kernel/Arch/x86_64/InterruptEntry.cpp
@@ -5,8 +5,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <Kernel/Arch/x86/DescriptorTable.h>
-#include <Kernel/Arch/x86/TrapFrame.h>
+#include <Kernel/Arch/x86_64/DescriptorTable.h>
+#include <Kernel/Arch/x86_64/TrapFrame.h>
// clang-format off
asm(
diff --git a/Kernel/Arch/x86/common/InterruptManagement.cpp b/Kernel/Arch/x86_64/InterruptManagement.cpp
index eac56328ad..16d866ff3d 100644
--- a/Kernel/Arch/x86/common/InterruptManagement.cpp
+++ b/Kernel/Arch/x86_64/InterruptManagement.cpp
@@ -7,10 +7,10 @@
#include <AK/ByteReader.h>
#include <Kernel/API/Syscall.h>
#include <Kernel/Arch/Interrupts.h>
-#include <Kernel/Arch/x86/InterruptManagement.h>
-#include <Kernel/Arch/x86/common/Interrupts/APIC.h>
-#include <Kernel/Arch/x86/common/Interrupts/IOAPIC.h>
-#include <Kernel/Arch/x86/common/Interrupts/PIC.h>
+#include <Kernel/Arch/x86_64/InterruptManagement.h>
+#include <Kernel/Arch/x86_64/Interrupts/APIC.h>
+#include <Kernel/Arch/x86_64/Interrupts/IOAPIC.h>
+#include <Kernel/Arch/x86_64/Interrupts/PIC.h>
#include <Kernel/CommandLine.h>
#include <Kernel/Firmware/MultiProcessor/Parser.h>
#include <Kernel/InterruptDisabler.h>
diff --git a/Kernel/Arch/x86/InterruptManagement.h b/Kernel/Arch/x86_64/InterruptManagement.h
index 6845118a9c..684e5f951e 100644
--- a/Kernel/Arch/x86/InterruptManagement.h
+++ b/Kernel/Arch/x86_64/InterruptManagement.h
@@ -10,8 +10,8 @@
#include <AK/NonnullOwnPtr.h>
#include <AK/OwnPtr.h>
#include <AK/Types.h>
-#include <Kernel/Arch/x86/IRQController.h>
-#include <Kernel/Arch/x86/common/Interrupts/IOAPIC.h>
+#include <Kernel/Arch/x86_64/IRQController.h>
+#include <Kernel/Arch/x86_64/Interrupts/IOAPIC.h>
#include <Kernel/Firmware/ACPI/Definitions.h>
#include <Kernel/Interrupts/GenericInterruptHandler.h>
#include <Kernel/Library/LockRefPtr.h>
diff --git a/Kernel/Arch/x86/common/Interrupts.cpp b/Kernel/Arch/x86_64/Interrupts.cpp
index a6c06fac11..726c535b5a 100644
--- a/Kernel/Arch/x86/common/Interrupts.cpp
+++ b/Kernel/Arch/x86_64/Interrupts.cpp
@@ -9,7 +9,7 @@
#include <AK/Types.h>
#include <Kernel/Arch/Interrupts.h>
-#include <Kernel/Arch/x86/common/Interrupts/PIC.h>
+#include <Kernel/Arch/x86_64/Interrupts/PIC.h>
#include <Kernel/Interrupts/GenericInterruptHandler.h>
#include <Kernel/Interrupts/SharedIRQHandler.h>
#include <Kernel/Interrupts/SpuriousInterruptHandler.h>
@@ -31,7 +31,7 @@
#include <Kernel/Arch/RegisterState.h>
#include <Kernel/Arch/SafeMem.h>
#include <Kernel/Arch/TrapFrame.h>
-#include <Kernel/Arch/x86/ISRStubs.h>
+#include <Kernel/Arch/x86_64/ISRStubs.h>
extern FlatPtr start_of_unmap_after_init;
extern FlatPtr end_of_unmap_after_init;
diff --git a/Kernel/Arch/x86/Interrupts.h b/Kernel/Arch/x86_64/Interrupts.h
index 79d0861491..79d0861491 100644
--- a/Kernel/Arch/x86/Interrupts.h
+++ b/Kernel/Arch/x86_64/Interrupts.h
diff --git a/Kernel/Arch/x86/common/Interrupts/APIC.cpp b/Kernel/Arch/x86_64/Interrupts/APIC.cpp
index 48d3ab902e..262c6011c2 100644
--- a/Kernel/Arch/x86/common/Interrupts/APIC.cpp
+++ b/Kernel/Arch/x86_64/Interrupts/APIC.cpp
@@ -9,10 +9,10 @@
#include <AK/Singleton.h>
#include <AK/Types.h>
#include <Kernel/Arch/Delay.h>
-#include <Kernel/Arch/x86/MSR.h>
-#include <Kernel/Arch/x86/ProcessorInfo.h>
-#include <Kernel/Arch/x86/Time/APICTimer.h>
-#include <Kernel/Arch/x86/common/Interrupts/APIC.h>
+#include <Kernel/Arch/x86_64/Interrupts/APIC.h>
+#include <Kernel/Arch/x86_64/MSR.h>
+#include <Kernel/Arch/x86_64/ProcessorInfo.h>
+#include <Kernel/Arch/x86_64/Time/APICTimer.h>
#include <Kernel/Debug.h>
#include <Kernel/Firmware/ACPI/Parser.h>
#include <Kernel/Interrupts/SpuriousInterruptHandler.h>
diff --git a/Kernel/Arch/x86/common/Interrupts/APIC.h b/Kernel/Arch/x86_64/Interrupts/APIC.h
index f64bca7844..f64bca7844 100644
--- a/Kernel/Arch/x86/common/Interrupts/APIC.h
+++ b/Kernel/Arch/x86_64/Interrupts/APIC.h
diff --git a/Kernel/Arch/x86/common/Interrupts/IOAPIC.cpp b/Kernel/Arch/x86_64/Interrupts/IOAPIC.cpp
index 7a17fffc0a..5b63d4b56f 100644
--- a/Kernel/Arch/x86/common/Interrupts/IOAPIC.cpp
+++ b/Kernel/Arch/x86_64/Interrupts/IOAPIC.cpp
@@ -5,9 +5,9 @@
*/
#include <AK/Optional.h>
-#include <Kernel/Arch/x86/InterruptManagement.h>
-#include <Kernel/Arch/x86/common/Interrupts/APIC.h>
-#include <Kernel/Arch/x86/common/Interrupts/IOAPIC.h>
+#include <Kernel/Arch/x86_64/InterruptManagement.h>
+#include <Kernel/Arch/x86_64/Interrupts/APIC.h>
+#include <Kernel/Arch/x86_64/Interrupts/IOAPIC.h>
#include <Kernel/Debug.h>
#include <Kernel/InterruptDisabler.h>
#include <Kernel/Sections.h>
diff --git a/Kernel/Arch/x86/common/Interrupts/IOAPIC.h b/Kernel/Arch/x86_64/Interrupts/IOAPIC.h
index ef8ff1ac85..106f16c996 100644
--- a/Kernel/Arch/x86/common/Interrupts/IOAPIC.h
+++ b/Kernel/Arch/x86_64/Interrupts/IOAPIC.h
@@ -6,7 +6,7 @@
#pragma once
-#include <Kernel/Arch/x86/IRQController.h>
+#include <Kernel/Arch/x86_64/IRQController.h>
#include <Kernel/Memory/TypedMapping.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/common/Interrupts/PIC.cpp b/Kernel/Arch/x86_64/Interrupts/PIC.cpp
index bcf4cc5f15..77c567d97b 100644
--- a/Kernel/Arch/x86/common/Interrupts/PIC.cpp
+++ b/Kernel/Arch/x86_64/Interrupts/PIC.cpp
@@ -6,8 +6,8 @@
#include <AK/Assertions.h>
#include <AK/Types.h>
-#include <Kernel/Arch/x86/IO.h>
-#include <Kernel/Arch/x86/common/Interrupts/PIC.h>
+#include <Kernel/Arch/x86_64/IO.h>
+#include <Kernel/Arch/x86_64/Interrupts/PIC.h>
#include <Kernel/InterruptDisabler.h>
#include <Kernel/Interrupts/GenericInterruptHandler.h>
#include <Kernel/Sections.h>
diff --git a/Kernel/Arch/x86/common/Interrupts/PIC.h b/Kernel/Arch/x86_64/Interrupts/PIC.h
index 25c3cb937b..e88e72326f 100644
--- a/Kernel/Arch/x86/common/Interrupts/PIC.h
+++ b/Kernel/Arch/x86_64/Interrupts/PIC.h
@@ -7,7 +7,7 @@
#pragma once
#include <AK/Types.h>
-#include <Kernel/Arch/x86/IRQController.h>
+#include <Kernel/Arch/x86_64/IRQController.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/MSR.h b/Kernel/Arch/x86_64/MSR.h
index 1acc1dfb41..ff2810d62e 100644
--- a/Kernel/Arch/x86/MSR.h
+++ b/Kernel/Arch/x86_64/MSR.h
@@ -8,7 +8,7 @@
#include <AK/Types.h>
-#include <Kernel/Arch/x86/CPUID.h>
+#include <Kernel/Arch/x86_64/CPUID.h>
#include <AK/Platform.h>
VALIDATE_IS_X86()
diff --git a/Kernel/Arch/x86/NonMaskableInterruptDisabler.h b/Kernel/Arch/x86_64/NonMaskableInterruptDisabler.h
index 881f884541..f08ada98fb 100644
--- a/Kernel/Arch/x86/NonMaskableInterruptDisabler.h
+++ b/Kernel/Arch/x86_64/NonMaskableInterruptDisabler.h
@@ -8,7 +8,7 @@
#include <AK/Types.h>
-#include <Kernel/Arch/x86/IO.h>
+#include <Kernel/Arch/x86_64/IO.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/PCI/Controller/HostBridge.cpp b/Kernel/Arch/x86_64/PCI/Controller/HostBridge.cpp
index 81c7e34444..7f7a460e99 100644
--- a/Kernel/Arch/x86/PCI/Controller/HostBridge.cpp
+++ b/Kernel/Arch/x86_64/PCI/Controller/HostBridge.cpp
@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <Kernel/Arch/x86/IO.h>
-#include <Kernel/Arch/x86/PCI/Controller/HostBridge.h>
+#include <Kernel/Arch/x86_64/IO.h>
+#include <Kernel/Arch/x86_64/PCI/Controller/HostBridge.h>
#include <Kernel/Bus/PCI/Access.h>
#include <Kernel/Sections.h>
diff --git a/Kernel/Arch/x86/PCI/Controller/HostBridge.h b/Kernel/Arch/x86_64/PCI/Controller/HostBridge.h
index 32705ea565..32705ea565 100644
--- a/Kernel/Arch/x86/PCI/Controller/HostBridge.h
+++ b/Kernel/Arch/x86_64/PCI/Controller/HostBridge.h
diff --git a/Kernel/Arch/x86/PCI/IDELegacyModeController.cpp b/Kernel/Arch/x86_64/PCI/IDELegacyModeController.cpp
index c89df06cce..35f6c5b8ed 100644
--- a/Kernel/Arch/x86/PCI/IDELegacyModeController.cpp
+++ b/Kernel/Arch/x86_64/PCI/IDELegacyModeController.cpp
@@ -6,7 +6,7 @@
#include <AK/OwnPtr.h>
#include <AK/Types.h>
-#include <Kernel/Arch/x86/PCI/IDELegacyModeController.h>
+#include <Kernel/Arch/x86_64/PCI/IDELegacyModeController.h>
#include <Kernel/Bus/PCI/API.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Sections.h>
diff --git a/Kernel/Arch/x86/PCI/IDELegacyModeController.h b/Kernel/Arch/x86_64/PCI/IDELegacyModeController.h
index 3d0170f7d9..3d0170f7d9 100644
--- a/Kernel/Arch/x86/PCI/IDELegacyModeController.h
+++ b/Kernel/Arch/x86_64/PCI/IDELegacyModeController.h
diff --git a/Kernel/Arch/x86/PCI/Initializer.cpp b/Kernel/Arch/x86_64/PCI/Initializer.cpp
index f6158e22a4..37f9bc6c4d 100644
--- a/Kernel/Arch/x86/PCI/Initializer.cpp
+++ b/Kernel/Arch/x86_64/PCI/Initializer.cpp
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <Kernel/Arch/x86/IO.h>
+#include <Kernel/Arch/x86_64/IO.h>
#include <Kernel/Bus/PCI/API.h>
#include <Kernel/Bus/PCI/Access.h>
#include <Kernel/Bus/PCI/Initializer.h>
diff --git a/Kernel/Arch/x86/common/PCSpeaker.cpp b/Kernel/Arch/x86_64/PCSpeaker.cpp
index 7c4bac5ebb..176a87073f 100644
--- a/Kernel/Arch/x86/common/PCSpeaker.cpp
+++ b/Kernel/Arch/x86_64/PCSpeaker.cpp
@@ -4,9 +4,9 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <Kernel/Arch/x86/IO.h>
-#include <Kernel/Arch/x86/Time/PIT.h>
-#include <Kernel/Arch/x86/common/PCSpeaker.h>
+#include <Kernel/Arch/x86_64/IO.h>
+#include <Kernel/Arch/x86_64/PCSpeaker.h>
+#include <Kernel/Arch/x86_64/Time/PIT.h>
void PCSpeaker::tone_on(int frequency)
{
diff --git a/Kernel/Arch/x86/common/PCSpeaker.h b/Kernel/Arch/x86_64/PCSpeaker.h
index ba08bb8f09..ba08bb8f09 100644
--- a/Kernel/Arch/x86/common/PCSpeaker.h
+++ b/Kernel/Arch/x86_64/PCSpeaker.h
diff --git a/Kernel/Arch/x86/common/PageDirectory.cpp b/Kernel/Arch/x86_64/PageDirectory.cpp
index 1efe016508..1efe016508 100644
--- a/Kernel/Arch/x86/common/PageDirectory.cpp
+++ b/Kernel/Arch/x86_64/PageDirectory.cpp
diff --git a/Kernel/Arch/x86/PageDirectory.h b/Kernel/Arch/x86_64/PageDirectory.h
index 86bc97bf8c..86bc97bf8c 100644
--- a/Kernel/Arch/x86/PageDirectory.h
+++ b/Kernel/Arch/x86_64/PageDirectory.h
diff --git a/Kernel/Arch/x86/common/Processor.cpp b/Kernel/Arch/x86_64/Processor.cpp
index 784975ac9e..3d1720048a 100644
--- a/Kernel/Arch/x86/common/Processor.cpp
+++ b/Kernel/Arch/x86_64/Processor.cpp
@@ -12,7 +12,7 @@
#include <AK/StringBuilder.h>
#include <AK/Types.h>
-#include <Kernel/Arch/x86/common/Interrupts/APIC.h>
+#include <Kernel/Arch/x86_64/Interrupts/APIC.h>
#include <Kernel/InterruptDisabler.h>
#include <Kernel/Process.h>
#include <Kernel/Scheduler.h>
@@ -25,9 +25,9 @@
#include <Kernel/Arch/SafeMem.h>
#include <Kernel/Arch/ScopedCritical.h>
#include <Kernel/Arch/TrapFrame.h>
-#include <Kernel/Arch/x86/CPUID.h>
-#include <Kernel/Arch/x86/MSR.h>
-#include <Kernel/Arch/x86/ProcessorInfo.h>
+#include <Kernel/Arch/x86_64/CPUID.h>
+#include <Kernel/Arch/x86_64/MSR.h>
+#include <Kernel/Arch/x86_64/ProcessorInfo.h>
#include <Kernel/Memory/PageDirectory.h>
#include <Kernel/Memory/ScopedAddressSpaceSwitcher.h>
@@ -1623,4 +1623,268 @@ u32 Processor::clear_critical()
return prev_critical;
}
+NAKED void thread_context_first_enter(void)
+{
+ // enter_thread_context returns to here first time a thread is executing
+ asm(
+ // switch_context will have pushed from_thread and to_thread to our news
+ // stack prior to thread_context_first_enter() being called, and the
+ // pointer to TrapFrame was the top of the stack before that
+ " popq %rdi \n" // from_thread (argument 0)
+ " popq %rsi \n" // to_thread (argument 1)
+ " popq %rdx \n" // pointer to TrapFrame (argument 2)
+ " cld \n"
+ " call context_first_init \n"
+ " jmp common_trap_exit \n");
+};
+
+NAKED void do_assume_context(Thread*, u32)
+{
+ // clang-format off
+ // FIXME: I hope (Thread* thread, u32 flags) aren't compiled away
+ asm(
+ " movq %rdi, %r12 \n" // save thread ptr
+ " movq %rsi, %r13 \n" // save flags
+ // We're going to call Processor::init_context, so just make sure
+ // we have enough stack space so we don't stomp over it
+ " subq $(" __STRINGIFY(16 + REGISTER_STATE_SIZE + TRAP_FRAME_SIZE + 8) "), %rsp \n"
+ " cld \n"
+ " call do_init_context \n"
+ " movq %rax, %rsp \n" // move stack pointer to what Processor::init_context set up for us
+ " movq %r12, %rdi \n" // to_thread
+ " movq %r12, %rsi \n" // from_thread
+ " pushq %r12 \n" // to_thread (for thread_context_first_enter)
+ " pushq %r12 \n" // from_thread (for thread_context_first_enter)
+ " leaq thread_context_first_enter(%rip), %r12 \n" // should be same as regs.rip
+ " pushq %r12 \n"
+ " jmp enter_thread_context \n");
+ // clang-format on
+}
+
+StringView Processor::platform_string()
+{
+ return "x86_64"sv;
+}
+
+// FIXME: For the most part this is a copy of the i386-specific function, get rid of the code duplication
+FlatPtr Processor::init_context(Thread& thread, bool leave_crit)
+{
+ VERIFY(is_kernel_mode());
+ VERIFY(g_scheduler_lock.is_locked());
+ if (leave_crit) {
+ // Leave the critical section we set up in in Process::exec,
+ // but because we still have the scheduler lock we should end up with 1
+ VERIFY(in_critical() == 2);
+ m_in_critical = 1; // leave it without triggering anything or restoring flags
+ }
+
+ u64 kernel_stack_top = thread.kernel_stack_top();
+
+ // Add a random offset between 0-256 (16-byte aligned)
+ kernel_stack_top -= round_up_to_power_of_two(get_fast_random<u8>(), 16);
+
+ u64 stack_top = kernel_stack_top;
+
+ // TODO: handle NT?
+ VERIFY((cpu_flags() & 0x24000) == 0); // Assume !(NT | VM)
+
+ auto& regs = thread.regs();
+ bool return_to_user = (regs.cs & 3) != 0;
+
+ stack_top -= 1 * sizeof(u64);
+ *reinterpret_cast<u64*>(kernel_stack_top - 2 * sizeof(u64)) = FlatPtr(&exit_kernel_thread);
+
+ stack_top -= sizeof(RegisterState);
+
+ // we want to end up 16-byte aligned, %rsp + 8 should be aligned
+ stack_top -= sizeof(u64);
+ *reinterpret_cast<u64*>(kernel_stack_top - sizeof(u64)) = 0;
+
+ // set up the stack so that after returning from thread_context_first_enter()
+ // we will end up either in kernel mode or user mode, depending on how the thread is set up
+ // However, the first step is to always start in kernel mode with thread_context_first_enter
+ RegisterState& iretframe = *reinterpret_cast<RegisterState*>(stack_top);
+ iretframe.rdi = regs.rdi;
+ iretframe.rsi = regs.rsi;
+ iretframe.rbp = regs.rbp;
+ iretframe.rsp = 0;
+ iretframe.rbx = regs.rbx;
+ iretframe.rdx = regs.rdx;
+ iretframe.rcx = regs.rcx;
+ iretframe.rax = regs.rax;
+ iretframe.r8 = regs.r8;
+ iretframe.r9 = regs.r9;
+ iretframe.r10 = regs.r10;
+ iretframe.r11 = regs.r11;
+ iretframe.r12 = regs.r12;
+ iretframe.r13 = regs.r13;
+ iretframe.r14 = regs.r14;
+ iretframe.r15 = regs.r15;
+ iretframe.rflags = regs.rflags;
+ iretframe.rip = regs.rip;
+ iretframe.cs = regs.cs;
+ if (return_to_user) {
+ iretframe.userspace_rsp = regs.rsp;
+ iretframe.userspace_ss = GDT_SELECTOR_DATA3 | 3;
+ } else {
+ iretframe.userspace_rsp = kernel_stack_top;
+ iretframe.userspace_ss = 0;
+ }
+
+ // make space for a trap frame
+ stack_top -= sizeof(TrapFrame);
+ TrapFrame& trap = *reinterpret_cast<TrapFrame*>(stack_top);
+ trap.regs = &iretframe;
+ trap.prev_irq_level = 0;
+ trap.next_trap = nullptr;
+
+ stack_top -= sizeof(u64); // pointer to TrapFrame
+ *reinterpret_cast<u64*>(stack_top) = stack_top + 8;
+
+ if constexpr (CONTEXT_SWITCH_DEBUG) {
+ if (return_to_user) {
+ dbgln("init_context {} ({}) set up to execute at rip={}:{}, rsp={}, stack_top={}, user_top={}",
+ thread,
+ VirtualAddress(&thread),
+ iretframe.cs, regs.rip,
+ VirtualAddress(regs.rsp),
+ VirtualAddress(stack_top),
+ iretframe.userspace_rsp);
+ } else {
+ dbgln("init_context {} ({}) set up to execute at rip={}:{}, rsp={}, stack_top={}",
+ thread,
+ VirtualAddress(&thread),
+ iretframe.cs, regs.rip,
+ VirtualAddress(regs.rsp),
+ VirtualAddress(stack_top));
+ }
+ }
+
+ // make switch_context() always first return to thread_context_first_enter()
+ // in kernel mode, so set up these values so that we end up popping iretframe
+ // off the stack right after the context switch completed, at which point
+ // control is transferred to what iretframe is pointing to.
+ regs.rip = FlatPtr(&thread_context_first_enter);
+ regs.rsp0 = kernel_stack_top;
+ regs.rsp = stack_top;
+ regs.cs = GDT_SELECTOR_CODE0;
+ return stack_top;
+}
+
+void Processor::switch_context(Thread*& from_thread, Thread*& to_thread)
+{
+ VERIFY(!m_in_irq);
+ VERIFY(m_in_critical == 1);
+ VERIFY(is_kernel_mode());
+
+ dbgln_if(CONTEXT_SWITCH_DEBUG, "switch_context --> switching out of: {} {}", VirtualAddress(from_thread), *from_thread);
+
+ // m_in_critical is restored in enter_thread_context
+ from_thread->save_critical(m_in_critical);
+
+ // clang-format off
+ // Switch to new thread context, passing from_thread and to_thread
+ // through to the new context using registers rdx and rax
+ asm volatile(
+ // NOTE: changing how much we push to the stack affects thread_context_first_enter()!
+ "pushfq \n"
+ "pushq %%rbx \n"
+ "pushq %%rcx \n"
+ "pushq %%rbp \n"
+ "pushq %%rsi \n"
+ "pushq %%rdi \n"
+ "pushq %%r8 \n"
+ "pushq %%r9 \n"
+ "pushq %%r10 \n"
+ "pushq %%r11 \n"
+ "pushq %%r12 \n"
+ "pushq %%r13 \n"
+ "pushq %%r14 \n"
+ "pushq %%r15 \n"
+ "movq %%rsp, %[from_rsp] \n"
+ "leaq 1f(%%rip), %%rbx \n"
+ "movq %%rbx, %[from_rip] \n"
+ "movq %[to_rsp0], %%rbx \n"
+ "movl %%ebx, %[tss_rsp0l] \n"
+ "shrq $32, %%rbx \n"
+ "movl %%ebx, %[tss_rsp0h] \n"
+ "movq %[to_rsp], %%rsp \n"
+ "pushq %[to_thread] \n"
+ "pushq %[from_thread] \n"
+ "pushq %[to_rip] \n"
+ "cld \n"
+ "movq 16(%%rsp), %%rsi \n"
+ "movq 8(%%rsp), %%rdi \n"
+ "jmp enter_thread_context \n"
+ "1: \n"
+ "popq %%rdx \n"
+ "popq %%rax \n"
+ "popq %%r15 \n"
+ "popq %%r14 \n"
+ "popq %%r13 \n"
+ "popq %%r12 \n"
+ "popq %%r11 \n"
+ "popq %%r10 \n"
+ "popq %%r9 \n"
+ "popq %%r8 \n"
+ "popq %%rdi \n"
+ "popq %%rsi \n"
+ "popq %%rbp \n"
+ "popq %%rcx \n"
+ "popq %%rbx \n"
+ "popfq \n"
+ : [from_rsp] "=m" (from_thread->regs().rsp),
+ [from_rip] "=m" (from_thread->regs().rip),
+ [tss_rsp0l] "=m" (m_tss.rsp0l),
+ [tss_rsp0h] "=m" (m_tss.rsp0h),
+ "=d" (from_thread), // needed so that from_thread retains the correct value
+ "=a" (to_thread) // needed so that to_thread retains the correct value
+ : [to_rsp] "g" (to_thread->regs().rsp),
+ [to_rsp0] "g" (to_thread->regs().rsp0),
+ [to_rip] "c" (to_thread->regs().rip),
+ [from_thread] "d" (from_thread),
+ [to_thread] "a" (to_thread)
+ : "memory", "rbx"
+ );
+ // clang-format on
+
+ dbgln_if(CONTEXT_SWITCH_DEBUG, "switch_context <-- from {} {} to {} {}", VirtualAddress(from_thread), *from_thread, VirtualAddress(to_thread), *to_thread);
+}
+
+UNMAP_AFTER_INIT void Processor::initialize_context_switching(Thread& initial_thread)
+{
+ VERIFY(initial_thread.process().is_kernel_process());
+
+ auto& regs = initial_thread.regs();
+ m_tss.iomapbase = sizeof(m_tss);
+ m_tss.rsp0l = regs.rsp0 & 0xffffffff;
+ m_tss.rsp0h = regs.rsp0 >> 32;
+
+ m_scheduler_initialized = true;
+
+ // clang-format off
+ asm volatile(
+ "movq %[new_rsp], %%rsp \n" // switch to new stack
+ "pushq %[from_to_thread] \n" // to_thread
+ "pushq %[from_to_thread] \n" // from_thread
+ "pushq %[new_rip] \n" // save the entry rip to the stack
+ "cld \n"
+ "pushq %[cpu] \n" // push argument for init_finished before register is clobbered
+ "call pre_init_finished \n"
+ "pop %%rdi \n" // move argument for init_finished into place
+ "call init_finished \n"
+ "call post_init_finished \n"
+ "movq 24(%%rsp), %%rdi \n" // move pointer to TrapFrame into place
+ "call enter_trap_no_irq \n"
+ "retq \n"
+ :: [new_rsp] "g" (regs.rsp),
+ [new_rip] "a" (regs.rip),
+ [from_to_thread] "b" (&initial_thread),
+ [cpu] "c" ((u64)id())
+ );
+ // clang-format on
+
+ VERIFY_NOT_REACHED();
+}
+
}
diff --git a/Kernel/Arch/x86/Processor.h b/Kernel/Arch/x86_64/Processor.h
index 21ab130272..cd1dc9c8ef 100644
--- a/Kernel/Arch/x86/Processor.h
+++ b/Kernel/Arch/x86_64/Processor.h
@@ -14,11 +14,11 @@
#include <Kernel/Arch/DeferredCallEntry.h>
#include <Kernel/Arch/PageDirectory.h>
#include <Kernel/Arch/ProcessorSpecificDataID.h>
-#include <Kernel/Arch/x86/ASM_wrapper.h>
-#include <Kernel/Arch/x86/CPUID.h>
-#include <Kernel/Arch/x86/DescriptorTable.h>
-#include <Kernel/Arch/x86/SIMDState.h>
-#include <Kernel/Arch/x86/TSS.h>
+#include <Kernel/Arch/x86_64/ASM_wrapper.h>
+#include <Kernel/Arch/x86_64/CPUID.h>
+#include <Kernel/Arch/x86_64/DescriptorTable.h>
+#include <Kernel/Arch/x86_64/SIMDState.h>
+#include <Kernel/Arch/x86_64/TSS.h>
#include <Kernel/Forward.h>
#include <Kernel/KString.h>
diff --git a/Kernel/Arch/x86/common/ProcessorInfo.cpp b/Kernel/Arch/x86_64/ProcessorInfo.cpp
index edc05b6306..43c8b0ed0a 100644
--- a/Kernel/Arch/x86/common/ProcessorInfo.cpp
+++ b/Kernel/Arch/x86_64/ProcessorInfo.cpp
@@ -8,8 +8,8 @@
#include <AK/StringBuilder.h>
#include <AK/Types.h>
#include <Kernel/Arch/Processor.h>
-#include <Kernel/Arch/x86/CPUID.h>
-#include <Kernel/Arch/x86/ProcessorInfo.h>
+#include <Kernel/Arch/x86_64/CPUID.h>
+#include <Kernel/Arch/x86_64/ProcessorInfo.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/ProcessorInfo.h b/Kernel/Arch/x86_64/ProcessorInfo.h
index 6bb90b0ea7..6bb90b0ea7 100644
--- a/Kernel/Arch/x86/ProcessorInfo.h
+++ b/Kernel/Arch/x86_64/ProcessorInfo.h
diff --git a/Kernel/Arch/x86/common/RTC.cpp b/Kernel/Arch/x86_64/RTC.cpp
index f9816f52e0..7af7c9637a 100644
--- a/Kernel/Arch/x86/common/RTC.cpp
+++ b/Kernel/Arch/x86_64/RTC.cpp
@@ -7,8 +7,8 @@
#include <AK/Format.h>
#include <AK/Time.h>
#include <Kernel/Arch/Delay.h>
-#include <Kernel/Arch/x86/common/CMOS.h>
-#include <Kernel/Arch/x86/common/RTC.h>
+#include <Kernel/Arch/x86_64/CMOS.h>
+#include <Kernel/Arch/x86_64/RTC.h>
namespace Kernel::RTC {
diff --git a/Kernel/Arch/x86/common/RTC.h b/Kernel/Arch/x86_64/RTC.h
index 80e49ff1e7..80e49ff1e7 100644
--- a/Kernel/Arch/x86/common/RTC.h
+++ b/Kernel/Arch/x86_64/RTC.h
diff --git a/Kernel/Arch/x86/RegisterState.h b/Kernel/Arch/x86_64/RegisterState.h
index abeeab7733..abdf67b9d8 100644
--- a/Kernel/Arch/x86/RegisterState.h
+++ b/Kernel/Arch/x86_64/RegisterState.h
@@ -10,7 +10,7 @@
#include <LibC/sys/arch/regs.h>
#include <Kernel/Arch/CPU.h>
-#include <Kernel/Arch/x86/ASM_wrapper.h>
+#include <Kernel/Arch/x86_64/ASM_wrapper.h>
#include <AK/Platform.h>
VALIDATE_IS_X86()
diff --git a/Kernel/Arch/x86/SIMDState.h b/Kernel/Arch/x86_64/SIMDState.h
index f2a6466a7d..f2a6466a7d 100644
--- a/Kernel/Arch/x86/SIMDState.h
+++ b/Kernel/Arch/x86_64/SIMDState.h
diff --git a/Kernel/Arch/x86/common/SafeMem.cpp b/Kernel/Arch/x86_64/SafeMem.cpp
index fe54941f57..fe54941f57 100644
--- a/Kernel/Arch/x86/common/SafeMem.cpp
+++ b/Kernel/Arch/x86_64/SafeMem.cpp
diff --git a/Kernel/Arch/x86/common/ScopedCritical.cpp b/Kernel/Arch/x86_64/ScopedCritical.cpp
index 5b1698e525..5b1698e525 100644
--- a/Kernel/Arch/x86/common/ScopedCritical.cpp
+++ b/Kernel/Arch/x86_64/ScopedCritical.cpp
diff --git a/Kernel/Arch/x86/common/Shutdown.cpp b/Kernel/Arch/x86_64/Shutdown.cpp
index 948f720981..bfc296ede1 100644
--- a/Kernel/Arch/x86/common/Shutdown.cpp
+++ b/Kernel/Arch/x86_64/Shutdown.cpp
@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <Kernel/Arch/x86/IO.h>
-#include <Kernel/Arch/x86/common/Shutdown.h>
+#include <Kernel/Arch/x86_64/IO.h>
+#include <Kernel/Arch/x86_64/Shutdown.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/common/Shutdown.h b/Kernel/Arch/x86_64/Shutdown.h
index 90a742176e..90a742176e 100644
--- a/Kernel/Arch/x86/common/Shutdown.h
+++ b/Kernel/Arch/x86_64/Shutdown.h
diff --git a/Kernel/Arch/x86/common/SmapDisabler.cpp b/Kernel/Arch/x86_64/SmapDisabler.cpp
index 1adf3154ed..530254b0c8 100644
--- a/Kernel/Arch/x86/common/SmapDisabler.cpp
+++ b/Kernel/Arch/x86_64/SmapDisabler.cpp
@@ -6,7 +6,7 @@
#include <Kernel/Arch/SmapDisabler.h>
-#include <Kernel/Arch/x86/ASM_wrapper.h>
+#include <Kernel/Arch/x86_64/ASM_wrapper.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/x86_64/SyscallEntry.cpp b/Kernel/Arch/x86_64/SyscallEntry.cpp
index c325cbd710..bd9ebfc7d1 100644
--- a/Kernel/Arch/x86/x86_64/SyscallEntry.cpp
+++ b/Kernel/Arch/x86_64/SyscallEntry.cpp
@@ -5,8 +5,8 @@
*/
#include <Kernel/Arch/TrapFrame.h>
-#include <Kernel/Arch/x86/DescriptorTable.h>
-#include <Kernel/Arch/x86/Processor.h>
+#include <Kernel/Arch/x86_64/DescriptorTable.h>
+#include <Kernel/Arch/x86_64/Processor.h>
extern "C" void syscall_entry();
extern "C" [[gnu::naked]] void syscall_entry()
diff --git a/Kernel/Arch/x86/TSS.h b/Kernel/Arch/x86_64/TSS.h
index b84cf2d618..b84cf2d618 100644
--- a/Kernel/Arch/x86/TSS.h
+++ b/Kernel/Arch/x86_64/TSS.h
diff --git a/Kernel/Arch/x86/Time/APICTimer.cpp b/Kernel/Arch/x86_64/Time/APICTimer.cpp
index d7543a8c7c..5c6499dcb1 100644
--- a/Kernel/Arch/x86/Time/APICTimer.cpp
+++ b/Kernel/Arch/x86_64/Time/APICTimer.cpp
@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <Kernel/Arch/x86/Time/APICTimer.h>
-#include <Kernel/Arch/x86/common/Interrupts/APIC.h>
+#include <Kernel/Arch/x86_64/Interrupts/APIC.h>
+#include <Kernel/Arch/x86_64/Time/APICTimer.h>
#include <Kernel/Panic.h>
#include <Kernel/Sections.h>
#include <Kernel/Time/TimeManagement.h>
diff --git a/Kernel/Arch/x86/Time/APICTimer.h b/Kernel/Arch/x86_64/Time/APICTimer.h
index 4474875538..ed02013b46 100644
--- a/Kernel/Arch/x86/Time/APICTimer.h
+++ b/Kernel/Arch/x86_64/Time/APICTimer.h
@@ -7,7 +7,7 @@
#pragma once
#include <AK/Types.h>
-#include <Kernel/Arch/x86/common/Interrupts/APIC.h>
+#include <Kernel/Arch/x86_64/Interrupts/APIC.h>
#include <Kernel/Interrupts/GenericInterruptHandler.h>
#include <Kernel/Time/HardwareTimer.h>
diff --git a/Kernel/Arch/x86/Time/HPET.cpp b/Kernel/Arch/x86_64/Time/HPET.cpp
index 024f722df6..88d99d5ca7 100644
--- a/Kernel/Arch/x86/Time/HPET.cpp
+++ b/Kernel/Arch/x86_64/Time/HPET.cpp
@@ -5,8 +5,8 @@
*/
#include <AK/StringView.h>
-#include <Kernel/Arch/x86/Time/HPET.h>
-#include <Kernel/Arch/x86/Time/HPETComparator.h>
+#include <Kernel/Arch/x86_64/Time/HPET.h>
+#include <Kernel/Arch/x86_64/Time/HPETComparator.h>
#include <Kernel/Debug.h>
#include <Kernel/Firmware/ACPI/Parser.h>
#include <Kernel/Memory/MemoryManager.h>
diff --git a/Kernel/Arch/x86/Time/HPET.h b/Kernel/Arch/x86_64/Time/HPET.h
index 8454985774..8454985774 100644
--- a/Kernel/Arch/x86/Time/HPET.h
+++ b/Kernel/Arch/x86_64/Time/HPET.h
diff --git a/Kernel/Arch/x86/Time/HPETComparator.cpp b/Kernel/Arch/x86_64/Time/HPETComparator.cpp
index baeea9b85f..952eec7e2f 100644
--- a/Kernel/Arch/x86/Time/HPETComparator.cpp
+++ b/Kernel/Arch/x86_64/Time/HPETComparator.cpp
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <Kernel/Arch/x86/Time/HPETComparator.h>
+#include <Kernel/Arch/x86_64/Time/HPETComparator.h>
#include <Kernel/Assertions.h>
#include <Kernel/Debug.h>
#include <Kernel/InterruptDisabler.h>
diff --git a/Kernel/Arch/x86/Time/HPETComparator.h b/Kernel/Arch/x86_64/Time/HPETComparator.h
index cfcb70581f..53bfd9c09c 100644
--- a/Kernel/Arch/x86/Time/HPETComparator.h
+++ b/Kernel/Arch/x86_64/Time/HPETComparator.h
@@ -8,7 +8,7 @@
#include <AK/Function.h>
#include <AK/Types.h>
-#include <Kernel/Arch/x86/Time/HPET.h>
+#include <Kernel/Arch/x86_64/Time/HPET.h>
#include <Kernel/Time/HardwareTimer.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/Time/PIT.cpp b/Kernel/Arch/x86_64/Time/PIT.cpp
index a9709e1229..bd1644956d 100644
--- a/Kernel/Arch/x86/Time/PIT.cpp
+++ b/Kernel/Arch/x86_64/Time/PIT.cpp
@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <Kernel/Arch/x86/IO.h>
-#include <Kernel/Arch/x86/Time/PIT.h>
+#include <Kernel/Arch/x86_64/IO.h>
+#include <Kernel/Arch/x86_64/Time/PIT.h>
#include <Kernel/InterruptDisabler.h>
#include <Kernel/Interrupts/GenericInterruptHandler.h>
#include <Kernel/Scheduler.h>
diff --git a/Kernel/Arch/x86/Time/PIT.h b/Kernel/Arch/x86_64/Time/PIT.h
index 552a638acd..552a638acd 100644
--- a/Kernel/Arch/x86/Time/PIT.h
+++ b/Kernel/Arch/x86_64/Time/PIT.h
diff --git a/Kernel/Arch/x86/Time/RTC.cpp b/Kernel/Arch/x86_64/Time/RTC.cpp
index 3686a73356..eb372beb05 100644
--- a/Kernel/Arch/x86/Time/RTC.cpp
+++ b/Kernel/Arch/x86_64/Time/RTC.cpp
@@ -4,10 +4,10 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <Kernel/Arch/x86/IO.h>
-#include <Kernel/Arch/x86/NonMaskableInterruptDisabler.h>
-#include <Kernel/Arch/x86/Time/RTC.h>
-#include <Kernel/Arch/x86/common/CMOS.h>
+#include <Kernel/Arch/x86_64/CMOS.h>
+#include <Kernel/Arch/x86_64/IO.h>
+#include <Kernel/Arch/x86_64/NonMaskableInterruptDisabler.h>
+#include <Kernel/Arch/x86_64/Time/RTC.h>
#include <Kernel/InterruptDisabler.h>
#include <Kernel/Time/TimeManagement.h>
diff --git a/Kernel/Arch/x86/Time/RTC.h b/Kernel/Arch/x86_64/Time/RTC.h
index b15e4aa7e1..4cfb520c8d 100644
--- a/Kernel/Arch/x86/Time/RTC.h
+++ b/Kernel/Arch/x86_64/Time/RTC.h
@@ -6,7 +6,7 @@
#pragma once
-#include <Kernel/Arch/x86/common/RTC.h>
+#include <Kernel/Arch/x86_64/RTC.h>
#include <Kernel/Library/NonnullLockRefPtr.h>
#include <Kernel/Time/HardwareTimer.h>
diff --git a/Kernel/Arch/x86/common/TrapFrame.cpp b/Kernel/Arch/x86_64/TrapFrame.cpp
index 5b96146d60..ba363c306e 100644
--- a/Kernel/Arch/x86/common/TrapFrame.cpp
+++ b/Kernel/Arch/x86_64/TrapFrame.cpp
@@ -5,7 +5,7 @@
*/
#include <Kernel/Arch/Processor.h>
-#include <Kernel/Arch/x86/TrapFrame.h>
+#include <Kernel/Arch/x86_64/TrapFrame.h>
#include <Kernel/InterruptDisabler.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/TrapFrame.h b/Kernel/Arch/x86_64/TrapFrame.h
index 6481e72b57..6481e72b57 100644
--- a/Kernel/Arch/x86/TrapFrame.h
+++ b/Kernel/Arch/x86_64/TrapFrame.h
diff --git a/Kernel/Arch/x86/VGA/IOArbiter.cpp b/Kernel/Arch/x86_64/VGA/IOArbiter.cpp
index cf558150ce..8d3e632f59 100644
--- a/Kernel/Arch/x86/VGA/IOArbiter.cpp
+++ b/Kernel/Arch/x86_64/VGA/IOArbiter.cpp
@@ -7,8 +7,8 @@
#include <AK/Try.h>
#include <Kernel/Arch/CPU.h>
#include <Kernel/Arch/Delay.h>
-#include <Kernel/Arch/x86/IO.h>
-#include <Kernel/Arch/x86/VGA/IOArbiter.h>
+#include <Kernel/Arch/x86_64/IO.h>
+#include <Kernel/Arch/x86_64/VGA/IOArbiter.h>
namespace Kernel {
diff --git a/Kernel/Arch/x86/VGA/IOArbiter.h b/Kernel/Arch/x86_64/VGA/IOArbiter.h
index 711f8324d8..711f8324d8 100644
--- a/Kernel/Arch/x86/VGA/IOArbiter.h
+++ b/Kernel/Arch/x86_64/VGA/IOArbiter.h
diff --git a/Kernel/Arch/x86/init.cpp b/Kernel/Arch/x86_64/init.cpp
index 2b4ee79bda..a9bcdeb773 100644
--- a/Kernel/Arch/x86/init.cpp
+++ b/Kernel/Arch/x86_64/init.cpp
@@ -7,9 +7,9 @@
#include <AK/Types.h>
#include <Kernel/Arch/InterruptManagement.h>
#include <Kernel/Arch/Processor.h>
-#include <Kernel/Arch/x86/Hypervisor/VMWareBackdoor.h>
-#include <Kernel/Arch/x86/common/Interrupts/APIC.h>
-#include <Kernel/Arch/x86/common/Interrupts/PIC.h>
+#include <Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.h>
+#include <Kernel/Arch/x86_64/Interrupts/APIC.h>
+#include <Kernel/Arch/x86_64/Interrupts/PIC.h>
#include <Kernel/BootInfo.h>
#include <Kernel/Bus/PCI/Access.h>
#include <Kernel/Bus/PCI/Initializer.h>
diff --git a/Kernel/Arch/x86/linker.ld b/Kernel/Arch/x86_64/linker.ld
index e11648fe13..e11648fe13 100644
--- a/Kernel/Arch/x86/linker.ld
+++ b/Kernel/Arch/x86_64/linker.ld
diff --git a/Kernel/Arch/x86/mcontext.h b/Kernel/Arch/x86_64/mcontext.h
index b2755dd431..b2755dd431 100644
--- a/Kernel/Arch/x86/mcontext.h
+++ b/Kernel/Arch/x86_64/mcontext.h
diff --git a/Kernel/Bus/PCI/Access.cpp b/Kernel/Bus/PCI/Access.cpp
index 050b8b8a43..460d9ece8a 100644
--- a/Kernel/Bus/PCI/Access.cpp
+++ b/Kernel/Bus/PCI/Access.cpp
@@ -8,7 +8,7 @@
#include <AK/Error.h>
#include <AK/HashTable.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/PCI/Controller/HostBridge.h>
+# include <Kernel/Arch/x86_64/PCI/Controller/HostBridge.h>
#endif
#include <Kernel/Bus/PCI/Access.h>
#include <Kernel/Bus/PCI/Controller/MemoryBackedHostBridge.h>
diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt
index bf0601c32a..2d4b95fdd6 100644
--- a/Kernel/CMakeLists.txt
+++ b/Kernel/CMakeLists.txt
@@ -350,46 +350,37 @@ set(KERNEL_SOURCES
if ("${SERENITY_ARCH}" STREQUAL "x86_64")
set(KERNEL_SOURCES
${KERNEL_SOURCES}
- Arch/x86/init.cpp
+ Arch/x86_64/init.cpp
Arch/Processor.cpp
- Arch/x86/common/Interrupts/APIC.cpp
- Arch/x86/common/Interrupts/IOAPIC.cpp
- Arch/x86/common/Interrupts/PIC.cpp
-
- Arch/x86/common/CMOS.cpp
- Arch/x86/common/DebugOutput.cpp
- Arch/x86/common/Delay.cpp
- Arch/x86/common/I8042Reboot.cpp
- Arch/x86/common/PCSpeaker.cpp
- Arch/x86/common/RTC.cpp
- Arch/x86/common/ScopedCritical.cpp
- Arch/x86/common/SmapDisabler.cpp
- Arch/x86/common/Shutdown.cpp
-
- Arch/x86/CurrentTime.cpp
-
- Arch/x86/Hypervisor/BochsDisplayConnector.cpp
- Arch/x86/Hypervisor/VMWareBackdoor.cpp
-
- Arch/x86/ISABus/HID/PS2KeyboardDevice.cpp
- Arch/x86/ISABus/HID/PS2MouseDevice.cpp
- Arch/x86/ISABus/HID/VMWareMouseDevice.cpp
- Arch/x86/ISABus/I8042Controller.cpp
- Arch/x86/ISABus/IDEController.cpp
- Arch/x86/ISABus/SerialDevice.cpp
- Arch/x86/PCI/Controller/HostBridge.cpp
- Arch/x86/PCI/IDELegacyModeController.cpp
- Arch/x86/PCI/Initializer.cpp
-
- Arch/x86/Time/APICTimer.cpp
- Arch/x86/Time/HPET.cpp
- Arch/x86/Time/HPETComparator.cpp
- Arch/x86/Time/PIT.cpp
- Arch/x86/Time/RTC.cpp
-
- Arch/x86/VGA/IOArbiter.cpp
+ Arch/x86_64/CMOS.cpp
+ Arch/x86_64/DebugOutput.cpp
+ Arch/x86_64/Delay.cpp
+
+ Arch/x86_64/Hypervisor/BochsDisplayConnector.cpp
+ Arch/x86_64/Hypervisor/VMWareBackdoor.cpp
+
+ Arch/x86_64/CurrentTime.cpp
+
+ Arch/x86_64/Hypervisor/BochsDisplayConnector.cpp
+ Arch/x86_64/Hypervisor/VMWareBackdoor.cpp
+
+ Arch/x86_64/Interrupts/APIC.cpp
+ Arch/x86_64/Interrupts/IOAPIC.cpp
+ Arch/x86_64/Interrupts/PIC.cpp
+
+ Arch/x86_64/ISABus/HID/PS2KeyboardDevice.cpp
+ Arch/x86_64/ISABus/HID/PS2MouseDevice.cpp
+ Arch/x86_64/ISABus/HID/VMWareMouseDevice.cpp
+ Arch/x86_64/ISABus/I8042Controller.cpp
+ Arch/x86_64/ISABus/IDEController.cpp
+ Arch/x86_64/ISABus/SerialDevice.cpp
+ Arch/x86_64/PCI/Controller/HostBridge.cpp
+ Arch/x86_64/PCI/IDELegacyModeController.cpp
+ Arch/x86_64/PCI/Initializer.cpp
+
+ Arch/x86_64/VGA/IOArbiter.cpp
# TODO: Share these with the aarch64 build
Interrupts/SpuriousInterruptHandler.cpp
@@ -405,32 +396,30 @@ if ("${SERENITY_ARCH}" STREQUAL "x86_64")
set(KERNEL_SOURCES
${KERNEL_SOURCES}
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/${KERNEL_ARCH}/ASM_wrapper.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/${KERNEL_ARCH}/Boot/ap_setup.S
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/${KERNEL_ARCH}/InterruptEntry.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/${KERNEL_ARCH}/Processor.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/Boot/ap_setup.S
+ ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/InterruptEntry.cpp
)
set(KERNEL_SOURCES
${KERNEL_SOURCES}
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/ASM_wrapper.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/CPU.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/CPUID.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/CrashHandler.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/InterruptManagement.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/Interrupts.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/PageDirectory.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/Processor.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/ProcessorInfo.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/SafeMem.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/common/TrapFrame.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/ASM_wrapper.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/CPU.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/CPUID.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/CrashHandler.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/InterruptManagement.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/Interrupts.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/PageDirectory.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/Processor.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/ProcessorInfo.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/SafeMem.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/TrapFrame.cpp
)
if("${SERENITY_ARCH}" STREQUAL "x86_64")
set(KERNEL_SOURCES
${KERNEL_SOURCES}
- ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/${KERNEL_ARCH}/SyscallEntry.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/SyscallEntry.cpp
)
endif()
elseif("${SERENITY_ARCH}" STREQUAL "aarch64")
@@ -623,7 +612,7 @@ if (ENABLE_KERNEL_COVERAGE_COLLECTION)
# otherwise we'll end up with recursive calls to that function.
../AK/Format.cpp
../AK/StringBuilder.cpp
- ../Kernel/Arch/x86/${KERNEL_ARCH}/Processor.cpp
+ ../Kernel/Arch/x86_64/Processor.cpp
../Kernel/Devices/KCOVDevice.cpp
../Kernel/Devices/KCOVInstance.cpp
../Kernel/FileSystem/File.cpp
@@ -635,7 +624,7 @@ if (ENABLE_KERNEL_COVERAGE_COLLECTION)
# function prologue for all functions. This assumption is not true for
# interrupt handlers because their calling convention is not compatible
# with the System V ABI.
- ../Kernel/Arch/x86/common/Interrupts.cpp
+ ../Kernel/Arch/x86_64/Interrupts.cpp
../Kernel/Syscall.cpp
)
set_source_files_properties(${KCOV_EXCLUDED_SOURCES} PROPERTIES COMPILE_FLAGS "-fno-sanitize-coverage=trace-pc")
@@ -677,8 +666,8 @@ add_dependencies(Kernel generate_EscapeSequenceStateMachine.h generate_version_h
if (NOT "${SERENITY_ARCH}" STREQUAL "aarch64")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/linker.ld
- COMMAND "${CMAKE_CXX_COMPILER}" ${TARGET_STRING} -E -P -x c -I${CMAKE_CURRENT_SOURCE_DIR}/.. "${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86/linker.ld" -o "${CMAKE_CURRENT_BINARY_DIR}/linker.ld"
- MAIN_DEPENDENCY "Arch/x86/linker.ld"
+ COMMAND "${CMAKE_CXX_COMPILER}" ${TARGET_STRING} -E -P -x c -I${CMAKE_CURRENT_SOURCE_DIR}/.. "${CMAKE_CURRENT_SOURCE_DIR}/Arch/x86_64/linker.ld" -o "${CMAKE_CURRENT_BINARY_DIR}/linker.ld"
+ MAIN_DEPENDENCY "Arch/x86_64/linker.ld"
COMMENT "Preprocessing linker.ld"
VERBATIM
)
diff --git a/Kernel/Devices/ConsoleDevice.cpp b/Kernel/Devices/ConsoleDevice.cpp
index 75179e5505..92044f852b 100644
--- a/Kernel/Devices/ConsoleDevice.cpp
+++ b/Kernel/Devices/ConsoleDevice.cpp
@@ -6,7 +6,7 @@
#include <AK/Platform.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/common/BochsDebugOutput.h>
+# include <Kernel/Arch/x86_64/BochsDebugOutput.h>
#endif
#include <Kernel/Devices/ConsoleDevice.h>
#include <Kernel/Devices/DeviceManagement.h>
diff --git a/Kernel/Devices/HID/HIDManagement.cpp b/Kernel/Devices/HID/HIDManagement.cpp
index 0dda36abe2..56b8d57e47 100644
--- a/Kernel/Devices/HID/HIDManagement.cpp
+++ b/Kernel/Devices/HID/HIDManagement.cpp
@@ -7,7 +7,7 @@
#include <AK/Platform.h>
#include <AK/Singleton.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/ISABus/I8042Controller.h>
+# include <Kernel/Arch/x86_64/ISABus/I8042Controller.h>
#endif
#include <Kernel/CommandLine.h>
#include <Kernel/Devices/HID/HIDManagement.h>
diff --git a/Kernel/FileSystem/SysFS/Subsystems/Kernel/CPUInfo.cpp b/Kernel/FileSystem/SysFS/Subsystems/Kernel/CPUInfo.cpp
index 0d948eec4f..84c0026256 100644
--- a/Kernel/FileSystem/SysFS/Subsystems/Kernel/CPUInfo.cpp
+++ b/Kernel/FileSystem/SysFS/Subsystems/Kernel/CPUInfo.cpp
@@ -6,7 +6,7 @@
#include <AK/JsonObjectSerializer.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/ProcessorInfo.h>
+# include <Kernel/Arch/x86_64/ProcessorInfo.h>
#endif
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/CPUInfo.h>
#include <Kernel/Sections.h>
diff --git a/Kernel/FileSystem/SysFS/Subsystems/Kernel/PowerStateSwitch.cpp b/Kernel/FileSystem/SysFS/Subsystems/Kernel/PowerStateSwitch.cpp
index 591763ba0b..f05b32d903 100644
--- a/Kernel/FileSystem/SysFS/Subsystems/Kernel/PowerStateSwitch.cpp
+++ b/Kernel/FileSystem/SysFS/Subsystems/Kernel/PowerStateSwitch.cpp
@@ -7,8 +7,8 @@
#include <AK/Platform.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/common/I8042Reboot.h>
-# include <Kernel/Arch/x86/common/Shutdown.h>
+# include <Kernel/Arch/x86_64/I8042Reboot.h>
+# include <Kernel/Arch/x86_64/Shutdown.h>
#endif
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/PowerStateSwitch.h>
diff --git a/Kernel/Firmware/ACPI/Parser.cpp b/Kernel/Firmware/ACPI/Parser.cpp
index 5eb04ea6c4..d9045a5e77 100644
--- a/Kernel/Firmware/ACPI/Parser.cpp
+++ b/Kernel/Firmware/ACPI/Parser.cpp
@@ -12,7 +12,7 @@
#include <AK/Try.h>
#include <Kernel/InterruptDisabler.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/IO.h>
+# include <Kernel/Arch/x86_64/IO.h>
#endif
#include <Kernel/Bus/PCI/API.h>
#include <Kernel/Debug.h>
diff --git a/Kernel/Firmware/MultiProcessor/Parser.cpp b/Kernel/Firmware/MultiProcessor/Parser.cpp
index 109292185f..2add19d74e 100644
--- a/Kernel/Firmware/MultiProcessor/Parser.cpp
+++ b/Kernel/Firmware/MultiProcessor/Parser.cpp
@@ -7,7 +7,7 @@
*/
#include <AK/StringView.h>
-#include <Kernel/Arch/x86/common/Interrupts/IOAPIC.h>
+#include <Kernel/Arch/x86_64/Interrupts/IOAPIC.h>
#include <Kernel/Debug.h>
#include <Kernel/Firmware/BIOS.h>
#include <Kernel/Firmware/MultiProcessor/Parser.h>
diff --git a/Kernel/Graphics/Bochs/GraphicsAdapter.cpp b/Kernel/Graphics/Bochs/GraphicsAdapter.cpp
index ffa3654359..f09060d5d9 100644
--- a/Kernel/Graphics/Bochs/GraphicsAdapter.cpp
+++ b/Kernel/Graphics/Bochs/GraphicsAdapter.cpp
@@ -8,7 +8,7 @@
#include <AK/Checked.h>
#include <AK/Try.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.h>
+# include <Kernel/Arch/x86_64/Hypervisor/BochsDisplayConnector.h>
#endif
#include <Kernel/Bus/PCI/API.h>
#include <Kernel/Bus/PCI/IDs.h>
diff --git a/Kernel/Graphics/GraphicsManagement.cpp b/Kernel/Graphics/GraphicsManagement.cpp
index ea3252e661..a65e69d58f 100644
--- a/Kernel/Graphics/GraphicsManagement.cpp
+++ b/Kernel/Graphics/GraphicsManagement.cpp
@@ -7,7 +7,7 @@
#include <AK/Singleton.h>
#include <Kernel/Arch/Delay.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.h>
+# include <Kernel/Arch/x86_64/Hypervisor/BochsDisplayConnector.h>
#endif
#include <Kernel/Bus/PCI/API.h>
#include <Kernel/Bus/PCI/IDs.h>
diff --git a/Kernel/Graphics/GraphicsManagement.h b/Kernel/Graphics/GraphicsManagement.h
index 8928bd5318..17e17bd06b 100644
--- a/Kernel/Graphics/GraphicsManagement.h
+++ b/Kernel/Graphics/GraphicsManagement.h
@@ -10,7 +10,7 @@
#include <AK/Platform.h>
#include <AK/Types.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/VGA/IOArbiter.h>
+# include <Kernel/Arch/x86_64/VGA/IOArbiter.h>
#endif
#include <Kernel/Bus/PCI/Definitions.h>
#include <Kernel/Graphics/Console/Console.h>
diff --git a/Kernel/IOWindow.h b/Kernel/IOWindow.h
index 06e76a9a95..9dc911f958 100644
--- a/Kernel/IOWindow.h
+++ b/Kernel/IOWindow.h
@@ -10,7 +10,7 @@
#include <AK/Platform.h>
#include <AK/Types.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/IO.h>
+# include <Kernel/Arch/x86_64/IO.h>
#endif
#include <Kernel/Bus/PCI/Definitions.h>
#include <Kernel/Memory/TypedMapping.h>
diff --git a/Kernel/Interrupts/SpuriousInterruptHandler.cpp b/Kernel/Interrupts/SpuriousInterruptHandler.cpp
index ea73a45887..893230a0da 100644
--- a/Kernel/Interrupts/SpuriousInterruptHandler.cpp
+++ b/Kernel/Interrupts/SpuriousInterruptHandler.cpp
@@ -5,7 +5,7 @@
*/
#include <Kernel/Arch/InterruptManagement.h>
-#include <Kernel/Arch/x86/Interrupts.h>
+#include <Kernel/Arch/x86_64/Interrupts.h>
#include <Kernel/Interrupts/SpuriousInterruptHandler.h>
#include <Kernel/Sections.h>
diff --git a/Kernel/Panic.cpp b/Kernel/Panic.cpp
index 5db7d78378..ad132f5032 100644
--- a/Kernel/Panic.cpp
+++ b/Kernel/Panic.cpp
@@ -7,7 +7,7 @@
#include <AK/Format.h>
#include <Kernel/Arch/Processor.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/common/Shutdown.h>
+# include <Kernel/Arch/x86_64/Shutdown.h>
#endif
#include <Kernel/CommandLine.h>
#include <Kernel/KSyms.h>
diff --git a/Kernel/Prekernel/init.cpp b/Kernel/Prekernel/init.cpp
index 1dffb1b4e9..1f95655941 100644
--- a/Kernel/Prekernel/init.cpp
+++ b/Kernel/Prekernel/init.cpp
@@ -15,8 +15,8 @@
#include <LibELF/Relocation.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/ASM_wrapper.h>
-# include <Kernel/Arch/x86/CPUID.h>
+# include <Kernel/Arch/x86_64/ASM_wrapper.h>
+# include <Kernel/Arch/x86_64/CPUID.h>
#endif
// Defined in the linker script
diff --git a/Kernel/Random.cpp b/Kernel/Random.cpp
index 65577cd63f..e49678a0f3 100644
--- a/Kernel/Random.cpp
+++ b/Kernel/Random.cpp
@@ -8,8 +8,8 @@
#include <AK/Singleton.h>
#include <Kernel/Arch/Processor.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/Time/HPET.h>
-# include <Kernel/Arch/x86/Time/RTC.h>
+# include <Kernel/Arch/x86_64/Time/HPET.h>
+# include <Kernel/Arch/x86_64/Time/RTC.h>
#endif
#include <Kernel/Devices/RandomDevice.h>
#include <Kernel/Random.h>
diff --git a/Kernel/Storage/StorageManagement.cpp b/Kernel/Storage/StorageManagement.cpp
index 961b6f5767..5d6ab6fe5d 100644
--- a/Kernel/Storage/StorageManagement.cpp
+++ b/Kernel/Storage/StorageManagement.cpp
@@ -11,8 +11,8 @@
#include <AK/StringView.h>
#include <AK/UUID.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/ISABus/IDEController.h>
-# include <Kernel/Arch/x86/PCI/IDELegacyModeController.h>
+# include <Kernel/Arch/x86_64/ISABus/IDEController.h>
+# include <Kernel/Arch/x86_64/PCI/IDELegacyModeController.h>
#endif
#include <Kernel/Bus/PCI/API.h>
#include <Kernel/Bus/PCI/Access.h>
diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp
index aaf45586d9..de769c04c1 100644
--- a/Kernel/Syscall.cpp
+++ b/Kernel/Syscall.cpp
@@ -7,7 +7,7 @@
#include <Kernel/API/Syscall.h>
#include <Kernel/Arch/TrapFrame.h>
-#include <Kernel/Arch/x86/Interrupts.h>
+#include <Kernel/Arch/x86_64/Interrupts.h>
#include <Kernel/Memory/MemoryManager.h>
#include <Kernel/Panic.h>
#include <Kernel/PerformanceManager.h>
diff --git a/Kernel/Syscalls/beep.cpp b/Kernel/Syscalls/beep.cpp
index 87eb0659fc..0e6d4e37b5 100644
--- a/Kernel/Syscalls/beep.cpp
+++ b/Kernel/Syscalls/beep.cpp
@@ -6,7 +6,7 @@
#include <Kernel/CommandLine.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/common/PCSpeaker.h>
+# include <Kernel/Arch/x86_64/PCSpeaker.h>
#endif
#include <Kernel/Process.h>
diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp
index c4ac350f50..78f1dcda97 100644
--- a/Kernel/Syscalls/mmap.cpp
+++ b/Kernel/Syscalls/mmap.cpp
@@ -8,7 +8,7 @@
#include <Kernel/API/VirtualMemoryAnnotations.h>
#include <Kernel/Arch/SafeMem.h>
#include <Kernel/Arch/SmapDisabler.h>
-#include <Kernel/Arch/x86/MSR.h>
+#include <Kernel/Arch/x86_64/MSR.h>
#include <Kernel/FileSystem/Custody.h>
#include <Kernel/FileSystem/OpenFileDescription.h>
#include <Kernel/Memory/AnonymousVMObject.h>
diff --git a/Kernel/TTY/VirtualConsole.cpp b/Kernel/TTY/VirtualConsole.cpp
index ddb6e8c311..52da68204b 100644
--- a/Kernel/TTY/VirtualConsole.cpp
+++ b/Kernel/TTY/VirtualConsole.cpp
@@ -9,7 +9,7 @@
#include <AK/StdLibExtras.h>
#include <Kernel/Arch/Delay.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/common/PCSpeaker.h>
+# include <Kernel/Arch/x86_64/PCSpeaker.h>
#endif
#include <Kernel/CommandLine.h>
#include <Kernel/Debug.h>
diff --git a/Kernel/Time/TimeManagement.cpp b/Kernel/Time/TimeManagement.cpp
index 74d1a4c3d8..e58b063b46 100644
--- a/Kernel/Time/TimeManagement.cpp
+++ b/Kernel/Time/TimeManagement.cpp
@@ -9,13 +9,13 @@
#include <AK/StdLibExtras.h>
#include <AK/Time.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/Time/APICTimer.h>
-# include <Kernel/Arch/x86/Time/HPET.h>
-# include <Kernel/Arch/x86/Time/HPETComparator.h>
-# include <Kernel/Arch/x86/Time/PIT.h>
-# include <Kernel/Arch/x86/Time/RTC.h>
-# include <Kernel/Arch/x86/common/Interrupts/APIC.h>
-# include <Kernel/Arch/x86/common/RTC.h>
+# include <Kernel/Arch/x86_64/Interrupts/APIC.h>
+# include <Kernel/Arch/x86_64/RTC.h>
+# include <Kernel/Arch/x86_64/Time/APICTimer.h>
+# include <Kernel/Arch/x86_64/Time/HPET.h>
+# include <Kernel/Arch/x86_64/Time/HPETComparator.h>
+# include <Kernel/Arch/x86_64/Time/PIT.h>
+# include <Kernel/Arch/x86_64/Time/RTC.h>
#elif ARCH(AARCH64)
# include <Kernel/Arch/aarch64/RPi/Timer.h>
#else
diff --git a/Kernel/kprintf.cpp b/Kernel/kprintf.cpp
index 2547989282..ce21cd6952 100644
--- a/Kernel/kprintf.cpp
+++ b/Kernel/kprintf.cpp
@@ -9,7 +9,7 @@
#include <AK/Types.h>
#include <Kernel/Arch/DebugOutput.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/common/BochsDebugOutput.h>
+# include <Kernel/Arch/x86_64/BochsDebugOutput.h>
#endif
#include <Kernel/Devices/ConsoleDevice.h>
#include <Kernel/Devices/DeviceManagement.h>
diff --git a/Tests/Kernel/crash.cpp b/Tests/Kernel/crash.cpp
index 4857262aa5..46f8d9aa3d 100644
--- a/Tests/Kernel/crash.cpp
+++ b/Tests/Kernel/crash.cpp
@@ -9,7 +9,7 @@
#include <AK/DeprecatedString.h>
#include <AK/Function.h>
#if ARCH(X86_64)
-# include <Kernel/Arch/x86/IO.h>
+# include <Kernel/Arch/x86_64/IO.h>
#endif
#include <LibCore/ArgsParser.h>
#include <LibCore/Object.h>