blob: 0f578b5b5131589d215f5f4b16b95d9c9f3e8ce3 [file] [log] [blame]
Sjoerd Simons2b22a992015-12-04 23:27:38 +01001/*
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
Simon Glassdb41d652019-12-28 10:45:07 -070012#include <hang.h>
Sjoerd Simons2b22a992015-12-04 23:27:38 +010013#if !defined(CONFIG_PANIC_HANG)
14#include <command.h>
15#endif
Simon Glassc05ed002020-05-10 11:40:11 -060016#include <linux/delay.h>
Tony Dinhc5f4cdb2023-03-14 17:24:26 -070017#include <stdio.h>
Sjoerd Simons2b22a992015-12-04 23:27:38 +010018
19static void panic_finish(void) __attribute__ ((noreturn));
20
21static void panic_finish(void)
22{
23 putc('\n');
24#if defined(CONFIG_PANIC_HANG)
25 hang();
26#else
Tony Dinhc5f4cdb2023-03-14 17:24:26 -070027 flush(); /* flush the panic message before reset */
28
Sjoerd Simons2b22a992015-12-04 23:27:38 +010029 do_reset(NULL, 0, 0, NULL);
30#endif
31 while (1)
32 ;
33}
34
35void panic_str(const char *str)
36{
37 puts(str);
38 panic_finish();
39}
40
41void panic(const char *fmt, ...)
42{
Alex Kiernan4f1eed72018-04-19 04:32:55 +000043#if CONFIG_IS_ENABLED(PRINTF)
Sjoerd Simons2b22a992015-12-04 23:27:38 +010044 va_list args;
45 va_start(args, fmt);
46 vprintf(fmt, args);
47 va_end(args);
Alex Kiernan4f1eed72018-04-19 04:32:55 +000048#endif
Sjoerd Simons2b22a992015-12-04 23:27:38 +010049 panic_finish();
50}
Alex Kiernane21c03b2018-04-19 04:32:56 +000051
52void __assert_fail(const char *assertion, const char *file, unsigned int line,
53 const char *function)
54{
55 /* This will not return */
56 panic("%s:%u: %s: Assertion `%s' failed.", file, line, function,
57 assertion);
58}