blob: 8e05659c53a6cca509218a2cb293b5938d564962 [file] [log] [blame]
Daniel Boulby6530adf2021-11-26 09:54:01 +00001/*
2 * Copyright 2021 The Hafnium Authors.
3 *
4 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://opensource.org/licenses/BSD-3-Clause.
7 */
8
9#pragma once
10
11#if !defined(__cplusplus)
12
Karl Meakin902af082024-11-28 14:58:38 +000013#include <stdbool.h>
Karl Meakin871b41e2024-06-03 13:45:24 +010014#include <stdint.h>
15
16#include "hf/dlog.h"
Daniel Boulby6530adf2021-11-26 09:54:01 +000017#include "hf/panic.h"
18
19#ifndef PLAT_LOG_LEVEL_ASSERT
20#define PLAT_LOG_LEVEL_ASSERT LOG_LEVEL
21#endif
22
Karl Meakin871b41e2024-06-03 13:45:24 +010023#define assert(e) assert_impl(e, __FILE__, __LINE__, #e)
24
25static inline void assert_impl(bool cond, const char *file, uint32_t line,
26 const char *expr)
27{
28 if (!ENABLE_ASSERTIONS) {
29 return;
30 }
31
32 if (cond) {
33 return;
34 }
35
36 if (PLAT_LOG_LEVEL_ASSERT >= LOG_LEVEL_VERBOSE) {
37 panic("ASSERT: %s:%d:%s\n", file, line, expr);
38 } else if (PLAT_LOG_LEVEL_ASSERT >= LOG_LEVEL_INFO) {
39 panic("ASSERT: %s:%d\n", file, line);
40 } else {
41 panic("ASSERT\n");
42 }
43}
Daniel Boulby6530adf2021-11-26 09:54:01 +000044
Kathleen Capella4df55202022-12-01 15:39:26 -050045#else
46#include <assert.h>
Daniel Boulby6530adf2021-11-26 09:54:01 +000047#endif /* !defined(__cplusplus) */