• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
18 
19 #include <stdint.h>
20 
21 #include <unwindstack/Regs.h>
22 
23 namespace unwindstack {
24 
25 template <typename AddressType>
26 struct RegsInfo {
27   static constexpr size_t MAX_REGISTERS = 64;
28 
RegsInfoRegsInfo29   RegsInfo(RegsImpl<AddressType>* regs) : regs(regs) {}
30 
31   RegsImpl<AddressType>* regs = nullptr;
32   uint64_t saved_reg_map = 0;
33   AddressType saved_regs[MAX_REGISTERS];
34 
GetRegsInfo35   inline AddressType Get(uint32_t reg) {
36     if (IsSaved(reg)) {
37       return saved_regs[reg];
38     }
39     return (*regs)[reg];
40   }
41 
SaveRegsInfo42   inline AddressType* Save(uint32_t reg) {
43     if (reg >= MAX_REGISTERS) {
44       // This should never happen since all currently supported
45       // architectures have < 64 total registers.
46       abort();
47     }
48     saved_reg_map |= 1ULL << reg;
49     saved_regs[reg] = (*regs)[reg];
50     return &(*regs)[reg];
51   }
52 
IsSavedRegsInfo53   inline bool IsSaved(uint32_t reg) {
54     if (reg > MAX_REGISTERS) {
55       // This should never happen since all currently supported
56       // architectures have < 64 total registers.
57       abort();
58     }
59     return saved_reg_map & (1ULL << reg);
60   }
61 
TotalRegsInfo62   inline uint16_t Total() { return regs->total_regs(); }
63 };
64 
65 }  // namespace unwindstack
66