Merge zizzer.eecs.umich.edu:/bk/newmem
[gem5.git] / src / base / misc.cc
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 */
30
31 #include <iostream>
32 #include <string>
33
34 #include "base/cprintf.hh"
35 #include "base/hostinfo.hh"
36 #include "base/misc.hh"
37 #include "base/output.hh"
38 #include "base/trace.hh"
39 #include "base/varargs.hh"
40 #include "sim/host.hh"
41 #include "sim/core.hh"
42
43 using namespace std;
44
45 void
46 __panic(const char *func, const char *file, int line, const char *fmt,
47 CPRINTF_DEFINITION)
48 {
49 string format = "panic: ";
50 format += fmt;
51 switch (format[format.size() - 1]) {
52 case '\n':
53 case '\r':
54 break;
55 default:
56 format += "\n";
57 }
58
59 format += " @ cycle %d\n[%s:%s, line %d]\n";
60
61 CPrintfArgsList args(VARARGS_ALLARGS);
62
63 args.push_back(curTick);
64 args.push_back(func);
65 args.push_back(file);
66 args.push_back(line);
67
68 ccprintf(cerr, format.c_str(), args);
69
70 abort();
71 }
72
73 void
74 __fatal(const char *func, const char *file, int line, const char *fmt,
75 CPRINTF_DEFINITION)
76 {
77 CPrintfArgsList args(VARARGS_ALLARGS);
78 string format = "fatal: ";
79 format += fmt;
80
81 switch (format[format.size() - 1]) {
82 case '\n':
83 case '\r':
84 break;
85 default:
86 format += "\n";
87 }
88
89 format += " @ cycle %d\n[%s:%s, line %d]\n";
90 format += "Memory Usage: %ld KBytes\n";
91
92 args.push_back(curTick);
93 args.push_back(func);
94 args.push_back(file);
95 args.push_back(line);
96 args.push_back(memUsage());
97
98 ccprintf(cerr, format.c_str(), args);
99
100 exit(1);
101 }
102
103 void
104 __warn(const char *func, const char *file, int line, const char *fmt,
105 CPRINTF_DEFINITION)
106 {
107 string format = "warn: ";
108 format += fmt;
109
110 switch (format[format.size() - 1]) {
111 case '\n':
112 case '\r':
113 break;
114 default:
115 format += "\n";
116 }
117
118 #ifdef VERBOSE_WARN
119 format += " @ cycle %d\n[%s:%s, line %d]\n";
120 #endif
121
122 CPrintfArgsList args(VARARGS_ALLARGS);
123
124 #ifdef VERBOSE_WARN
125 args.push_back(curTick);
126 args.push_back(func);
127 args.push_back(file);
128 args.push_back(line);
129 #endif
130
131 ccprintf(cerr, format.c_str(), args);
132 if (simout.isFile(*outputStream))
133 ccprintf(*outputStream, format.c_str(), args);
134 }