sim: Add a returnInto function to the SyscallDesc class.
[gem5.git] / src / sim / process.hh
index ae23de42052d2233a9551604006c39bdeb750a74..e40e741b9e5049a495b66ebe579eb48571fc1413 100644 (file)
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * Authors: Nathan Binkert
- *          Steve Reinhardt
- *          Brandon Potter
  */
 
 #ifndef __PROCESS_HH__
@@ -41,6 +37,7 @@
 #include <vector>
 
 #include "arch/registers.hh"
+#include "base/loader/memory_image.hh"
 #include "base/statistics.hh"
 #include "base/types.hh"
 #include "config/the_isa.hh"
@@ -62,6 +59,9 @@ class ThreadContext;
 
 class Process : public SimObject
 {
+  protected:
+    void doSyscall(int64_t callnum, ThreadContext *tc, Fault *fault);
+
   public:
     Process(ProcessParams *params, EmulationPageTable *pTable,
             ObjectFile *obj_file);
@@ -69,13 +69,11 @@ class Process : public SimObject
     void serialize(CheckpointOut &cp) const override;
     void unserialize(CheckpointIn &cp) override;
 
+    void init() override;
     void initState() override;
     DrainState drain() override;
 
-    virtual void syscall(int64_t callnum, ThreadContext *tc, Fault *fault);
-    virtual RegVal getSyscallArg(ThreadContext *tc, int &i) = 0;
-    virtual RegVal getSyscallArg(ThreadContext *tc, int &i, int width);
-    virtual void setSyscallArg(ThreadContext *tc, int i, RegVal val) = 0;
+    virtual void syscall(ThreadContext *tc, Fault *fault) = 0;
     virtual void setSyscallReturn(ThreadContext *tc,
                                   SyscallReturn return_value) = 0;
     virtual SyscallDesc *getDesc(int callnum) = 0;
@@ -125,9 +123,6 @@ class Process : public SimObject
         contextIds.push_back(context_id);
     }
 
-    // Find a free context to use
-    ThreadContext *findFreeContext();
-
     /**
      * After delegating a thread context to a child process
      * no longer should relate to the ThreadContext
@@ -181,7 +176,41 @@ class Process : public SimObject
 
     SETranslatingPortProxy initVirtMem; // memory proxy for initial image load
 
+    /**
+     * Each instance of a Loader subclass will have a chance to try to load
+     * an object file when tryLoaders is called. If they can't because they
+     * aren't compatible with it (wrong arch, wrong OS, etc), then they
+     * silently fail by returning nullptr so other loaders can try.
+     */
+    class Loader
+    {
+      public:
+        Loader();
+
+        /* Loader instances are singletons. */
+        Loader(const Loader &) = delete;
+        void operator=(const Loader &) = delete;
+
+        virtual ~Loader() {}
+
+        /**
+         * Each subclass needs to implement this method. If the loader is
+         * compatible with the passed in object file, it should return the
+         * created Process object corresponding to it. If not, it should fail
+         * silently and return nullptr. If there's a non-compatibliity related
+         * error like file IO errors, etc., those should fail non-silently
+         * with a panic or fail as normal.
+         */
+        virtual Process *load(ProcessParams *params, ObjectFile *obj_file) = 0;
+    };
+
+    // Try all the Loader instance's "load" methods one by one until one is
+    // successful. If none are, complain and fail.
+    static Process *tryLoaders(ProcessParams *params, ObjectFile *obj_file);
+
     ObjectFile *objFile;
+    MemoryImage image;
+    MemoryImage interpImage;
     std::vector<std::string> argv;
     std::vector<std::string> envp;
     std::string executable;