blob: a47329a2214ae5e57b5baeccabc7b379244c820b [file] [log] [blame]
Johnny Chen832d3132011-01-26 01:18:52 +00001//===-- lldb_ARMDefines.h ---------------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Johnny Chen832d3132011-01-26 01:18:52 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef lldb_ARMDefines_h_
10#define lldb_ARMDefines_h_
11
Pavel Labathdc2b3b72016-08-10 13:30:20 +000012#include <cassert>
13#include <cstdint>
14
Bruce Mitcheneraaa0ba32014-07-08 18:05:41 +000015// Common definitions for the ARM/Thumb Instruction Set Architecture.
Johnny Chen832d3132011-01-26 01:18:52 +000016
17namespace lldb_private {
18
Johnny Chen22deaa52011-02-16 01:27:54 +000019// ARM shifter types
Kate Stoneb9c1b512016-09-06 20:57:50 +000020typedef enum {
21 SRType_LSL,
22 SRType_LSR,
23 SRType_ASR,
24 SRType_ROR,
25 SRType_RRX,
26 SRType_Invalid
Johnny Chen22deaa52011-02-16 01:27:54 +000027} ARM_ShifterType;
28
Kate Stoneb9c1b512016-09-06 20:57:50 +000029// 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
Johnny Chen832d3132011-01-26 01:18:52 +000067#define COND_UNCOND 0xF
68
Kate Stoneb9c1b512016-09-06 20:57:50 +000069static 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 }
Johnny Chen2246ff12011-02-04 21:27:54 +0000104}
105
Kate Stoneb9c1b512016-09-06 20:57:50 +0000106static 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
Greg Claytona97c4d22014-12-09 23:31:02 +0000112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113 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;
Greg Claytona97c4d22014-12-09 23:31:02 +0000148}
149
Johnny Chen0cfda5b2011-02-10 19:29:03 +0000150// Bit positions for CPSR
Kate Stoneb9c1b512016-09-06 20:57:50 +0000151#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
Johnny Chen673badf2011-02-23 00:15:56 +0000156#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
Johnny Chen0cfda5b2011-02-10 19:29:03 +0000162
Greg Clayton2ed751b2011-04-26 04:39:08 +0000163// CPSR mode definitions
Kate Stoneb9c1b512016-09-06 20:57:50 +0000164#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
Johnny Chen832d3132011-01-26 01:18:52 +0000172// Masks for CPSR
Greg Claytoncd482e32011-05-18 01:58:14 +0000173#define MASK_CPSR_MODE_MASK (0x0000001fu)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000174#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)
Johnny Chen832d3132011-01-26 01:18:52 +0000187
Kate Stoneb9c1b512016-09-06 20:57:50 +0000188} // namespace lldb_private
Johnny Chen832d3132011-01-26 01:18:52 +0000189
Kate Stoneb9c1b512016-09-06 20:57:50 +0000190#endif // lldb_ARMDefines_h_