ARM: Add minimal ARM_SE support for m5threads.
[gem5.git] / src / sim / system.hh
index e993a7a503baf6046dc5fc5a8c4ea7d50b1fee5d..0be16247fd8a911291b060af5f51cd0fbec108bd 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2002-2005 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
@@ -28,6 +29,7 @@
  * Authors: Steve Reinhardt
  *          Lisa Hsu
  *          Nathan Binkert
+ *          Rick Strong
  */
 
 #ifndef __SYSTEM_HH__
@@ -45,9 +47,9 @@
 #include "mem/port.hh"
 #include "params/System.hh"
 #include "sim/sim_object.hh"
+
 #if FULL_SYSTEM
 #include "kern/system_events.hh"
-#include "mem/vport.hh"
 #endif
 
 class BaseCPU;
@@ -57,12 +59,11 @@ class PhysicalMemory;
 
 #if FULL_SYSTEM
 class Platform;
+class FunctionalPort;
+class VirtualPort;
 #endif
 class GDBListener;
-namespace TheISA
-{
-    class RemoteGDB;
-}
+class BaseRemoteGDB;
 
 class System : public SimObject
 {
@@ -89,27 +90,29 @@ class System : public SimObject
     std::vector<ThreadContext *> threadContexts;
     int _numContexts;
 
-    ThreadContext * getThreadContext(int tid)
+    ThreadContext *getThreadContext(ThreadID tid)
     {
         return threadContexts[tid];
     }
 
     int numContexts()
     {
-        if (_numContexts != threadContexts.size())
-            panic("cpu array not fully populated!");
-
+        assert(_numContexts == (int)threadContexts.size());
         return _numContexts;
     }
 
+    /** Return number of running (non-halted) thread contexts in
+     * system.  These threads could be Active or Suspended. */
+    int numRunningContexts();
+
 #if FULL_SYSTEM
     Platform *platform;
     uint64_t init_param;
 
     /** Port to physical memory used for writing object files into ram at
      * boot.*/
-    FunctionalPort functionalPort;
-    VirtualPort virtPort;
+    FunctionalPort *functionalPort;
+    VirtualPort *virtPort;
 
     /** kernel symbol table */
     SymbolTable *kernelSymtab;
@@ -126,24 +129,80 @@ class System : public SimObject
     /** Entry point in the kernel to start at */
     Addr kernelEntry;
 
+    /** Mask that should be anded for binary/symbol loading.
+     * This allows one two different OS requirements for the same ISA to be
+     * handled.  Some OSes are compiled for a virtual address and need to be
+     * loaded into physical memory that starts at address 0, while other
+     * bare metal tools generate images that start at address 0.
+     */
+    Addr loadAddrMask;
+
 #else
 
-    int page_ptr;
+    Addr pagePtr;
 
   protected:
-    uint64_t next_PID;
+    uint64_t nextPID;
 
   public:
     uint64_t allocatePID()
     {
-        return next_PID++;
+        return nextPID++;
     }
 
+    /** Amount of physical memory that is still free */
+    Addr freeMemSize();
+
+    /** Amount of physical memory that exists */
+    Addr memSize();
+
 
 #endif // FULL_SYSTEM
 
   protected:
     Enums::MemoryMode memoryMode;
+    uint64_t workItemsBegin;
+    uint64_t workItemsEnd;
+    std::vector<bool> activeCpus;
+
+  public:
+    /**
+     * Called by pseudo_inst to track the number of work items started by this
+     * system.
+     */
+    uint64_t 
+    incWorkItemsBegin()
+    {
+        return ++workItemsBegin;
+    }
+
+    /**
+     * Called by pseudo_inst to track the number of work items completed by
+     * this system.
+     */
+    uint64_t 
+    incWorkItemsEnd()
+    {
+        return ++workItemsEnd;
+    }
+
+    /**
+     * Called by pseudo_inst to mark the cpus actively executing work items.
+     * Returns the total number of cpus that have executed work item begin or
+     * ends.
+     */
+    int 
+    markWorkItem(int index)
+    {
+        int count = 0;
+        assert(index < activeCpus.size());
+        activeCpus[index] = true;
+        for (std::vector<bool>::iterator i = activeCpus.begin(); 
+             i < activeCpus.end(); i++) {
+            if (*i) count++;
+        }
+        return count;
+    }
 
 #if FULL_SYSTEM
     /**
@@ -179,7 +238,7 @@ class System : public SimObject
 
 #endif
   public:
-    std::vector<TheISA::RemoteGDB *> remoteGDB;
+    std::vector<BaseRemoteGDB *> remoteGDB;
     std::vector<GDBListener *> gdbListen;
     bool breakpoint();
 
@@ -193,7 +252,7 @@ class System : public SimObject
     System(Params *p);
     ~System();
 
-    void startup();
+    void initState();
 
     const Params *params() const { return (const Params *)_params; }
 
@@ -224,13 +283,17 @@ class System : public SimObject
 
 #endif // FULL_SYSTEM
 
-    int registerThreadContext(ThreadContext *tc);
+    int registerThreadContext(ThreadContext *tc, int assigned=-1);
     void replaceThreadContext(ThreadContext *tc, int context_id);
 
     void serialize(std::ostream &os);
     void unserialize(Checkpoint *cp, const std::string &section);
+    virtual void resume();
 
   public:
+    Counter totalNumInsts;
+    EventQueue instEventQueue;
+
     ////////////////////////////////////////////
     //
     // STATIC GLOBAL SYSTEM LIST