add translations for new sections that are mmapped or when the brk
authorAli Saidi <saidi@eecs.umich.edu>
Wed, 15 Mar 2006 22:04:50 +0000 (17:04 -0500)
committerAli Saidi <saidi@eecs.umich.edu>
Wed, 15 Mar 2006 22:04:50 +0000 (17:04 -0500)
is changed
Add a default machine width parameter
Arch based live processes

arch/alpha/linux/process.cc:
arch/alpha/linux/process.hh:
arch/alpha/process.cc:
arch/alpha/process.hh:
arch/alpha/tru64/process.cc:
arch/alpha/tru64/process.hh:
arch/mips/linux_process.cc:
arch/mips/process.cc:
arch/mips/process.hh:
arch/sparc/linux/process.cc:
arch/sparc/linux/process.hh:
arch/sparc/process.cc:
arch/sparc/process.hh:
configs/test/test.py:
python/m5/objects/Process.py:
sim/process.cc:
sim/process.hh:
    Architecture based live processes
arch/mips/isa_traits.hh:
arch/sparc/isa_traits.hh:
    Add a default machine width parameter
mem/port.hh:
    gcc 4 really wants  a virtual destructor
sim/byteswap.hh:
    remove the comment around long and unsigned long even though uint32_t
    and int32_t are defined. Seems to work with gcc 4 and 3.4.3.
sim/syscall_emul.cc:
sim/syscall_emul.hh:
    add translations for new sections that are mmapped or when the brk
    is changed

--HG--
extra : convert_revision : e2f9f228113c7127c87ef2358209a399c30ed5c6

23 files changed:
arch/alpha/linux/process.cc
arch/alpha/linux/process.hh
arch/alpha/process.cc
arch/alpha/process.hh
arch/alpha/tru64/process.cc
arch/alpha/tru64/process.hh
arch/mips/isa_traits.hh
arch/mips/linux_process.cc
arch/mips/process.cc
arch/mips/process.hh
arch/sparc/isa_traits.hh
arch/sparc/linux/process.cc
arch/sparc/linux/process.hh
arch/sparc/process.cc
arch/sparc/process.hh
configs/test/test.py
mem/port.hh
python/m5/objects/Process.py
sim/byteswap.hh
sim/process.cc
sim/process.hh
sim/syscall_emul.cc
sim/syscall_emul.hh

index 704773fdf7a74860692f26f8fe2b218767c2c385..4bc28356362fc3d96d4aeb3eb41c7181eb7d3ed8 100644 (file)
@@ -572,7 +572,7 @@ AlphaLinuxProcess::AlphaLinuxProcess(const std::string &name,
                                      int stderr_fd,
                                      std::vector<std::string> &argv,
                                      std::vector<std::string> &envp)
