LLDB  mainline
ARMDefines.h
Go to the documentation of this file.
1 //===-- lldb_ARMDefines.h ---------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef lldb_ARMDefines_h_
10 #define lldb_ARMDefines_h_
11 
12 #include <cassert>
13 #include <cstdint>
14 
15 // Common definitions for the ARM/Thumb Instruction Set Architecture.
16 
17 namespace lldb_private {
18 
19 // ARM shifter types
20 typedef enum {
28 
29 // ARM conditions // Meaning (integer) Meaning (floating-point)
30 // Condition flags
31 #define COND_EQ \
32  0x0 // Equal Equal Z == 1
33 #define COND_NE \
34  0x1 // Not equal Not equal, or unordered Z == 0
35 #define COND_CS \
36  0x2 // Carry set >, ==, or unordered C == 1
37 #define COND_HS 0x2
38 #define COND_CC \
39  0x3 // Carry clear Less than C == 0
40 #define COND_LO 0x3
41 #define COND_MI \
42  0x4 // Minus, negative Less than N == 1
43 #define COND_PL \
44  0x5 // Plus, positive or zero >, ==, or unordered N == 0
45 #define COND_VS \
46  0x6 // Overflow Unordered V == 1
47 #define COND_VC \
48  0x7 // No overflow Not unordered V == 0
49 #define COND_HI \
50  0x8 // Unsigned higher Greater than, or unordered C == 1 and Z ==
51  // 0
52 #define COND_LS \
53  0x9 // Unsigned lower or same Less than or equal C == 0 or Z ==
54  // 1
55 #define COND_GE \
56  0xA // Greater than or equal Greater than or equal N == V
57 #define COND_LT \
58  0xB // Less than Less than, or unordered N != V
59 #define COND_GT \
60  0xC // Greater than Greater than Z == 0 and N ==
61  // V
62 #define COND_LE \
63  0xD // Less than or equal <, ==, or unordered Z == 1 or N !=
64  // V
65 #define COND_AL \
66  0xE // Always (unconditional) Always (unconditional) Any
67 #define COND_UNCOND 0xF
68 
69 static inline const char *ARMCondCodeToString(uint32_t CC) {
70  switch (CC) {
71  default:
72  assert(0 && "Unknown condition code");
73  case COND_EQ:
74  return "eq";
75  case COND_NE:
76  return "ne";
77  case COND_HS:
78  return "hs";
79  case COND_LO:
80  return "lo";
81  case COND_MI:
82  return "mi";
83  case COND_PL:
84  return "pl";
85  case COND_VS:
86  return "vs";
87  case COND_VC:
88  return "vc";
89  case COND_HI:
90  return "hi";
91  case COND_LS:
92  return "ls";
93  case COND_GE:
94  return "ge";
95  case COND_LT:
96  return "lt";
97  case COND_GT:
98  return "gt";
99  case COND_LE:
100  return "le";
101  case COND_AL:
102  return "al";
103  }
104 }
105 
106 static inline bool ARMConditionPassed(const uint32_t condition,
107  const uint32_t cpsr) {
108  const uint32_t cpsr_n = (cpsr >> 31) & 1u; // Negative condition code flag
109  const uint32_t cpsr_z = (cpsr >> 30) & 1u; // Zero condition code flag
110  const uint32_t cpsr_c = (cpsr >> 29) & 1u; // Carry condition code flag
111  const uint32_t cpsr_v = (cpsr >> 28) & 1u; // Overflow condition code flag
112 
113  switch (condition) {
114  case COND_EQ:
115  return (cpsr_z == 1);
116  case COND_NE:
117  return (cpsr_z == 0);
118  case COND_CS:
119  return (cpsr_c == 1);
120  case COND_CC:
121  return (cpsr_c == 0);
122  case COND_MI:
123  return (cpsr_n == 1);
124  case COND_PL:
125  return (cpsr_n == 0);
126  case COND_VS:
127  return (cpsr_v == 1);
128  case COND_VC:
129  return (cpsr_v == 0);
130  case COND_HI:
131  return ((cpsr_c == 1) && (cpsr_z == 0));
132  case COND_LS:
133  return ((cpsr_c == 0) || (cpsr_z == 1));
134  case COND_GE:
135  return (cpsr_n == cpsr_v);
136  case COND_LT:
137  return (cpsr_n != cpsr_v);
138  case COND_GT:
139  return ((cpsr_z == 0) && (cpsr_n == cpsr_v));
140  case COND_LE:
141  return ((cpsr_z == 1) || (cpsr_n != cpsr_v));
142  case COND_AL:
143  case COND_UNCOND:
144  default:
145  return true;
146  }
147  return false;
148 }
149 
150 // Bit positions for CPSR
151 #define CPSR_T_POS 5
152 #define CPSR_F_POS 6
153 #define CPSR_I_POS 7
154 #define CPSR_A_POS 8
155 #define CPSR_E_POS 9
156 #define CPSR_J_POS 24
157 #define CPSR_Q_POS 27
158 #define CPSR_V_POS 28
159 #define CPSR_C_POS 29
160 #define CPSR_Z_POS 30
161 #define CPSR_N_POS 31
162 
163 // CPSR mode definitions
164 #define CPSR_MODE_USR 0x10u
165 #define CPSR_MODE_FIQ 0x11u
166 #define CPSR_MODE_IRQ 0x12u
167 #define CPSR_MODE_SVC 0x13u
168 #define CPSR_MODE_ABT 0x17u
169 #define CPSR_MODE_UND 0x1bu
170 #define CPSR_MODE_SYS 0x1fu
171 
172 // Masks for CPSR
173 #define MASK_CPSR_MODE_MASK (0x0000001fu)
174 #define MASK_CPSR_IT_MASK (0x0600fc00u)
175 #define MASK_CPSR_T (1u << CPSR_T_POS)
176 #define MASK_CPSR_F (1u << CPSR_F_POS)
177 #define MASK_CPSR_I (1u << CPSR_I_POS)
178 #define MASK_CPSR_A (1u << CPSR_A_POS)
179 #define MASK_CPSR_E (1u << CPSR_E_POS)
180 #define MASK_CPSR_GE_MASK (0x000f0000u)
181 #define MASK_CPSR_J (1u << CPSR_J_POS)
182 #define MASK_CPSR_Q (1u << CPSR_Q_POS)
183 #define MASK_CPSR_V (1u << CPSR_V_POS)
184 #define MASK_CPSR_C (1u << CPSR_C_POS)
185 #define MASK_CPSR_Z (1u << CPSR_Z_POS)
186 #define MASK_CPSR_N (1u << CPSR_N_POS)
187 
188 } // namespace lldb_private
189 
190 #endif // lldb_ARMDefines_h_
#define COND_LT
Definition: ARMDefines.h:57
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
#define COND_GE
Definition: ARMDefines.h:55
#define COND_LO
Definition: ARMDefines.h:40
#define COND_GT
Definition: ARMDefines.h:59
#define COND_LS
Definition: ARMDefines.h:52
#define COND_HS
Definition: ARMDefines.h:37
#define COND_CC
Definition: ARMDefines.h:38
#define COND_MI
Definition: ARMDefines.h:41
#define COND_AL
Definition: ARMDefines.h:65
#define COND_UNCOND
Definition: ARMDefines.h:67
#define COND_VS
Definition: ARMDefines.h:45
#define COND_HI
Definition: ARMDefines.h:49
#define COND_CS
Definition: ARMDefines.h:35
#define COND_VC
Definition: ARMDefines.h:47
#define COND_NE
Definition: ARMDefines.h:33
#define COND_EQ
Definition: ARMDefines.h:31
static bool ARMConditionPassed(const uint32_t condition, const uint32_t cpsr)
Definition: ARMDefines.h:106
static const char * ARMCondCodeToString(uint32_t CC)
Definition: ARMDefines.h:69
#define COND_LE
Definition: ARMDefines.h:62
#define COND_PL
Definition: ARMDefines.h:43