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