Major changes to how SimObjects are created and initialized. Almost all
[gem5.git] / src / sim / process.cc
index 68239fa523016c450287251b358adbf193f87cef..c556ade127b09c711d179e2eb4be7966c66a86cf 100644 (file)
@@ -45,8 +45,9 @@
 #include "mem/page_table.hh"
 #include "mem/physical.hh"
 #include "mem/translating_port.hh"
-#include "sim/builder.hh"
+#include "params/LiveProcess.hh"
 #include "sim/process.hh"
+#include "sim/process_impl.hh"
 #include "sim/stats.hh"
 #include "sim/syscall_emul.hh"
 #include "sim/system.hh"
@@ -182,7 +183,8 @@ Process::startup()
 
     Port *mem_port;
     mem_port = system->physmem->getPort("functional");
-    initVirtMem = new TranslatingPort("process init port", pTable, true);
+    initVirtMem = new TranslatingPort("process init port", this,
+            TranslatingPort::Always);
     mem_port->setPeer(initVirtMem);
     initVirtMem->setPeer(mem_port);
 }
@@ -250,6 +252,29 @@ Process::sim_fd(int tgt_fd)
     return fd_map[tgt_fd];
 }
 
+bool
+Process::checkAndAllocNextPage(Addr vaddr)
+{
+    // if this is an initial write we might not have
+    if (vaddr >= stack_min && vaddr < stack_base) {
+        pTable->allocate(roundDown(vaddr, VMPageSize), VMPageSize);
+        return true;
+    }
+
+    // We've accessed the next page of the stack, so extend the stack
+    // to cover it.
+    if(vaddr < stack_min && vaddr >= stack_min - TheISA::PageBytes)
+    {
+        stack_min -= TheISA::PageBytes;
+        if(stack_base - stack_min > 8*1024*1024)
+            fatal("Over max stack size for one thread\n");
+        pTable->allocate(stack_min, TheISA::PageBytes);
+        warn("Increasing stack size by one page.");
+        return true;
+    }
+    return false;
+}
+
 void
 Process::serialize(std::ostream &os)
 {
@@ -287,14 +312,6 @@ Process::unserialize(Checkpoint *cp, const std::string &section)
 }
 
 
-//
-// need to declare these here since there is no concrete Process type
-// that can be constructed (i.e., no REGISTER_SIM_OBJECT() macro call,
-// which is where these get declared for concrete types).
-//
-DEFINE_SIM_OBJECT_CLASS_NAME("Process", Process)
-
-
 ////////////////////////////////////////////////////////////////////////
 //
 // LiveProcess member definitions
@@ -526,46 +543,8 @@ LiveProcess::create(const std::string &nm, System *system, int stdin_fd,
     return process;
 }
 
-
-BEGIN_DECLARE_SIM_OBJECT_PARAMS(LiveProcess)
-
-    VectorParam<string> cmd;
-    Param<string> executable;
-    Param<string> input;
-    Param<string> output;
-    VectorParam<string> env;
-    Param<string> cwd;
-    SimObjectParam<System *> system;
-    Param<uint64_t> uid;
-    Param<uint64_t> euid;
-    Param<uint64_t> gid;
-    Param<uint64_t> egid;
-    Param<uint64_t> pid;
-    Param<uint64_t> ppid;
-
-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(cwd, "current working directory"),
-    INIT_PARAM(system, "system"),
-    INIT_PARAM(uid, "user id"),
-    INIT_PARAM(euid, "effective user id"),
-    INIT_PARAM(gid, "group id"),
-    INIT_PARAM(egid, "effective group id"),
-    INIT_PARAM(pid, "process id"),
-    INIT_PARAM(ppid, "parent process id")
-
-END_INIT_SIM_OBJECT_PARAMS(LiveProcess)
-
-
-CREATE_SIM_OBJECT(LiveProcess)
+LiveProcess *
+LiveProcessParams::create()
 {
     string in = input;
     string out = output;
@@ -587,12 +566,9 @@ CREATE_SIM_OBJECT(LiveProcess)
 
     stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
 
-    return LiveProcess::create(getInstanceName(), system,
+    return LiveProcess::create(name, system,
                                stdin_fd, stdout_fd, stderr_fd,
                                (string)executable == "" ? cmd[0] : executable,
                                cmd, env, cwd,
                                uid, euid, gid, egid, pid, ppid);
 }
-
-
-REGISTER_SIM_OBJECT("LiveProcess", LiveProcess)