2021-12-11 19:58:00 +01:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdbool.h>
|
2021-12-31 10:58:05 +01:00
|
|
|
#include <stdnoreturn.h>
|
2021-03-01 23:38:55 +01:00
|
|
|
#include <lib/print.h>
|
|
|
|
#include <lib/real.h>
|
|
|
|
#include <lib/trace.h>
|
2022-09-02 02:29:12 +02:00
|
|
|
#if defined (UEFI)
|
2021-05-19 12:14:00 +05:30
|
|
|
# include <efi.h>
|
|
|
|
#endif
|
2022-08-26 23:44:47 +02:00
|
|
|
#include <lib/misc.h>
|
2021-05-19 11:49:53 +05:30
|
|
|
#include <lib/readline.h>
|
|
|
|
#include <lib/gterm.h>
|
2021-10-30 01:58:35 +02:00
|
|
|
#include <lib/term.h>
|
2021-05-19 11:49:53 +05:30
|
|
|
#include <mm/pmm.h>
|
2021-12-11 19:58:00 +01:00
|
|
|
#include <menu.h>
|
2021-03-01 23:38:55 +01:00
|
|
|
|
2021-12-31 10:58:05 +01:00
|
|
|
noreturn void panic(bool allow_menu, const char *fmt, ...) {
|
2021-03-01 23:38:55 +01:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
2021-11-20 21:47:51 +01:00
|
|
|
quiet = false;
|
|
|
|
|
2022-09-23 20:59:02 +02:00
|
|
|
if (
|
|
|
|
#if defined (BIOS)
|
|
|
|
stage3_loaded == true &&
|
|
|
|
#endif
|
|
|
|
term_backend == _NOT_READY) {
|
2022-09-20 09:54:35 +02:00
|
|
|
term_fallback();
|
|
|
|
}
|
|
|
|
|
2022-09-23 20:59:02 +02:00
|
|
|
if (
|
|
|
|
#if defined (BIOS)
|
|
|
|
stage3_loaded == true &&
|
|
|
|
#endif
|
|
|
|
term_backend != FALLBACK) {
|
2022-01-25 08:41:17 +01:00
|
|
|
print("\033[31mPANIC\033[37;1m\033[0m: ");
|
|
|
|
} else {
|
|
|
|
print("PANIC: ");
|
|
|
|
}
|
2021-03-01 23:38:55 +01:00
|
|
|
vprint(fmt, args);
|
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
print("\n");
|
|
|
|
print_stacktrace(NULL);
|
|
|
|
|
2021-12-11 19:58:00 +01:00
|
|
|
if (
|
2022-09-02 02:29:12 +02:00
|
|
|
#if defined (BIOS)
|
2021-12-11 19:58:00 +01:00
|
|
|
stage3_loaded == true &&
|
|
|
|
#endif
|
|
|
|
allow_menu == true) {
|
|
|
|
print("Press a key to return to menu.");
|
|
|
|
|
|
|
|
getchar();
|
|
|
|
|
2023-02-16 03:54:10 +01:00
|
|
|
// This fixes a crash
|
|
|
|
term_notready();
|
|
|
|
|
2021-12-11 19:58:00 +01:00
|
|
|
menu(false);
|
|
|
|
/*
|
2021-07-06 09:59:49 +02:00
|
|
|
fb_clear(&fbinfo);
|
2021-05-19 11:49:53 +05:30
|
|
|
|
2021-07-06 09:59:49 +02:00
|
|
|
// release all uefi memory and return to firmware
|
|
|
|
pmm_release_uefi_mem();
|
2021-08-25 22:03:00 +02:00
|
|
|
gBS->Exit(efi_image_handle, EFI_ABORTED, 0, NULL);
|
2021-12-11 19:58:00 +01:00
|
|
|
*/
|
2021-07-06 09:59:49 +02:00
|
|
|
} else {
|
2022-09-02 02:29:12 +02:00
|
|
|
#if defined (BIOS)
|
2021-12-11 19:58:00 +01:00
|
|
|
print("Press CTRL+ALT+DEL to reboot.");
|
|
|
|
rm_hcf();
|
2022-09-02 02:29:12 +02:00
|
|
|
#elif defined (UEFI)
|
2021-07-06 09:59:49 +02:00
|
|
|
print("System halted.");
|
|
|
|
for (;;) {
|
2022-08-18 17:32:54 +02:00
|
|
|
#if defined (__x86_64__) || defined (__i386__)
|
2021-07-06 09:59:49 +02:00
|
|
|
asm ("hlt");
|
2023-06-03 18:36:06 -05:00
|
|
|
#elif defined (__aarch64__) || defined (__riscv64)
|
2022-08-18 17:32:54 +02:00
|
|
|
asm ("wfi");
|
|
|
|
#else
|
|
|
|
#error Unknown architecture
|
|
|
|
#endif
|
2021-07-06 09:59:49 +02:00
|
|
|
}
|
2021-03-02 10:23:43 +01:00
|
|
|
#endif
|
2021-12-11 19:58:00 +01:00
|
|
|
}
|
2021-03-01 23:38:55 +01:00
|
|
|
}
|