2006-08-23 16:28:37 +02:00
|
|
|
/*
|
2010-02-16 00:10:19 +01:00
|
|
|
* This file is part of the coreboot project.
|
2010-03-01 18:19:55 +01:00
|
|
|
*
|
2010-02-28 19:13:09 +01:00
|
|
|
* Copyright (C) 2010 coresystems GmbH
|
2006-08-23 16:28:37 +02:00
|
|
|
*
|
2010-02-28 19:13:09 +01:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
2010-03-01 18:19:55 +01:00
|
|
|
* published by the Free Software Foundation; version 2 of the License.
|
2006-08-23 16:28:37 +02:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2010-02-28 19:13:09 +01:00
|
|
|
#ifndef __ASSERT_H__
|
|
|
|
#define __ASSERT_H__
|
2010-02-16 00:10:19 +01:00
|
|
|
|
2015-02-18 02:27:23 +01:00
|
|
|
#include <arch/hlt.h>
|
2014-02-21 09:22:52 +01:00
|
|
|
#include <console/console.h>
|
|
|
|
|
2019-05-09 23:12:17 +02:00
|
|
|
/* TODO: Fix vendorcode headers to not define macros coreboot uses or to be more
|
|
|
|
properly isolated. */
|
|
|
|
#ifdef ASSERT
|
|
|
|
#undef ASSERT
|
|
|
|
#endif
|
|
|
|
|
2010-02-28 19:13:09 +01:00
|
|
|
/* GCC and CAR versions */
|
|
|
|
#define ASSERT(x) { \
|
|
|
|
if (!(x)) { \
|
2015-02-18 02:27:23 +01:00
|
|
|
printk(BIOS_EMERG, "ASSERTION ERROR: file '%s'" \
|
|
|
|
", line %d\n", __FILE__, __LINE__); \
|
2019-03-06 01:53:33 +01:00
|
|
|
if (CONFIG(FATAL_ASSERTS)) \
|
2017-03-07 20:44:05 +01:00
|
|
|
hlt(); \
|
2010-02-28 19:13:09 +01:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
#define BUG() { \
|
2015-02-18 02:27:23 +01:00
|
|
|
printk(BIOS_EMERG, "ERROR: BUG ENCOUNTERED at file '%s'"\
|
|
|
|
", line %d\n", __FILE__, __LINE__); \
|
2019-03-06 01:53:33 +01:00
|
|
|
if (CONFIG(FATAL_ASSERTS)) \
|
2017-03-07 20:44:05 +01:00
|
|
|
hlt(); \
|
2010-02-28 19:13:09 +01:00
|
|
|
}
|
|
|
|
|
2014-02-21 09:22:52 +01:00
|
|
|
#define assert(statement) ASSERT(statement)
|
2010-03-01 18:19:55 +01:00
|
|
|
|
2017-07-14 23:14:11 +02:00
|
|
|
/*
|
|
|
|
* These macros can be used to assert that a certain branch of code is dead and
|
|
|
|
* will be compile-time eliminated. This differs from _Static_assert(), which
|
|
|
|
* will generate a compiler error even if the scope it was called from is dead
|
|
|
|
* code. This may be useful to double-check things like constants that are only
|
|
|
|
* valid if a certain Kconfig option is set.
|
2019-03-28 21:39:06 +01:00
|
|
|
*
|
|
|
|
* The error message when this hits will look like this:
|
|
|
|
*
|
|
|
|
* ramstage/lib/bootmode.o: In function `display_init_required':
|
|
|
|
* bootmode.c:42: undefined reference to `dead_code_assertion_failed_at_line_42'
|
2017-07-14 23:14:11 +02:00
|
|
|
*/
|
2019-03-28 21:39:06 +01:00
|
|
|
#define __dead_code(line) do { \
|
2019-05-16 00:52:12 +02:00
|
|
|
extern void dead_code_assertion_failed_at_line_##line(void) \
|
|
|
|
__attribute__((noreturn)); \
|
2019-03-28 21:39:06 +01:00
|
|
|
dead_code_assertion_failed_at_line_##line(); \
|
2017-07-14 23:14:11 +02:00
|
|
|
} while (0)
|
2019-03-28 21:39:06 +01:00
|
|
|
#define _dead_code(line) __dead_code(line)
|
|
|
|
#define dead_code() _dead_code(__LINE__)
|
2017-07-14 23:14:11 +02:00
|
|
|
|
|
|
|
/* This can be used in the context of an expression of type 'type'. */
|
2019-03-28 21:39:06 +01:00
|
|
|
#define dead_code_t(type) ({ \
|
|
|
|
dead_code(); \
|
2017-07-14 23:14:11 +02:00
|
|
|
*(type *)(uintptr_t)0; \
|
|
|
|
})
|
|
|
|
|
2010-03-01 18:19:55 +01:00
|
|
|
#endif // __ASSERT_H__
|