Merge iceaxe.:/Volumes/work/research/m5/head
[gem5.git] / src / base / misc.hh
1 /*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Nathan Binkert
29 * Dave Greene
30 */
31
32 #ifndef __MISC_HH__
33 #define __MISC_HH__
34
35 #include <assert.h>
36 #include "base/cprintf.hh"
37
38 //
39 // This implements a cprintf based panic() function. panic() should
40 // be called when something happens that should never ever happen
41 // regardless of what the user does (i.e., an acutal m5 bug). panic()
42 // calls abort which can dump core or enter the debugger.
43 //
44 //
45 void __panic(const std::string&, cp::ArgList &, const char*, const char*, int)
46 __attribute__((noreturn));
47 #define __panic__(format, args...) \
48 __panic(format, (*(new cp::ArgList), args), \
49 __FUNCTION__, __FILE__, __LINE__)
50 #define panic(args...) \
51 __panic__(args, cp::ArgListNull())
52
53 //
54 // This implements a cprintf based fatal() function. fatal() should
55 // be called when the simulation cannot continue due to some condition
56 // that is the user's fault (bad configuration, invalid arguments,
57 // etc.) and not a simulator bug. fatal() calls exit(1), i.e., a
58 // "normal" exit with an error code, as opposed to abort() like
59 // panic() does.
60 //
61 void __fatal(const std::string&, cp::ArgList &, const char*, const char*, int)
62 __attribute__((noreturn));
63 #define __fatal__(format, args...) \
64 __fatal(format, (*(new cp::ArgList), args), \
65 __FUNCTION__, __FILE__, __LINE__)
66 #define fatal(args...) \
67 __fatal__(args, cp::ArgListNull())
68
69 //
70 // This implements a cprintf based warn
71 //
72 void __warn(const std::string&, cp::ArgList &, const char*, const char*, int);
73 #define __warn__(format, args...) \
74 __warn(format, (*(new cp::ArgList), args), \
75 __FUNCTION__, __FILE__, __LINE__)
76 #define warn(args...) \
77 __warn__(args, cp::ArgListNull())
78
79 //
80 // assert() that prints out the current cycle
81 //
82 #define m5_assert(TEST) \
83 if (!(TEST)) { \
84 std::cerr << "Assertion failure, curTick = " << curTick << std::endl; \
85 } \
86 assert(TEST);
87
88 #endif // __MISC_HH__