Panic.cpp 976 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Format.h>
  7. #include <Kernel/Arch/x86/Processor.h>
  8. #include <Kernel/CommandLine.h>
  9. #include <Kernel/IO.h>
  10. #include <Kernel/KSyms.h>
  11. #include <Kernel/Panic.h>
  12. namespace Kernel {
  13. [[noreturn]] static void __shutdown()
  14. {
  15. // Note: This will invoke QEMU Shutdown, but for other platforms (or emulators),
  16. // this has no effect on the system, so we still need to halt afterwards.
  17. // We also try the Bochs/Old QEMU shutdown method, if the first didn't work.
  18. IO::out16(0x604, 0x2000);
  19. IO::out16(0xb004, 0x2000);
  20. Processor::halt();
  21. }
  22. void __panic(const char* file, unsigned int line, const char* function)
  23. {
  24. critical_dmesgln("at {}:{} in {}", file, line, function);
  25. dump_backtrace(PrintToScreen::Yes);
  26. if (kernel_command_line().boot_mode() == BootMode::SelfTest)
  27. __shutdown();
  28. else
  29. Processor::halt();
  30. }
  31. }