fetch.cc:
[gem5.git] / arch / alpha / pseudo_inst.cc
index f4201ab09c94a3234134af8b1e3c198dcc9208b7..22d65638b970c11c29b8f2c3de09f93ef719a90a 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <fcntl.h>
+#include <unistd.h>
+#include <cstdio>
+
 #include <string>
 
 #include "arch/alpha/pseudo_inst.hh"
+#include "arch/alpha/vtophys.hh"
+#include "cpu/base_cpu.hh"
+#include "cpu/sampling_cpu/sampling_cpu.hh"
 #include "cpu/exec_context.hh"
+#include "kern/kernel_stats.hh"
 #include "sim/param.hh"
 #include "sim/serialize.hh"
 #include "sim/sim_exit.hh"
 #include "sim/stat_control.hh"
 #include "sim/stats.hh"
+#include "sim/system.hh"
+#include "sim/debug.hh"
 
 using namespace std;
+
+extern SamplingCPU *SampCPU;
+
 using namespace Stats;
 
 namespace AlphaPseudo
@@ -48,7 +61,7 @@ namespace AlphaPseudo
     void
     arm(ExecContext *xc)
     {
-        xc->kernelStats.arm();
+        xc->kernelStats->arm();
     }
 
     void
@@ -58,13 +71,13 @@ namespace AlphaPseudo
             return;
 
         xc->suspend();
-        xc->kernelStats.quiesce();
+        xc->kernelStats->quiesce();
     }
 
     void
     ivlb(ExecContext *xc)
     {
-        xc->kernelStats.ivlb();
+        xc->kernelStats->ivlb();
     }
 
     void
@@ -149,6 +162,43 @@ namespace AlphaPseudo
         Checkpoint::setup(when, repeat);
     }
 
+    void
+    readfile(ExecContext *xc)
+    {
+        const string &file = xc->cpu->system->params->readfile;
+        if (file.empty()) {
+            xc->regs.intRegFile[0] = ULL(0);
+            return;
+        }
+
+        Addr vaddr = xc->regs.intRegFile[16];
+        uint64_t len = xc->regs.intRegFile[17];
+        uint64_t offset = xc->regs.intRegFile[18];
+        uint64_t result = 0;
+
+        int fd = ::open(file.c_str(), O_RDONLY, 0);
+        if (fd < 0)
+            panic("could not open file %s\n", file);
+
+        char *buf = new char[len];
+        char *p = buf;
+        while (len > 0) {
+            int bytes = ::pread(fd, p, len, offset);
+            if (bytes <= 0)
+                break;
+
+            p += bytes;
+            offset += bytes;
+            result += bytes;
+            len -= bytes;
+        }
+
+        close(fd);
+        CopyIn(xc, vaddr, buf, result);
+        delete [] buf;
+        xc->regs.intRegFile[0] = result;
+    }
+
     class Context : public ParamContext
     {
       public:
@@ -156,7 +206,7 @@ namespace AlphaPseudo
         void checkParams();
     };
 
-    Context context("PseudoInsts");
+    Context context("pseudo_inst");
 
     Param<bool> __quiesce(&context, "quiesce",
                           "enable quiesce instructions",
@@ -175,4 +225,15 @@ namespace AlphaPseudo
         doStatisticsInsts = __statistics;
         doCheckpointInsts = __checkpoint;
     }
+
+    void debugbreak(ExecContext *xc)
+    {
+        debug_break();
+    }
+
+    void switchcpu(ExecContext *xc)
+    {
+        if (SampCPU)
+            SampCPU->switchCPUs();
+    }
 }