blob: 569a469cd9dcffa241307dc727e9cc3680a31443 [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)
Yabin Cui8ca8ae82015-07-13 21:41:05 -070021#include <uapi/asm-arm/asm/perf_regs.h>
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +020022#include <uapi/asm-x86/asm/perf_regs.h>
Yabin Cui8ca8ae82015-07-13 21:41:05 -070023#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-arm/asm/perf_regs.h>
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +020027#include <asm-x86/asm/perf_regs.h>
Yabin Cui76769e52015-07-13 12:23:54 -070028#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 Cuifaa7b922021-01-11 17:35:57 -080038namespace simpleperf {
39
Yabin Cui76769e52015-07-13 12:23:54 -070040enum ArchType {
41 ARCH_X86_32,
42 ARCH_X86_64,
43 ARCH_ARM,
44 ARCH_ARM64,
Yabin Cuica7b9e72015-07-13 19:44:24 -070045 ARCH_UNSUPPORTED,
Yabin Cui76769e52015-07-13 12:23:54 -070046};
47
Yabin Cui38076912021-08-16 16:59:09 -070048constexpr ArchType GetTargetArch() {
Yabin Cui3c8c2132015-08-13 20:30:20 -070049#if defined(__i386__)
50 return ARCH_X86_32;
51#elif defined(__x86_64__)
52 return ARCH_X86_64;
53#elif defined(__aarch64__)
54 return ARCH_ARM64;
55#elif defined(__arm__)
56 return ARCH_ARM;
57#else
58 return ARCH_UNSUPPORTED;
59#endif
60}
61
Yabin Cui48460892016-03-18 12:30:31 -070062ArchType GetArchType(const std::string& arch);
Yabin Cui257d5e62016-03-30 16:21:47 -070063ArchType GetArchForAbi(ArchType machine_arch, int abi);
64std::string GetArchString(ArchType arch);
Yabin Cui48460892016-03-18 12:30:31 -070065uint64_t GetSupportedRegMask(ArchType arch);
66std::string GetRegName(size_t regno, ArchType arch);
Yabin Cui76769e52015-07-13 12:23:54 -070067
Yabin Cui48460892016-03-18 12:30:31 -070068class ScopedCurrentArch {
69 public:
Chih-Hung Hsieh5674ed82016-07-12 11:35:16 -070070 explicit ScopedCurrentArch(ArchType arch) : saved_arch(current_arch) {
Yabin Cui48460892016-03-18 12:30:31 -070071 current_arch = arch;
72 }
73 ~ScopedCurrentArch() {
74 current_arch = saved_arch;
75 }
Thiébaud Weksteen4848ee02020-10-23 16:06:59 +020076 static ArchType GetCurrentArch() { return current_arch; }
Yabin Cui76769e52015-07-13 12:23:54 -070077
Yabin Cui48460892016-03-18 12:30:31 -070078 private:
79 ArchType saved_arch;
80 static ArchType current_arch;
81};
Yabin Cui76769e52015-07-13 12:23:54 -070082
Yabin Cui3c8c2132015-08-13 20:30:20 -070083struct RegSet {
Yabin Cui6e75e1b2018-02-06 13:42:16 -080084 ArchType arch;
85 // For each setting bit in valid_mask, there is a valid reg value in data[].
Yabin Cui3c8c2132015-08-13 20:30:20 -070086 uint64_t valid_mask;
Yabin Cui6e75e1b2018-02-06 13:42:16 -080087 // Stores reg values. Values for invalid regs are 0.
Yabin Cui3c8c2132015-08-13 20:30:20 -070088 uint64_t data[64];
Yabin Cui6e75e1b2018-02-06 13:42:16 -080089
90 RegSet(int abi, uint64_t valid_mask, const uint64_t* valid_regs);
91
92 bool GetRegValue(size_t regno, uint64_t* value) const;
93 bool GetSpRegValue(uint64_t* value) const;
94 bool GetIpRegValue(uint64_t* value) const;
Yabin Cui3c8c2132015-08-13 20:30:20 -070095};
96
Yabin Cuifaa7b922021-01-11 17:35:57 -080097} // namespace simpleperf
98
Yabin Cui76769e52015-07-13 12:23:54 -070099#endif // SIMPLE_PERF_PERF_REGS_H_