Yabin Cui | 76769e5 | 2015-07-13 12:23:54 -0700 | [diff] [blame] | 1 | /* |
| 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 Cui | 8ca8ae8 | 2015-07-13 21:41:05 -0700 | [diff] [blame] | 20 | #if defined(USE_BIONIC_UAPI_HEADERS) |
Yabin Cui | 8ca8ae8 | 2015-07-13 21:41:05 -0700 | [diff] [blame] | 21 | #include <uapi/asm-arm/asm/perf_regs.h> |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 22 | #include <uapi/asm-x86/asm/perf_regs.h> |
Yabin Cui | 8ca8ae8 | 2015-07-13 21:41:05 -0700 | [diff] [blame] | 23 | #define perf_event_arm_regs perf_event_arm64_regs |
| 24 | #include <uapi/asm-arm64/asm/perf_regs.h> |
| 25 | #else |
Yabin Cui | 76769e5 | 2015-07-13 12:23:54 -0700 | [diff] [blame] | 26 | #include <asm-arm/asm/perf_regs.h> |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 27 | #include <asm-x86/asm/perf_regs.h> |
Yabin Cui | 76769e5 | 2015-07-13 12:23:54 -0700 | [diff] [blame] | 28 | #define perf_event_arm_regs perf_event_arm64_regs |
| 29 | #include <asm-arm64/asm/perf_regs.h> |
Yabin Cui | 8ca8ae8 | 2015-07-13 21:41:05 -0700 | [diff] [blame] | 30 | #endif |
| 31 | |
Yabin Cui | 76769e5 | 2015-07-13 12:23:54 -0700 | [diff] [blame] | 32 | #include <stdint.h> |
| 33 | #include <string> |
Yabin Cui | 3c8c213 | 2015-08-13 20:30:20 -0700 | [diff] [blame] | 34 | #include <vector> |
Yabin Cui | 76769e5 | 2015-07-13 12:23:54 -0700 | [diff] [blame] | 35 | |
Yabin Cui | 417df29 | 2016-11-16 12:26:13 -0800 | [diff] [blame] | 36 | #include "perf_event.h" |
| 37 | |
Yabin Cui | faa7b92 | 2021-01-11 17:35:57 -0800 | [diff] [blame] | 38 | namespace simpleperf { |
| 39 | |
Yabin Cui | 76769e5 | 2015-07-13 12:23:54 -0700 | [diff] [blame] | 40 | enum ArchType { |
| 41 | ARCH_X86_32, |
| 42 | ARCH_X86_64, |
| 43 | ARCH_ARM, |
| 44 | ARCH_ARM64, |
Yabin Cui | ca7b9e7 | 2015-07-13 19:44:24 -0700 | [diff] [blame] | 45 | ARCH_UNSUPPORTED, |
Yabin Cui | 76769e5 | 2015-07-13 12:23:54 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
Yabin Cui | 3807691 | 2021-08-16 16:59:09 -0700 | [diff] [blame] | 48 | constexpr ArchType GetTargetArch() { |
Yabin Cui | 3c8c213 | 2015-08-13 20:30:20 -0700 | [diff] [blame] | 49 | #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 Cui | 4846089 | 2016-03-18 12:30:31 -0700 | [diff] [blame] | 62 | ArchType GetArchType(const std::string& arch); |
Yabin Cui | 257d5e6 | 2016-03-30 16:21:47 -0700 | [diff] [blame] | 63 | ArchType GetArchForAbi(ArchType machine_arch, int abi); |
| 64 | std::string GetArchString(ArchType arch); |
Yabin Cui | 4846089 | 2016-03-18 12:30:31 -0700 | [diff] [blame] | 65 | uint64_t GetSupportedRegMask(ArchType arch); |
| 66 | std::string GetRegName(size_t regno, ArchType arch); |
Yabin Cui | 76769e5 | 2015-07-13 12:23:54 -0700 | [diff] [blame] | 67 | |
Yabin Cui | 4846089 | 2016-03-18 12:30:31 -0700 | [diff] [blame] | 68 | class ScopedCurrentArch { |
| 69 | public: |
Chih-Hung Hsieh | 5674ed8 | 2016-07-12 11:35:16 -0700 | [diff] [blame] | 70 | explicit ScopedCurrentArch(ArchType arch) : saved_arch(current_arch) { |
Yabin Cui | 4846089 | 2016-03-18 12:30:31 -0700 | [diff] [blame] | 71 | current_arch = arch; |
| 72 | } |
| 73 | ~ScopedCurrentArch() { |
| 74 | current_arch = saved_arch; |
| 75 | } |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 76 | static ArchType GetCurrentArch() { return current_arch; } |
Yabin Cui | 76769e5 | 2015-07-13 12:23:54 -0700 | [diff] [blame] | 77 | |
Yabin Cui | 4846089 | 2016-03-18 12:30:31 -0700 | [diff] [blame] | 78 | private: |
| 79 | ArchType saved_arch; |
| 80 | static ArchType current_arch; |
| 81 | }; |
Yabin Cui | 76769e5 | 2015-07-13 12:23:54 -0700 | [diff] [blame] | 82 | |
Yabin Cui | 3c8c213 | 2015-08-13 20:30:20 -0700 | [diff] [blame] | 83 | struct RegSet { |
Yabin Cui | 6e75e1b | 2018-02-06 13:42:16 -0800 | [diff] [blame] | 84 | ArchType arch; |
| 85 | // For each setting bit in valid_mask, there is a valid reg value in data[]. |
Yabin Cui | 3c8c213 | 2015-08-13 20:30:20 -0700 | [diff] [blame] | 86 | uint64_t valid_mask; |
Yabin Cui | 6e75e1b | 2018-02-06 13:42:16 -0800 | [diff] [blame] | 87 | // Stores reg values. Values for invalid regs are 0. |
Yabin Cui | 3c8c213 | 2015-08-13 20:30:20 -0700 | [diff] [blame] | 88 | uint64_t data[64]; |
Yabin Cui | 6e75e1b | 2018-02-06 13:42:16 -0800 | [diff] [blame] | 89 | |
| 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 Cui | 3c8c213 | 2015-08-13 20:30:20 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Yabin Cui | faa7b92 | 2021-01-11 17:35:57 -0800 | [diff] [blame] | 97 | } // namespace simpleperf |
| 98 | |
Yabin Cui | 76769e5 | 2015-07-13 12:23:54 -0700 | [diff] [blame] | 99 | #endif // SIMPLE_PERF_PERF_REGS_H_ |