ARM: Implement WFE/WFI/SEV semantics.
[gem5.git] / src / sim / system.cc
index 9704c83f02acbed13903f2e4718f902f421394b9..bb8eccf148e908519d16d9a10c25c74661b0f28b 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2003-2006 The Regents of The University of Michigan
+ * Copyright (c) 2011 Regents of the University of California
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,6 +30,7 @@
  *          Lisa Hsu
  *          Nathan Binkert
  *          Ali Saidi
+ *          Rick Strong
  */
 
 #include "arch/isa_traits.hh"
 #include "base/loader/object_file.hh"
 #include "base/loader/symtab.hh"
 #include "base/trace.hh"
+#include "config/full_system.hh"
+#include "config/the_isa.hh"
 #include "cpu/thread_context.hh"
+#include "debug/Loader.hh"
 #include "mem/mem_object.hh"
 #include "mem/physical.hh"
 #include "sim/byteswap.hh"
-#include "sim/system.hh"
 #include "sim/debug.hh"
+#include "sim/system.hh"
+
 #if FULL_SYSTEM
 #include "arch/vtophys.hh"
 #include "kern/kernel_stats.hh"
+#include "mem/vport.hh"
 #else
 #include "params/System.hh"
 #endif
@@ -61,13 +68,17 @@ System::System(Params *p)
     : SimObject(p), physmem(p->physmem), _numContexts(0),
 #if FULL_SYSTEM
       init_param(p->init_param),
-      functionalPort(p->name + "-fport"),
-      virtPort(p->name + "-vport"),
+      loadAddrMask(p->load_addr_mask),
 #else
-      page_ptr(0),
-      next_PID(0),
+      pagePtr(0),
+      nextPID(0),
 #endif
