sim, arch, base: Refactor the base remote GDB class.
[gem5.git] / src / sim / process.cc
index 71f3988931e51ca31de6c01f0ae0e0e7835db6e5..07c936e76d81fc14fc9b49bd860de3b5d0048972 100644 (file)
@@ -50,6 +50,7 @@
 #include <unistd.h>
 
 #include <array>
+#include <csignal>
 #include <map>
 #include <string>
 #include <vector>
 
 #if THE_ISA == ALPHA_ISA
 #include "arch/alpha/linux/process.hh"
+
 #elif THE_ISA == SPARC_ISA
 #include "arch/sparc/linux/process.hh"
 #include "arch/sparc/solaris/process.hh"
+
 #elif THE_ISA == MIPS_ISA
 #include "arch/mips/linux/process.hh"
+
 #elif THE_ISA == ARM_ISA
-#include "arch/arm/linux/process.hh"
 #include "arch/arm/freebsd/process.hh"
+#include "arch/arm/linux/process.hh"
+
 #elif THE_ISA == X86_ISA
 #include "arch/x86/linux/process.hh"
+
 #elif THE_ISA == POWER_ISA
 #include "arch/power/linux/process.hh"
+
 #elif THE_ISA == RISCV_ISA
 #include "arch/riscv/linux/process.hh"
+
 #else
 #error "THE_ISA not set"
 #endif
 using namespace std;
 using namespace TheISA;
 
-Process::Process(ProcessParams * params, ObjectFile * obj_file)
+Process::Process(ProcessParams *params, EmulationPageTable *pTable,
+                 ObjectFile *obj_file)
     : SimObject(params), system(params->system),
       useArchPT(params->useArchPT),
       kvmInSE(params->kvmInSE),
-      pTable(useArchPT ?
-        static_cast<PageTableBase *>(new ArchPageTable(name(), params->pid,
-            system)) :
-        static_cast<PageTableBase *>(new FuncPageTable(name(), params->pid))),
+      pTable(pTable),
       initVirtMem(system->getSystemPort(), this,
                   SETranslatingPortProxy::Always),
       objFile(obj_file),
@@ -143,7 +149,7 @@ Process::Process(ProcessParams * params, ObjectFile * obj_file)
             !objFile->loadLocalSymbols(debugSymbolTable) ||
             !objFile->loadWeakSymbols(debugSymbolTable)) {
             delete debugSymbolTable;
-            debugSymbolTable = NULL;
+            debugSymbolTable = nullptr;
         }
     }
 }
@@ -152,6 +158,15 @@ void
 Process::clone(ThreadContext *otc, ThreadContext *ntc,
                Process *np, TheISA::IntReg flags)
 {
+#ifndef CLONE_VM
+#define CLONE_VM 0
+#endif
+#ifndef CLONE_FILES
+#define CLONE_FILES 0
+#endif
+#ifndef CLONE_THREAD
+#define CLONE_THREAD 0
+#endif
     if (CLONE_VM & flags) {
         /**
          * Share the process memory address space between the new process
@@ -251,7 +266,7 @@ Process::findFreeContext()
         if (ThreadContext::Halted == it->status())
             return it;
     }
-    return NULL;
+    return nullptr;
 }
 
 void
@@ -295,7 +310,8 @@ Process::allocateMem(Addr vaddr, int64_t size, bool clobber)
     int npages = divCeil(size, (int64_t)PageBytes);
     Addr paddr = system->allocPhysPages(npages);
     pTable->map(vaddr, paddr, size,
-                clobber ? PageTableBase::Clobber : PageTableBase::Zero);
+                clobber ? EmulationPageTable::Clobber :
+                          EmulationPageTable::Zero);
 }
 
 void
@@ -350,6 +366,7 @@ Process::fixupStackFault(Addr vaddr)
 void
 Process::serialize(CheckpointOut &cp) const
 {
+    memState->serialize(cp);
     pTable->serialize(cp);
     /**
      * Checkpoints for file descriptors currently do not work. Need to
@@ -367,6 +384,7 @@ Process::serialize(CheckpointOut &cp) const
 void
 Process::unserialize(CheckpointIn &cp)
 {
+    memState->unserialize(cp);
     pTable->unserialize(cp);
     /**
      * Checkpoints for file descriptors currently do not work. Need to
@@ -388,7 +406,8 @@ bool
 Process::map(Addr vaddr, Addr paddr, int size, bool cacheable)
 {
     pTable->map(vaddr, paddr, size,
-                cacheable ? PageTableBase::Zero : PageTableBase::Uncacheable);
+                cacheable ? EmulationPageTable::Zero :
+                            EmulationPageTable::Uncacheable);
     return true;
 }
 
@@ -398,7 +417,7 @@ Process::syscall(int64_t callnum, ThreadContext *tc, Fault *fault)
     numSyscalls++;
 
     SyscallDesc *desc = getDesc(callnum);
-    if (desc == NULL)
+    if (desc == nullptr)
         fatal("Syscall %d out of range", callnum);
 
     desc->doSyscall(callnum, this, tc, fault);
@@ -418,7 +437,7 @@ Process::findDriver(std::string filename)
             return d;
     }
 
-    return NULL;
+    return nullptr;
 }
 
 void
@@ -472,7 +491,7 @@ Process::getStartPC()
 Process *
 ProcessParams::create()
 {
-    Process *process = NULL;
+    Process *process = nullptr;
 
     // If not specified, set the executable parameter equal to the
     // simulated system's zeroth command line parameter
@@ -481,7 +500,7 @@ ProcessParams::create()
     }
 
     ObjectFile *obj_file = createObjectFile(executable);
-    if (obj_file == NULL) {
+    if (obj_file == nullptr) {
         fatal("Can't load object file %s", executable);
     }
 
@@ -620,7 +639,7 @@ ProcessParams::create()
 #error "THE_ISA not set"
 #endif
 
-    if (process == NULL)
+    if (process == nullptr)
         fatal("Unknown error creating process object.");
     return process;
 }