-    : LiveProcess(name, objFile, system, stdin_fd, stdout_fd,
+    : AlphaLiveProcess(name, objFile, system, stdin_fd, stdout_fd,
             stderr_fd, argv, envp),
      Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc))
 {
index 2cabc3f76ad73b14f22f403917bc562a6fd2f50c..2e0566665d009d205e5801c31272f6eba348cc5f 100644 (file)
 #ifndef __ALPHA_LINUX_PROCESS_HH__
 #define __ALPHA_LINUX_PROCESS_HH__
 
-#include "sim/process.hh"
+#include "arch/alpha/process.hh"
 
+namespace AlphaISA  {
 
 /// A process with emulated Alpha/Linux syscalls.
-class AlphaLinuxProcess : public LiveProcess
+class AlphaLinuxProcess : public AlphaLiveProcess
 {
   public:
     /// Constructor.
@@ -55,5 +56,5 @@ class AlphaLinuxProcess : public LiveProcess
     const int Num_Syscall_Descs;
 };
 
-
+} // namespace AlphaISA
 #endif // __ALPHA_LINUX_PROCESS_HH__
index 17a54ee80e988b967520b9f4ce6658b535bf52f1..25ee79692e2b9020292a7585ea0533d2acf555c9 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "arch/alpha/constants.hh"
 #include "arch/alpha/process.hh"
 #include "arch/alpha/linux/process.hh"
 #include "arch/alpha/tru64/process.hh"
 #include "base/loader/object_file.hh"
 #include "base/misc.hh"
+#include "cpu/exec_context.hh"
+#include "sim/builder.hh"
+#include "sim/system.hh"
 
-namespace AlphaISA
-{
 
-LiveProcess *
-createProcess(const std::string &nm, ObjectFile * objFile, System *system,
-        int stdin_fd, int stdout_fd, int stderr_fd,
+using namespace AlphaISA;
+using namespace std;
+
+AlphaLiveProcess *
+AlphaLiveProcess::create(const std::string &nm, System *system, int stdin_fd,
+        int stdout_fd, int stderr_fd, std::string executable,
         std::vector<std::string> &argv, std::vector<std::string> &envp)
 {
-    LiveProcess * process = NULL;
+    AlphaLiveProcess *process = NULL;
+
+    ObjectFile *objFile = createObjectFile(executable);
+    if (objFile == NULL) {
+        fatal("Can't load object file %s", executable);
+    }
+
+
     if (objFile->getArch() != ObjectFile::Alpha)
         fatal("Object file does not match architecture.");
     switch (objFile->getOpSys()) {
@@ -59,7 +71,97 @@ createProcess(const std::string &nm, ObjectFile * objFile, System *system,
       default:
         fatal("Unknown/unsupported operating system.");
     }
+
+    if (process == NULL)
+        fatal("Unknown error creating process object.");
     return process;
 }
 
-} // namespace AlphaISA
+AlphaLiveProcess::AlphaLiveProcess(const std::string &nm, ObjectFile *objFile,
+        System *_system, int stdin_fd, int stdout_fd, int stderr_fd,
+        std::vector<std::string> &argv, std::vector<std::string> &envp)
+    : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd,
+        argv, envp)
+{
+    brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize();
+    brk_point = roundUp(brk_point, VMPageSize);
+
+    // Set up stack.  On Alpha, stack goes below text section.  This
+    // code should get moved to some architecture-specific spot.
+    stack_base = objFile->textBase() - (409600+4096);
+
+    // Set up region for mmaps.  Tru64 seems to start just above 0 and
+    // grow up from there.
+    mmap_start = mmap_end = 0x10000;
+
+    // Set pointer for next thread stack.  Reserve 8M for main stack.
+    next_thread_stack_base = stack_base - (8 * 1024 * 1024);
+
+}
+
+void
+AlphaLiveProcess::startup()
+{
+    argsInit(MachineBytes, VMPageSize);
+
+    execContexts[0]->setIntReg(GlobalPointerReg, objFile->globalPointer());
+}
+
+
+
+
+BEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess)
+
+    VectorParam<string> cmd;
+    Param<string> executable;
+    Param<string> input;
+    Param<string> output;
+    VectorParam<string> env;
+    SimObjectParam<System *> system;
+
+END_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess)
+
+
+BEGIN_INIT_SIM_OBJECT_PARAMS(AlphaLiveProcess)
+
+    INIT_PARAM(cmd, "command line (executable plus arguments)"),
+    INIT_PARAM(executable, "executable (overrides cmd[0] if set)"),
+    INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"),
+    INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"),
+    INIT_PARAM(env, "environment settings"),
+    INIT_PARAM(system, "system")
+
+END_INIT_SIM_OBJECT_PARAMS(AlphaLiveProcess)
+
+
+CREATE_SIM_OBJECT(AlphaLiveProcess)
+{
+    string in = input;
+    string out = output;
+
+    // initialize file descriptors to default: same as simulator
+    int stdin_fd, stdout_fd, stderr_fd;
+
+    if (in == "stdin" || in == "cin")
+        stdin_fd = STDIN_FILENO;
+    else
+        stdin_fd = Process::openInputFile(input);
+
+    if (out == "stdout" || out == "cout")
+        stdout_fd = STDOUT_FILENO;
+    else if (out == "stderr" || out == "cerr")
+        stdout_fd = STDERR_FILENO;
+    else
+        stdout_fd = Process::openOutputFile(out);
+
+    stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
+
+    return AlphaLiveProcess::create(getInstanceName(), system,
+                               stdin_fd, stdout_fd, stderr_fd,
+                               (string)executable == "" ? cmd[0] : executable,
+                               cmd, env);
+}
+
+
+REGISTER_SIM_OBJECT("AlphaLiveProcess", AlphaLiveProcess)
+
index 6d65851751c25f4d0dc4249d8e35feb5168ba5e3..d97b36e2ddaa856acbbbdd9696ea2466d1d0c304 100644 (file)
 
 #include <string>
 #include <vector>
+#include "sim/process.hh"
 
-class LiveProcess;
 class ObjectFile;
 class System;
 
-namespace AlphaISA
+
+class AlphaLiveProcess : public LiveProcess
 {
+  protected:
+    AlphaLiveProcess(const std::string &nm, ObjectFile *objFile,
+                System *_system, int stdin_fd, int stdout_fd, int stderr_fd,
+                std::vector<std::string> &argv,
+                std::vector<std::string> &envp);
+
+    void startup();
+
+  public:
+    // this function is used to create the LiveProcess object, since
+    // we can't tell which subclass of LiveProcess to use until we
+    // open and look at the object file.
+    static AlphaLiveProcess *create(const std::string &nm,
+                               System *_system,
+                               int stdin_fd, int stdout_fd, int stderr_fd,
+                               std::string executable,
+                               std::vector<std::string> &argv,
+                               std::vector<std::string> &envp);
 
-LiveProcess *
-createProcess(const std::string &nm, ObjectFile * objFile, System * system,
-              int stdin_fd, int stdout_fd, int stderr_fd,
-              std::vector<std::string> &argv, std::vector<std::string> &envp);
+};
 
-} // namespace AlphaISA
 
 #endif // __ALPHA_PROCESS_HH__
