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