|
|
44a132 |
From 3516f05627b33cb2e6e74965650c6d6c043f78f9 Mon Sep 17 00:00:00 2001
|
|
|
44a132 |
From: Sumanth Korikkar <sumanthk@linux.ibm.com>
|
|
|
44a132 |
Date: Mon, 6 Apr 2020 09:23:34 +0200
|
|
|
44a132 |
Subject: [PATCH] bpftrace: Add s390x register support
|
|
|
44a132 |
|
|
|
44a132 |
Add s390x specific registers. This is needed for bpftrace builtins like argX,
|
|
|
44a132 |
regs(), retval etc. This commit provides various functions to perform proper
|
|
|
44a132 |
offset calculation from the pt_regs context. The builtin functions of
|
|
|
44a132 |
bpftrace uses these offset functions to generate the proper bytecode for s390x
|
|
|
44a132 |
|
|
|
44a132 |
Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
|
|
|
44a132 |
Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
|
|
|
44a132 |
---
|
|
|
44a132 |
src/arch/CMakeLists.txt | 3 ++
|
|
|
44a132 |
src/arch/s390.cpp | 85 +++++++++++++++++++++++++++++++++++++++++
|
|
|
44a132 |
2 files changed, 88 insertions(+)
|
|
|
44a132 |
create mode 100644 src/arch/s390.cpp
|
|
|
44a132 |
|
|
|
44a132 |
diff --git a/src/arch/CMakeLists.txt b/src/arch/CMakeLists.txt
|
|
|
44a132 |
index 7156276..51707cb 100644
|
|
|
44a132 |
--- a/src/arch/CMakeLists.txt
|
|
|
44a132 |
+++ b/src/arch/CMakeLists.txt
|
|
|
44a132 |
@@ -3,6 +3,9 @@ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
|
|
|
44a132 |
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64" OR
|
|
|
44a132 |
CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le")
|
|
|
44a132 |
add_library(arch ppc64.cpp)
|
|
|
44a132 |
+elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "s390" OR
|
|
|
44a132 |
+ CMAKE_SYSTEM_PROCESSOR STREQUAL "s390x")
|
|
|
44a132 |
+ add_library(arch s390.cpp)
|
|
|
44a132 |
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
|
|
|
44a132 |
add_library(arch x86_64.cpp)
|
|
|
44a132 |
else()
|
|
|
44a132 |
diff --git a/src/arch/s390.cpp b/src/arch/s390.cpp
|
|
|
44a132 |
new file mode 100644
|
|
|
44a132 |
index 0000000..a2278c8
|
|
|
44a132 |
--- /dev/null
|
|
|
44a132 |
+++ b/src/arch/s390.cpp
|
|
|
44a132 |
@@ -0,0 +1,85 @@
|
|
|
44a132 |
+#include "arch.h"
|
|
|
44a132 |
+
|
|
|
44a132 |
+#include <algorithm>
|
|
|
44a132 |
+#include <array>
|
|
|
44a132 |
+
|
|
|
44a132 |
+#define REQ_REGISTERS 19
|
|
|
44a132 |
+#define ARG_REGISTERS 5
|
|
|
44a132 |
+
|
|
|
44a132 |
+namespace bpftrace {
|
|
|
44a132 |
+namespace arch {
|
|
|
44a132 |
+
|
|
|
44a132 |
+// clang-format off
|
|
|
44a132 |
+static std::array<std::string, REQ_REGISTERS> registers = {
|
|
|
44a132 |
+ // Breakpoint event address
|
|
|
44a132 |
+ "arg",
|
|
|
44a132 |
+ "pswmask",
|
|
|
44a132 |
+ // Instruction address
|
|
|
44a132 |
+ "pswaddr",
|
|
|
44a132 |
+ "r0",
|
|
|
44a132 |
+ "r1",
|
|
|
44a132 |
+ "r2",
|
|
|
44a132 |
+ "r3",
|
|
|
44a132 |
+ "r4",
|
|
|
44a132 |
+ "r5",
|
|
|
44a132 |
+ "r6",
|
|
|
44a132 |
+ "r7",
|
|
|
44a132 |
+ "r8",
|
|
|
44a132 |
+ "r9",
|
|
|
44a132 |
+ "r10",
|
|
|
44a132 |
+ "r11",
|
|
|
44a132 |
+ "r12",
|
|
|
44a132 |
+ "r13",
|
|
|
44a132 |
+ "r14",
|
|
|
44a132 |
+ "r15",
|
|
|
44a132 |
+};
|
|
|
44a132 |
+
|
|
|
44a132 |
+static std::array<std::string, ARG_REGISTERS> arg_registers = {
|
|
|
44a132 |
+ "r2",
|
|
|
44a132 |
+ "r3",
|
|
|
44a132 |
+ "r4",
|
|
|
44a132 |
+ "r5",
|
|
|
44a132 |
+ "r6",
|
|
|
44a132 |
+};
|
|
|
44a132 |
+// clang-format on
|
|
|
44a132 |
+
|
|
|
44a132 |
+int offset(std::string reg_name)
|
|
|
44a132 |
+{
|
|
|
44a132 |
+ auto it = find(registers.begin(), registers.end(), reg_name);
|
|
|
44a132 |
+ if (it == registers.end())
|
|
|
44a132 |
+ return -1;
|
|
|
44a132 |
+ return distance(registers.begin(), it);
|
|
|
44a132 |
+}
|
|
|
44a132 |
+
|
|
|
44a132 |
+int max_arg()
|
|
|
44a132 |
+{
|
|
|
44a132 |
+ return arg_registers.size() - 1;
|
|
|
44a132 |
+}
|
|
|
44a132 |
+
|
|
|
44a132 |
+int arg_offset(int arg_num)
|
|
|
44a132 |
+{
|
|
|
44a132 |
+ return offset(arg_registers.at(arg_num));
|
|
|
44a132 |
+}
|
|
|
44a132 |
+
|
|
|
44a132 |
+int ret_offset()
|
|
|
44a132 |
+{
|
|
|
44a132 |
+ return offset("r2");
|
|
|
44a132 |
+}
|
|
|
44a132 |
+
|
|
|
44a132 |
+int pc_offset()
|
|
|
44a132 |
+{
|
|
|
44a132 |
+ return offset("pswaddr");
|
|
|
44a132 |
+}
|
|
|
44a132 |
+
|
|
|
44a132 |
+int sp_offset()
|
|
|
44a132 |
+{
|
|
|
44a132 |
+ return offset("r15");
|
|
|
44a132 |
+}
|
|
|
44a132 |
+
|
|
|
44a132 |
+std::string name()
|
|
|
44a132 |
+{
|
|
|
44a132 |
+ return std::string("s390x");
|
|
|
44a132 |
+}
|
|
|
44a132 |
+
|
|
|
44a132 |
+} // namespace arch
|
|
|
44a132 |
+} // namespace bpftrace
|
|
|
44a132 |
--
|
|
|
44a132 |
2.25.3
|
|
|
44a132 |
|