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