blob: fd88de6997e4dd0a85550604ea5f3929a60c2dd8 [file] [log] [blame]
Yabin Cui76769e52015-07-13 12:23:54 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SIMPLE_PERF_PERF_REGS_H_
18#define SIMPLE_PERF_PERF_REGS_H_
19
Yabin Cui8ca8ae82015-07-13 21:41:05 -070020#if defined(USE_BIONIC_UAPI_HEADERS)
21#include <uapi/asm-x86/asm/perf_regs.h>
22#include <uapi/asm-arm/asm/perf_regs.h>
23#define perf_event_arm_regs perf_event_arm64_regs
24#include <uapi/asm-arm64/asm/perf_regs.h>
25#else
Yabin Cui76769e52015-07-13 12:23:54 -070026#include <asm-x86/asm/perf_regs.h>
27#include <asm-arm/asm/perf_regs.h>
28#define perf_event_arm_regs perf_event_arm64_regs
29#include <asm-arm64/asm/perf_regs.h>
Yabin Cui8ca8ae82015-07-13 21:41:05 -070030#endif
31
Yabin Cui76769e52015-07-13 12:23:54 -070032#include <stdint.h>
33#include <string>
Yabin Cui3c8c2132015-08-13 20:30:20 -070034#include <vector>
Yabin Cui76769e52015-07-13 12:23:54 -070035
Yabin Cui417df292016-11-16 12:26:13 -080036#include "perf_event.h"
37
Yabin Cui76769e52015-07-13 12:23:54 -070038enum ArchType {
39 ARCH_X86_32,
40 ARCH_X86_64,
41 ARCH_ARM,
42 ARCH_ARM64,
Yabin Cuica7b9e72015-07-13 19:44:24 -070043 ARCH_UNSUPPORTED,
Yabin Cui76769e52015-07-13 12:23:54 -070044};
45
Yabin Cui3c8c2132015-08-13 20:30:20 -070046constexpr ArchType GetBuildArch() {
47#if defined(__i386__)
48 return ARCH_X86_32;
49#elif defined(__x86_64__)
50 return ARCH_X86_64;
51#elif defined(__aarch64__)
52 return ARCH_ARM64;
53#elif defined(__arm__)
54 return ARCH_ARM;
55#else
56 return ARCH_UNSUPPORTED;
57#endif
58}
59
Yabin Cui48460892016-03-18 12:30:31 -070060ArchType GetArchType(const std::string& arch);
Yabin Cui257d5e62016-03-30 16:21:47 -070061ArchType GetArchForAbi(ArchType machine_arch, int abi);
62std::string GetArchString(ArchType arch);
Yabin Cui4b6720d2016-03-31 14:39:19 -070063bool IsArchTheSame(ArchType arch1, ArchType arch2, bool strict_check);
Yabin Cui48460892016-03-18 12:30:31 -070064uint64_t GetSupportedRegMask(ArchType arch);
65std::string GetRegName(size_t regno, ArchType arch);
Yabin Cui76769e52015-07-13 12:23:54 -070066
Yabin Cui48460892016-03-18 12:30:31 -070067class ScopedCurrentArch {
68 public:
Chih-Hung Hsieh5674ed82016-07-12 11:35:16 -070069 explicit ScopedCurrentArch(ArchType arch) : saved_arch(current_arch) {
Yabin Cui48460892016-03-18 12:30:31 -070070 current_arch = arch;
Yabin Cui417df292016-11-16 12:26:13 -080071 current_arch32 = GetArchForAbi(arch, PERF_SAMPLE_REGS_ABI_32);
Yabin Cui48460892016-03-18 12:30:31 -070072 }
73 ~ScopedCurrentArch() {
74 current_arch = saved_arch;
Yabin Cui417df292016-11-16 12:26:13 -080075 current_arch32 = GetArchForAbi(saved_arch, PERF_SAMPLE_REGS_ABI_32);
Yabin Cui48460892016-03-18 12:30:31 -070076 }
77 static ArchType GetCurrentArch() {
78 return current_arch;
79 }
Yabin Cui417df292016-11-16 12:26:13 -080080 static ArchType GetCurrentArch32() {
81 return current_arch32;
82 }
Yabin Cui76769e52015-07-13 12:23:54 -070083
Yabin Cui48460892016-03-18 12:30:31 -070084 private:
85 ArchType saved_arch;
86 static ArchType current_arch;
Yabin Cui417df292016-11-16 12:26:13 -080087 static ArchType current_arch32;
Yabin Cui48460892016-03-18 12:30:31 -070088};
Yabin Cui76769e52015-07-13 12:23:54 -070089
Yabin Cui3c8c2132015-08-13 20:30:20 -070090struct RegSet {
91 uint64_t valid_mask;
92 uint64_t data[64];
93};
94
Yabin Cui417df292016-11-16 12:26:13 -080095RegSet CreateRegSet(int abi, uint64_t valid_mask, const uint64_t* valid_regs);
Yabin Cui3c8c2132015-08-13 20:30:20 -070096
97bool GetRegValue(const RegSet& regs, size_t regno, uint64_t* value);
Yabin Cui48460892016-03-18 12:30:31 -070098bool GetSpRegValue(const RegSet& regs, ArchType arch, uint64_t* value);
Yabin Cui3c8c2132015-08-13 20:30:20 -070099
Yabin Cui76769e52015-07-13 12:23:54 -0700100#endif // SIMPLE_PERF_PERF_REGS_H_