1 /* 2 * Copyright (C) 2018 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 _LIBUNWINDSTACK_REGS_INFO_H 18 #define _LIBUNWINDSTACK_REGS_INFO_H 19 20 #include <stdint.h> 21 22 #include <unwindstack/Regs.h> 23 24 namespace unwindstack { 25 26 template <typename AddressType> 27 struct RegsInfo { 28 static constexpr size_t MAX_REGISTERS = 64; 29 RegsInfoRegsInfo30 RegsInfo(RegsImpl<AddressType>* regs) : regs(regs) {} 31 32 RegsImpl<AddressType>* regs = nullptr; 33 uint64_t saved_reg_map = 0; 34 AddressType saved_regs[MAX_REGISTERS]; 35 GetRegsInfo36 inline AddressType Get(uint32_t reg) { 37 if (IsSaved(reg)) { 38 return saved_regs[reg]; 39 } 40 return (*regs)[reg]; 41 } 42 SaveRegsInfo43 inline AddressType* Save(uint32_t reg) { 44 if (reg >= MAX_REGISTERS) { 45 // This should never happen since all currently supported 46 // architectures have < 64 total registers. 47 abort(); 48 } 49 saved_reg_map |= 1ULL << reg; 50 saved_regs[reg] = (*regs)[reg]; 51 return &(*regs)[reg]; 52 } 53 IsSavedRegsInfo54 inline bool IsSaved(uint32_t reg) { 55 if (reg > MAX_REGISTERS) { 56 // This should never happen since all currently supported 57 // architectures have < 64 total registers. 58 abort(); 59 } 60 return saved_reg_map & (1ULL << reg); 61 } 62 TotalRegsInfo63 inline uint16_t Total() { return regs->total_regs(); } 64 }; 65 66 } // namespace unwindstack 67 68 #endif // _LIBUNWINDSTACK_REGS_INFO_H 69