mips: Use a mips specific GuestABI for mips system calls.
authorGabe Black <gabeblack@google.com>
Sun, 8 Dec 2019 04:03:28 +0000 (20:03 -0800)
committerGabe Black <gabeblack@google.com>
Thu, 12 Mar 2020 01:35:34 +0000 (01:35 +0000)
Change-Id: Ice9fb867b47e56bc00b171399a82b2892b16c9e4
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23451
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
Maintainer: Gabe Black <gabeblack@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/arch/mips/linux/process.cc
src/arch/mips/linux/process.hh
src/arch/mips/process.cc
src/arch/mips/process.hh

index 03fcc87ab0516d5875f2dfeaf1a6c2d62f56d32b..b3deaecc4b8b13c15fca0c96ea93b0fd78f4610b 100644 (file)
@@ -151,7 +151,7 @@ setThreadAreaFunc(SyscallDesc *desc, int callnum, ThreadContext *tc, Addr addr)
     return 0;
 }
 
-SyscallDescABI<DefaultSyscallABI> MipsLinuxProcess::syscallDescs[] = {
+SyscallDescABI<MipsProcess::SyscallABI> MipsLinuxProcess::syscallDescs[] = {
     /*  0 */ { "syscall" },
     /*  1 */ { "exit", exitFunc },
     /*  2 */ { "fork" },
index fa54701e78de328b725e79e985dffb7889633fd0..239b88b2a57e5d812cc6ff905d9838c191905e2a 100644 (file)
@@ -52,7 +52,7 @@ class MipsLinuxProcess : public MipsProcess
     void syscall(ThreadContext *tc, Fault *fault) override;
 
     /// Array of syscall descriptors, indexed by call number.
-    static SyscallDescABI<DefaultSyscallABI> syscallDescs[];
+    static SyscallDescABI<SyscallABI> syscallDescs[];
     const int Num_Syscall_Descs;
 };
 
index b9385337b448ad6d28d1fb56589e0caaabc8005b..93b64ffa3fe5c3c2351772ed417019259a2a7df8 100644 (file)
@@ -211,3 +211,7 @@ MipsProcess::setSyscallReturn(ThreadContext *tc, SyscallReturn sysret)
     if (sysret.count() > 1)
         tc->setIntReg(SyscallPseudoReturnReg, sysret.value2());
 }
+
+const std::vector<int> MipsProcess::SyscallABI::ArgumentRegs = {
+    4, 5, 6, 7, 8, 9
+};
index 8b093d37b23053617e4633ccec2b44dd1feac5da..c1539794479537fcb280a33cfa3002df1da71ed8 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "mem/page_table.hh"
 #include "sim/process.hh"
+#include "sim/syscall_abi.hh"
 
 class ObjectFile;
 
@@ -52,6 +53,39 @@ class MipsProcess : public Process
     /// Explicitly import the otherwise hidden getSyscallArg
     using Process::getSyscallArg;
     void setSyscallReturn(ThreadContext *tc, SyscallReturn return_value);
+
+    struct SyscallABI : public GenericSyscallABI64
+    {
+        static const std::vector<int> ArgumentRegs;
+    };
+};
+
+namespace GuestABI
+{
+
+template <>
+struct Result<MipsProcess::SyscallABI, SyscallReturn>
+{
+    static void
+    store(ThreadContext *tc, const SyscallReturn &ret)
+    {
+        if (ret.suppressed() || ret.needsRetry())
+            return;
+
+        if (ret.successful()) {
+            // no error
+            tc->setIntReg(MipsISA::SyscallSuccessReg, 0);
+            tc->setIntReg(MipsISA::ReturnValueReg, ret.returnValue());
+        } else {
+            // got an error, return details
+            tc->setIntReg(MipsISA::SyscallSuccessReg, (uint32_t)(-1));
+            tc->setIntReg(MipsISA::ReturnValueReg, ret.errnoValue());
+        }
+        if (ret.count() > 1)
+            tc->setIntReg(MipsISA::SyscallPseudoReturnReg, ret.value2());
+    }
 };
 
+} // namespace GuestABI
+
 #endif // __MIPS_PROCESS_HH__