From 4555cac63974914c52f711acd2f64ac02e0e9df8 Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 2 Sep 2022 09:45:30 +0300 Subject: [PATCH] Kernel: Move QEMU shutdown code to the x86 subdirectory QEMU VM shutdown code is really x86 specific, so let's ensure we only use it when compiling a Kernel for x86 machines. --- Kernel/Arch/x86/common/QEMUShutdown.cpp | 21 +++++++++++++++++++++ Kernel/Arch/x86/common/QEMUShutdown.h | 13 +++++++++++++ Kernel/CMakeLists.txt | 1 + Kernel/Panic.cpp | 14 ++++++++------ 4 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 Kernel/Arch/x86/common/QEMUShutdown.cpp create mode 100644 Kernel/Arch/x86/common/QEMUShutdown.h diff --git a/Kernel/Arch/x86/common/QEMUShutdown.cpp b/Kernel/Arch/x86/common/QEMUShutdown.cpp new file mode 100644 index 0000000000..0c3149dff5 --- /dev/null +++ b/Kernel/Arch/x86/common/QEMUShutdown.cpp @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022, Liav A. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Kernel { + +void qemu_shutdown() +{ + // Note: This will invoke QEMU Shutdown, but for other platforms (or emulators), + // this has no effect on the system. + // We also try the Bochs/Old QEMU shutdown method, if the first didn't work. + IO::out16(0x604, 0x2000); + IO::out16(0xb004, 0x2000); +} + +} diff --git a/Kernel/Arch/x86/common/QEMUShutdown.h b/Kernel/Arch/x86/common/QEMUShutdown.h new file mode 100644 index 0000000000..18634ff622 --- /dev/null +++ b/Kernel/Arch/x86/common/QEMUShutdown.h @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2022, Liav A. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +namespace Kernel { + +void qemu_shutdown(); + +} diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index ca3d5528f0..d13ae0b1e5 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -335,6 +335,7 @@ if ("${SERENITY_ARCH}" STREQUAL "i686" OR "${SERENITY_ARCH}" STREQUAL "x86_64") Arch/x86/common/ScopedCritical.cpp Arch/x86/common/SmapDisabler.cpp + Arch/x86/common/QEMUShutdown.cpp ) set(KERNEL_SOURCES diff --git a/Kernel/Panic.cpp b/Kernel/Panic.cpp index f2f20accc6..ca36075151 100644 --- a/Kernel/Panic.cpp +++ b/Kernel/Panic.cpp @@ -6,7 +6,9 @@ #include #include -#include +#if ARCH(I386) || ARCH(X86_64) +# include +#endif #include #include #include @@ -16,11 +18,11 @@ namespace Kernel { [[noreturn]] static void __shutdown() { - // Note: This will invoke QEMU Shutdown, but for other platforms (or emulators), - // this has no effect on the system, so we still need to halt afterwards. - // We also try the Bochs/Old QEMU shutdown method, if the first didn't work. - IO::out16(0x604, 0x2000); - IO::out16(0xb004, 0x2000); +#if ARCH(I386) || ARCH(X86_64) + qemu_shutdown(); +#endif + // Note: If we failed to invoke platform shutdown, we need to halt afterwards + // to ensure no further execution on any CPU still happens. Processor::halt(); }