2021-02-14 05:01:52 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-14 05:01:52 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <AK/Format.h>
|
2021-10-13 20:07:37 -03:00
|
|
|
#include <Kernel/Arch/Processor.h>
|
2022-10-03 21:05:54 -03:00
|
|
|
#if ARCH(X86_64)
|
2022-10-04 07:46:11 -03:00
|
|
|
# include <Kernel/Arch/x86_64/Shutdown.h>
|
2023-05-15 02:34:19 -03:00
|
|
|
#elif ARCH(AARCH64)
|
|
|
|
|
# include <Kernel/Arch/aarch64/RPi/Watchdog.h>
|
2022-09-02 03:45:30 -03:00
|
|
|
#endif
|
2023-02-24 15:21:53 -03:00
|
|
|
#include <Kernel/Boot/CommandLine.h>
|
2021-02-14 05:01:52 -03:00
|
|
|
#include <Kernel/KSyms.h>
|
2023-02-24 15:10:59 -03:00
|
|
|
#include <Kernel/Library/Panic.h>
|
2023-02-24 14:45:37 -03:00
|
|
|
#include <Kernel/Tasks/Thread.h>
|
2021-02-14 05:01:52 -03:00
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
2021-07-26 15:34:43 -03:00
|
|
|
[[noreturn]] static void __shutdown()
|
2021-07-25 16:40:41 -03:00
|
|
|
{
|
2022-10-03 21:05:54 -03:00
|
|
|
#if ARCH(X86_64)
|
2022-09-02 03:45:30 -03:00
|
|
|
qemu_shutdown();
|
2022-09-02 04:17:55 -03:00
|
|
|
virtualbox_shutdown();
|
2023-05-15 02:34:19 -03:00
|
|
|
#elif ARCH(AARCH64)
|
|
|
|
|
RPi::Watchdog::the().system_shutdown();
|
2022-09-02 03:45:30 -03:00
|
|
|
#endif
|
|
|
|
|
// Note: If we failed to invoke platform shutdown, we need to halt afterwards
|
|
|
|
|
// to ensure no further execution on any CPU still happens.
|
2021-07-26 15:34:43 -03:00
|
|
|
Processor::halt();
|
2021-07-25 16:40:41 -03:00
|
|
|
}
|
|
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
void __panic(char const* file, unsigned int line, char const* function)
|
2021-02-14 05:01:52 -03:00
|
|
|
{
|
2021-09-07 04:17:45 -03:00
|
|
|
// Avoid lock ranking checks on crashing paths, just try to get some debugging messages out.
|
2021-12-28 21:01:27 -03:00
|
|
|
auto* thread = Thread::current();
|
2021-09-07 04:17:45 -03:00
|
|
|
if (thread)
|
|
|
|
|
thread->set_crashing();
|
|
|
|
|
|
2021-04-16 16:58:51 -03:00
|
|
|
critical_dmesgln("at {}:{} in {}", file, line, function);
|
2021-08-04 12:52:14 -03:00
|
|
|
dump_backtrace(PrintToScreen::Yes);
|
2022-01-21 06:36:32 -03:00
|
|
|
if (!CommandLine::was_initialized())
|
|
|
|
|
Processor::halt();
|
2021-10-23 12:31:00 -03:00
|
|
|
switch (kernel_command_line().panic_mode()) {
|
|
|
|
|
case PanicMode::Shutdown:
|
2021-07-26 15:34:43 -03:00
|
|
|
__shutdown();
|
2021-10-23 12:31:00 -03:00
|
|
|
case PanicMode::Halt:
|
|
|
|
|
[[fallthrough]];
|
|
|
|
|
default:
|
2021-07-25 16:40:41 -03:00
|
|
|
Processor::halt();
|
2021-10-23 12:31:00 -03:00
|
|
|
}
|
2021-02-14 05:01:52 -03:00
|
|
|
}
|
|
|
|
|
}
|