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>
|
2021-07-15 10:03:47 +02:00
|
|
|
#if uefi == 1
|
2021-05-19 12:14:00 +05:30
|
|
|
# include <efi.h>
|
|
|
|
#endif
|
2021-05-19 11:49:53 +05:30
|
|
|
#include <lib/blib.h>
|
|
|
|
#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-03-14 12:03:12 +01:00
|
|
|
static bool is_nested = false;
|
|
|
|
|
|
|
|
if (is_nested) {
|
|
|
|
goto nested;
|
|
|
|
}
|
|
|
|
|
|
|
|
is_nested = true;
|
|
|
|
|
2022-01-25 08:41:17 +01:00
|
|
|
if (
|
|
|
|
#if bios == 1
|
|
|
|
stage3_loaded == true &&
|
|
|
|
#endif
|
|
|
|
term_backend == NOT_READY) {
|
2022-03-14 12:03:12 +01:00
|
|
|
early_term = true;
|
2021-10-30 01:58:35 +02:00
|
|
|
term_vbe(0, 0);
|
|
|
|
}
|
|
|
|
|
2022-03-14 12:03:12 +01:00
|
|
|
nested:
|
|
|
|
if (term_backend == NOT_READY) {
|
2022-01-05 16:03:26 +01:00
|
|
|
term_fallback();
|
2021-12-14 06:47:28 +01:00
|
|
|
}
|
|
|
|
|
2022-01-25 08:50:36 +01:00
|
|
|
#if bios == 1
|
2022-01-25 08:41:17 +01:00
|
|
|
if (stage3_loaded) {
|
2022-01-25 08:50:36 +01:00
|
|
|
#endif
|
2022-01-25 08:41:17 +01:00
|
|
|
print("\033[31mPANIC\033[37;1m\033[0m: ");
|
2022-01-25 08:50:36 +01:00
|
|
|
#if bios == 1
|
2022-01-25 08:41:17 +01:00
|
|
|
} else {
|
|
|
|
print("PANIC: ");
|
|
|
|
}
|
2022-01-25 08:50:36 +01:00
|
|
|
#endif
|
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 (
|
2021-07-15 10:03:47 +02:00
|
|
|
#if bios == 1
|
2021-12-11 19:58:00 +01:00
|
|
|
stage3_loaded == true &&
|
|
|
|
#endif
|
|
|
|
allow_menu == true) {
|
|
|
|
print("Press a key to return to menu.");
|
|
|
|
|
|
|
|
getchar();
|
|
|
|
|
|
|
|
menu(false);
|
|
|
|
__builtin_unreachable();
|
|
|
|
/*
|
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 {
|
2021-12-11 19:58:00 +01:00
|
|
|
#if bios == 1
|
|
|
|
print("Press CTRL+ALT+DEL to reboot.");
|
|
|
|
rm_hcf();
|
|
|
|
#elif uefi == 1
|
2021-07-06 09:59:49 +02:00
|
|
|
print("System halted.");
|
|
|
|
for (;;) {
|
|
|
|
asm ("hlt");
|
|
|
|
}
|
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
|
|
|
}
|