Stefan Reinauer | eca92fb | 2006-08-23 14:28:37 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Uwe Hermann | 2bb4acf | 2010-03-01 17:19:55 +0000 | [diff] [blame] | 3 | * |
Stefan Reinauer | 55259bd | 2010-02-28 18:13:09 +0000 | [diff] [blame] | 4 | * Copyright (C) 2010 coresystems GmbH |
Stefan Reinauer | eca92fb | 2006-08-23 14:28:37 +0000 | [diff] [blame] | 5 | * |
Stefan Reinauer | 55259bd | 2010-02-28 18:13:09 +0000 | [diff] [blame] | 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 |
Uwe Hermann | 2bb4acf | 2010-03-01 17:19:55 +0000 | [diff] [blame] | 8 | * published by the Free Software Foundation; version 2 of the License. |
Stefan Reinauer | eca92fb | 2006-08-23 14:28:37 +0000 | [diff] [blame] | 9 | * |
| 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 Reinauer | eca92fb | 2006-08-23 14:28:37 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
Stefan Reinauer | 55259bd | 2010-02-28 18:13:09 +0000 | [diff] [blame] | 16 | #ifndef __ASSERT_H__ |
| 17 | #define __ASSERT_H__ |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 18 | |
Julius Werner | d82e0cf | 2015-02-17 17:27:23 -0800 | [diff] [blame] | 19 | #include <arch/hlt.h> |
Hung-Te Lin | 34c5933 | 2014-02-21 16:22:52 +0800 | [diff] [blame] | 20 | #include <console/console.h> |
| 21 | |
Stefan Reinauer | 55259bd | 2010-02-28 18:13:09 +0000 | [diff] [blame] | 22 | /* GCC and CAR versions */ |
| 23 | #define ASSERT(x) { \ |
| 24 | if (!(x)) { \ |
Julius Werner | d82e0cf | 2015-02-17 17:27:23 -0800 | [diff] [blame] | 25 | printk(BIOS_EMERG, "ASSERTION ERROR: file '%s'" \ |
| 26 | ", line %d\n", __FILE__, __LINE__); \ |
Lee Leahy | e0f5dfc | 2017-03-07 11:44:05 -0800 | [diff] [blame] | 27 | if (IS_ENABLED(CONFIG_FATAL_ASSERTS)) \ |
| 28 | hlt(); \ |
Stefan Reinauer | 55259bd | 2010-02-28 18:13:09 +0000 | [diff] [blame] | 29 | } \ |
| 30 | } |
| 31 | #define BUG() { \ |
Julius Werner | d82e0cf | 2015-02-17 17:27:23 -0800 | [diff] [blame] | 32 | printk(BIOS_EMERG, "ERROR: BUG ENCOUNTERED at file '%s'"\ |
| 33 | ", line %d\n", __FILE__, __LINE__); \ |
Lee Leahy | e0f5dfc | 2017-03-07 11:44:05 -0800 | [diff] [blame] | 34 | if (IS_ENABLED(CONFIG_FATAL_ASSERTS)) \ |
| 35 | hlt(); \ |
Stefan Reinauer | 55259bd | 2010-02-28 18:13:09 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Hung-Te Lin | 34c5933 | 2014-02-21 16:22:52 +0800 | [diff] [blame] | 38 | #define assert(statement) ASSERT(statement) |
Uwe Hermann | 2bb4acf | 2010-03-01 17:19:55 +0000 | [diff] [blame] | 39 | |
Julius Werner | b8534f7 | 2017-07-14 14:14:11 -0700 | [diff] [blame] | 40 | /* |
| 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 Hermann | 2bb4acf | 2010-03-01 17:19:55 +0000 | [diff] [blame] | 61 | #endif // __ASSERT_H__ |