2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Nathan Binkert
32 #ifndef __BASE_MISC_HH__
33 #define __BASE_MISC_HH__
35 #include "base/compiler.hh"
36 #include "base/cprintf.hh"
37 #include "base/varargs.hh"
39 #if defined(__SUNPRO_CC)
40 #define __FUNCTION__ "how to fix me?"
44 // This implements a cprintf based panic() function. panic() should
45 // be called when something happens that should never ever happen
46 // regardless of what the user does (i.e., an acutal m5 bug). panic()
47 // calls abort which can dump core or enter the debugger.
50 void __panic(const char *func, const char *file, int line, const char *format,
51 CPRINTF_DECLARATION) M5_ATTR_NORETURN;
52 void __panic(const char *func, const char *file, int line,
53 const std::string &format, CPRINTF_DECLARATION)
57 __panic(const char *func, const char *file, int line,
58 const std::string &format, CPRINTF_DEFINITION)
60 __panic(func, file, line, format.c_str(), VARARGS_ALLARGS);
62 M5_PRAGMA_NORETURN(__panic)
63 #define panic(...) __panic(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
66 // This implements a cprintf based fatal() function. fatal() should
67 // be called when the simulation cannot continue due to some condition
68 // that is the user's fault (bad configuration, invalid arguments,
69 // etc.) and not a simulator bug. fatal() calls exit(1), i.e., a
70 // "normal" exit with an error code, as opposed to abort() like
73 void __fatal(const char *func, const char *file, int line, const char *format,
74 CPRINTF_DECLARATION) M5_ATTR_NORETURN;
75 void __fatal(const char *func, const char *file, int line,
76 const std::string &format, CPRINTF_DECLARATION)
80 __fatal(const char *func, const char *file, int line,
81 const std::string &format, CPRINTF_DEFINITION)
83 __fatal(func, file, line, format.c_str(), VARARGS_ALLARGS);
85 M5_PRAGMA_NORETURN(__fatal)
86 #define fatal(...) __fatal(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
89 // This implements a cprintf based warn
91 void __warn(const char *func, const char *file, int line, const char *format,
94 __warn(const char *func, const char *file, int line, const std::string &format,
97 __warn(func, file, line, format, VARARGS_ALLARGS);
99 #define warn(...) __warn(__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
101 // Only print the warning message the first time it is seen. This
102 // doesn't check the warning string itself, it just only lets one
103 // warning come from the statement. So, even if the arguments change
104 // and that would have resulted in a different warning message,
105 // subsequent messages would still be supressed.
106 #define warn_once(...) do { \
107 static bool once = false; \
114 #endif // __BASE_MISC_HH__