Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/23443 )
Change subject: x86: Define a local ABI for system calls.
......................................................................
x86: Define a local ABI for system calls.
These ABIs (one 32 bit and one 64 bit) take advantage of the
GenericSyscallABI and X86Linux::SyscallABI partial ABIs set up earlier.
This removes x86's dependence on the getSyscallArg and setSyscallReturn
Process methods.
Change-Id: Ia07834cea1afa827d77e590af5397e2a1e0e2099
---
M src/arch/x86/linux/linux.hh
M src/arch/x86/linux/process.cc
M src/arch/x86/linux/process.hh
3 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/src/arch/x86/linux/linux.hh b/src/arch/x86/linux/linux.hh
index fe8bd23..3fd1778 100644
--- a/src/arch/x86/linux/linux.hh
+++ b/src/arch/x86/linux/linux.hh
@@ -67,9 +67,7 @@
ctc->setIntReg(X86ISA::StackPointerReg, stack);
}
- class SyscallABI
- {
- };
+ class SyscallABI {};
};
namespace GuestABI
@@ -83,7 +81,10 @@
static void
store(ThreadContext *tc, const SyscallReturn &ret)
{
- tc->setIntReg(ABI::ReturnValueReg, ret.encodedValue());
+ if (ret.suppressed() || ret.needsRetry())
+ return;
+
+ tc->setIntReg(X86ISA::INTREG_RAX, ret.encodedValue());
}
};
diff --git a/src/arch/x86/linux/process.cc b/src/arch/x86/linux/process.cc
index 47e9f27..31b8989 100644
--- a/src/arch/x86/linux/process.cc
+++ b/src/arch/x86/linux/process.cc
@@ -252,7 +252,11 @@
return 0;
}
-static SyscallDescABI<DefaultSyscallABI> syscallDescs64[] = {
+const std::vector<IntRegIndex>
X86_64LinuxProcess::SyscallABI::ArgumentRegs = {
+ INTREG_RDI, INTREG_RSI, INTREG_RDX, INTREG_R10W, INTREG_R8W, INTREG_R9W
+};
+
+static SyscallDescABI<X86_64LinuxProcess::SyscallABI> syscallDescs64[] = {
/* 0 */ { "read", readFunc<X86Linux64> },
/* 1 */ { "write", writeFunc<X86Linux64> },
/* 2 */ { "open", openFunc<X86Linux64> },
@@ -592,7 +596,11 @@
X86_64Process::clone(old_tc, new_tc, (X86_64Process*)process, flags);
}
-static SyscallDescABI<DefaultSyscallABI> syscallDescs32[] = {
+const std::vector<IntRegIndex> I386LinuxProcess::SyscallABI::ArgumentRegs
= {
+ INTREG_EBX, INTREG_ECX, INTREG_EDX, INTREG_ESI, INTREG_EDI, INTREG_EBP
+};
+
+static SyscallDescABI<I386LinuxProcess::SyscallABI> syscallDescs32[] = {
/* 0 */ { "restart_syscall" },
/* 1 */ { "exit", exitFunc },
/* 2 */ { "fork" },
diff --git a/src/arch/x86/linux/process.hh b/src/arch/x86/linux/process.hh
index 5f3135d..d7df138 100644
--- a/src/arch/x86/linux/process.hh
+++ b/src/arch/x86/linux/process.hh
@@ -43,6 +43,7 @@
#include "arch/x86/linux/linux.hh"
#include "arch/x86/process.hh"
#include "sim/process.hh"
+#include "sim/syscall_abi.hh"
struct ProcessParams;
struct ThreadContext;
@@ -57,6 +58,11 @@
void syscall(ThreadContext *tc, Fault *fault) override;
void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process
*process,
RegVal flags);
+
+ struct SyscallABI : public GenericSyscallABI64, public
X86Linux::SyscallABI
+ {
+ static const std::vector<IntRegIndex> ArgumentRegs;
+ };
};
class I386LinuxProcess : public I386Process
@@ -67,7 +73,36 @@
void syscall(ThreadContext *tc, Fault *fault) override;
void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process
*process,
RegVal flags);
+
+ struct SyscallABI : public GenericSyscallABI32, public
X86Linux::SyscallABI
+ {
+ static const std::vector<IntRegIndex> ArgumentRegs;
+ };
};
} // namespace X86ISA
+
+namespace GuestABI
+{
+
+template <typename Arg>
+struct Argument<X86ISA::I386LinuxProcess::SyscallABI, Arg,
+ typename std::enable_if<
+ X86ISA::I386LinuxProcess::SyscallABI::IsWide<Arg>::value>::type>
+{
+ using ABI = X86ISA::I386LinuxProcess::SyscallABI;
+
+ static Arg
+ get(ThreadContext *tc, typename ABI::Position &position)
+ {
+ panic_if(position + 1 >= ABI::ArgumentRegs.size(),
+ "Ran out of syscall argument registers.");
+ auto low = ABI::ArgumentRegs[position++];
+ auto high = ABI::ArgumentRegs[position++];
+ return (Arg)ABI::mergeRegs(tc, low, high);
+ }
+};
+
+} // namespace GuestABI
+
#endif // __X86_LINUX_PROCESS_HH__
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/23443
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ia07834cea1afa827d77e590af5397e2a1e0e2099
Gerrit-Change-Number: 23443
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev