error.c 804 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. void warn(const char *m)
  10. {
  11. error_putstr("\n\n");
  12. error_putstr(m);
  13. error_putstr("\n\n");
  14. }
  15. void error(char *m)
  16. {
  17. warn(m);
  18. error_putstr(" -- System halted");
  19. while (1)
  20. asm("hlt");
  21. }
  22. /* EFI libstub provides vsnprintf() */
  23. #ifdef CONFIG_EFI_STUB
  24. void panic(const char *fmt, ...)
  25. {
  26. static char buf[1024];
  27. va_list args;
  28. int len;
  29. va_start(args, fmt);
  30. len = vsnprintf(buf, sizeof(buf), fmt, args);
  31. va_end(args);
  32. if (len && buf[len - 1] == '\n')
  33. buf[len - 1] = '\0';
  34. error(buf);
  35. }
  36. #endif