syscall emulation: fix fast build issue
[gem5.git] / src / sim / system.cc
index 20fcbd948734a6ca8d57939ab48f05876df44afd..88d2a1625b2db90354f925e8c14e1b09a1764dd8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2012 ARM Limited
+ * Copyright (c) 2011-2013 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -48,7 +48,6 @@
 #include "arch/isa_traits.hh"
 #include "arch/remote_gdb.hh"
 #include "arch/utility.hh"
-#include "arch/vtophys.hh"
 #include "base/loader/object_file.hh"
 #include "base/loader/symtab.hh"
 #include "base/str.hh"
@@ -58,6 +57,7 @@
 #include "debug/Loader.hh"
 #include "debug/WorkItems.hh"
 #include "kern/kernel_stats.hh"
+#include "mem/abstract_mem.hh"
 #include "mem/physical.hh"
 #include "params/System.hh"
 #include "sim/byteswap.hh"
@@ -77,12 +77,13 @@ System::System(Params *p)
       _numContexts(0),
       pagePtr(0),
       init_param(p->init_param),
-      physProxy(_systemPort),
-      virtProxy(_systemPort),
+      physProxy(_systemPort, p->cache_line_size),
       loadAddrMask(p->load_addr_mask),
+      loadAddrOffset(p->load_offset),
       nextPID(0),
-      physmem(p->memories),
+      physmem(name() + ".physmem", p->memories),
       memoryMode(p->mem_mode),
+      _cacheLineSize(p->cache_line_size),
       workItemsBegin(0),
       workItemsEnd(0),
       numWorkIds(p->num_work_ids),
@@ -99,6 +100,11 @@ System::System(Params *p)
             debugSymbolTable = new SymbolTable;
     }
 
+    // check if the cache line size is a value known to work
+    if (!(_cacheLineSize == 16 || _cacheLineSize == 32 ||
+          _cacheLineSize == 64 || _cacheLineSize == 128))
+        warn_once("Cache line size is neither 16, 32, 64 nor 128 bytes.\n");
+
     // Get the generic system master IDs
     MasterID tmp_id M5_VAR_USED;
     tmp_id = getMasterId("writebacks");
@@ -111,7 +117,9 @@ System::System(Params *p)
     if (FullSystem) {
         if (params()->kernel == "") {
             inform("No kernel set for full system simulation. "
-                    "Assuming you know what you're doing if not SPARC ISA\n");
+                   "Assuming you know what you're doing\n");
+
+            kernel = NULL;
         } else {
             // Get the kernel code
             kernel = createObjectFile(params()->kernel);
@@ -168,8 +176,8 @@ System::init()
         panic("System port on %s is not connected.\n", name());
 }
 
-MasterPort&
-System::getMasterPort(const std::string &if_name, int idx)
+BaseMasterPort&
+System::getMasterPort(const std::string &if_name, PortID idx)
 {
     // no need to distinguish at the moment (besides checking)
     return _systemPort;
@@ -178,7 +186,7 @@ System::getMasterPort(const std::string &if_name, int idx)
 void
 System::setMemoryMode(Enums::MemoryMode mode)
 {
-    assert(getState() == Drained);
+    assert(getDrainState() == Drainable::Drained);
     memoryMode = mode;
 }
 
@@ -220,6 +228,7 @@ System::registerThreadContext(ThreadContext *tc, int assigned)
     threadContexts[id] = tc;
     _numContexts++;
 
+#if THE_ISA != NULL_ISA
     int port = getRemoteGDBPort();
     if (port) {
         RemoteGDB *rgdb = new RemoteGDB(this, tc);
@@ -235,6 +244,7 @@ System::registerThreadContext(ThreadContext *tc, int assigned)
 
         remoteGDB[id] = rgdb;
     }
+#endif
 
     activeCpus.push_back(false);
 
@@ -255,9 +265,8 @@ System::numRunningContexts()
 void
 System::initState()
 {
-    int i;
     if (FullSystem) {
-        for (i = 0; i < threadContexts.size(); i++)
+        for (int i = 0; i < threadContexts.size(); i++)
             TheISA::startupCPU(threadContexts[i], i);
         // Moved from the constructor to here since it relies on the
         // address map being resolved in the interconnect
@@ -265,8 +274,16 @@ System::initState()
          * Load the kernel code into memory
          */
         if (params()->kernel != "")  {
+            // Validate kernel mapping before loading binary
+            if (!(isMemAddr((kernelStart & loadAddrMask) + loadAddrOffset) &&
+                     isMemAddr((kernelEnd & loadAddrMask) + loadAddrOffset))) {
+                fatal("Kernel is mapped to invalid location (not memory). "
+                      "kernelStart 0x(%x) - kernelEnd 0x(%x) %#x:%#x\n", kernelStart,
+                      kernelEnd, (kernelStart & loadAddrMask) + loadAddrOffset,
+                      (kernelEnd & loadAddrMask) + loadAddrOffset);
+            }
             // Load program sections into memory
-            kernel->loadSections(physProxy, loadAddrMask);
+            kernel->loadSections(physProxy, loadAddrMask, loadAddrOffset);
 
             DPRINTF(Loader, "Kernel start = %#x\n", kernelStart);
             DPRINTF(Loader, "Kernel end   = %#x\n", kernelEnd);
@@ -276,12 +293,6 @@ System::initState()
     }
 
     activeCpus.clear();
-
-    if (!FullSystem)
-        return;
-
-    for (i = 0; i < threadContexts.size(); i++)
-        TheISA::startupCPU(threadContexts[i], i);
 }
 
 void
@@ -325,10 +336,17 @@ System::isMemAddr(Addr addr) const
     return physmem.isMemAddr(addr);
 }
 
+unsigned int
+System::drain(DrainManager *dm)
+{
+    setDrainState(Drainable::Drained);
+    return 0;
+}
+
 void
-System::resume()
+System::drainResume()
 {
-    SimObject::resume();
+    Drainable::drainResume();
     totalNumInsts = 0;
 }
 
@@ -339,6 +357,11 @@ System::serialize(ostream &os)
         kernelSymtab->serialize("kernel_symtab", os);
     SERIALIZE_SCALAR(pagePtr);
     SERIALIZE_SCALAR(nextPID);
+    serializeSymtab(os);
+
+    // also serialize the memories in the system
+    nameOut(os, csprintf("%s.physmem", name()));
+    physmem.serialize(os);
 }
 
 
@@ -349,6 +372,10 @@ System::unserialize(Checkpoint *cp, const string &section)
         kernelSymtab->unserialize("kernel_symtab", cp, section);
     UNSERIALIZE_SCALAR(pagePtr);
     UNSERIALIZE_SCALAR(nextPID);
+    unserializeSymtab(cp, section);
+
+    // also unserialize the memories in the system
+    physmem.unserialize(cp, csprintf("%s.physmem", name()));
 }
 
 void
@@ -435,9 +462,6 @@ System::getMasterName(MasterID master_id)
     return masterIds[master_id];
 }
 
-const char *System::MemoryModeStrings[3] = {"invalid", "atomic",
-    "timing"};
-
 System *
 SystemParams::create()
 {