arm: Add support for ARMv8 (AArch64 & AArch32)
[gem5.git] / src / sim / process.cc
index bec33c70b9e937a748f9883899b9b72add57635d..ccaac2096bcb4e0220a53992f8a6db026bbe7881 100644 (file)
@@ -1,4 +1,16 @@
 /*
+ * Copyright (c) 2012 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
  * Copyright (c) 2001-2005 The Regents of The University of Michigan
  * All rights reserved.
  *
 #include "base/loader/symtab.hh"
 #include "base/intmath.hh"
 #include "base/statistics.hh"
-#include "config/full_system.hh"
 #include "config/the_isa.hh"
 #include "cpu/thread_context.hh"
 #include "mem/page_table.hh"
-#include "mem/physical.hh"
-#include "mem/translating_port.hh"
+#include "mem/se_translating_port_proxy.hh"
 #include "params/LiveProcess.hh"
 #include "params/Process.hh"
 #include "sim/debug.hh"
 using namespace std;
 using namespace TheISA;
 
-//
-// The purpose of this code is to fake the loader & syscall mechanism
-// when there's no OS: thus there's no resone to use it in FULL_SYSTEM
-// mode when we do have an OS
-//
-#if FULL_SYSTEM
-#error "process.cc not compatible with FULL_SYSTEM"
-#endif
-
 // current number of allocated processes
 int num_processes = 0;
 
@@ -96,12 +97,16 @@ AuxVector<IntType>::AuxVector(IntType type, IntType val)
     a_val = TheISA::htog(val);
 }
 
-template class AuxVector<uint32_t>;
-template class AuxVector<uint64_t>;
+template struct AuxVector<uint32_t>;
+template struct AuxVector<uint64_t>;
 
 Process::Process(ProcessParams * params)
     : SimObject(params), system(params->system),
-      max_stack_size(params->max_stack_size)
+      max_stack_size(params->max_stack_size),
+      M5_pid(system->allocatePID()),
+      pTable(new PageTable(name(), M5_pid)),
+      initVirtMem(system->getSystemPort(), this,
+                  SETranslatingPortProxy::Always)
 {
     string in = params->input;
     string out = params->output;
@@ -137,7 +142,6 @@ Process::Process(ProcessParams * params)
     else
         stderr_fd = Process::openOutputFile(err);
 
-    M5_pid = system->allocatePID();
     // initialize first 3 fds (stdin, stdout, stderr)
     Process::FdMap *fdo = &fd_map[STDIN_FILENO];
     fdo->fd = stdin_fd;
@@ -163,13 +167,12 @@ Process::Process(ProcessParams * params)
 
     // mark remaining fds as free
     for (int i = 3; i <= MAX_FD; ++i) {
-        Process::FdMap *fdo = &fd_map[i];
+        fdo = &fd_map[i];
         fdo->fd = -1;
     }
 
     mmap_start = mmap_end = 0;
     nxm_start = nxm_end = 0;
-    pTable = new PageTable(this);
     // other parameters will be initialized when the program is loaded
 }
 
@@ -242,14 +245,7 @@ Process::initState()
     ThreadContext *tc = system->getThreadContext(contextIds[0]);
 
     // mark this context as active so it will start ticking.
-    tc->activate(0);
-
-    Port *mem_port;
-    mem_port = system->physmem->getPort("functional");
-    initVirtMem = new TranslatingPort("process init port", this,
-            TranslatingPort::Always);
-    mem_port->setPeer(initVirtMem);
-    initVirtMem->setPeer(mem_port);
+    tc->activate(Cycles(0));
 }
 
 // map simulator fd sim_fd to target fd tgt_fd
@@ -328,30 +324,36 @@ Process::sim_fd_obj(int tgt_fd)
     return &fd_map[tgt_fd];
 }
 
+void
+Process::allocateMem(Addr vaddr, int64_t size, bool clobber)
+{
+    int npages = divCeil(size, (int64_t)VMPageSize);
+    Addr paddr = system->allocPhysPages(npages);
+    pTable->map(vaddr, paddr, size, clobber);
+}
+
 bool
-Process::checkAndAllocNextPage(Addr vaddr)
+Process::fixupStackFault(Addr vaddr)
 {
-    // if this is an initial write we might not have
+    // Check if this is already on the stack and there's just no page there
+    // yet.
     if (vaddr >= stack_min && vaddr < stack_base) {
-        pTable->allocate(roundDown(vaddr, VMPageSize), VMPageSize);
+        allocateMem(roundDown(vaddr, VMPageSize), VMPageSize);
         return true;
     }
 
-    // We've accessed the next page of the stack, so extend the stack
-    // to cover it.
+    // We've accessed the next page of the stack, so extend it to include
+    // this address.
     if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) {
         while (vaddr < stack_min) {
             stack_min -= TheISA::PageBytes;
-            if(stack_base - stack_min > max_stack_size)
+            if (stack_base - stack_min > max_stack_size)
                 fatal("Maximum stack size exceeded\n");
-            if(stack_base - stack_min > 8*1024*1024)
-                fatal("Over max stack size for one thread\n");
-            pTable->allocate(stack_min, TheISA::PageBytes);
+            allocateMem(stack_min, TheISA::PageBytes);
             inform("Increasing stack size by one page.");
         };
         return true;
     }
-    warn("Not increasing stack: requested vaddr is outside of stack range.");
     return false;
 }
 
@@ -541,6 +543,14 @@ Process::unserialize(Checkpoint *cp, const std::string &section)
 }
 
 
+bool
+Process::map(Addr vaddr, Addr paddr, int size)
+{
+    pTable->map(vaddr, paddr, size);
+    return true;
+}
+
+
 ////////////////////////////////////////////////////////////////////////
 //
 // LiveProcess member definitions
@@ -559,14 +569,13 @@ LiveProcess::LiveProcess(LiveProcessParams * params, ObjectFile *_objFile)
     __pid = params->pid;
     __ppid = params->ppid;
 
-    prog_fname = params->cmd[0];
-
     // load up symbols, if any... these may be used for debugging or
     // profiling.
     if (!debugSymbolTable) {
         debugSymbolTable = new SymbolTable();
         if (!objFile->loadGlobalSymbols(debugSymbolTable) ||
-            !objFile->loadLocalSymbols(debugSymbolTable)) {
+            !objFile->loadLocalSymbols(debugSymbolTable) ||
+            !objFile->loadWeakSymbols(debugSymbolTable)) {
             // didn't load any symbols
             delete debugSymbolTable;
             debugSymbolTable = NULL;
@@ -686,15 +695,22 @@ LiveProcess::create(LiveProcessParams * params)
         fatal("Unknown/unsupported operating system.");
     }
 #elif THE_ISA == ARM_ISA
-    if (objFile->getArch() != ObjectFile::Arm &&
-        objFile->getArch() != ObjectFile::Thumb)
+    ObjectFile::Arch arch = objFile->getArch();
+    if (arch != ObjectFile::Arm && arch != ObjectFile::Thumb &&
+        arch != ObjectFile::Arm64)
         fatal("Object file architecture does not match compiled ISA (ARM).");
     switch (objFile->getOpSys()) {
       case ObjectFile::UnknownOpSys:
         warn("Unknown operating system; assuming Linux.");
         // fall through
       case ObjectFile::Linux:
-        process = new ArmLinuxProcess(params, objFile, objFile->getArch());
+        if (arch == ObjectFile::Arm64) {
+            process = new ArmLinuxProcess64(params, objFile,
+                                            objFile->getArch());
+        } else {
+            process = new ArmLinuxProcess32(params, objFile,
+                                            objFile->getArch());
+        }
         break;
       case ObjectFile::LinuxArmOABI:
         fatal("M5 does not support ARM OABI binaries. Please recompile with an"
@@ -720,7 +736,6 @@ LiveProcess::create(LiveProcessParams * params)
 #error "THE_ISA not set"
 #endif
 
-
     if (process == NULL)
         fatal("Unknown error creating process object.");
     return process;