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