:: commit 2c679dcec3773f49dd9eb2d0498be498faa80b37

aditya <aarshisback@gmail.com> — 2021-05-19 06:19

parents: 4c1782357a

return to firmware instead of halting in uefi mode

diff --git a/stage23/lib/panic.s2.c b/stage23/lib/panic.s2.c
index cb979d20..f15a411e 100644
--- a/stage23/lib/panic.s2.c
+++ b/stage23/lib/panic.s2.c
@@ -1,6 +1,10 @@
 #include <lib/print.h>
 #include <lib/real.h>
 #include <lib/trace.h>
+#include <lib/blib.h>
+#include <lib/readline.h>
+#include <lib/gterm.h>
+#include <mm/pmm.h>
 
 __attribute__((noreturn)) void panic(const char *fmt, ...) {
     asm volatile ("cli" ::: "memory");
@@ -18,8 +22,16 @@ __attribute__((noreturn)) void panic(const char *fmt, ...) {
     print_stacktrace(NULL);
 
 #if defined (bios)
+    print("System halted.");
     rm_hcf();
 #elif defined (uefi)
-    for (;;) asm ("hlt");
+    print("Press any key to return to firmware.");
+    getchar();
+    gterm_clear(true);
+
+    // release all uefi memory and return to firmware
+    pmm_release_uefi_mem();
+    uefi_call_wrapper(gBS->Exit, 4, efi_image_handle, EFI_ABORTED, 0, NULL);
+    __builtin_unreachable();
 #endif
 }
diff --git a/stage23/lib/trace.s2.c b/stage23/lib/trace.s2.c
index 47fb9a85..73647564 100644
--- a/stage23/lib/trace.s2.c
+++ b/stage23/lib/trace.s2.c
@@ -73,5 +73,5 @@ void print_stacktrace(size_t *base_ptr) {
             break;
         base_ptr = (void*)old_bp;
     }
-    print("End of trace.\n");
+    print("End of trace. ");
 }
tab: 248 wrap: offon