index be78cb96e01f45cc1626e84b252eba6b5d3251aa..355d7f3e6a23c9f2ec25de7b5be79b0e497122f7 100644 (file)
@@ -535,7 +535,7 @@ AlphaTru64Process::AlphaTru64Process(const std::string &name,
                                      int stderr_fd,
                                      std::vector<std::string> &argv,
                                      std::vector<std::string> &envp)
-    : LiveProcess(name, objFile, system, stdin_fd, stdout_fd,
+    : AlphaLiveProcess(name, objFile, system, stdin_fd, stdout_fd,
             stderr_fd, argv, envp),
       Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc)),
       Num_Mach_Syscall_Descs(sizeof(machSyscallDescs) / sizeof(SyscallDesc))
index 84abd54bf270807aa27c7bf56149411ce627b4d8..1cde4cac0af4bc679d9371dc57ea6453e5f65a8f 100644 (file)
 #ifndef __ALPHA_TRU64_PROCESS_HH__
 #define __ALPHA_TRU64_PROCESS_HH__
 
-#include "sim/process.hh"
+#include "arch/alpha/process.hh"
 
+namespace AlphaISA {
 /// A process with emulated Alpha Tru64 syscalls.
-class AlphaTru64Process : public LiveProcess
+class AlphaTru64Process : public AlphaLiveProcess
 {
   public:
     /// Constructor.
@@ -55,5 +56,6 @@ class AlphaTru64Process : public LiveProcess
     virtual SyscallDesc* getDesc(int callnum);
 };
 
+} // namespace AlphaISA
 
 #endif // __ALPHA_TRU64_PROCESS_HH__
index bd56ce2ccc1bfc483aa3b797ed4315026e7a38f4..833d3cc63a3892b36a0e79865d34a30bea300112 100644 (file)
@@ -142,6 +142,7 @@ namespace MipsISA
 
     const int BranchPredAddrShiftAmt = 2; // instructions are 4-byte aligned
 
+    const int MachineBytes = 4;
     const int WordBytes = 4;
     const int HalfwordBytes = 2;
     const int ByteBytes = 1;
index 318b7934a350bdbea454929302986789116673f7..93706d8aaf634ac624fc709639ea8118d8960f4e 100644 (file)
@@ -571,7 +571,8 @@ MipsLinuxProcess::MipsLinuxProcess(const std::string &name,
                                      int stderr_fd,
                                      std::vector<std::string> &argv,
                                      std::vector<std::string> &envp)
