limine/common/lib/panic.s2.c

90 lines
1.6 KiB
C
Raw Normal View History

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>
#include <lib/print.h>
#include <lib/real.h>
#include <lib/trace.h>
#if uefi == 1
2021-05-19 09:44:00 +03:00
# include <efi.h>
#endif
#include <lib/blib.h>
#include <lib/readline.h>
#include <lib/gterm.h>
#include <lib/term.h>
#include <mm/pmm.h>
2021-12-11 21:58:00 +03:00
#include <menu.h>
2021-12-31 12:58:05 +03:00
noreturn void panic(bool allow_menu, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
2021-11-20 23:47:51 +03:00
quiet = false;
if (
#if bios == 1
stage3_loaded == true &&
#endif
term_backend == NOT_READY) {
#if bios == 1
term_textmode();
#elif uefi == 1
term_vbe(0, 0);
#endif
}
if (
#if bios == 1
stage3_loaded == true &&
#endif
term_backend == NOT_READY) {
term_fallback();
}
2022-01-25 10:50:36 +03:00
#if bios == 1
if (stage3_loaded) {
2022-01-25 10:50:36 +03:00
#endif
print("\033[31mPANIC\033[37;1m\033[0m: ");
2022-01-25 10:50:36 +03:00
#if bios == 1
} else {
print("PANIC: ");
}
2022-01-25 10:50:36 +03:00
#endif
vprint(fmt, args);
va_end(args);
print("\n");
print_stacktrace(NULL);
2021-12-11 21:58:00 +03:00
if (
#if bios == 1
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);
__builtin_unreachable();
/*
fb_clear(&fbinfo);
// release all uefi memory and return to firmware
pmm_release_uefi_mem();
gBS->Exit(efi_image_handle, EFI_ABORTED, 0, NULL);
2021-12-11 21:58:00 +03:00
*/
} else {
2021-12-11 21:58:00 +03:00
#if bios == 1
print("Press CTRL+ALT+DEL to reboot.");
rm_hcf();
#elif uefi == 1
print("System halted.");
for (;;) {
asm ("hlt");
}
2021-03-02 12:23:43 +03:00
#endif
2021-12-11 21:58:00 +03:00
}
}