]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - wimboot/wimboot-2.7.3/src/die.c
1.1.07 release
[Ventoy.git] / wimboot / wimboot-2.7.3 / src / die.c
1 /*
2 * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 */
19
20 /**
21 * @file
22 *
23 * Fatal errors
24 *
25 */
26
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include "wimboot.h"
30 #include "efi.h"
31
32 /**
33 * Handle fatal errors
34 *
35 * @v fmt Error message format string
36 * @v ... Arguments
37 */
38 void die ( const char *fmt, ... ) {
39 EFI_BOOT_SERVICES *bs;
40 EFI_RUNTIME_SERVICES *rs;
41 va_list args;
42
43 /* Print message */
44 va_start ( args, fmt );
45 vprintf ( fmt, args );
46 va_end ( args );
47
48 /* Reboot or exit as applicable */
49 if ( efi_systab ) {
50
51 /* Exit */
52 bs = efi_systab->BootServices;
53 bs->Exit ( efi_image_handle, EFI_LOAD_ERROR, 0, NULL );
54 printf ( "Failed to exit\n" );
55 rs = efi_systab->RuntimeServices;
56 rs->ResetSystem ( EfiResetWarm, 0, 0, NULL );
57 printf ( "Failed to reboot\n" );
58
59 } else {
60
61 /* Wait for keypress */
62 printf ( "Press a key to reboot..." );
63 getchar();
64 printf ( "\n" );
65
66 /* Reboot system */
67 reboot();
68 }
69
70 /* Should be impossible to reach this */
71 __builtin_unreachable();
72 }