2021-02-14 11:01:52 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-14 11:01:52 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/Format.h>
|
2021-06-21 18:34:09 +03:00
|
|
|
#include <Kernel/Arch/x86/Processor.h>
|
2021-07-25 22:40:41 +03:00
|
|
|
#include <Kernel/CommandLine.h>
|
2021-07-26 21:34:43 +03:00
|
|
|
#include <Kernel/IO.h>
|
2021-02-14 11:01:52 +03:00
|
|
|
#include <Kernel/KSyms.h>
|
|
|
|
#include <Kernel/Panic.h>
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-07-26 21:34:43 +03:00
|
|
|
[[noreturn]] static void __shutdown()
|
2021-07-25 22:40:41 +03:00
|
|
|
{
|
2021-07-26 21:34:43 +03:00
|
|
|
// 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);
|
|
|
|
Processor::halt();
|
2021-07-25 22:40:41 +03:00
|
|
|
}
|
|
|
|
|
2021-02-14 11:01:52 +03:00
|
|
|
void __panic(const char* file, unsigned int line, const char* function)
|
|
|
|
{
|
2021-04-16 22:58:51 +03:00
|
|
|
critical_dmesgln("at {}:{} in {}", file, line, function);
|
2021-02-14 11:01:52 +03:00
|
|
|
dump_backtrace();
|
2021-07-25 22:40:41 +03:00
|
|
|
if (kernel_command_line().boot_mode() == BootMode::SelfTest)
|
2021-07-26 21:34:43 +03:00
|
|
|
__shutdown();
|
2021-07-25 22:40:41 +03:00
|
|
|
else
|
|
|
|
Processor::halt();
|
2021-02-14 11:01:52 +03:00
|
|
|
}
|
|
|
|
}
|