blob: 2766c6f40a4e131f82a0b99d9b410e3d1c88b89b [file] [log] [blame]
Christopher Ferris723cf9b2017-01-19 20:08:48 -08001/*
2 * Copyright (C) 2016 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_H
18#define _LIBUNWINDSTACK_REGS_H
19
20#include <stdint.h>
21
22#include <vector>
23
24class Regs {
25 public:
26 Regs(uint16_t pc_reg, uint16_t sp_reg, uint16_t total_regs)
27 : pc_reg_(pc_reg), sp_reg_(sp_reg), total_regs_(total_regs) {
28 }
29 virtual ~Regs() = default;
30
31 uint16_t pc_reg() { return pc_reg_; }
32 uint16_t sp_reg() { return sp_reg_; }
33 uint16_t total_regs() { return total_regs_; }
34
35 virtual void* raw_data() = 0;
36 virtual uint64_t pc() = 0;
37 virtual uint64_t sp() = 0;
38
39 protected:
40 uint16_t pc_reg_;
41 uint16_t sp_reg_;
42 uint16_t total_regs_;
43};
44
45template <typename AddressType>
46class RegsTmpl : public Regs {
47 public:
48 RegsTmpl(uint16_t pc_reg, uint16_t sp_reg, uint16_t total_regs)
49 : Regs(pc_reg, sp_reg, total_regs), regs_(total_regs) {}
50 virtual ~RegsTmpl() = default;
51
52 uint64_t pc() override { return regs_[pc_reg_]; }
53 uint64_t sp() override { return regs_[sp_reg_]; }
54
55 inline AddressType& operator[](size_t reg) { return regs_[reg]; }
56
57 void* raw_data() override { return regs_.data(); }
58
59 private:
60 std::vector<AddressType> regs_;
61};
62
63class Regs32 : public RegsTmpl<uint32_t> {
64 public:
65 Regs32(uint16_t pc_reg, uint16_t sp_reg, uint16_t total_regs)
66 : RegsTmpl(pc_reg, sp_reg, total_regs) {}
67 virtual ~Regs32() = default;
68};
69
70class Regs64 : public RegsTmpl<uint64_t> {
71 public:
72 Regs64(uint16_t pc_reg, uint16_t sp_reg, uint16_t total_regs)
73 : RegsTmpl(pc_reg, sp_reg, total_regs) {}
74 virtual ~Regs64() = default;
75};
76
77#endif // _LIBUNWINDSTACK_REGS_H