| 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Callers outside of misc.c need access to the error reporting routines, |
| 4 | * but the *_putstr() functions need to stay in misc.c because of how |
| 5 | * memcpy() and memmove() are defined for the compressed boot environment. |
| 6 | */ |
| 7 | #include "misc.h" |
| 8 | #include "error.h" |
| 9 | |
| 10 | void warn(const char *m) |
| 11 | { |
| 12 | error_putstr("\n\n" ); |
| 13 | error_putstr(m); |
| 14 | error_putstr("\n\n" ); |
| 15 | } |
| 16 | |
| 17 | void error(char *m) |
| 18 | { |
| 19 | warn(m); |
| 20 | error_putstr(" -- System halted" ); |
| 21 | |
| 22 | while (1) |
| 23 | asm("hlt" ); |
| 24 | } |
| 25 | |
| 26 | /* EFI libstub provides vsnprintf() */ |
| 27 | #ifdef CONFIG_EFI_STUB |
| 28 | void panic(const char *fmt, ...) |
| 29 | { |
| 30 | static char buf[1024]; |
| 31 | va_list args; |
| 32 | int len; |
| 33 | |
| 34 | va_start(args, fmt); |
| 35 | len = vsnprintf(buf, size: sizeof(buf), fmt, args); |
| 36 | va_end(args); |
| 37 | |
| 38 | if (len && buf[len - 1] == '\n') |
| 39 | buf[len - 1] = '\0'; |
| 40 | |
| 41 | error(m: buf); |
| 42 | } |
| 43 | #endif |
| 44 | |