Port: Stricter port bind/unbind semantics
[gem5.git] / src / cpu / simple_thread.cc
index 53534a4f3886f5c992cb0cafa4b0c34f0d58ca15..c114d04ac05f64ccd38a19459f23deff62832c46 100644 (file)
 #include <string>
 
 #include "arch/isa_traits.hh"
-#include "arch/utility.hh"
-#include "config/the_isa.hh"
-#include "cpu/base.hh"
-#include "cpu/simple_thread.hh"
-#include "cpu/thread_context.hh"
-#include "mem/vport.hh"
-#include "params/BaseCPU.hh"
-#include "sim/process.hh"
-
-#if FULL_SYSTEM
 #include "arch/kernel_stats.hh"
 #include "arch/stacktrace.hh"
+#include "arch/utility.hh"
 #include "base/callback.hh"
 #include "base/cprintf.hh"
 #include "base/output.hh"
 #include "base/trace.hh"
+#include "config/the_isa.hh"
+#include "cpu/base.hh"
 #include "cpu/profile.hh"
 #include "cpu/quiesce_event.hh"
+#include "cpu/simple_thread.hh"
+#include "cpu/thread_context.hh"
+#include "mem/fs_translating_port_proxy.hh"
+#include "mem/se_translating_port_proxy.hh"
+#include "params/BaseCPU.hh"
+#include "sim/full_system.hh"
+#include "sim/process.hh"
 #include "sim/serialize.hh"
 #include "sim/sim_exit.hh"
-#else
-#include "mem/translating_port.hh"
 #include "sim/system.hh"
-#endif
 
 using namespace std;
 
 // constructor
-#if !FULL_SYSTEM
-SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, Process *_process,
-                           TheISA::TLB *_itb, TheISA::TLB *_dtb)
-    : ThreadState(_cpu, _thread_num, _process),
-      cpu(_cpu), itb(_itb), dtb(_dtb)
+SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
+                           Process *_process, TheISA::TLB *_itb,
+                           TheISA::TLB *_dtb)
+    : ThreadState(_cpu, _thread_num, _process), system(_sys), itb(_itb),
+      dtb(_dtb), decoder(NULL)
 {
     clearArchRegs();
     tc = new ProxyThreadContext<SimpleThread>(this);
 }
-#else
 SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
                            TheISA::TLB *_itb, TheISA::TLB *_dtb,
                            bool use_kernel_stats)
