panic.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * linux/lib/vsprintf.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. /* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
  7. /*
  8. * Wirzenius wrote this portably, Torvalds fucked it up :-)
  9. */
  10. #include <common.h>
  11. #include <hang.h>
  12. #if !defined(CONFIG_PANIC_HANG)
  13. #include <command.h>
  14. #endif
  15. #include <linux/delay.h>
  16. static void panic_finish(void) __attribute__ ((noreturn));
  17. static void panic_finish(void)
  18. {
  19. putc('\n');
  20. #if defined(CONFIG_PANIC_HANG)
  21. hang();
  22. #else
  23. udelay(100000); /* allow messages to go out */
  24. do_reset(NULL, 0, 0, NULL);
  25. #endif
  26. while (1)
  27. ;
  28. }
  29. void panic_str(const char *str)
  30. {
  31. puts(str);
  32. panic_finish();
  33. }
  34. void panic(const char *fmt, ...)
  35. {
  36. #if CONFIG_IS_ENABLED(PRINTF)
  37. va_list args;
  38. va_start(args, fmt);
  39. vprintf(fmt, args);
  40. va_end(args);
  41. #endif
  42. panic_finish();
  43. }
  44. void __assert_fail(const char *assertion, const char *file, unsigned int line,
  45. const char *function)
  46. {
  47. /* This will not return */
  48. panic("%s:%u: %s: Assertion `%s' failed.", file, line, function,
  49. assertion);
  50. }