Time: Add a mechanism to prevent M5 from running faster than real time.
[gem5.git] / src / sim / system.hh
index b3a67bf7a74d8fbcd4f717896257de7d450f3344..cdf7d3d7e9d606c6a4c796a867fb10eacbdcfc43 100644 (file)
 #include "base/statistics.hh"
 #include "config/full_system.hh"
 #include "cpu/pc_event.hh"
+#include "enums/MemoryMode.hh"
 #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;
@@ -55,12 +57,11 @@ class PhysicalMemory;
 
 #if FULL_SYSTEM
 class Platform;
-class GDBListener;
-namespace TheISA
-{
-    class RemoteGDB;
-}
+class FunctionalPort;
+class VirtualPort;
 #endif
+class GDBListener;
+class BaseRemoteGDB;
 
 class System : public SimObject
 {
@@ -68,36 +69,48 @@ class System : public SimObject
 
     static const char *MemoryModeStrings[3];
 
-    SimObject::MemoryMode getMemoryMode() { assert(memoryMode); return memoryMode; }
+    Enums::MemoryMode
+    getMemoryMode()
+    {
+        assert(memoryMode);
+        return memoryMode;
+    }
 
     /** Change the memory mode of the system. This should only be called by the
      * python!!
      * @param mode Mode to change to (atomic/timing)
      */
-    void setMemoryMode(SimObject::MemoryMode mode);
+    void setMemoryMode(Enums::MemoryMode mode);
 
     PhysicalMemory *physmem;
     PCEventQueue pcEventQueue;
 
     std::vector<ThreadContext *> threadContexts;
-    int numcpus;
+    int _numContexts;
 
-    int getNumCPUs()
+    ThreadContext *getThreadContext(ThreadID tid)
     {
-        if (numcpus != threadContexts.size())
-            panic("cpu array not fully populated!");
+        return threadContexts[tid];
+    }
 
-        return numcpus;
+    int numContexts()
+    {
+        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;
@@ -114,16 +127,38 @@ 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 nextPID;
+
+  public:
+    uint64_t allocatePID()
+    {
+        return nextPID++;
+    }
+
+    /** Amount of physical memory that is still free */
+    Addr freeMemSize();
+
+    /** Amount of physical memory that exists */
+    Addr memSize();
 
 
 #endif // FULL_SYSTEM
 
   protected:
-
-    SimObject::MemoryMode memoryMode;
+    Enums::MemoryMode memoryMode;
 
 #if FULL_SYSTEM
     /**
@@ -159,29 +194,12 @@ class System : public SimObject
 
 #endif
   public:
-#if FULL_SYSTEM
-    std::vector<TheISA::RemoteGDB *> remoteGDB;
+    std::vector<BaseRemoteGDB *> remoteGDB;
     std::vector<GDBListener *> gdbListen;
-    virtual bool breakpoint() = 0;
-#endif // FULL_SYSTEM
+    bool breakpoint();
 
   public:
-    struct Params
-    {
-        std::string name;
-        PhysicalMemory *physmem;
-        SimObject::MemoryMode mem_mode;
-
-#if FULL_SYSTEM
-        Tick boot_cpu_frequency;
-        std::string boot_osflags;
-        uint64_t init_param;
-
-        std::string kernel_path;
-        std::string readfile;
-        std::string symbolfile;
-#endif
-    };
+    typedef SystemParams Params;
 
   protected:
     Params *_params;
@@ -190,7 +208,7 @@ class System : public SimObject
     System(Params *p);
     ~System();
 
-    void startup();
+    void initState();
 
     const Params *params() const { return (const Params *)_params; }
 
@@ -221,8 +239,8 @@ class System : public SimObject
 
 #endif // FULL_SYSTEM
 
-    int registerThreadContext(ThreadContext *tc, int tcIndex);
-    void replaceThreadContext(ThreadContext *tc, int tcIndex);
+    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);