-      memoryMode(p->mem_mode), _params(p)
+      memoryMode(p->mem_mode),
+      workItemsBegin(0),
+      workItemsEnd(0),
+      _params(p),
+      totalNumInsts(0), 
+      instEventQueue("system instruction-based event queue")
 {
     // add self to global system list
     systemList.push_back(this);
@@ -82,31 +93,33 @@ System::System(Params *p)
      * Get a functional port to memory
      */
     Port *mem_port;
+    functionalPort = new FunctionalPort(name() + "-fport");
     mem_port = physmem->getPort("functional");
-    functionalPort.setPeer(mem_port);
-    mem_port->setPeer(&functionalPort);
+    functionalPort->setPeer(mem_port);
+    mem_port->setPeer(functionalPort);
 
+    virtPort = new VirtualPort(name() + "-fport");
     mem_port = physmem->getPort("functional");
-    virtPort.setPeer(mem_port);
-    mem_port->setPeer(&virtPort);
+    virtPort->setPeer(mem_port);
+    mem_port->setPeer(virtPort);
 
 
     /**
      * Load the kernel code into memory
      */
     if (params()->kernel == "") {
-        warn("No kernel set for full system simulation. Assuming you know what"
+        inform("No kernel set for full system simulation. Assuming you know what"
                 " you're doing...\n");
     } else {
         // Load kernel code
         kernel = createObjectFile(params()->kernel);
-        warn("kernel located at: %s", params()->kernel);
+        inform("kernel located at: %s", params()->kernel);
 
         if (kernel == NULL)
             fatal("Could not load kernel file %s", params()->kernel);
 
         // Load program sections into memory
-        kernel->loadSections(&functionalPort, LoadAddrMask);
+        kernel->loadSections(functionalPort, loadAddrMask);
 
         // setup entry points
         kernelStart = kernel->textBase();
@@ -115,16 +128,16 @@ System::System(Params *p)
 
         // load symbols
         if (!kernel->loadGlobalSymbols(kernelSymtab))
-            panic("could not load kernel symbols\n");
+            fatal("could not load kernel symbols\n");
 
         if (!kernel->loadLocalSymbols(kernelSymtab))
-            panic("could not load kernel local symbols\n");
+            fatal("could not load kernel local symbols\n");
 
         if (!kernel->loadGlobalSymbols(debugSymbolTable))
-            panic("could not load kernel symbols\n");
+            fatal("could not load kernel symbols\n");
 
         if (!kernel->loadLocalSymbols(debugSymbolTable))
-            panic("could not load kernel local symbols\n");
+            fatal("could not load kernel local symbols\n");
 
         DPRINTF(Loader, "Kernel start = %#x\n", kernelStart);
         DPRINTF(Loader, "Kernel end   = %#x\n", kernelEnd);
@@ -135,6 +148,8 @@ System::System(Params *p)
 
     // increment the number of running systms
     numSystemsRunning++;
+
+    activeCpus.clear();
 }
 
 System::~System()
@@ -148,9 +163,6 @@ System::~System()
 #endif // FULL_SYSTEM}
 }
 
-int rgdb_wait = -1;
-int rgdb_enable = true;
-
 void
 System::setMemoryMode(Enums::MemoryMode mode)
 {
@@ -165,33 +177,43 @@ bool System::breakpoint()
     return false;
 }
 
+/**
+ * Setting rgdb_wait to a positive integer waits for a remote debugger to
+ * connect to that context ID before continuing.  This should really
+   be a parameter on the CPU object or something...
+ */
+int rgdb_wait = -1;
+
 int
-System::registerThreadContext(ThreadContext *tc)
+System::registerThreadContext(ThreadContext *tc, int assigned)
 {
     int id;
-    for (id = 0; id < threadContexts.size(); id++) {
-        if (!threadContexts[id])
-            break;
-    }
+    if (assigned == -1) {
+        for (id = 0; id < threadContexts.size(); id++) {
+            if (!threadContexts[id])
+                break;
+        }
 
-    if (threadContexts.size() <= id)
-        threadContexts.resize(id + 1);
+        if (threadContexts.size() <= id)
+            threadContexts.resize(id + 1);
+    } else {
+        if (threadContexts.size() <= assigned)
+            threadContexts.resize(assigned + 1);
+        id = assigned;
+    }
 
     if (threadContexts[id])
-        panic("Cannot have two CPUs with the same id (%d)\n", id);
+        fatal("Cannot have two CPUs with the same id (%d)\n", id);
 
     threadContexts[id] = tc;
     _numContexts++;
 
     int port = getRemoteGDBPort();
-    if (rgdb_enable && port) {
+    if (port) {
         RemoteGDB *rgdb = new RemoteGDB(this, tc);
         GDBListener *gdbl = new GDBListener(rgdb, port + id);
         gdbl->listen();
-        /**
-         * Uncommenting this line waits for a remote debugger to
-         * connect to the simulator before continuing.
-         */
+
         if (rgdb_wait != -1 && rgdb_wait == id)
             gdbl->accept();
 
@@ -202,11 +224,24 @@ System::registerThreadContext(ThreadContext *tc)
         remoteGDB[id] = rgdb;
     }
 
+    activeCpus.push_back(false);
+
     return id;
 }
 
+int
+System::numRunningContexts()
+{
+    int running = 0;
+    for (int i = 0; i < _numContexts; ++i) {
+        if (threadContexts[i]->status() != ThreadContext::Halted)
+            ++running;
+    }
+    return running;
+}
+
 void
-System::startup()
+System::initState()
 {
 #if FULL_SYSTEM
     int i;
@@ -232,21 +267,42 @@ System::replaceThreadContext(ThreadContext *tc, int context_id)
 Addr
 System::new_page()
 {
-    Addr return_addr = page_ptr << LogVMPageSize;
-    ++page_ptr;
+    Addr return_addr = pagePtr << LogVMPageSize;
+    ++pagePtr;
     if (return_addr >= physmem->size())
         fatal("Out of memory, please increase size of physical memory.");
     return return_addr;
 }
+
+Addr
+System::memSize()
+{
+    return physmem->size();
+}
+
+Addr
+System::freeMemSize()
+{
+   return physmem->size() - (pagePtr << LogVMPageSize);
+}
+
 #endif
 
+void
+System::resume()
+{
+    SimObject::resume();
+    totalNumInsts = 0;
+}
+
 void
 System::serialize(ostream &os)
 {
 #if FULL_SYSTEM
     kernelSymtab->serialize("kernel_symtab", os);
 #else // !FULL_SYSTEM
-    SERIALIZE_SCALAR(page_ptr);
+    SERIALIZE_SCALAR(pagePtr);
+    SERIALIZE_SCALAR(nextPID);
 #endif
 }
 
@@ -257,7 +313,8 @@ System::unserialize(Checkpoint *cp, const string &section)
 #if FULL_SYSTEM
     kernelSymtab->unserialize("kernel_symtab", cp, section);
 #else // !FULL_SYSTEM
-    UNSERIALIZE_SCALAR(page_ptr);
+    UNSERIALIZE_SCALAR(pagePtr);
+    UNSERIALIZE_SCALAR(nextPID);
 #endif
 }