blob: a4ae39f6065ce07dc7bd2eca1f51b07a15081f64 [file] [log] [blame]
Stefan Reinauereca92fb2006-08-23 14:28:37 +00001/*
Uwe Hermannc70e9fc2010-02-15 23:10:19 +00002 * This file is part of the coreboot project.
Uwe Hermann2bb4acf2010-03-01 17:19:55 +00003 *
Stefan Reinauer55259bd2010-02-28 18:13:09 +00004 * Copyright (C) 2010 coresystems GmbH
Stefan Reinauereca92fb2006-08-23 14:28:37 +00005 *
Stefan Reinauer55259bd2010-02-28 18:13:09 +00006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
Uwe Hermann2bb4acf2010-03-01 17:19:55 +00008 * published by the Free Software Foundation; version 2 of the License.
Stefan Reinauereca92fb2006-08-23 14:28:37 +00009 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Stefan Reinauereca92fb2006-08-23 14:28:37 +000014 */
15
Stefan Reinauer55259bd2010-02-28 18:13:09 +000016#ifndef __ASSERT_H__
17#define __ASSERT_H__
Uwe Hermannc70e9fc2010-02-15 23:10:19 +000018
Julius Wernerd82e0cf2015-02-17 17:27:23 -080019#include <arch/hlt.h>
Hung-Te Lin34c59332014-02-21 16:22:52 +080020#include <console/console.h>
21
Stefan Reinauer55259bd2010-02-28 18:13:09 +000022/* GCC and CAR versions */
23#define ASSERT(x) { \
24 if (!(x)) { \
Julius Wernerd82e0cf2015-02-17 17:27:23 -080025 printk(BIOS_EMERG, "ASSERTION ERROR: file '%s'" \
26 ", line %d\n", __FILE__, __LINE__); \
Lee Leahye0f5dfc2017-03-07 11:44:05 -080027 if (IS_ENABLED(CONFIG_FATAL_ASSERTS)) \
28 hlt(); \
Stefan Reinauer55259bd2010-02-28 18:13:09 +000029 } \
30}
31#define BUG() { \
Julius Wernerd82e0cf2015-02-17 17:27:23 -080032 printk(BIOS_EMERG, "ERROR: BUG ENCOUNTERED at file '%s'"\
33 ", line %d\n", __FILE__, __LINE__); \
Lee Leahye0f5dfc2017-03-07 11:44:05 -080034 if (IS_ENABLED(CONFIG_FATAL_ASSERTS)) \
35 hlt(); \
Stefan Reinauer55259bd2010-02-28 18:13:09 +000036}
37
Hung-Te Lin34c59332014-02-21 16:22:52 +080038#define assert(statement) ASSERT(statement)
Uwe Hermann2bb4acf2010-03-01 17:19:55 +000039
Julius Wernerb8534f72017-07-14 14:14:11 -070040/*
41 * These macros can be used to assert that a certain branch of code is dead and
42 * will be compile-time eliminated. This differs from _Static_assert(), which
43 * will generate a compiler error even if the scope it was called from is dead
44 * code. This may be useful to double-check things like constants that are only
45 * valid if a certain Kconfig option is set.
46 */
47#define __dead_code(message, line) do { \
48 __attribute__((error(#message " in " __FILE__ ":" #line))) \
49 extern void dead_code_assertion_failed_##line(void); \
50 dead_code_assertion_failed_##line(); \
51} while (0)
52#define _dead_code(message, line) __dead_code(message, line)
53#define dead_code(message) _dead_code(message, __LINE__)
54
55/* This can be used in the context of an expression of type 'type'. */
56#define dead_code_t(type, message) ({ \
57 dead_code(message); \
58 *(type *)(uintptr_t)0; \
59})
60
Uwe Hermann2bb4acf2010-03-01 17:19:55 +000061#endif // __ASSERT_H__