mb/{asrock,intel,purism}: Copy channel arrays separately
[coreboot.git] / src / include / assert.h
blobe0db0bc05c82515836aaa059cf72ea02501eae43
1 /*
2 * This file is part of the coreboot project.
4 * Copyright (C) 2010 coresystems GmbH
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of the License.
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.
16 #ifndef __ASSERT_H__
17 #define __ASSERT_H__
19 #include <arch/hlt.h>
20 #include <console/console.h>
22 /* TODO: Fix vendorcode headers to not define macros coreboot uses or to be more
23 properly isolated. */
24 #ifdef ASSERT
25 #undef ASSERT
26 #endif
28 /* GCC and CAR versions */
29 #define ASSERT(x) { \
30 if (!(x)) { \
31 printk(BIOS_EMERG, "ASSERTION ERROR: file '%s'" \
32 ", line %d\n", __FILE__, __LINE__); \
33 if (CONFIG(FATAL_ASSERTS)) \
34 hlt(); \
35 } \
37 #define BUG() { \
38 printk(BIOS_EMERG, "ERROR: BUG ENCOUNTERED at file '%s'"\
39 ", line %d\n", __FILE__, __LINE__); \
40 if (CONFIG(FATAL_ASSERTS)) \
41 hlt(); \
44 #define assert(statement) ASSERT(statement)
47 * These macros can be used to assert that a certain branch of code is dead and
48 * will be compile-time eliminated. This differs from _Static_assert(), which
49 * will generate a compiler error even if the scope it was called from is dead
50 * code. This may be useful to double-check things like constants that are only
51 * valid if a certain Kconfig option is set.
53 * The error message when this hits will look like this:
55 * ramstage/lib/bootmode.o: In function `display_init_required':
56 * bootmode.c:42: undefined reference to `dead_code_assertion_failed_at_line_42'
58 #define __dead_code(line) do { \
59 extern void dead_code_assertion_failed_at_line_##line(void) \
60 __attribute__((noreturn)); \
61 dead_code_assertion_failed_at_line_##line(); \
62 } while (0)
63 #define _dead_code(line) __dead_code(line)
64 #define dead_code() _dead_code(__LINE__)
66 /* This can be used in the context of an expression of type 'type'. */
67 #define dead_code_t(type) ({ \
68 dead_code(); \
69 *(type *)(uintptr_t)0; \
72 #endif // __ASSERT_H__