Loader: Use address mask provided to load*Symbols when loading the symbols from the...
[gem5.git] / src / base / misc.cc
index 0ab1d6041f1594bce0e98e296260ef0abac2ff8e..65cb133568b521ceedd80c50869f5297d1790ae0 100644 (file)
  * Authors: Nathan Binkert
  */
 
+#include <cstdlib>
 #include <iostream>
 #include <string>
+#include <zlib.h>
 
 #include "base/cprintf.hh"
 #include "base/hostinfo.hh"
 #include "base/misc.hh"
 #include "base/output.hh"
 #include "base/trace.hh"
+#include "base/types.hh"
 #include "base/varargs.hh"
-#include "sim/host.hh"
 #include "sim/core.hh"
 
 using namespace std;
 
-void
-__panic(const char *func, const char *file, int line, const char *fmt,
-    CPRINTF_DEFINITION)
-{
-    string format = "panic: ";
-    format += fmt;
-    switch (format[format.size() - 1]) {
-      case '\n':
-      case '\r':
-        break;
-      default:
-        format += "\n";
-    }
-
-    format += " @ cycle %d\n[%s:%s, line %d]\n";
-
-    CPrintfArgsList args(VARARGS_ALLARGS);
-
-    args.push_back(curTick);
-    args.push_back(func);
-    args.push_back(file);
-    args.push_back(line);
+bool want_warn = true;
+bool want_info = true;
+bool want_hack = true;
 
-    ccprintf(cerr, format.c_str(), args);
-
-    abort();
-}
+bool warn_verbose = false;
+bool info_verbose = false;
+bool hack_verbose = false;
 
 void
-__fatal(const char *func, const char *file, int line, const char *fmt,
-    CPRINTF_DEFINITION)
+__exit_message(const char *prefix, int code,
+    const char *func, const char *file, int line,
+    const char *fmt, CPRINTF_DEFINITION)
 {
     CPrintfArgsList args(VARARGS_ALLARGS);
-    string format = "fatal: ";
-    format += fmt;
 
+    string format = prefix;
+    format += ": ";
+    format += fmt;
     switch (format[format.size() - 1]) {
       case '\n':
       case '\r':
@@ -85,28 +69,39 @@ __fatal(const char *func, const char *file, int line, const char *fmt,
       default:
         format += "\n";
     }
+    
+    uint32_t crc = crc32(0, (const Bytef*)fmt, strlen(fmt));
 
     format += " @ cycle %d\n[%s:%s, line %d]\n";
     format += "Memory Usage: %ld KBytes\n";
+    format += "For more information see: http://www.m5sim.org/%s/%x\n";
 
     args.push_back(curTick);
     args.push_back(func);
     args.push_back(file);
     args.push_back(line);
     args.push_back(memUsage());
+    args.push_back(prefix);
+    args.push_back(crc);
 
     ccprintf(cerr, format.c_str(), args);
 
-    exit(1);
+    if (code < 0)
+        abort();
+    else
+        exit(code);
 }
 
 void
-__warn(const char *func, const char *file, int line, const char *fmt,
-    CPRINTF_DEFINITION)
+__base_message(std::ostream &stream, const char *prefix, bool verbose,
+    const char *func, const char *file, int line,
+    const char *fmt, CPRINTF_DEFINITION)
 {
-    string format = "warn: ";
-    format += fmt;
+    CPrintfArgsList args(VARARGS_ALLARGS);
 
+    string format = prefix;
+    format += ": ";
+    format += fmt;
     switch (format[format.size() - 1]) {
       case '\n':
       case '\r':
@@ -114,19 +109,22 @@ __warn(const char *func, const char *file, int line, const char *fmt,
       default:
         format += "\n";
     }
+    
+    uint32_t crc = crc32(0, (const Bytef*)fmt, strlen(fmt));
+
+    if (verbose) {
+        format += " @ cycle %d\n[%s:%s, line %d]\n";
+        args.push_back(curTick);
+        args.push_back(func);
+        args.push_back(file);
+        args.push_back(line);
+    }
 
-#ifdef VERBOSE_WARN
-    format += " @ cycle %d\n[%s:%s, line %d]\n";
-#endif
-
-    CPrintfArgsList args(VARARGS_ALLARGS);
-
-#ifdef VERBOSE_WARN
-    args.push_back(curTick);
-    args.push_back(func);
-    args.push_back(file);
-    args.push_back(line);
-#endif
+    if (strcmp(prefix, "warn") == 0) {
+        format += "For more information see: http://www.m5sim.org/%s/%x\n";
+        args.push_back(prefix);
+        args.push_back(crc);
+    }
 
-    ccprintf(cerr, format.c_str(), args);
+    ccprintf(stream, format.c_str(), args);
 }