From 91db482ad333459a8513c98e6488087f327f5d2d Mon Sep 17 00:00:00 2001 From: Liav A Date: Tue, 4 Oct 2022 13:46:11 +0300 Subject: [PATCH] Kernel: Reorganize Arch/x86 directory to Arch/x86_64 after i686 removal No functional change. --- Kernel/Arch/CPU.h | 2 +- Kernel/Arch/IRQController.h | 2 +- Kernel/Arch/InterruptManagement.h | 2 +- Kernel/Arch/Interrupts.h | 2 +- Kernel/Arch/PageDirectory.h | 2 +- Kernel/Arch/Processor.h | 2 +- Kernel/Arch/RegisterState.h | 2 +- Kernel/Arch/TrapFrame.h | 2 +- Kernel/Arch/aarch64/Interrupts.cpp | 2 +- Kernel/Arch/mcontext.h | 2 +- Kernel/Arch/x86/common/ASM_wrapper.cpp | 49 --- Kernel/Arch/x86/i386/ASM_wrapper.cpp | 82 ----- Kernel/Arch/x86/i386/Boot/ap_setup.S | 179 ----------- Kernel/Arch/x86/i386/InterruptEntry.cpp | 52 ---- Kernel/Arch/x86/i386/Processor.cpp | 277 ----------------- Kernel/Arch/x86/x86_64/Processor.cpp | 283 ------------------ Kernel/Arch/{x86 => }/x86_64/ASM_wrapper.cpp | 37 ++- Kernel/Arch/{x86 => x86_64}/ASM_wrapper.h | 0 .../{x86/common => x86_64}/BochsDebugOutput.h | 0 Kernel/Arch/{x86 => }/x86_64/Boot/ap_setup.S | 0 Kernel/Arch/{x86/common => x86_64}/CMOS.cpp | 4 +- Kernel/Arch/{x86/common => x86_64}/CMOS.h | 0 Kernel/Arch/{x86/common => x86_64}/CPU.cpp | 0 Kernel/Arch/{x86 => x86_64}/CPU.h | 2 +- Kernel/Arch/{x86/common => x86_64}/CPUID.cpp | 2 +- Kernel/Arch/{x86 => x86_64}/CPUID.h | 0 .../{x86/common => x86_64}/CrashHandler.cpp | 0 Kernel/Arch/{x86 => x86_64}/CurrentTime.cpp | 4 +- .../{x86/common => x86_64}/DebugOutput.cpp | 4 +- Kernel/Arch/{x86/common => x86_64}/Delay.cpp | 2 +- Kernel/Arch/{x86 => x86_64}/DescriptorTable.h | 0 .../Hypervisor/BochsDisplayConnector.cpp | 4 +- .../Hypervisor/BochsDisplayConnector.h | 0 .../Hypervisor/VMWareBackdoor.cpp | 2 +- .../Hypervisor/VMWareBackdoor.h | 0 .../{x86/common => x86_64}/I8042Reboot.cpp | 4 +- .../Arch/{x86/common => x86_64}/I8042Reboot.h | 0 Kernel/Arch/{x86 => x86_64}/IO.h | 0 Kernel/Arch/{x86 => x86_64}/IRQController.h | 0 .../ISABus/HID/PS2KeyboardDevice.cpp | 2 +- .../ISABus/HID/PS2KeyboardDevice.h | 2 +- .../ISABus/HID/PS2MouseDevice.cpp | 4 +- .../ISABus/HID/PS2MouseDevice.h | 2 +- .../ISABus/HID/VMWareMouseDevice.cpp | 4 +- .../ISABus/HID/VMWareMouseDevice.h | 4 +- .../ISABus/I8042Controller.cpp | 10 +- .../{x86 => x86_64}/ISABus/I8042Controller.h | 0 .../{x86 => x86_64}/ISABus/IDEController.cpp | 2 +- .../{x86 => x86_64}/ISABus/IDEController.h | 0 .../{x86 => x86_64}/ISABus/SerialDevice.cpp | 0 Kernel/Arch/{x86 => x86_64}/ISRStubs.h | 2 +- .../Arch/{x86 => }/x86_64/InterruptEntry.cpp | 4 +- .../common => x86_64}/InterruptManagement.cpp | 8 +- .../{x86 => x86_64}/InterruptManagement.h | 4 +- .../{x86/common => x86_64}/Interrupts.cpp | 4 +- Kernel/Arch/{x86 => x86_64}/Interrupts.h | 0 .../common => x86_64}/Interrupts/APIC.cpp | 8 +- .../{x86/common => x86_64}/Interrupts/APIC.h | 0 .../common => x86_64}/Interrupts/IOAPIC.cpp | 6 +- .../common => x86_64}/Interrupts/IOAPIC.h | 2 +- .../{x86/common => x86_64}/Interrupts/PIC.cpp | 4 +- .../{x86/common => x86_64}/Interrupts/PIC.h | 2 +- Kernel/Arch/{x86 => x86_64}/MSR.h | 2 +- .../NonMaskableInterruptDisabler.h | 2 +- .../PCI/Controller/HostBridge.cpp | 4 +- .../PCI/Controller/HostBridge.h | 0 .../PCI/IDELegacyModeController.cpp | 2 +- .../PCI/IDELegacyModeController.h | 0 .../Arch/{x86 => x86_64}/PCI/Initializer.cpp | 2 +- .../Arch/{x86/common => x86_64}/PCSpeaker.cpp | 6 +- .../Arch/{x86/common => x86_64}/PCSpeaker.h | 0 .../{x86/common => x86_64}/PageDirectory.cpp | 0 Kernel/Arch/{x86 => x86_64}/PageDirectory.h | 0 .../Arch/{x86/common => x86_64}/Processor.cpp | 272 ++++++++++++++++- Kernel/Arch/{x86 => x86_64}/Processor.h | 10 +- .../{x86/common => x86_64}/ProcessorInfo.cpp | 4 +- Kernel/Arch/{x86 => x86_64}/ProcessorInfo.h | 0 Kernel/Arch/{x86/common => x86_64}/RTC.cpp | 4 +- Kernel/Arch/{x86/common => x86_64}/RTC.h | 0 Kernel/Arch/{x86 => x86_64}/RegisterState.h | 2 +- Kernel/Arch/{x86 => x86_64}/SIMDState.h | 0 .../Arch/{x86/common => x86_64}/SafeMem.cpp | 0 .../{x86/common => x86_64}/ScopedCritical.cpp | 0 .../Arch/{x86/common => x86_64}/Shutdown.cpp | 4 +- Kernel/Arch/{x86/common => x86_64}/Shutdown.h | 0 .../{x86/common => x86_64}/SmapDisabler.cpp | 2 +- Kernel/Arch/{x86 => }/x86_64/SyscallEntry.cpp | 4 +- Kernel/Arch/{x86 => x86_64}/TSS.h | 0 .../Arch/{x86 => x86_64}/Time/APICTimer.cpp | 4 +- Kernel/Arch/{x86 => x86_64}/Time/APICTimer.h | 2 +- Kernel/Arch/{x86 => x86_64}/Time/HPET.cpp | 4 +- Kernel/Arch/{x86 => x86_64}/Time/HPET.h | 0 .../{x86 => x86_64}/Time/HPETComparator.cpp | 2 +- .../{x86 => x86_64}/Time/HPETComparator.h | 2 +- Kernel/Arch/{x86 => x86_64}/Time/PIT.cpp | 4 +- Kernel/Arch/{x86 => x86_64}/Time/PIT.h | 0 Kernel/Arch/{x86 => x86_64}/Time/RTC.cpp | 8 +- Kernel/Arch/{x86 => x86_64}/Time/RTC.h | 2 +- .../Arch/{x86/common => x86_64}/TrapFrame.cpp | 2 +- Kernel/Arch/{x86 => x86_64}/TrapFrame.h | 0 Kernel/Arch/{x86 => x86_64}/VGA/IOArbiter.cpp | 4 +- Kernel/Arch/{x86 => x86_64}/VGA/IOArbiter.h | 0 Kernel/Arch/{x86 => x86_64}/init.cpp | 6 +- Kernel/Arch/{x86 => x86_64}/linker.ld | 0 Kernel/Arch/{x86 => x86_64}/mcontext.h | 0 Kernel/Bus/PCI/Access.cpp | 2 +- Kernel/CMakeLists.txt | 91 +++--- Kernel/Devices/ConsoleDevice.cpp | 2 +- Kernel/Devices/HID/HIDManagement.cpp | 2 +- .../SysFS/Subsystems/Kernel/CPUInfo.cpp | 2 +- .../Subsystems/Kernel/PowerStateSwitch.cpp | 4 +- Kernel/Firmware/ACPI/Parser.cpp | 2 +- Kernel/Firmware/MultiProcessor/Parser.cpp | 2 +- Kernel/Graphics/Bochs/GraphicsAdapter.cpp | 2 +- Kernel/Graphics/GraphicsManagement.cpp | 2 +- Kernel/Graphics/GraphicsManagement.h | 2 +- Kernel/IOWindow.h | 2 +- .../Interrupts/SpuriousInterruptHandler.cpp | 2 +- Kernel/Panic.cpp | 2 +- Kernel/Prekernel/init.cpp | 4 +- Kernel/Random.cpp | 4 +- Kernel/Storage/StorageManagement.cpp | 4 +- Kernel/Syscall.cpp | 2 +- Kernel/Syscalls/beep.cpp | 2 +- Kernel/Syscalls/mmap.cpp | 2 +- Kernel/TTY/VirtualConsole.cpp | 2 +- Kernel/Time/TimeManagement.cpp | 14 +- Kernel/kprintf.cpp | 2 +- Tests/Kernel/crash.cpp | 2 +- 129 files changed, 482 insertions(+), 1116 deletions(-) delete mode 100644 Kernel/Arch/x86/common/ASM_wrapper.cpp delete mode 100644 Kernel/Arch/x86/i386/ASM_wrapper.cpp delete mode 100644 Kernel/Arch/x86/i386/Boot/ap_setup.S delete mode 100644 Kernel/Arch/x86/i386/InterruptEntry.cpp delete mode 100644 Kernel/Arch/x86/i386/Processor.cpp delete mode 100644 Kernel/Arch/x86/x86_64/Processor.cpp rename Kernel/Arch/{x86 => }/x86_64/ASM_wrapper.cpp (70%) rename Kernel/Arch/{x86 => x86_64}/ASM_wrapper.h (100%) rename Kernel/Arch/{x86/common => x86_64}/BochsDebugOutput.h (100%) rename Kernel/Arch/{x86 => }/x86_64/Boot/ap_setup.S (100%) rename Kernel/Arch/{x86/common => x86_64}/CMOS.cpp (80%) rename Kernel/Arch/{x86/common => x86_64}/CMOS.h (100%) rename Kernel/Arch/{x86/common => x86_64}/CPU.cpp (100%) rename Kernel/Arch/{x86 => x86_64}/CPU.h (95%) rename Kernel/Arch/{x86/common => x86_64}/CPUID.cpp (99%) rename Kernel/Arch/{x86 => x86_64}/CPUID.h (100%) rename Kernel/Arch/{x86/common => x86_64}/CrashHandler.cpp (100%) rename Kernel/Arch/{x86 => x86_64}/CurrentTime.cpp (86%) rename Kernel/Arch/{x86/common => x86_64}/DebugOutput.cpp (92%) rename Kernel/Arch/{x86/common => x86_64}/Delay.cpp (87%) rename Kernel/Arch/{x86 => x86_64}/DescriptorTable.h (100%) rename Kernel/Arch/{x86 => x86_64}/Hypervisor/BochsDisplayConnector.cpp (98%) rename Kernel/Arch/{x86 => x86_64}/Hypervisor/BochsDisplayConnector.h (100%) rename Kernel/Arch/{x86 => x86_64}/Hypervisor/VMWareBackdoor.cpp (99%) rename Kernel/Arch/{x86 => x86_64}/Hypervisor/VMWareBackdoor.h (100%) rename Kernel/Arch/{x86/common => x86_64}/I8042Reboot.cpp (76%) rename Kernel/Arch/{x86/common => x86_64}/I8042Reboot.h (100%) rename Kernel/Arch/{x86 => x86_64}/IO.h (100%) rename Kernel/Arch/{x86 => x86_64}/IRQController.h (100%) rename Kernel/Arch/{x86 => x86_64}/ISABus/HID/PS2KeyboardDevice.cpp (98%) rename Kernel/Arch/{x86 => x86_64}/ISABus/HID/PS2KeyboardDevice.h (95%) rename Kernel/Arch/{x86 => x86_64}/ISABus/HID/PS2MouseDevice.cpp (98%) rename Kernel/Arch/{x86 => x86_64}/ISABus/HID/PS2MouseDevice.h (96%) rename Kernel/Arch/{x86 => x86_64}/ISABus/HID/VMWareMouseDevice.cpp (94%) rename Kernel/Arch/{x86 => x86_64}/ISABus/HID/VMWareMouseDevice.h (85%) rename Kernel/Arch/{x86 => x86_64}/ISABus/I8042Controller.cpp (98%) rename Kernel/Arch/{x86 => x86_64}/ISABus/I8042Controller.h (100%) rename Kernel/Arch/{x86 => x86_64}/ISABus/IDEController.cpp (97%) rename Kernel/Arch/{x86 => x86_64}/ISABus/IDEController.h (100%) rename Kernel/Arch/{x86 => x86_64}/ISABus/SerialDevice.cpp (100%) rename Kernel/Arch/{x86 => x86_64}/ISRStubs.h (99%) rename Kernel/Arch/{x86 => }/x86_64/InterruptEntry.cpp (95%) rename Kernel/Arch/{x86/common => x86_64}/InterruptManagement.cpp (97%) rename Kernel/Arch/{x86 => x86_64}/InterruptManagement.h (95%) rename Kernel/Arch/{x86/common => x86_64}/Interrupts.cpp (99%) rename Kernel/Arch/{x86 => x86_64}/Interrupts.h (100%) rename Kernel/Arch/{x86/common => x86_64}/Interrupts/APIC.cpp (99%) rename Kernel/Arch/{x86/common => x86_64}/Interrupts/APIC.h (100%) rename Kernel/Arch/{x86/common => x86_64}/Interrupts/IOAPIC.cpp (98%) rename Kernel/Arch/{x86/common => x86_64}/Interrupts/IOAPIC.h (98%) rename Kernel/Arch/{x86/common => x86_64}/Interrupts/PIC.cpp (98%) rename Kernel/Arch/{x86/common => x86_64}/Interrupts/PIC.h (96%) rename Kernel/Arch/{x86 => x86_64}/MSR.h (95%) rename Kernel/Arch/{x86 => x86_64}/NonMaskableInterruptDisabler.h (92%) rename Kernel/Arch/{x86 => x86_64}/PCI/Controller/HostBridge.cpp (95%) rename Kernel/Arch/{x86 => x86_64}/PCI/Controller/HostBridge.h (100%) rename Kernel/Arch/{x86 => x86_64}/PCI/IDELegacyModeController.cpp (99%) rename Kernel/Arch/{x86 => x86_64}/PCI/IDELegacyModeController.h (100%) rename Kernel/Arch/{x86 => x86_64}/PCI/Initializer.cpp (98%) rename Kernel/Arch/{x86/common => x86_64}/PCSpeaker.cpp (80%) rename Kernel/Arch/{x86/common => x86_64}/PCSpeaker.h (100%) rename Kernel/Arch/{x86/common => x86_64}/PageDirectory.cpp (100%) rename Kernel/Arch/{x86 => x86_64}/PageDirectory.h (100%) rename Kernel/Arch/{x86/common => x86_64}/Processor.cpp (86%) rename Kernel/Arch/{x86 => x86_64}/Processor.h (98%) rename Kernel/Arch/{x86/common => x86_64}/ProcessorInfo.cpp (98%) rename Kernel/Arch/{x86 => x86_64}/ProcessorInfo.h (100%) rename Kernel/Arch/{x86/common => x86_64}/RTC.cpp (97%) rename Kernel/Arch/{x86/common => x86_64}/RTC.h (100%) rename Kernel/Arch/{x86 => x86_64}/RegisterState.h (99%) rename Kernel/Arch/{x86 => x86_64}/SIMDState.h (100%) rename Kernel/Arch/{x86/common => x86_64}/SafeMem.cpp (100%) rename Kernel/Arch/{x86/common => x86_64}/ScopedCritical.cpp (100%) rename Kernel/Arch/{x86/common => x86_64}/Shutdown.cpp (86%) rename Kernel/Arch/{x86/common => x86_64}/Shutdown.h (100%) rename Kernel/Arch/{x86/common => x86_64}/SmapDisabler.cpp (88%) rename Kernel/Arch/{x86 => }/x86_64/SyscallEntry.cpp (96%) rename Kernel/Arch/{x86 => x86_64}/TSS.h (100%) rename Kernel/Arch/{x86 => x86_64}/Time/APICTimer.cpp (98%) rename Kernel/Arch/{x86 => x86_64}/Time/APICTimer.h (96%) rename Kernel/Arch/{x86 => x86_64}/Time/HPET.cpp (99%) rename Kernel/Arch/{x86 => x86_64}/Time/HPET.h (100%) rename Kernel/Arch/{x86 => x86_64}/Time/HPETComparator.cpp (98%) rename Kernel/Arch/{x86 => x86_64}/Time/HPETComparator.h (97%) rename Kernel/Arch/{x86 => x86_64}/Time/PIT.cpp (96%) rename Kernel/Arch/{x86 => x86_64}/Time/PIT.h (100%) rename Kernel/Arch/{x86 => x86_64}/Time/RTC.cpp (93%) rename Kernel/Arch/{x86 => x86_64}/Time/RTC.h (97%) rename Kernel/Arch/{x86/common => x86_64}/TrapFrame.cpp (93%) rename Kernel/Arch/{x86 => x86_64}/TrapFrame.h (100%) rename Kernel/Arch/{x86 => x86_64}/VGA/IOArbiter.cpp (96%) rename Kernel/Arch/{x86 => x86_64}/VGA/IOArbiter.h (100%) rename Kernel/Arch/{x86 => x86_64}/init.cpp (99%) rename Kernel/Arch/{x86 => x86_64}/linker.ld (100%) rename Kernel/Arch/{x86 => x86_64}/mcontext.h (100%) diff --git a/Kernel/Arch/CPU.h b/Kernel/Arch/CPU.h index 24f2fcb640d..f6a61bb9b51 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 +# include #elif ARCH(AARCH64) # include #else diff --git a/Kernel/Arch/IRQController.h b/Kernel/Arch/IRQController.h index 57fc2ad4412..5b58bfca759 100644 --- a/Kernel/Arch/IRQController.h +++ b/Kernel/Arch/IRQController.h @@ -9,7 +9,7 @@ #include #if ARCH(X86_64) -# include +# include #elif ARCH(AARCH64) # include #else diff --git a/Kernel/Arch/InterruptManagement.h b/Kernel/Arch/InterruptManagement.h index 1fa182015e7..f9e3b4908f3 100644 --- a/Kernel/Arch/InterruptManagement.h +++ b/Kernel/Arch/InterruptManagement.h @@ -9,7 +9,7 @@ #include #if ARCH(X86_64) -# include +# include #elif ARCH(AARCH64) # include #else diff --git a/Kernel/Arch/Interrupts.h b/Kernel/Arch/Interrupts.h index ba39657b20e..14e11147add 100644 --- a/Kernel/Arch/Interrupts.h +++ b/Kernel/Arch/Interrupts.h @@ -10,7 +10,7 @@ #include #if ARCH(X86_64) -# include +# include #endif namespace Kernel { diff --git a/Kernel/Arch/PageDirectory.h b/Kernel/Arch/PageDirectory.h index e8c989cc012..e6c8e14b76f 100644 --- a/Kernel/Arch/PageDirectory.h +++ b/Kernel/Arch/PageDirectory.h @@ -10,7 +10,7 @@ #include #if ARCH(X86_64) -# include +# include #elif ARCH(AARCH64) # include #else diff --git a/Kernel/Arch/Processor.h b/Kernel/Arch/Processor.h index 8ee7d6fc81a..598be46915f 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 +# include #elif ARCH(AARCH64) # include #else diff --git a/Kernel/Arch/RegisterState.h b/Kernel/Arch/RegisterState.h index f7a2928ac26..bb2d117c98e 100644 --- a/Kernel/Arch/RegisterState.h +++ b/Kernel/Arch/RegisterState.h @@ -9,7 +9,7 @@ #include #if ARCH(X86_64) -# include +# include #elif ARCH(AARCH64) # include #else diff --git a/Kernel/Arch/TrapFrame.h b/Kernel/Arch/TrapFrame.h index 9bfe840747d..33ddf4ca874 100644 --- a/Kernel/Arch/TrapFrame.h +++ b/Kernel/Arch/TrapFrame.h @@ -9,7 +9,7 @@ #include #if ARCH(X86_64) -# include +# include #elif ARCH(AARCH64) # include #else diff --git a/Kernel/Arch/aarch64/Interrupts.cpp b/Kernel/Arch/aarch64/Interrupts.cpp index 8a49bfb1207..b319fb123de 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 95d35a0d7e8..1da74966343 100644 --- a/Kernel/Arch/mcontext.h +++ b/Kernel/Arch/mcontext.h @@ -7,7 +7,7 @@ #pragma once #if defined(__i386__) || defined(__x86_64__) -# include +# include #elif defined(__aarch64__) # include #endif diff --git a/Kernel/Arch/x86/common/ASM_wrapper.cpp b/Kernel/Arch/x86/common/ASM_wrapper.cpp deleted file mode 100644 index e19f9dc5d35..00000000000 --- a/Kernel/Arch/x86/common/ASM_wrapper.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018-2021, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include - -#include -#include -#include - -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 81490562f78..00000000000 --- a/Kernel/Arch/x86/i386/ASM_wrapper.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2018-2021, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include - -#include -#include - -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 915a1ad4c25..00000000000 --- a/Kernel/Arch/x86/i386/Boot/ap_setup.S +++ /dev/null @@ -1,179 +0,0 @@ -#include - -.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 be32d22c553..00000000000 --- a/Kernel/Arch/x86/i386/InterruptEntry.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include - -// 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 9a23a5d0839..00000000000 --- a/Kernel/Arch/x86/i386/Processor.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright (c) 2018-2021, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -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(), 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(kernel_stack_top - 2 * sizeof(u32)) = regs.esp; - *reinterpret_cast(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(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(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(stack_top); - trap.regs = &iretframe; - trap.prev_irq_level = 0; - trap.next_trap = nullptr; - - stack_top -= sizeof(u32); // pointer to TrapFrame - *reinterpret_cast(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 7925258e82c..00000000000 --- a/Kernel/Arch/x86/x86_64/Processor.cpp +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright (c) 2018-2021, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -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(), 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(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(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(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(stack_top); - trap.regs = &iretframe; - trap.prev_irq_level = 0; - trap.next_trap = nullptr; - - stack_top -= sizeof(u64); // pointer to TrapFrame - *reinterpret_cast(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 similarity index 70% rename from Kernel/Arch/x86/x86_64/ASM_wrapper.cpp rename to Kernel/Arch/x86_64/ASM_wrapper.cpp index f92605572ed..e406f9910f6 100644 --- a/Kernel/Arch/x86/x86_64/ASM_wrapper.cpp +++ b/Kernel/Arch/x86_64/ASM_wrapper.cpp @@ -6,11 +6,46 @@ #include -#include +#include +#include #include 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 similarity index 100% rename from Kernel/Arch/x86/ASM_wrapper.h rename to Kernel/Arch/x86_64/ASM_wrapper.h diff --git a/Kernel/Arch/x86/common/BochsDebugOutput.h b/Kernel/Arch/x86_64/BochsDebugOutput.h similarity index 100% rename from Kernel/Arch/x86/common/BochsDebugOutput.h rename to 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 similarity index 100% rename from Kernel/Arch/x86/x86_64/Boot/ap_setup.S rename to Kernel/Arch/x86_64/Boot/ap_setup.S diff --git a/Kernel/Arch/x86/common/CMOS.cpp b/Kernel/Arch/x86_64/CMOS.cpp similarity index 80% rename from Kernel/Arch/x86/common/CMOS.cpp rename to Kernel/Arch/x86_64/CMOS.cpp index ad2b5ee0157..310fd87e295 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 -#include +#include +#include namespace Kernel::CMOS { diff --git a/Kernel/Arch/x86/common/CMOS.h b/Kernel/Arch/x86_64/CMOS.h similarity index 100% rename from Kernel/Arch/x86/common/CMOS.h rename to Kernel/Arch/x86_64/CMOS.h diff --git a/Kernel/Arch/x86/common/CPU.cpp b/Kernel/Arch/x86_64/CPU.cpp similarity index 100% rename from Kernel/Arch/x86/common/CPU.cpp rename to Kernel/Arch/x86_64/CPU.cpp diff --git a/Kernel/Arch/x86/CPU.h b/Kernel/Arch/x86_64/CPU.h similarity index 95% rename from Kernel/Arch/x86/CPU.h rename to Kernel/Arch/x86_64/CPU.h index 4bc1a50490c..3b3e0c48455 100644 --- a/Kernel/Arch/x86/CPU.h +++ b/Kernel/Arch/x86_64/CPU.h @@ -10,7 +10,7 @@ #include #include -#include +#include #include VALIDATE_IS_X86() diff --git a/Kernel/Arch/x86/common/CPUID.cpp b/Kernel/Arch/x86_64/CPUID.cpp similarity index 99% rename from Kernel/Arch/x86/common/CPUID.cpp rename to Kernel/Arch/x86_64/CPUID.cpp index 835f697fc19..be39e2ae3c7 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 +#include namespace Kernel { diff --git a/Kernel/Arch/x86/CPUID.h b/Kernel/Arch/x86_64/CPUID.h similarity index 100% rename from Kernel/Arch/x86/CPUID.h rename to Kernel/Arch/x86_64/CPUID.h diff --git a/Kernel/Arch/x86/common/CrashHandler.cpp b/Kernel/Arch/x86_64/CrashHandler.cpp similarity index 100% rename from Kernel/Arch/x86/common/CrashHandler.cpp rename to Kernel/Arch/x86_64/CrashHandler.cpp diff --git a/Kernel/Arch/x86/CurrentTime.cpp b/Kernel/Arch/x86_64/CurrentTime.cpp similarity index 86% rename from Kernel/Arch/x86/CurrentTime.cpp rename to Kernel/Arch/x86_64/CurrentTime.cpp index 3963263ab49..6204f0a10f1 100644 --- a/Kernel/Arch/x86/CurrentTime.cpp +++ b/Kernel/Arch/x86_64/CurrentTime.cpp @@ -5,8 +5,8 @@ */ #include -#include -#include +#include +#include namespace Kernel { diff --git a/Kernel/Arch/x86/common/DebugOutput.cpp b/Kernel/Arch/x86_64/DebugOutput.cpp similarity index 92% rename from Kernel/Arch/x86/common/DebugOutput.cpp rename to Kernel/Arch/x86_64/DebugOutput.cpp index 22e5485e309..b2eef622962 100644 --- a/Kernel/Arch/x86/common/DebugOutput.cpp +++ b/Kernel/Arch/x86_64/DebugOutput.cpp @@ -5,8 +5,8 @@ */ #include -#include -#include +#include +#include namespace Kernel { diff --git a/Kernel/Arch/x86/common/Delay.cpp b/Kernel/Arch/x86_64/Delay.cpp similarity index 87% rename from Kernel/Arch/x86/common/Delay.cpp rename to Kernel/Arch/x86_64/Delay.cpp index 444d6604c0b..9896abfd4f0 100644 --- a/Kernel/Arch/x86/common/Delay.cpp +++ b/Kernel/Arch/x86_64/Delay.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include namespace Kernel { diff --git a/Kernel/Arch/x86/DescriptorTable.h b/Kernel/Arch/x86_64/DescriptorTable.h similarity index 100% rename from Kernel/Arch/x86/DescriptorTable.h rename to Kernel/Arch/x86_64/DescriptorTable.h diff --git a/Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.cpp b/Kernel/Arch/x86_64/Hypervisor/BochsDisplayConnector.cpp similarity index 98% rename from Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.cpp rename to Kernel/Arch/x86_64/Hypervisor/BochsDisplayConnector.cpp index 74fb9b33389..0a438190046 100644 --- a/Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.cpp +++ b/Kernel/Arch/x86_64/Hypervisor/BochsDisplayConnector.cpp @@ -5,8 +5,8 @@ */ #include -#include -#include +#include +#include #include #include #include diff --git a/Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.h b/Kernel/Arch/x86_64/Hypervisor/BochsDisplayConnector.h similarity index 100% rename from Kernel/Arch/x86/Hypervisor/BochsDisplayConnector.h rename to Kernel/Arch/x86_64/Hypervisor/BochsDisplayConnector.h diff --git a/Kernel/Arch/x86/Hypervisor/VMWareBackdoor.cpp b/Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.cpp similarity index 99% rename from Kernel/Arch/x86/Hypervisor/VMWareBackdoor.cpp rename to Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.cpp index 5c110a4896a..013cad97d96 100644 --- a/Kernel/Arch/x86/Hypervisor/VMWareBackdoor.cpp +++ b/Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Kernel/Arch/x86/Hypervisor/VMWareBackdoor.h b/Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.h similarity index 100% rename from Kernel/Arch/x86/Hypervisor/VMWareBackdoor.h rename to Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.h diff --git a/Kernel/Arch/x86/common/I8042Reboot.cpp b/Kernel/Arch/x86_64/I8042Reboot.cpp similarity index 76% rename from Kernel/Arch/x86/common/I8042Reboot.cpp rename to Kernel/Arch/x86_64/I8042Reboot.cpp index 2eaf0a0df73..6f987d280f5 100644 --- a/Kernel/Arch/x86/common/I8042Reboot.cpp +++ b/Kernel/Arch/x86_64/I8042Reboot.cpp @@ -5,8 +5,8 @@ */ #include -#include -#include +#include +#include namespace Kernel { diff --git a/Kernel/Arch/x86/common/I8042Reboot.h b/Kernel/Arch/x86_64/I8042Reboot.h similarity index 100% rename from Kernel/Arch/x86/common/I8042Reboot.h rename to Kernel/Arch/x86_64/I8042Reboot.h diff --git a/Kernel/Arch/x86/IO.h b/Kernel/Arch/x86_64/IO.h similarity index 100% rename from Kernel/Arch/x86/IO.h rename to Kernel/Arch/x86_64/IO.h diff --git a/Kernel/Arch/x86/IRQController.h b/Kernel/Arch/x86_64/IRQController.h similarity index 100% rename from Kernel/Arch/x86/IRQController.h rename to 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 similarity index 98% rename from Kernel/Arch/x86/ISABus/HID/PS2KeyboardDevice.cpp rename to Kernel/Arch/x86_64/ISABus/HID/PS2KeyboardDevice.cpp index b569f16e48d..02e1d3ab013 100644 --- a/Kernel/Arch/x86/ISABus/HID/PS2KeyboardDevice.cpp +++ b/Kernel/Arch/x86_64/ISABus/HID/PS2KeyboardDevice.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include #include #include #include diff --git a/Kernel/Arch/x86/ISABus/HID/PS2KeyboardDevice.h b/Kernel/Arch/x86_64/ISABus/HID/PS2KeyboardDevice.h similarity index 95% rename from Kernel/Arch/x86/ISABus/HID/PS2KeyboardDevice.h rename to Kernel/Arch/x86_64/ISABus/HID/PS2KeyboardDevice.h index 89815f5a098..7faedbe9215 100644 --- a/Kernel/Arch/x86/ISABus/HID/PS2KeyboardDevice.h +++ b/Kernel/Arch/x86_64/ISABus/HID/PS2KeyboardDevice.h @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.cpp b/Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.cpp similarity index 98% rename from Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.cpp rename to Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.cpp index e1bc3370c2b..72b73cbba00 100644 --- a/Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.cpp +++ b/Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.cpp @@ -5,8 +5,8 @@ */ #include -#include -#include +#include +#include #include #include #include diff --git a/Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.h b/Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.h similarity index 96% rename from Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.h rename to Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.h index e874ae42f43..177097f5f3a 100644 --- a/Kernel/Arch/x86/ISABus/HID/PS2MouseDevice.h +++ b/Kernel/Arch/x86_64/ISABus/HID/PS2MouseDevice.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include diff --git a/Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.cpp b/Kernel/Arch/x86_64/ISABus/HID/VMWareMouseDevice.cpp similarity index 94% rename from Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.cpp rename to Kernel/Arch/x86_64/ISABus/HID/VMWareMouseDevice.cpp index b2e9bc046ac..ec6029b5b00 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 -#include +#include +#include #include #include diff --git a/Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.h b/Kernel/Arch/x86_64/ISABus/HID/VMWareMouseDevice.h similarity index 85% rename from Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.h rename to Kernel/Arch/x86_64/ISABus/HID/VMWareMouseDevice.h index 63711ab1e73..b0d753cc786 100644 --- a/Kernel/Arch/x86/ISABus/HID/VMWareMouseDevice.h +++ b/Kernel/Arch/x86_64/ISABus/HID/VMWareMouseDevice.h @@ -8,8 +8,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/Kernel/Arch/x86/ISABus/I8042Controller.cpp b/Kernel/Arch/x86_64/ISABus/I8042Controller.cpp similarity index 98% rename from Kernel/Arch/x86/ISABus/I8042Controller.cpp rename to Kernel/Arch/x86_64/ISABus/I8042Controller.cpp index c4ce6b62f13..096ba932b03 100644 --- a/Kernel/Arch/x86/ISABus/I8042Controller.cpp +++ b/Kernel/Arch/x86_64/ISABus/I8042Controller.cpp @@ -5,11 +5,11 @@ */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include namespace Kernel { diff --git a/Kernel/Arch/x86/ISABus/I8042Controller.h b/Kernel/Arch/x86_64/ISABus/I8042Controller.h similarity index 100% rename from Kernel/Arch/x86/ISABus/I8042Controller.h rename to Kernel/Arch/x86_64/ISABus/I8042Controller.h diff --git a/Kernel/Arch/x86/ISABus/IDEController.cpp b/Kernel/Arch/x86_64/ISABus/IDEController.cpp similarity index 97% rename from Kernel/Arch/x86/ISABus/IDEController.cpp rename to Kernel/Arch/x86_64/ISABus/IDEController.cpp index 64831f5ebd5..fc701d4a8ec 100644 --- a/Kernel/Arch/x86/ISABus/IDEController.cpp +++ b/Kernel/Arch/x86_64/ISABus/IDEController.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/Kernel/Arch/x86/ISABus/IDEController.h b/Kernel/Arch/x86_64/ISABus/IDEController.h similarity index 100% rename from Kernel/Arch/x86/ISABus/IDEController.h rename to Kernel/Arch/x86_64/ISABus/IDEController.h diff --git a/Kernel/Arch/x86/ISABus/SerialDevice.cpp b/Kernel/Arch/x86_64/ISABus/SerialDevice.cpp similarity index 100% rename from Kernel/Arch/x86/ISABus/SerialDevice.cpp rename to Kernel/Arch/x86_64/ISABus/SerialDevice.cpp diff --git a/Kernel/Arch/x86/ISRStubs.h b/Kernel/Arch/x86_64/ISRStubs.h similarity index 99% rename from Kernel/Arch/x86/ISRStubs.h rename to Kernel/Arch/x86_64/ISRStubs.h index 1108d8556ad..6ffc1e24d7e 100644 --- a/Kernel/Arch/x86/ISRStubs.h +++ b/Kernel/Arch/x86_64/ISRStubs.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include VALIDATE_IS_X86() diff --git a/Kernel/Arch/x86/x86_64/InterruptEntry.cpp b/Kernel/Arch/x86_64/InterruptEntry.cpp similarity index 95% rename from Kernel/Arch/x86/x86_64/InterruptEntry.cpp rename to Kernel/Arch/x86_64/InterruptEntry.cpp index cc1811106cb..7c91ce38c5a 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 -#include +#include +#include // clang-format off asm( diff --git a/Kernel/Arch/x86/common/InterruptManagement.cpp b/Kernel/Arch/x86_64/InterruptManagement.cpp similarity index 97% rename from Kernel/Arch/x86/common/InterruptManagement.cpp rename to Kernel/Arch/x86_64/InterruptManagement.cpp index eac56328ad4..16d866ff3de 100644 --- a/Kernel/Arch/x86/common/InterruptManagement.cpp +++ b/Kernel/Arch/x86_64/InterruptManagement.cpp @@ -7,10 +7,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include diff --git a/Kernel/Arch/x86/InterruptManagement.h b/Kernel/Arch/x86_64/InterruptManagement.h similarity index 95% rename from Kernel/Arch/x86/InterruptManagement.h rename to Kernel/Arch/x86_64/InterruptManagement.h index 6845118a9c1..684e5f951ec 100644 --- a/Kernel/Arch/x86/InterruptManagement.h +++ b/Kernel/Arch/x86_64/InterruptManagement.h @@ -10,8 +10,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/Kernel/Arch/x86/common/Interrupts.cpp b/Kernel/Arch/x86_64/Interrupts.cpp similarity index 99% rename from Kernel/Arch/x86/common/Interrupts.cpp rename to Kernel/Arch/x86_64/Interrupts.cpp index a6c06fac113..726c535b5af 100644 --- a/Kernel/Arch/x86/common/Interrupts.cpp +++ b/Kernel/Arch/x86_64/Interrupts.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include @@ -31,7 +31,7 @@ #include #include #include -#include +#include 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 similarity index 100% rename from Kernel/Arch/x86/Interrupts.h rename to Kernel/Arch/x86_64/Interrupts.h diff --git a/Kernel/Arch/x86/common/Interrupts/APIC.cpp b/Kernel/Arch/x86_64/Interrupts/APIC.cpp similarity index 99% rename from Kernel/Arch/x86/common/Interrupts/APIC.cpp rename to Kernel/Arch/x86_64/Interrupts/APIC.cpp index 48d3ab902e4..262c6011c2f 100644 --- a/Kernel/Arch/x86/common/Interrupts/APIC.cpp +++ b/Kernel/Arch/x86_64/Interrupts/APIC.cpp @@ -9,10 +9,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include diff --git a/Kernel/Arch/x86/common/Interrupts/APIC.h b/Kernel/Arch/x86_64/Interrupts/APIC.h similarity index 100% rename from Kernel/Arch/x86/common/Interrupts/APIC.h rename to 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 similarity index 98% rename from Kernel/Arch/x86/common/Interrupts/IOAPIC.cpp rename to Kernel/Arch/x86_64/Interrupts/IOAPIC.cpp index 7a17fffc0ae..5b63d4b56fb 100644 --- a/Kernel/Arch/x86/common/Interrupts/IOAPIC.cpp +++ b/Kernel/Arch/x86_64/Interrupts/IOAPIC.cpp @@ -5,9 +5,9 @@ */ #include -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/Kernel/Arch/x86/common/Interrupts/IOAPIC.h b/Kernel/Arch/x86_64/Interrupts/IOAPIC.h similarity index 98% rename from Kernel/Arch/x86/common/Interrupts/IOAPIC.h rename to Kernel/Arch/x86_64/Interrupts/IOAPIC.h index ef8ff1ac851..106f16c996a 100644 --- a/Kernel/Arch/x86/common/Interrupts/IOAPIC.h +++ b/Kernel/Arch/x86_64/Interrupts/IOAPIC.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include namespace Kernel { diff --git a/Kernel/Arch/x86/common/Interrupts/PIC.cpp b/Kernel/Arch/x86_64/Interrupts/PIC.cpp similarity index 98% rename from Kernel/Arch/x86/common/Interrupts/PIC.cpp rename to Kernel/Arch/x86_64/Interrupts/PIC.cpp index bcf4cc5f156..77c567d97bb 100644 --- a/Kernel/Arch/x86/common/Interrupts/PIC.cpp +++ b/Kernel/Arch/x86_64/Interrupts/PIC.cpp @@ -6,8 +6,8 @@ #include #include -#include -#include +#include +#include #include #include #include diff --git a/Kernel/Arch/x86/common/Interrupts/PIC.h b/Kernel/Arch/x86_64/Interrupts/PIC.h similarity index 96% rename from Kernel/Arch/x86/common/Interrupts/PIC.h rename to Kernel/Arch/x86_64/Interrupts/PIC.h index 25c3cb937b8..e88e72326fd 100644 --- a/Kernel/Arch/x86/common/Interrupts/PIC.h +++ b/Kernel/Arch/x86_64/Interrupts/PIC.h @@ -7,7 +7,7 @@ #pragma once #include -#include +#include namespace Kernel { diff --git a/Kernel/Arch/x86/MSR.h b/Kernel/Arch/x86_64/MSR.h similarity index 95% rename from Kernel/Arch/x86/MSR.h rename to Kernel/Arch/x86_64/MSR.h index 1acc1dfb41c..ff2810d62e7 100644 --- a/Kernel/Arch/x86/MSR.h +++ b/Kernel/Arch/x86_64/MSR.h @@ -8,7 +8,7 @@ #include -#include +#include #include VALIDATE_IS_X86() diff --git a/Kernel/Arch/x86/NonMaskableInterruptDisabler.h b/Kernel/Arch/x86_64/NonMaskableInterruptDisabler.h similarity index 92% rename from Kernel/Arch/x86/NonMaskableInterruptDisabler.h rename to Kernel/Arch/x86_64/NonMaskableInterruptDisabler.h index 881f8845419..f08ada98fb2 100644 --- a/Kernel/Arch/x86/NonMaskableInterruptDisabler.h +++ b/Kernel/Arch/x86_64/NonMaskableInterruptDisabler.h @@ -8,7 +8,7 @@ #include -#include +#include namespace Kernel { diff --git a/Kernel/Arch/x86/PCI/Controller/HostBridge.cpp b/Kernel/Arch/x86_64/PCI/Controller/HostBridge.cpp similarity index 95% rename from Kernel/Arch/x86/PCI/Controller/HostBridge.cpp rename to Kernel/Arch/x86_64/PCI/Controller/HostBridge.cpp index 81c7e344448..7f7a460e990 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 -#include +#include +#include #include #include diff --git a/Kernel/Arch/x86/PCI/Controller/HostBridge.h b/Kernel/Arch/x86_64/PCI/Controller/HostBridge.h similarity index 100% rename from Kernel/Arch/x86/PCI/Controller/HostBridge.h rename to 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 similarity index 99% rename from Kernel/Arch/x86/PCI/IDELegacyModeController.cpp rename to Kernel/Arch/x86_64/PCI/IDELegacyModeController.cpp index c89df06cce5..35f6c5b8ed9 100644 --- a/Kernel/Arch/x86/PCI/IDELegacyModeController.cpp +++ b/Kernel/Arch/x86_64/PCI/IDELegacyModeController.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include diff --git a/Kernel/Arch/x86/PCI/IDELegacyModeController.h b/Kernel/Arch/x86_64/PCI/IDELegacyModeController.h similarity index 100% rename from Kernel/Arch/x86/PCI/IDELegacyModeController.h rename to Kernel/Arch/x86_64/PCI/IDELegacyModeController.h diff --git a/Kernel/Arch/x86/PCI/Initializer.cpp b/Kernel/Arch/x86_64/PCI/Initializer.cpp similarity index 98% rename from Kernel/Arch/x86/PCI/Initializer.cpp rename to Kernel/Arch/x86_64/PCI/Initializer.cpp index f6158e22a4a..37f9bc6c4df 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 +#include #include #include #include diff --git a/Kernel/Arch/x86/common/PCSpeaker.cpp b/Kernel/Arch/x86_64/PCSpeaker.cpp similarity index 80% rename from Kernel/Arch/x86/common/PCSpeaker.cpp rename to Kernel/Arch/x86_64/PCSpeaker.cpp index 7c4bac5ebb1..176a87073f5 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 -#include -#include +#include +#include +#include void PCSpeaker::tone_on(int frequency) { diff --git a/Kernel/Arch/x86/common/PCSpeaker.h b/Kernel/Arch/x86_64/PCSpeaker.h similarity index 100% rename from Kernel/Arch/x86/common/PCSpeaker.h rename to Kernel/Arch/x86_64/PCSpeaker.h diff --git a/Kernel/Arch/x86/common/PageDirectory.cpp b/Kernel/Arch/x86_64/PageDirectory.cpp similarity index 100% rename from Kernel/Arch/x86/common/PageDirectory.cpp rename to Kernel/Arch/x86_64/PageDirectory.cpp diff --git a/Kernel/Arch/x86/PageDirectory.h b/Kernel/Arch/x86_64/PageDirectory.h similarity index 100% rename from Kernel/Arch/x86/PageDirectory.h rename to Kernel/Arch/x86_64/PageDirectory.h diff --git a/Kernel/Arch/x86/common/Processor.cpp b/Kernel/Arch/x86_64/Processor.cpp similarity index 86% rename from Kernel/Arch/x86/common/Processor.cpp rename to Kernel/Arch/x86_64/Processor.cpp index 784975ac9e6..3d1720048ae 100644 --- a/Kernel/Arch/x86/common/Processor.cpp +++ b/Kernel/Arch/x86_64/Processor.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include #include @@ -25,9 +25,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -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(), 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(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(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(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(stack_top); + trap.regs = &iretframe; + trap.prev_irq_level = 0; + trap.next_trap = nullptr; + + stack_top -= sizeof(u64); // pointer to TrapFrame + *reinterpret_cast(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 similarity index 98% rename from Kernel/Arch/x86/Processor.h rename to Kernel/Arch/x86_64/Processor.h index 21ab1302726..cd1dc9c8ef3 100644 --- a/Kernel/Arch/x86/Processor.h +++ b/Kernel/Arch/x86_64/Processor.h @@ -14,11 +14,11 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include diff --git a/Kernel/Arch/x86/common/ProcessorInfo.cpp b/Kernel/Arch/x86_64/ProcessorInfo.cpp similarity index 98% rename from Kernel/Arch/x86/common/ProcessorInfo.cpp rename to Kernel/Arch/x86_64/ProcessorInfo.cpp index edc05b63068..43c8b0ed0ac 100644 --- a/Kernel/Arch/x86/common/ProcessorInfo.cpp +++ b/Kernel/Arch/x86_64/ProcessorInfo.cpp @@ -8,8 +8,8 @@ #include #include #include -#include -#include +#include +#include namespace Kernel { diff --git a/Kernel/Arch/x86/ProcessorInfo.h b/Kernel/Arch/x86_64/ProcessorInfo.h similarity index 100% rename from Kernel/Arch/x86/ProcessorInfo.h rename to Kernel/Arch/x86_64/ProcessorInfo.h diff --git a/Kernel/Arch/x86/common/RTC.cpp b/Kernel/Arch/x86_64/RTC.cpp similarity index 97% rename from Kernel/Arch/x86/common/RTC.cpp rename to Kernel/Arch/x86_64/RTC.cpp index f9816f52e09..7af7c9637af 100644 --- a/Kernel/Arch/x86/common/RTC.cpp +++ b/Kernel/Arch/x86_64/RTC.cpp @@ -7,8 +7,8 @@ #include #include #include -#include -#include +#include +#include namespace Kernel::RTC { diff --git a/Kernel/Arch/x86/common/RTC.h b/Kernel/Arch/x86_64/RTC.h similarity index 100% rename from Kernel/Arch/x86/common/RTC.h rename to Kernel/Arch/x86_64/RTC.h diff --git a/Kernel/Arch/x86/RegisterState.h b/Kernel/Arch/x86_64/RegisterState.h similarity index 99% rename from Kernel/Arch/x86/RegisterState.h rename to Kernel/Arch/x86_64/RegisterState.h index abeeab77333..abdf67b9d87 100644 --- a/Kernel/Arch/x86/RegisterState.h +++ b/Kernel/Arch/x86_64/RegisterState.h @@ -10,7 +10,7 @@ #include #include -#include +#include #include VALIDATE_IS_X86() diff --git a/Kernel/Arch/x86/SIMDState.h b/Kernel/Arch/x86_64/SIMDState.h similarity index 100% rename from Kernel/Arch/x86/SIMDState.h rename to Kernel/Arch/x86_64/SIMDState.h diff --git a/Kernel/Arch/x86/common/SafeMem.cpp b/Kernel/Arch/x86_64/SafeMem.cpp similarity index 100% rename from Kernel/Arch/x86/common/SafeMem.cpp rename to Kernel/Arch/x86_64/SafeMem.cpp diff --git a/Kernel/Arch/x86/common/ScopedCritical.cpp b/Kernel/Arch/x86_64/ScopedCritical.cpp similarity index 100% rename from Kernel/Arch/x86/common/ScopedCritical.cpp rename to Kernel/Arch/x86_64/ScopedCritical.cpp diff --git a/Kernel/Arch/x86/common/Shutdown.cpp b/Kernel/Arch/x86_64/Shutdown.cpp similarity index 86% rename from Kernel/Arch/x86/common/Shutdown.cpp rename to Kernel/Arch/x86_64/Shutdown.cpp index 948f7209816..bfc296ede1c 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 -#include +#include +#include namespace Kernel { diff --git a/Kernel/Arch/x86/common/Shutdown.h b/Kernel/Arch/x86_64/Shutdown.h similarity index 100% rename from Kernel/Arch/x86/common/Shutdown.h rename to Kernel/Arch/x86_64/Shutdown.h diff --git a/Kernel/Arch/x86/common/SmapDisabler.cpp b/Kernel/Arch/x86_64/SmapDisabler.cpp similarity index 88% rename from Kernel/Arch/x86/common/SmapDisabler.cpp rename to Kernel/Arch/x86_64/SmapDisabler.cpp index 1adf3154ed9..530254b0c86 100644 --- a/Kernel/Arch/x86/common/SmapDisabler.cpp +++ b/Kernel/Arch/x86_64/SmapDisabler.cpp @@ -6,7 +6,7 @@ #include -#include +#include namespace Kernel { diff --git a/Kernel/Arch/x86/x86_64/SyscallEntry.cpp b/Kernel/Arch/x86_64/SyscallEntry.cpp similarity index 96% rename from Kernel/Arch/x86/x86_64/SyscallEntry.cpp rename to Kernel/Arch/x86_64/SyscallEntry.cpp index c325cbd710a..bd9ebfc7d1d 100644 --- a/Kernel/Arch/x86/x86_64/SyscallEntry.cpp +++ b/Kernel/Arch/x86_64/SyscallEntry.cpp @@ -5,8 +5,8 @@ */ #include -#include -#include +#include +#include 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 similarity index 100% rename from Kernel/Arch/x86/TSS.h rename to Kernel/Arch/x86_64/TSS.h diff --git a/Kernel/Arch/x86/Time/APICTimer.cpp b/Kernel/Arch/x86_64/Time/APICTimer.cpp similarity index 98% rename from Kernel/Arch/x86/Time/APICTimer.cpp rename to Kernel/Arch/x86_64/Time/APICTimer.cpp index d7543a8c7cb..5c6499dcb14 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 -#include +#include +#include #include #include #include diff --git a/Kernel/Arch/x86/Time/APICTimer.h b/Kernel/Arch/x86_64/Time/APICTimer.h similarity index 96% rename from Kernel/Arch/x86/Time/APICTimer.h rename to Kernel/Arch/x86_64/Time/APICTimer.h index 44748755386..ed02013b461 100644 --- a/Kernel/Arch/x86/Time/APICTimer.h +++ b/Kernel/Arch/x86_64/Time/APICTimer.h @@ -7,7 +7,7 @@ #pragma once #include -#include +#include #include #include diff --git a/Kernel/Arch/x86/Time/HPET.cpp b/Kernel/Arch/x86_64/Time/HPET.cpp similarity index 99% rename from Kernel/Arch/x86/Time/HPET.cpp rename to Kernel/Arch/x86_64/Time/HPET.cpp index 024f722df63..88d99d5ca73 100644 --- a/Kernel/Arch/x86/Time/HPET.cpp +++ b/Kernel/Arch/x86_64/Time/HPET.cpp @@ -5,8 +5,8 @@ */ #include -#include -#include +#include +#include #include #include #include diff --git a/Kernel/Arch/x86/Time/HPET.h b/Kernel/Arch/x86_64/Time/HPET.h similarity index 100% rename from Kernel/Arch/x86/Time/HPET.h rename to Kernel/Arch/x86_64/Time/HPET.h diff --git a/Kernel/Arch/x86/Time/HPETComparator.cpp b/Kernel/Arch/x86_64/Time/HPETComparator.cpp similarity index 98% rename from Kernel/Arch/x86/Time/HPETComparator.cpp rename to Kernel/Arch/x86_64/Time/HPETComparator.cpp index baeea9b85f4..952eec7e2f8 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 +#include #include #include #include diff --git a/Kernel/Arch/x86/Time/HPETComparator.h b/Kernel/Arch/x86_64/Time/HPETComparator.h similarity index 97% rename from Kernel/Arch/x86/Time/HPETComparator.h rename to Kernel/Arch/x86_64/Time/HPETComparator.h index cfcb70581f5..53bfd9c09c9 100644 --- a/Kernel/Arch/x86/Time/HPETComparator.h +++ b/Kernel/Arch/x86_64/Time/HPETComparator.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include namespace Kernel { diff --git a/Kernel/Arch/x86/Time/PIT.cpp b/Kernel/Arch/x86_64/Time/PIT.cpp similarity index 96% rename from Kernel/Arch/x86/Time/PIT.cpp rename to Kernel/Arch/x86_64/Time/PIT.cpp index a9709e12292..bd1644956d3 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 -#include +#include +#include #include #include #include diff --git a/Kernel/Arch/x86/Time/PIT.h b/Kernel/Arch/x86_64/Time/PIT.h similarity index 100% rename from Kernel/Arch/x86/Time/PIT.h rename to Kernel/Arch/x86_64/Time/PIT.h diff --git a/Kernel/Arch/x86/Time/RTC.cpp b/Kernel/Arch/x86_64/Time/RTC.cpp similarity index 93% rename from Kernel/Arch/x86/Time/RTC.cpp rename to Kernel/Arch/x86_64/Time/RTC.cpp index 3686a73356b..eb372beb052 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 -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/Kernel/Arch/x86/Time/RTC.h b/Kernel/Arch/x86_64/Time/RTC.h similarity index 97% rename from Kernel/Arch/x86/Time/RTC.h rename to Kernel/Arch/x86_64/Time/RTC.h index b15e4aa7e14..4cfb520c8dd 100644 --- a/Kernel/Arch/x86/Time/RTC.h +++ b/Kernel/Arch/x86_64/Time/RTC.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include diff --git a/Kernel/Arch/x86/common/TrapFrame.cpp b/Kernel/Arch/x86_64/TrapFrame.cpp similarity index 93% rename from Kernel/Arch/x86/common/TrapFrame.cpp rename to Kernel/Arch/x86_64/TrapFrame.cpp index 5b96146d60e..ba363c306ec 100644 --- a/Kernel/Arch/x86/common/TrapFrame.cpp +++ b/Kernel/Arch/x86_64/TrapFrame.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include #include namespace Kernel { diff --git a/Kernel/Arch/x86/TrapFrame.h b/Kernel/Arch/x86_64/TrapFrame.h similarity index 100% rename from Kernel/Arch/x86/TrapFrame.h rename to Kernel/Arch/x86_64/TrapFrame.h diff --git a/Kernel/Arch/x86/VGA/IOArbiter.cpp b/Kernel/Arch/x86_64/VGA/IOArbiter.cpp similarity index 96% rename from Kernel/Arch/x86/VGA/IOArbiter.cpp rename to Kernel/Arch/x86_64/VGA/IOArbiter.cpp index cf558150cea..8d3e632f59f 100644 --- a/Kernel/Arch/x86/VGA/IOArbiter.cpp +++ b/Kernel/Arch/x86_64/VGA/IOArbiter.cpp @@ -7,8 +7,8 @@ #include #include #include -#include -#include +#include +#include namespace Kernel { diff --git a/Kernel/Arch/x86/VGA/IOArbiter.h b/Kernel/Arch/x86_64/VGA/IOArbiter.h similarity index 100% rename from Kernel/Arch/x86/VGA/IOArbiter.h rename to Kernel/Arch/x86_64/VGA/IOArbiter.h diff --git a/Kernel/Arch/x86/init.cpp b/Kernel/Arch/x86_64/init.cpp similarity index 99% rename from Kernel/Arch/x86/init.cpp rename to Kernel/Arch/x86_64/init.cpp index 2b4ee79bdac..a9bcdeb7736 100644 --- a/Kernel/Arch/x86/init.cpp +++ b/Kernel/Arch/x86_64/init.cpp @@ -7,9 +7,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/Kernel/Arch/x86/linker.ld b/Kernel/Arch/x86_64/linker.ld similarity index 100% rename from Kernel/Arch/x86/linker.ld rename to Kernel/Arch/x86_64/linker.ld diff --git a/Kernel/Arch/x86/mcontext.h b/Kernel/Arch/x86_64/mcontext.h similarity index 100% rename from Kernel/Arch/x86/mcontext.h rename to Kernel/Arch/x86_64/mcontext.h diff --git a/Kernel/Bus/PCI/Access.cpp b/Kernel/Bus/PCI/Access.cpp index 050b8b8a43d..460d9ece8a8 100644 --- a/Kernel/Bus/PCI/Access.cpp +++ b/Kernel/Bus/PCI/Access.cpp @@ -8,7 +8,7 @@ #include #include #if ARCH(X86_64) -# include +# include #endif #include #include diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index bf0601c32a4..2d4b95fdd69 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_64/CMOS.cpp + Arch/x86_64/DebugOutput.cpp + Arch/x86_64/Delay.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_64/Hypervisor/BochsDisplayConnector.cpp + Arch/x86_64/Hypervisor/VMWareBackdoor.cpp - Arch/x86/CurrentTime.cpp + Arch/x86_64/CurrentTime.cpp - Arch/x86/Hypervisor/BochsDisplayConnector.cpp - Arch/x86/Hypervisor/VMWareBackdoor.cpp + Arch/x86_64/Hypervisor/BochsDisplayConnector.cpp + Arch/x86_64/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_64/Interrupts/APIC.cpp + Arch/x86_64/Interrupts/IOAPIC.cpp + Arch/x86_64/Interrupts/PIC.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_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/VGA/IOArbiter.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 75179e55051..92044f852b7 100644 --- a/Kernel/Devices/ConsoleDevice.cpp +++ b/Kernel/Devices/ConsoleDevice.cpp @@ -6,7 +6,7 @@ #include #if ARCH(X86_64) -# include +# include #endif #include #include diff --git a/Kernel/Devices/HID/HIDManagement.cpp b/Kernel/Devices/HID/HIDManagement.cpp index 0dda36abe2e..56b8d57e478 100644 --- a/Kernel/Devices/HID/HIDManagement.cpp +++ b/Kernel/Devices/HID/HIDManagement.cpp @@ -7,7 +7,7 @@ #include #include #if ARCH(X86_64) -# include +# include #endif #include #include diff --git a/Kernel/FileSystem/SysFS/Subsystems/Kernel/CPUInfo.cpp b/Kernel/FileSystem/SysFS/Subsystems/Kernel/CPUInfo.cpp index 0d948eec4fc..84c00262565 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Kernel/CPUInfo.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/Kernel/CPUInfo.cpp @@ -6,7 +6,7 @@ #include #if ARCH(X86_64) -# include +# include #endif #include #include diff --git a/Kernel/FileSystem/SysFS/Subsystems/Kernel/PowerStateSwitch.cpp b/Kernel/FileSystem/SysFS/Subsystems/Kernel/PowerStateSwitch.cpp index 591763ba0be..f05b32d9036 100644 --- a/Kernel/FileSystem/SysFS/Subsystems/Kernel/PowerStateSwitch.cpp +++ b/Kernel/FileSystem/SysFS/Subsystems/Kernel/PowerStateSwitch.cpp @@ -7,8 +7,8 @@ #include #if ARCH(X86_64) -# include -# include +# include +# include #endif #include #include diff --git a/Kernel/Firmware/ACPI/Parser.cpp b/Kernel/Firmware/ACPI/Parser.cpp index 5eb04ea6c4b..d9045a5e771 100644 --- a/Kernel/Firmware/ACPI/Parser.cpp +++ b/Kernel/Firmware/ACPI/Parser.cpp @@ -12,7 +12,7 @@ #include #include #if ARCH(X86_64) -# include +# include #endif #include #include diff --git a/Kernel/Firmware/MultiProcessor/Parser.cpp b/Kernel/Firmware/MultiProcessor/Parser.cpp index 109292185fb..2add19d74ea 100644 --- a/Kernel/Firmware/MultiProcessor/Parser.cpp +++ b/Kernel/Firmware/MultiProcessor/Parser.cpp @@ -7,7 +7,7 @@ */ #include -#include +#include #include #include #include diff --git a/Kernel/Graphics/Bochs/GraphicsAdapter.cpp b/Kernel/Graphics/Bochs/GraphicsAdapter.cpp index ffa3654359d..f09060d5d91 100644 --- a/Kernel/Graphics/Bochs/GraphicsAdapter.cpp +++ b/Kernel/Graphics/Bochs/GraphicsAdapter.cpp @@ -8,7 +8,7 @@ #include #include #if ARCH(X86_64) -# include +# include #endif #include #include diff --git a/Kernel/Graphics/GraphicsManagement.cpp b/Kernel/Graphics/GraphicsManagement.cpp index ea3252e6610..a65e69d58f2 100644 --- a/Kernel/Graphics/GraphicsManagement.cpp +++ b/Kernel/Graphics/GraphicsManagement.cpp @@ -7,7 +7,7 @@ #include #include #if ARCH(X86_64) -# include +# include #endif #include #include diff --git a/Kernel/Graphics/GraphicsManagement.h b/Kernel/Graphics/GraphicsManagement.h index 8928bd53188..17e17bd06b3 100644 --- a/Kernel/Graphics/GraphicsManagement.h +++ b/Kernel/Graphics/GraphicsManagement.h @@ -10,7 +10,7 @@ #include #include #if ARCH(X86_64) -# include +# include #endif #include #include diff --git a/Kernel/IOWindow.h b/Kernel/IOWindow.h index 06e76a9a954..9dc911f958d 100644 --- a/Kernel/IOWindow.h +++ b/Kernel/IOWindow.h @@ -10,7 +10,7 @@ #include #include #if ARCH(X86_64) -# include +# include #endif #include #include diff --git a/Kernel/Interrupts/SpuriousInterruptHandler.cpp b/Kernel/Interrupts/SpuriousInterruptHandler.cpp index ea73a458873..893230a0da8 100644 --- a/Kernel/Interrupts/SpuriousInterruptHandler.cpp +++ b/Kernel/Interrupts/SpuriousInterruptHandler.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include diff --git a/Kernel/Panic.cpp b/Kernel/Panic.cpp index 5db7d78378a..ad132f50324 100644 --- a/Kernel/Panic.cpp +++ b/Kernel/Panic.cpp @@ -7,7 +7,7 @@ #include #include #if ARCH(X86_64) -# include +# include #endif #include #include diff --git a/Kernel/Prekernel/init.cpp b/Kernel/Prekernel/init.cpp index 1dffb1b4e92..1f956559416 100644 --- a/Kernel/Prekernel/init.cpp +++ b/Kernel/Prekernel/init.cpp @@ -15,8 +15,8 @@ #include #if ARCH(X86_64) -# include -# include +# include +# include #endif // Defined in the linker script diff --git a/Kernel/Random.cpp b/Kernel/Random.cpp index 65577cd63fb..e49678a0f36 100644 --- a/Kernel/Random.cpp +++ b/Kernel/Random.cpp @@ -8,8 +8,8 @@ #include #include #if ARCH(X86_64) -# include -# include +# include +# include #endif #include #include diff --git a/Kernel/Storage/StorageManagement.cpp b/Kernel/Storage/StorageManagement.cpp index 961b6f5767d..5d6ab6fe5db 100644 --- a/Kernel/Storage/StorageManagement.cpp +++ b/Kernel/Storage/StorageManagement.cpp @@ -11,8 +11,8 @@ #include #include #if ARCH(X86_64) -# include -# include +# include +# include #endif #include #include diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index aaf45586d91..de769c04c13 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include diff --git a/Kernel/Syscalls/beep.cpp b/Kernel/Syscalls/beep.cpp index 87eb0659fc1..0e6d4e37b5b 100644 --- a/Kernel/Syscalls/beep.cpp +++ b/Kernel/Syscalls/beep.cpp @@ -6,7 +6,7 @@ #include #if ARCH(X86_64) -# include +# include #endif #include diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp index c4ac350f50b..78f1dcda971 100644 --- a/Kernel/Syscalls/mmap.cpp +++ b/Kernel/Syscalls/mmap.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Kernel/TTY/VirtualConsole.cpp b/Kernel/TTY/VirtualConsole.cpp index ddb6e8c311a..52da68204b5 100644 --- a/Kernel/TTY/VirtualConsole.cpp +++ b/Kernel/TTY/VirtualConsole.cpp @@ -9,7 +9,7 @@ #include #include #if ARCH(X86_64) -# include +# include #endif #include #include diff --git a/Kernel/Time/TimeManagement.cpp b/Kernel/Time/TimeManagement.cpp index 74d1a4c3d80..e58b063b46c 100644 --- a/Kernel/Time/TimeManagement.cpp +++ b/Kernel/Time/TimeManagement.cpp @@ -9,13 +9,13 @@ #include #include #if ARCH(X86_64) -# include -# include -# include -# include -# include -# include -# include +# include +# include +# include +# include +# include +# include +# include #elif ARCH(AARCH64) # include #else diff --git a/Kernel/kprintf.cpp b/Kernel/kprintf.cpp index 25479892823..ce21cd6952a 100644 --- a/Kernel/kprintf.cpp +++ b/Kernel/kprintf.cpp @@ -9,7 +9,7 @@ #include #include #if ARCH(X86_64) -# include +# include #endif #include #include diff --git a/Tests/Kernel/crash.cpp b/Tests/Kernel/crash.cpp index 4857262aa58..46f8d9aa3d9 100644 --- a/Tests/Kernel/crash.cpp +++ b/Tests/Kernel/crash.cpp @@ -9,7 +9,7 @@ #include #include #if ARCH(X86_64) -# include +# include #endif #include #include