xref: /rk3399_ARM-atf/include/common/debug.h (revision 4ecca33988b90de43ec4f4a929094a38a23fda31)
1*4ecca339SDan Handley /*
2*4ecca339SDan Handley  * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
3*4ecca339SDan Handley  *
4*4ecca339SDan Handley  * Redistribution and use in source and binary forms, with or without
5*4ecca339SDan Handley  * modification, are permitted provided that the following conditions are met:
6*4ecca339SDan Handley  *
7*4ecca339SDan Handley  * Redistributions of source code must retain the above copyright notice, this
8*4ecca339SDan Handley  * list of conditions and the following disclaimer.
9*4ecca339SDan Handley  *
10*4ecca339SDan Handley  * Redistributions in binary form must reproduce the above copyright notice,
11*4ecca339SDan Handley  * this list of conditions and the following disclaimer in the documentation
12*4ecca339SDan Handley  * and/or other materials provided with the distribution.
13*4ecca339SDan Handley  *
14*4ecca339SDan Handley  * Neither the name of ARM nor the names of its contributors may be used
15*4ecca339SDan Handley  * to endorse or promote products derived from this software without specific
16*4ecca339SDan Handley  * prior written permission.
17*4ecca339SDan Handley  *
18*4ecca339SDan Handley  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*4ecca339SDan Handley  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*4ecca339SDan Handley  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*4ecca339SDan Handley  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22*4ecca339SDan Handley  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*4ecca339SDan Handley  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*4ecca339SDan Handley  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*4ecca339SDan Handley  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*4ecca339SDan Handley  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*4ecca339SDan Handley  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*4ecca339SDan Handley  * POSSIBILITY OF SUCH DAMAGE.
29*4ecca339SDan Handley  */
30*4ecca339SDan Handley 
31*4ecca339SDan Handley #ifndef __DEBUG_H__
32*4ecca339SDan Handley #define __DEBUG_H__
33*4ecca339SDan Handley 
34*4ecca339SDan Handley /* Do not try to call this from ASM code. */
35*4ecca339SDan Handley #ifndef __ASSEMBLY__
36*4ecca339SDan Handley 
37*4ecca339SDan Handley #include <stdio.h>
38*4ecca339SDan Handley 
39*4ecca339SDan Handley /* If building the project with DEBUG disabled the INFO and WARN macros
40*4ecca339SDan Handley  * won't produce any output. The ERROR macro is always enabled.
41*4ecca339SDan Handley  * The format expected is the same as for printf().
42*4ecca339SDan Handley  * INFO("Info %s.\n", "message")    -> INFO: Info message.
43*4ecca339SDan Handley  * WARN("Warning %s.\n", "message") -> WARN: Warning message.
44*4ecca339SDan Handley  * ERROR("Error %s.\n", "message")  -> ERROR: Error message.
45*4ecca339SDan Handley  *
46*4ecca339SDan Handley  * TODO : add debug levels.
47*4ecca339SDan Handley  */
48*4ecca339SDan Handley #if DEBUG
49*4ecca339SDan Handley  #define INFO(...)	printf("INFO: " __VA_ARGS__)
50*4ecca339SDan Handley  #define WARN(...)	printf("WARN: " __VA_ARGS__)
51*4ecca339SDan Handley #else
52*4ecca339SDan Handley  #define INFO(...)
53*4ecca339SDan Handley  #define WARN(...)
54*4ecca339SDan Handley #endif
55*4ecca339SDan Handley 
56*4ecca339SDan Handley #define ERROR(...)	printf("ERROR: " __VA_ARGS__)
57*4ecca339SDan Handley 
58*4ecca339SDan Handley 
59*4ecca339SDan Handley /* For the moment this Panic function is very basic, Report an error and
60*4ecca339SDan Handley  * spin. This can be expanded in the future to provide more information.
61*4ecca339SDan Handley  */
62*4ecca339SDan Handley static inline void __attribute__((noreturn)) panic(void)
63*4ecca339SDan Handley {
64*4ecca339SDan Handley 	ERROR("PANIC\n");
65*4ecca339SDan Handley 	while (1)
66*4ecca339SDan Handley 		;
67*4ecca339SDan Handley }
68*4ecca339SDan Handley 
69*4ecca339SDan Handley #endif /* __ASSEMBLY__ */
70*4ecca339SDan Handley #endif /* __DEBUG_H__ */
71