DebugServer2
Loading...
Searching...
No Matches
Branching.h
1//
2// Copyright (c) 2014-present, Facebook, Inc.
3// All rights reserved.
4//
5// This source code is licensed under the University of Illinois/NCSA Open
6// Source License found in the LICENSE file in the root directory of this
7// source tree. An additional grant of patent rights can be found in the
8// PATENTS file in the same directory.
9//
10
11#pragma once
12
13#include "DebugServer2/Base.h"
14
15#include <cstdint>
16
17//
18// Possible instructions that affect PC:
19//
20// ARM | Thumb-2 | Thumb-1
21// --------------+----------------+---------------
22// b i | b.n i | b i
23// bl i | b.w i | bl i
24// blx i | bl i | bx r
25// bx r | blx i | mov pc, ...
26// blx r | bx r | pop {...,pc}
27// ldr pc, ... | blx r |
28// mov pc, ... | cbz r, i |
29// pop {...,pc} | cbnz r, i |
30// <aop> pc, ... | mov pc, ... |
31// | ldr pc, ... |
32// | pop {...,pc} |
33// | ldm.w {...,pc} |
34//
35// aop = alu op (add, sub, big, etc...)
36//
37
38namespace ds2 {
39namespace Architecture {
40namespace ARM {
41
42enum BranchType {
43 //
44 // ARM/Thumb
45 //
46 kBranchTypeNone,
47 kBranchTypeB_i,
48 kBranchTypeBcc_i,
49 kBranchTypeCB_i,
50 kBranchTypeBX_r,
51 kBranchTypeBL_i,
52 kBranchTypeBLX_i,
53 kBranchTypeBLX_r,
54 kBranchTypeMOV_pc,
55 kBranchTypeLDR_pc,
56 kBranchTypeLDM_pc,
57 kBranchTypePOP_pc,
58 kBranchTypeSUB_pc,
59 kBranchTypeTBB,
60 kBranchTypeTBH,
61
62 //
63 // ARM (legacy)
64 //
65 kBranchTypeADC_pc,
66 kBranchTypeADD_pc,
67 kBranchTypeAND_pc,
68 kBranchTypeBIC_pc,
69 kBranchTypeEOR_pc,
70 kBranchTypeORR_pc,
71 kBranchTypeRSB_pc,
72 kBranchTypeRSC_pc,
73 kBranchTypeSBC_pc,
74 kBranchTypeMVN_pc,
75 kBranchTypeASR_pc,
76 kBranchTypeLSL_pc,
77 kBranchTypeLSR_pc,
78 kBranchTypeROR_pc,
79 kBranchTypeRRX_pc,
80};
81
82enum BranchDisp {
83 kBranchDispNormal,
84 kBranchDispLSL,
85 kBranchDispLSR,
86 kBranchDispASR,
87 kBranchDispROR,
88 kBranchDispRRX
89};
90
91enum BranchCond {
92 kCondEQ,
93 kCondNE,
94 kCondCS,
95 kCondCC,
96 kCondMI,
97 kCondPL,
98 kCondVS,
99 kCondVC,
100 kCondHI,
101 kCondLS,
102 kCondGE,
103 kCondLT,
104 kCondLE,
105 kCondGT,
106 kCondAL,
107 kCondNV
108};
109
110enum class ThumbInstSize {
111 TwoByteInst = 2,
112 FourByteInst = 4,
113};
114
116 union {
117 struct {
118 uint32_t it : 1;
119 uint32_t itCount : 3;
120 uint32_t : 28;
121 } /*thumb*/;
122 struct {
123 uint32_t subt : 1;
124 uint32_t : 31;
125 } /*arm*/;
126 };
127 BranchType type;
128 BranchCond cond;
129 BranchDisp mode;
130 int32_t reg1;
131 int32_t reg2;
132 int32_t disp;
133 size_t align;
134};
135
136bool GetARMBranchInfo(uint32_t insn, BranchInfo &info);
137
138bool GetThumbBranchInfo(uint32_t const insn[2], BranchInfo &info);
139
140ThumbInstSize GetThumbInstSize(uint32_t insn);
141} // namespace ARM
142} // namespace Architecture
143} // namespace ds2
Definition Branching.h:115