-    : ThreadState(_cpu, _thread_num, NULL),
-      cpu(_cpu), system(_sys), itb(_itb), dtb(_dtb)
-
+    : ThreadState(_cpu, _thread_num, NULL), system(_sys), itb(_itb), dtb(_dtb),
+      decoder(NULL)
 {
     tc = new ProxyThreadContext<SimpleThread>(this);
 
@@ -85,7 +80,7 @@ SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
 
     clearArchRegs();
 
-    if (cpu->params()->profile) {
+    if (baseCpu->params()->profile) {
         profile = new FunctionProfile(system->kernelSymtab);
         Callback *cb =
             new MakeCallback<SimpleThread,
@@ -102,18 +97,15 @@ SimpleThread::SimpleThread(BaseCPU *_cpu, int _thread_num, System *_sys,
     if (use_kernel_stats)
         kernelStats = new TheISA::Kernel::Statistics(system);
 }
-#endif
 
 SimpleThread::SimpleThread()
-    : ThreadState(NULL, -1, NULL)
+    : ThreadState(NULL, -1, NULL), decoder(NULL)
 {
     tc = new ProxyThreadContext<SimpleThread>(this);
 }
 
 SimpleThread::~SimpleThread()
 {
-    delete physPort;
-    delete virtPort;
     delete tc;
 }
 
@@ -121,29 +113,28 @@ void
 SimpleThread::takeOverFrom(ThreadContext *oldContext)
 {
     // some things should already be set up
-#if FULL_SYSTEM
-    assert(system == oldContext->getSystemPtr());
-#endif
+    if (FullSystem)
+        assert(system == oldContext->getSystemPtr());
     assert(process == oldContext->getProcessPtr());
 
     copyState(oldContext);
-#if FULL_SYSTEM
-    EndQuiesceEvent *quiesce = oldContext->getQuiesceEvent();
-    if (quiesce) {
-        // Point the quiesce event's TC at this TC so that it wakes up
-        // the proper CPU.
-        quiesce->tc = tc;
-    }
-    if (quiesceEvent) {
-        quiesceEvent->tc = tc;
+    if (FullSystem) {
+        EndQuiesceEvent *quiesce = oldContext->getQuiesceEvent();
+        if (quiesce) {
+            // Point the quiesce event's TC at this TC so that it wakes up
+            // the proper CPU.
+            quiesce->tc = tc;
+        }
+        if (quiesceEvent) {
+            quiesceEvent->tc = tc;
+        }
+
+        TheISA::Kernel::Statistics *stats = oldContext->getKernelStats();
+        if (stats) {
+            kernelStats = stats;
+        }
     }
 
-    TheISA::Kernel::Statistics *stats = oldContext->getKernelStats();
-    if (stats) {
-        kernelStats = stats;
-    }
-#endif
-
     storeCondFailures = 0;
 
     oldContext->setStatus(ThreadContext::Halted);
@@ -154,16 +145,16 @@ SimpleThread::copyTC(ThreadContext *context)
 {
     copyState(context);
 
-#if FULL_SYSTEM
-    EndQuiesceEvent *quiesce = context->getQuiesceEvent();
-    if (quiesce) {
-        quiesceEvent = quiesce;
-    }
-    TheISA::Kernel::Statistics *stats = context->getKernelStats();
-    if (stats) {
-        kernelStats = stats;
+    if (FullSystem) {
+        EndQuiesceEvent *quiesce = context->getQuiesceEvent();
+        if (quiesce) {
+            quiesceEvent = quiesce;
+        }
+        TheISA::Kernel::Statistics *stats = context->getKernelStats();
+        if (stats) {
+            kernelStats = stats;
+        }
     }
-#endif
 }
 
 void
@@ -172,9 +163,8 @@ SimpleThread::copyState(ThreadContext *oldContext)
     // copy over functional state
     _status = oldContext->status();
     copyArchRegs(oldContext);
-#if !FULL_SYSTEM
-    funcExeInst = oldContext->readFuncExeInst();
-#endif
+    if (FullSystem)
+        funcExeInst = oldContext->readFuncExeInst();
 
     _threadId = oldContext->threadId();
     _contextId = oldContext->contextId();
@@ -192,7 +182,7 @@ SimpleThread::serialize(ostream &os)
     // 
     // Now must serialize all the ISA dependent state
     //
-    isa.serialize(cpu, os);
+    isa.serialize(baseCpu, os);
 }
 
 
@@ -208,17 +198,16 @@ SimpleThread::unserialize(Checkpoint *cp, const std::string &section)
     // 
     // Now must unserialize all the ISA dependent state
     //
-    isa.unserialize(cpu, cp, section);
+    isa.unserialize(baseCpu, cp, section);
 }
 
-#if FULL_SYSTEM
 void
 SimpleThread::dumpFuncProfile()
 {
-    std::ostream *os = simout.create(csprintf("profile.%s.dat", cpu->name()));
+    std::ostream *os = simout.create(csprintf("profile.%s.dat",
+                                              baseCpu->name()));
     profile->dump(tc, *os);
 }
-#endif
 
 void
 SimpleThread::activate(int delay)
@@ -236,7 +225,7 @@ SimpleThread::activate(int delay)
     _status = ThreadContext::Active;
 
     // status() == Suspended
-    cpu->activateContext(_threadId, delay);
+    baseCpu->activateContext(_threadId, delay);
 }
 
 void
@@ -247,17 +236,8 @@ SimpleThread::suspend()
 
     lastActivate = curTick();
     lastSuspend = curTick();
-/*
-#if FULL_SYSTEM
-    // Don't change the status from active if there are pending interrupts
-    if (cpu->checkInterrupts()) {
-        assert(status() == ThreadContext::Active);
-        return;
-    }
-#endif
-*/
     _status = ThreadContext::Suspended;
-    cpu->suspendContext(_threadId);
+    baseCpu->suspendContext(_threadId);
 }
 
 
@@ -268,17 +248,15 @@ SimpleThread::halt()
         return;
 
     _status = ThreadContext::Halted;
-    cpu->haltContext(_threadId);
+    baseCpu->haltContext(_threadId);
 }
 
 
 void
 SimpleThread::regStats(const string &name)
 {
-#if FULL_SYSTEM
-    if (kernelStats)
+    if (FullSystem && kernelStats)
         kernelStats->regStats(name + ".kern");
-#endif
 }
 
 void