xref: /openbmc/linux/arch/x86/boot/compressed/error.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2dc425a6eSKees Cook /*
3dc425a6eSKees Cook  * Callers outside of misc.c need access to the error reporting routines,
4dc425a6eSKees Cook  * but the *_putstr() functions need to stay in misc.c because of how
5dc425a6eSKees Cook  * memcpy() and memmove() are defined for the compressed boot environment.
6dc425a6eSKees Cook  */
7dc425a6eSKees Cook #include "misc.h"
86b1cc946SZhengyi Shen #include "error.h"
9dc425a6eSKees Cook 
warn(const char * m)10*6d33531bSArnd Bergmann void warn(const char *m)
11dc425a6eSKees Cook {
12dc425a6eSKees Cook 	error_putstr("\n\n");
13dc425a6eSKees Cook 	error_putstr(m);
14dc425a6eSKees Cook 	error_putstr("\n\n");
15dc425a6eSKees Cook }
16dc425a6eSKees Cook 
error(char * m)17dc425a6eSKees Cook void error(char *m)
18dc425a6eSKees Cook {
19dc425a6eSKees Cook 	warn(m);
20dc425a6eSKees Cook 	error_putstr(" -- System halted");
21dc425a6eSKees Cook 
22dc425a6eSKees Cook 	while (1)
23dc425a6eSKees Cook 		asm("hlt");
24dc425a6eSKees Cook }
2575d090fdSKirill A. Shutemov 
2675d090fdSKirill A. Shutemov /* EFI libstub  provides vsnprintf() */
2775d090fdSKirill A. Shutemov #ifdef CONFIG_EFI_STUB
panic(const char * fmt,...)2875d090fdSKirill A. Shutemov void panic(const char *fmt, ...)
2975d090fdSKirill A. Shutemov {
3075d090fdSKirill A. Shutemov 	static char buf[1024];
3175d090fdSKirill A. Shutemov 	va_list args;
3275d090fdSKirill A. Shutemov 	int len;
3375d090fdSKirill A. Shutemov 
3475d090fdSKirill A. Shutemov 	va_start(args, fmt);
3575d090fdSKirill A. Shutemov 	len = vsnprintf(buf, sizeof(buf), fmt, args);
3675d090fdSKirill A. Shutemov 	va_end(args);
3775d090fdSKirill A. Shutemov 
3875d090fdSKirill A. Shutemov 	if (len && buf[len - 1] == '\n')
3975d090fdSKirill A. Shutemov 		buf[len - 1] = '\0';
4075d090fdSKirill A. Shutemov 
4175d090fdSKirill A. Shutemov 	error(buf);
4275d090fdSKirill A. Shutemov }
4375d090fdSKirill A. Shutemov #endif
44