-    : LiveProcess(name, objFile, system, stdin_fd, stdout_fd, stderr_fd, argv, envp),
+    : MipsLiveProcess(name, objFile, system, stdin_fd, stdout_fd, stderr_fd,
+                      argv, envp),
      Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc))
 {
     //init_regs->intRegFile[0] = 0;
index 8f8a34934b00ba8148ef569e9c7e0a3337435cf1..a4ce3f5f159717b06cec04bfec7651effb8c718a 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "arch/mips/isa_traits.hh"
 #include "arch/mips/process.hh"
 #include "arch/mips/linux_process.hh"
 #include "base/loader/object_file.hh"
 #include "base/misc.hh"
+#include "cpu/exec_context.hh"
+#include "sim/builder.hh"
+#include "sim/system.hh"
 
 using namespace std;
+using namespace MipsISA;
 
-namespace MipsISA
-{
 
-LiveProcess *
-createProcess(const string &nm, ObjectFile * objFile, System * system,
-        int stdin_fd, int stdout_fd, int stderr_fd,
-        vector<string> &argv, vector<string> &envp)
+MipsLiveProcess *
+MipsLiveProcess::create(const std::string &nm, System *system, int stdin_fd,
+        int stdout_fd, int stderr_fd, std::string executable,
+        std::vector<std::string> &argv, std::vector<std::string> &envp)
 {
-    LiveProcess * process = NULL;
+    MipsLiveProcess *process = NULL;
+
+    ObjectFile *objFile = createObjectFile(executable);
+    if (objFile == NULL) {
+        fatal("Can't load object file %s", executable);
+    }
+
+
     if (objFile->getArch() != ObjectFile::MIPS)
         fatal("Object file does not match architecture.");
     switch (objFile->getOpSys()) {
       case ObjectFile::Linux:
-        process = new MipsLinuxProcess(nm, objFile,system,
+        process = new MipsLinuxProcess(nm, objFile, system,
                                         stdin_fd, stdout_fd, stderr_fd,
                                         argv, envp);
         break;
@@ -54,8 +64,98 @@ createProcess(const string &nm, ObjectFile * objFile, System * system,
       default:
         fatal("Unknown/unsupported operating system.");
     }
+
+    if (process == NULL)
+        fatal("Unknown error creating process object.");
     return process;
 }
 
-} // namespace MipsISA
+MipsLiveProcess::MipsLiveProcess(const std::string &nm, ObjectFile *objFile,
+        System *_system, int stdin_fd, int stdout_fd, int stderr_fd,
+        std::vector<std::string> &argv, std::vector<std::string> &envp)
+    : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd,
+        argv, envp)
+{
+
+    // XXX all the below need to be updated for SPARC - Ali
+    brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize();
+    brk_point = roundUp(brk_point, VMPageSize);
+
+    // Set up stack.  On Alpha, stack goes below text section.  This
+    // code should get moved to some architecture-specific spot.
+    stack_base = objFile->textBase() - (409600+4096);
+
+    // Set up region for mmaps.  Tru64 seems to start just above 0 and
+    // grow up from there.
+    mmap_start = mmap_end = 0x10000;
+
+    // Set pointer for next thread stack.  Reserve 8M for main stack.
+    next_thread_stack_base = stack_base - (8 * 1024 * 1024);
+
+}
+
+void
+MipsLiveProcess::startup()
+{
+    argsInit(MachineBytes, VMPageSize);
+}
+
+
+
+
+BEGIN_DECLARE_SIM_OBJECT_PARAMS(MipsLiveProcess)
+
+    VectorParam<string> cmd;
+    Param<string> executable;
+    Param<string> input;
+    Param<string> output;
+    VectorParam<string> env;
+    SimObjectParam<System *> system;
+
+END_DECLARE_SIM_OBJECT_PARAMS(MipsLiveProcess)
+
+
+BEGIN_INIT_SIM_OBJECT_PARAMS(MipsLiveProcess)
+
+    INIT_PARAM(cmd, "command line (executable plus arguments)"),
+    INIT_PARAM(executable, "executable (overrides cmd[0] if set)"),
+    INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"),
+    INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"),
+    INIT_PARAM(env, "environment settings"),
+    INIT_PARAM(system, "system")
+
+END_INIT_SIM_OBJECT_PARAMS(MipsLiveProcess)
+
+
+CREATE_SIM_OBJECT(MipsLiveProcess)
+{
+    string in = input;
+    string out = output;
+
+    // initialize file descriptors to default: same as simulator
+    int stdin_fd, stdout_fd, stderr_fd;
+
+    if (in == "stdin" || in == "cin")
+        stdin_fd = STDIN_FILENO;
+    else
+        stdin_fd = Process::openInputFile(input);
+
+    if (out == "stdout" || out == "cout")
+        stdout_fd = STDOUT_FILENO;
+    else if (out == "stderr" || out == "cerr")
+        stdout_fd = STDERR_FILENO;
+    else
+        stdout_fd = Process::openOutputFile(out);
+
+    stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
+
+    return MipsLiveProcess::create(getInstanceName(), system,
+                               stdin_fd, stdout_fd, stderr_fd,
+                               (string)executable == "" ? cmd[0] : executable,
+                               cmd, env);
+}
+
+
+REGISTER_SIM_OBJECT("MipsLiveProcess", MipsLiveProcess)
+
 
index 8f5d74d967a88ba6fc1822a9c7b691eb81d53a37..2a13dc95505e8366b2e7d2369ae32eefa237fe45 100644 (file)
 
 #include <string>
 #include <vector>
+#include "sim/process.hh"
 
 class LiveProcess;
 class ObjectFile;
 class System;
 
-namespace MipsISA
+class MipsLiveProcess : public LiveProcess
 {
+  protected:
+    MipsLiveProcess(const std::string &nm, ObjectFile *objFile,
+                System *_system, int stdin_fd, int stdout_fd, int stderr_fd,
+                std::vector<std::string> &argv,
+                std::vector<std::string> &envp);
 
-LiveProcess *
-createProcess(const std::string &nm, ObjectFile * objFile,System * system,
-              int stdin_fd, int stdout_fd, int stderr_fd,
-              std::vector<std::string> &argv, std::vector<std::string> &envp);
+    void startup();
+
+  public:
+    // this function is used to create the LiveProcess object, since
+    // we can't tell which subclass of LiveProcess to use until we
+    // open and look at the object file.
+    static MipsLiveProcess *create(const std::string &nm,
+                               System *_system,
+                               int stdin_fd, int stdout_fd, int stderr_fd,
+                               std::string executable,
+                               std::vector<std::string> &argv,
+                               std::vector<std::string> &envp);
+
+};
 
-} // namespace MipsISA
 
 #endif // __MIPS_PROCESS_HH__
index 3e7800910cd58de8e235b3a4881759800c78b9ba..23e3dad74a54e8abc4c7a30a075afed909573f63 100644 (file)
@@ -132,6 +132,7 @@ namespace SparcISA
 
     const int BranchPredAddrShiftAmt = 2;
 
+    const int MachineBytes = 8;
     const int WordBytes = 4;
     const int HalfwordBytes = 2;
     const int ByteBytes = 1;
index 30c786ad39eca20247a94f6a20858b425e5636ba..cb056eadc6a7a8204d2d158fe5e91fb116ba0e16 100644 (file)
@@ -352,7 +352,7 @@ SparcLinuxProcess::SparcLinuxProcess(const std::string &name,
                                      int stderr_fd,
                                      std::vector<std::string> &argv,
                                      std::vector<std::string> &envp)
-    : LiveProcess(name, objFile, system,
+    : SparcLiveProcess(name, objFile, system,
             stdin_fd, stdout_fd, stderr_fd, argv, envp),
      Num_Syscall_Descs(sizeof(syscallDescs) / sizeof(SyscallDesc))
 {
index 36b2819daad9c6ed0b7d6c24052e16e8f20bcd3a..1565ab549ad08dafc7e82779c24b34db48acbf5f 100644 (file)
 #ifndef __SPARC_LINUX_PROCESS_HH__
 #define __SPARC_LINUX_PROCESS_HH__
 
+#include "arch/sparc/process.hh"
 #include "sim/process.hh"
 
+namespace SparcISA {
 
 /// A process with emulated SPARC/Linux syscalls.
-class SparcLinuxProcess : public LiveProcess
+class SparcLinuxProcess : public SparcLiveProcess
 {
   public:
     /// Constructor.
@@ -55,5 +57,5 @@ class SparcLinuxProcess : public LiveProcess
     const int Num_Syscall_Descs;
 };
 
-
+} // namespace SparcISA
 #endif // __ALPHA_LINUX_PROCESS_HH__
index 174df2be4357e3d901354aec89c0beda3bbd54fc..c7e08358dc503a18fa17f7e8d9346df514abd2e5 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "arch/sparc/isa_traits.hh"
 #include "arch/sparc/process.hh"
 #include "arch/sparc/linux/process.hh"
 #include "base/loader/object_file.hh"
 #include "base/misc.hh"
+#include "cpu/exec_context.hh"
+#include "sim/builder.hh"
+#include "sim/system.hh"
 
 using namespace std;
+using namespace SparcISA;
 
-namespace SparcISA
+SparcLiveProcess *
+SparcLiveProcess::create(const std::string &nm, System *system, int stdin_fd,
+        int stdout_fd, int stderr_fd, std::string executable,
+        std::vector<std::string> &argv, std::vector<std::string> &envp)
 {
+    SparcLiveProcess *process = NULL;
+
+    ObjectFile *objFile = createObjectFile(executable);
+    if (objFile == NULL) {
+        fatal("Can't load object file %s", executable);
+    }
+
 
-LiveProcess *
-createProcess(const string &nm, ObjectFile * objFile, System * system,
-        int stdin_fd, int stdout_fd, int stderr_fd,
-        vector<string> &argv, vector<string> &envp)
-{
-    LiveProcess * process = NULL;
     if (objFile->getArch() != ObjectFile::SPARC)
         fatal("Object file does not match architecture.");
     switch (objFile->getOpSys()) {
@@ -55,7 +64,98 @@ createProcess(const string &nm, ObjectFile * objFile, System * system,
       default:
         fatal("Unknown/unsupported operating system.");
     }
+
+    if (process == NULL)
+        fatal("Unknown error creating process object.");
     return process;
 }
 
-} // namespace SparcISA
+SparcLiveProcess::SparcLiveProcess(const std::string &nm, ObjectFile *objFile,
+        System *_system, int stdin_fd, int stdout_fd, int stderr_fd,
+        std::vector<std::string> &argv, std::vector<std::string> &envp)
+    : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd,
+        argv, envp)
+{
+
+    // XXX all the below need to be updated for SPARC - Ali
+    brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize();
+    brk_point = roundUp(brk_point, VMPageSize);
+
+    // Set up stack.  On Alpha, stack goes below text section.  This
+    // code should get moved to some architecture-specific spot.
+    stack_base = objFile->textBase() - (409600+4096);
+
+    // Set up region for mmaps.  Tru64 seems to start just above 0 and
+    // grow up from there.
+    mmap_start = mmap_end = 0x10000;
+
+    // Set pointer for next thread stack.  Reserve 8M for main stack.
+    next_thread_stack_base = stack_base - (8 * 1024 * 1024);
+
+}
+
+void
+SparcLiveProcess::startup()
+{
+    argsInit(MachineBytes, VMPageSize);
+}
+
+
+
+
+BEGIN_DECLARE_SIM_OBJECT_PARAMS(SparcLiveProcess)
+
+    VectorParam<string> cmd;
+    Param<string> executable;
+    Param<string> input;
+    Param<string> output;
+    VectorParam<string> env;
+    SimObjectParam<System *> system;
+
+END_DECLARE_SIM_OBJECT_PARAMS(SparcLiveProcess)
+
+
+BEGIN_INIT_SIM_OBJECT_PARAMS(SparcLiveProcess)
+
+    INIT_PARAM(cmd, "command line (executable plus arguments)"),
+    INIT_PARAM(executable, "executable (overrides cmd[0] if set)"),
+    INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"),
+    INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"),
+    INIT_PARAM(env, "environment settings"),
+    INIT_PARAM(system, "system")
+
+END_INIT_SIM_OBJECT_PARAMS(SparcLiveProcess)
+
+
+CREATE_SIM_OBJECT(SparcLiveProcess)
+{
+    string in = input;
+    string out = output;
+
+    // initialize file descriptors to default: same as simulator
+    int stdin_fd, stdout_fd, stderr_fd;
+
+    if (in == "stdin" || in == "cin")
+        stdin_fd = STDIN_FILENO;
+    else
+        stdin_fd = Process::openInputFile(input);
+
+    if (out == "stdout" || out == "cout")
+        stdout_fd = STDOUT_FILENO;
+    else if (out == "stderr" || out == "cerr")
+        stdout_fd = STDERR_FILENO;
+    else
+        stdout_fd = Process::openOutputFile(out);
+
+    stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
+
+    return SparcLiveProcess::create(getInstanceName(), system,
+                               stdin_fd, stdout_fd, stderr_fd,
+                               (string)executable == "" ? cmd[0] : executable,
+                               cmd, env);
+}
+
+
+REGISTER_SIM_OBJECT("SparcLiveProcess", SparcLiveProcess)
+
+
index 1c2d86b6a550f9aa5b9ddb940ba85d9103add8ff..cc4d0ae0a4cb462aec07ab0ccf3dccff41cb4049 100644 (file)
 
 #include <string>
 #include <vector>
+#include "sim/process.hh"
 
-class LiveProcess;
 class ObjectFile;
 class System;
 
-namespace SparcISA
+class SparcLiveProcess : public LiveProcess
 {
+  protected:
+    SparcLiveProcess(const std::string &nm, ObjectFile *objFile,
+                System *_system, int stdin_fd, int stdout_fd, int stderr_fd,
+                std::vector<std::string> &argv,
+                std::vector<std::string> &envp);
 
-LiveProcess *
-createProcess(const std::string &nm, ObjectFile * objFile, System * system,
-              int stdin_fd, int stdout_fd, int stderr_fd,
-              std::vector<std::string> &argv, std::vector<std::string> &envp);
+    void startup();
 
-} // namespace SparcISA
+  public:
+    // this function is used to create the LiveProcess object, since
+    // we can't tell which subclass of LiveProcess to use until we
+    // open and look at the object file.
+    static SparcLiveProcess *create(const std::string &nm,
+                               System *_system,
+                               int stdin_fd, int stdout_fd, int stderr_fd,
+                               std::string executable,
+                               std::vector<std::string> &argv,
+                               std::vector<std::string> &envp);
+
+};
 
 #endif // __SPARC_PROCESS_HH__
index 0982ba4f2ca6f2268ef0e8ce42a1320a4c638486..86a44313a5121845bdd4c8a983d689537f5c01e4 100644 (file)
@@ -1,6 +1,6 @@
 from m5 import *
 
-class HelloWorld(LiveProcess):
+class HelloWorld(AlphaLiveProcess):
     executable = '../configs/test/hello'
     cmd = 'hello'
 
index ea2929a81b9ac85c3308e6dd40b6947b62114d4a..947e7896a7a78b6d5b93fc89a7dca76c8bc1b846 100644 (file)
@@ -71,6 +71,7 @@ class Port
 {
   public:
 
+    virtual ~Port() {};
     // mey be better to use subclasses & RTTI?
     /** Holds the ports status.  Keeps track if it is blocked, or has
         calculated a range change. */
index def70dbaa5b7858cd7e1ab2516af0d6588ce41b1..60b00229e111e7f39115e226c2c757d1a8e97d01 100644 (file)
@@ -12,6 +12,15 @@ class LiveProcess(Process):
     env = VectorParam.String('', "environment settings")
     input = Param.String('cin', "filename for stdin")
 
+class AlphaLiveProcess(LiveProcess):
+    type = 'AlphaLiveProcess'
+
+class SparcLiveProcess(LiveProcess):
+    type = 'SparcLiveProcess'
+
+class MipsLiveProcess(LiveProcess):
+    type = 'MipsLiveProcess'
+
 class EioProcess(Process):
     type = 'EioProcess'
     chkpt = Param.String('', "EIO checkpoint file name (optional)")
index c5d8801ab0f6d318614bd0b7562b6d7e2deab6b3..cec11f15e88b3b265dee508bc9e74c7c97d4650c 100644 (file)
@@ -79,11 +79,11 @@ static inline uint64_t swap_byte(uint64_t x) {return swap_byte64(x);}
 static inline int64_t swap_byte(int64_t x) {return swap_byte64((uint64_t)x);}
 static inline uint32_t swap_byte(uint32_t x) {return swap_byte32(x);}
 static inline int32_t swap_byte(int32_t x) {return swap_byte32((uint32_t)x);}
-#if defined(__APPLE__)
+//#if defined(__APPLE__)
 static inline long swap_byte(long x) {return swap_byte32((long)x);}
 static inline unsigned long swap_byte(unsigned long x)
                                 { return swap_byte32((unsigned long)x);}
-#endif
+//#endif
 static inline uint16_t swap_byte(uint16_t x) {return swap_byte32(x);}
 static inline int16_t swap_byte(int16_t x) {return swap_byte16((uint16_t)x);}
 static inline uint8_t swap_byte(uint8_t x) {return x;}
index 260abcfe2cf92b6c16241c71f21fed24554f0017..7b27c42746c610afdcc2aec966a7585c8a6190f7 100644 (file)
@@ -47,8 +47,6 @@
 #include "sim/syscall_emul.hh"
 #include "sim/system.hh"
 
-#include "arch/process.hh"
-
 using namespace std;
 using namespace TheISA;
 
@@ -279,20 +277,6 @@ LiveProcess::LiveProcess(const string &nm, ObjectFile *_objFile,
 {
     prog_fname = argv[0];
 
-    brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize();
-    brk_point = roundUp(brk_point, VMPageSize);
-
-    // Set up stack.  On Alpha, stack goes below text section.  This
-    // code should get moved to some architecture-specific spot.
-    stack_base = objFile->textBase() - (409600+4096);
-
-    // Set up region for mmaps.  Tru64 seems to start just above 0 and
-    // grow up from there.
-    mmap_start = mmap_end = 0x10000;
-
-    // Set pointer for next thread stack.  Reserve 8M for main stack.
-    next_thread_stack_base = stack_base - (8 * 1024 * 1024);
-
     // load up symbols, if any... these may be used for debugging or
     // profiling.
     if (!debugSymbolTable) {
@@ -307,7 +291,7 @@ LiveProcess::LiveProcess(const string &nm, ObjectFile *_objFile,
 }
 
 void
-LiveProcess::startup()
+LiveProcess::argsInit(int intSize, int pageSize)
 {
     Process::startup();
 
@@ -315,8 +299,8 @@ LiveProcess::startup()
     objFile->loadSections(initVirtMem);
 
     // Calculate how much space we need for arg & env arrays.
-    int argv_array_size = sizeof(Addr) * (argv.size() + 1);
-    int envp_array_size = sizeof(Addr) * (envp.size() + 1);
+    int argv_array_size = intSize * (argv.size() + 1);
+    int envp_array_size = intSize * (envp.size() + 1);
     int arg_data_size = 0;
     for (int i = 0; i < argv.size(); ++i) {
         arg_data_size += argv[i].size() + 1;
@@ -335,11 +319,11 @@ LiveProcess::startup()
     // set bottom of stack
     stack_min = stack_base - space_needed;
     // align it
-    stack_min &= ~7;
+    stack_min &= ~(intSize-1);
     stack_size = stack_base - stack_min;
     // map memory
-    pTable->allocate(roundDown(stack_min, VMPageSize),
-                     roundUp(stack_size, VMPageSize));
+    pTable->allocate(roundDown(stack_min, pageSize),
+                     roundUp(stack_size, pageSize));
 
     // map out initial stack contents
     Addr argv_array_base = stack_min + sizeof(uint64_t); // room for argc
@@ -349,8 +333,14 @@ LiveProcess::startup()
 
     // write contents to stack
     uint64_t argc = argv.size();
-    argc = htog(argc);
-    initVirtMem->writeBlob(stack_min, (uint8_t*)&argc, sizeof(uint64_t));
+    if (intSize == 8)
+        argc = htog((uint64_t)argc);
+    else if (intSize == 4)
+        argc = htog((uint32_t)argc);
+    else
+        panic("Unknown int size");
+
+    initVirtMem->writeBlob(stack_min, (uint8_t*)&argc, intSize);
 
     copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
     copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
@@ -358,7 +348,6 @@ LiveProcess::startup()
     execContexts[0]->setIntReg(ArgumentReg0, argc);
     execContexts[0]->setIntReg(ArgumentReg1, argv_array_base);
     execContexts[0]->setIntReg(StackPointerReg, stack_min);
-    execContexts[0]->setIntReg(GlobalPointerReg, objFile->globalPointer());
 
     Addr prog_entry = objFile->entryPoint();
     execContexts[0]->setPC(prog_entry);
@@ -382,82 +371,4 @@ LiveProcess::syscall(ExecContext *xc)
     desc->doSyscall(callnum, this, xc);
 }
 
-
-LiveProcess *
-LiveProcess::create(const string &nm, System *system,
-                    int stdin_fd, int stdout_fd, int stderr_fd,
-                    string executable,
-                    vector<string> &argv, vector<string> &envp)
-{
-    LiveProcess *process = NULL;
-    ObjectFile *objFile = createObjectFile(executable);
-    if (objFile == NULL) {
-        fatal("Can't load object file %s", executable);
-    }
-
-    // set up syscall emulation pointer for the current ISA
-    process = createProcess(nm, objFile, system,
-                            stdin_fd, stdout_fd, stderr_fd,
-                            argv, envp);
-
-    if (process == NULL)
-        fatal("Unknown error creating process object.");
-
-    return process;
-}
-
-
-
-BEGIN_DECLARE_SIM_OBJECT_PARAMS(LiveProcess)
-
-    VectorParam<string> cmd;
-    Param<string> executable;
-    Param<string> input;
-    Param<string> output;
-    VectorParam<string> env;
-    SimObjectParam<System *> system;
-
-END_DECLARE_SIM_OBJECT_PARAMS(LiveProcess)
-
-
-BEGIN_INIT_SIM_OBJECT_PARAMS(LiveProcess)
-
-    INIT_PARAM(cmd, "command line (executable plus arguments)"),
-    INIT_PARAM(executable, "executable (overrides cmd[0] if set)"),
-    INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"),
-    INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"),
-    INIT_PARAM(env, "environment settings"),
-    INIT_PARAM(system, "system")
-
-END_INIT_SIM_OBJECT_PARAMS(LiveProcess)
-
-
-CREATE_SIM_OBJECT(LiveProcess)
-{
-    string in = input;
-    string out = output;
-
-    // initialize file descriptors to default: same as simulator
-    int stdin_fd, stdout_fd, stderr_fd;
-
-    if (in == "stdin" || in == "cin")
-        stdin_fd = STDIN_FILENO;
-    else
-        stdin_fd = Process::openInputFile(input);
-
-    if (out == "stdout" || out == "cout")
-        stdout_fd = STDOUT_FILENO;
-    else if (out == "stderr" || out == "cerr")
-        stdout_fd = STDERR_FILENO;
-    else
-        stdout_fd = Process::openOutputFile(out);
-
-    stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
-
-    return LiveProcess::create(getInstanceName(), system,
-                               stdin_fd, stdout_fd, stderr_fd,
-                               (string)executable == "" ? cmd[0] : executable,
-                               cmd, env);
-}
-
-REGISTER_SIM_OBJECT("LiveProcess", LiveProcess)
+DEFINE_SIM_OBJECT_CLASS_NAME("LiveProcess", LiveProcess);
index 68312f11576a57ab9070cb47db2eebb75182d465..b5b9d18b34e99e913873f2be3241124386bb1d15 100644 (file)
@@ -174,19 +174,9 @@ class LiveProcess : public Process
                 std::vector<std::string> &argv,
                 std::vector<std::string> &envp);
 
-    void startup();
+    void argsInit(int intSize, int pageSize);
 
   public:
-    // this function is used to create the LiveProcess object, since
-    // we can't tell which subclass of LiveProcess to use until we
-    // open and look at the object file.
-    static LiveProcess *create(const std::string &nm,
-                               System *_system,
-                               int stdin_fd, int stdout_fd, int stderr_fd,
-                               std::string executable,
-                               std::vector<std::string> &argv,
-                               std::vector<std::string> &envp);
-
     virtual void syscall(ExecContext *xc);
 
     virtual SyscallDesc* getDesc(int callnum) = 0;
index 3dedb7c5e59d7e46a739d311b3e44c66030c4748..d13591c06e81ce937f96ec5ae6944286479a79e8 100644 (file)
 #include <iostream>
 
 #include "sim/syscall_emul.hh"
+#include "base/chunk_generator.hh"
 #include "base/trace.hh"
 #include "cpu/exec_context.hh"
 #include "cpu/base.hh"
+#include "mem/page_table.hh"
 #include "sim/process.hh"
 
 #include "sim/sim_events.hh"
@@ -98,11 +100,18 @@ getpagesizeFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
 SyscallReturn
 obreakFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
 {
+    Addr junk;
+
     // change brk addr to first arg
     Addr new_brk = xc->getSyscallArg(0);
-    if (new_brk != 0)
-    {
-        p->brk_point = xc->getSyscallArg(0);
+    if (new_brk != 0) {
+        for (ChunkGenerator gen(p->brk_point, new_brk - p->brk_point,
+                                VMPageSize); !gen.done(); gen.next()) {
+            if (!p->pTable->translate(gen.addr(), junk))
+                p->pTable->allocate(roundDown(gen.addr(), VMPageSize),
+                                    VMPageSize);
+        }
+        p->brk_point = new_brk;
     }
     DPRINTF(SyscallVerbose, "Break Point changed to: %#X\n", p->brk_point);
     return p->brk_point;
index 9554ab3185a65504a786b1c76ab0987bbff202b5..ae1196f03f5596e70b050109955648edc43e8fd0 100644 (file)
 #endif
 #include <sys/uio.h>
 
-#include "base/intmath.hh"     // for RoundUp
-#include "mem/translating_port.hh"
 #include "arch/isa_traits.hh"  // for Addr
+#include "base/chunk_generator.hh"
+#include "base/intmath.hh"     // for RoundUp
 #include "base/misc.hh"
 #include "base/trace.hh"
-#include "cpu/exec_context.hh"
 #include "cpu/base.hh"
+#include "cpu/exec_context.hh"
+#include "mem/translating_port.hh"
+#include "mem/page_table.hh"
 #include "sim/process.hh"
 
 ///
@@ -698,10 +700,15 @@ mmapFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
     int flags = xc->getSyscallArg(3);
     // int fd = p->sim_fd(xc->getSyscallArg(4));
     // int offset = xc->getSyscallArg(5);
+    Addr junk;
 
     if (start == 0) {
         // user didn't give an address... pick one from our "mmap region"
         start = p->mmap_end;
+        for (ChunkGenerator gen(start, roundUp(length, TheISA::VMPageSize), TheISA::VMPageSize); !gen.done(); gen.next()) {
+            if (!p->pTable->translate(gen.addr(), junk))
+                p->pTable->allocate(roundDown(gen.addr(), TheISA::VMPageSize), TheISA::VMPageSize);
+        }
         p->mmap_end += roundUp(length, TheISA::VMPageSize);
         if (p->nxm_start != 0) {
             //If we have an nxm space, make sure we haven't colided