23extern CHAR8 *gCondition[];
28#define LOAD_STORE_FORMAT1 1
29#define LOAD_STORE_FORMAT1_H 101
30#define LOAD_STORE_FORMAT1_B 111
31#define LOAD_STORE_FORMAT2 2
32#define LOAD_STORE_FORMAT3 3
33#define LOAD_STORE_FORMAT4 4
34#define LOAD_STORE_MULTIPLE_FORMAT1 5
38#define CONDITIONAL_BRANCH 8
39#define UNCONDITIONAL_BRANCH 9
40#define UNCONDITIONAL_BRANCH_SHORT 109
41#define BRANCH_EXCHANGE 10
42#define DATA_FORMAT1 11
43#define DATA_FORMAT2 12
44#define DATA_FORMAT3 13
45#define DATA_FORMAT4 14
46#define DATA_FORMAT5 15
47#define DATA_FORMAT6_SP 16
48#define DATA_FORMAT6_PC 116
49#define DATA_FORMAT7 17
50#define DATA_FORMAT8 19
52#define ENDIAN_FORMAT 21
64#define LDM_REG_IMM12_SIGNED 206
65#define LDM_REG_IMM12_LSL 207
66#define LDM_REG_IMM8 208
67#define LDM_REG_IMM12 209
68#define LDM_REG_INDIRECT_LSL 210
69#define LDM_REG_IMM8_SIGNED 211
70#define LDRD_REG_IMM8 212
75#define LDRD_REG_IMM8_SIGNED 217
84#define THUMB2_NO_ARGS 226
85#define THUMB2_2REGS 227
86#define ADD_IMM5_2REG 228
88#define THUMB2_4REGS 230
89#define ADD_IMM12_1REG 231
90#define THUMB2_IMM16 232
92#define MRRC_THUMB2 234
106 {
"ADC", 0x4140, 0xffc0, DATA_FORMAT5 },
107 {
"ADR", 0xa000, 0xf800, ADR_FORMAT },
108 {
"ADD", 0x1c00, 0xfe00, DATA_FORMAT2 },
109 {
"ADD", 0x3000, 0xf800, DATA_FORMAT3 },
110 {
"ADD", 0x1800, 0xfe00, DATA_FORMAT1 },
111 {
"ADD", 0x4400, 0xff00, DATA_FORMAT8 },
112 {
"ADD", 0xa000, 0xf100, DATA_FORMAT6_PC },
113 {
"ADD", 0xa800, 0xf800, DATA_FORMAT6_SP },
114 {
"ADD", 0xb000, 0xff80, DATA_FORMAT7 },
116 {
"AND", 0x4000, 0xffc0, DATA_FORMAT5 },
118 {
"ASR", 0x1000, 0xf800, DATA_FORMAT4 },
119 {
"ASR", 0x4100, 0xffc0, DATA_FORMAT5 },
121 {
"B", 0xd000, 0xf000, CONDITIONAL_BRANCH },
122 {
"B", 0xe000, 0xf800, UNCONDITIONAL_BRANCH_SHORT },
123 {
"BLX", 0x4780, 0xff80, BRANCH_EXCHANGE },
124 {
"BX", 0x4700, 0xff87, BRANCH_EXCHANGE },
126 {
"BIC", 0x4380, 0xffc0, DATA_FORMAT5 },
127 {
"BKPT", 0xdf00, 0xff00, IMMED_8 },
128 {
"CBZ", 0xb100, 0xfd00, DATA_CBZ },
129 {
"CBNZ", 0xb900, 0xfd00, DATA_CBZ },
130 {
"CMN", 0x42c0, 0xffc0, DATA_FORMAT5 },
132 {
"CMP", 0x2800, 0xf800, DATA_FORMAT3 },
133 {
"CMP", 0x4280, 0xffc0, DATA_FORMAT5 },
134 {
"CMP", 0x4500, 0xff00, DATA_FORMAT8 },
136 {
"CPS", 0xb660, 0xffe8, CPS_FORMAT },
137 {
"MOV", 0x4600, 0xff00, DATA_FORMAT8 },
138 {
"EOR", 0x4040, 0xffc0, DATA_FORMAT5 },
140 {
"LDMIA", 0xc800, 0xf800, LOAD_STORE_MULTIPLE_FORMAT1 },
141 {
"LDR", 0x6800, 0xf800, LOAD_STORE_FORMAT1 },
142 {
"LDR", 0x5800, 0xfe00, LOAD_STORE_FORMAT2 },
143 {
"LDR", 0x4800, 0xf800, LOAD_STORE_FORMAT3 },
144 {
"LDR", 0x9800, 0xf800, LOAD_STORE_FORMAT4 },
145 {
"LDRB", 0x7800, 0xf800, LOAD_STORE_FORMAT1_B },
146 {
"LDRB", 0x5c00, 0xfe00, LOAD_STORE_FORMAT2 },
147 {
"LDRH", 0x8800, 0xf800, LOAD_STORE_FORMAT1_H },
148 {
"LDRH", 0x7a00, 0xfe00, LOAD_STORE_FORMAT2 },
149 {
"LDRSB", 0x5600, 0xfe00, LOAD_STORE_FORMAT2 },
150 {
"LDRSH", 0x5e00, 0xfe00, LOAD_STORE_FORMAT2 },
152 {
"MOVS", 0x0000, 0xffc0, DATA_FORMAT5 },
153 {
"LSL", 0x0000, 0xf800, DATA_FORMAT4 },
154 {
"LSL", 0x4080, 0xffc0, DATA_FORMAT5 },
155 {
"LSR", 0x0001, 0xf800, DATA_FORMAT4 },
156 {
"LSR", 0x40c0, 0xffc0, DATA_FORMAT5 },
157 {
"LSRS", 0x0800, 0xf800, DATA_FORMAT4 },
159 {
"MOVS", 0x2000, 0xf800, DATA_FORMAT3 },
160 {
"MOV", 0x1c00, 0xffc0, DATA_FORMAT3 },
161 {
"MOV", 0x4600, 0xff00, DATA_FORMAT8 },
163 {
"MUL", 0x4340, 0xffc0, DATA_FORMAT5 },
164 {
"MVN", 0x41c0, 0xffc0, DATA_FORMAT5 },
165 {
"NEG", 0x4240, 0xffc0, DATA_FORMAT5 },
166 {
"ORR", 0x4300, 0xffc0, DATA_FORMAT5 },
167 {
"POP", 0xbc00, 0xfe00, POP_FORMAT },
168 {
"PUSH", 0xb400, 0xfe00, PUSH_FORMAT },
170 {
"REV", 0xba00, 0xffc0, DATA_FORMAT5 },
171 {
"REV16", 0xba40, 0xffc0, DATA_FORMAT5 },
172 {
"REVSH", 0xbac0, 0xffc0, DATA_FORMAT5 },
174 {
"ROR", 0x41c0, 0xffc0, DATA_FORMAT5 },
175 {
"SBC", 0x4180, 0xffc0, DATA_FORMAT5 },
176 {
"SETEND", 0xb650, 0xfff0, ENDIAN_FORMAT },
178 {
"STMIA", 0xc000, 0xf800, LOAD_STORE_MULTIPLE_FORMAT1 },
179 {
"STR", 0x6000, 0xf800, LOAD_STORE_FORMAT1 },
180 {
"STR", 0x5000, 0xfe00, LOAD_STORE_FORMAT2 },
181 {
"STR", 0x9000, 0xf800, LOAD_STORE_FORMAT4 },
182 {
"STRB", 0x7000, 0xf800, LOAD_STORE_FORMAT1_B },
183 {
"STRB", 0x5400, 0xfe00, LOAD_STORE_FORMAT2 },
184 {
"STRH", 0x8000, 0xf800, LOAD_STORE_FORMAT1_H },
185 {
"STRH", 0x5200, 0xfe00, LOAD_STORE_FORMAT2 },
187 {
"SUB", 0x1e00, 0xfe00, DATA_FORMAT2 },
188 {
"SUB", 0x3800, 0xf800, DATA_FORMAT3 },
189 {
"SUB", 0x1a00, 0xfe00, DATA_FORMAT1 },
190 {
"SUB", 0xb080, 0xff80, DATA_FORMAT7 },
192 {
"SBC", 0x4180, 0xffc0, DATA_FORMAT5 },
194 {
"SWI", 0xdf00, 0xff00, IMMED_8 },
195 {
"SXTB", 0xb240, 0xffc0, DATA_FORMAT5 },
196 {
"SXTH", 0xb200, 0xffc0, DATA_FORMAT5 },
197 {
"TST", 0x4200, 0xffc0, DATA_FORMAT5 },
198 {
"UXTB", 0xb2c0, 0xffc0, DATA_FORMAT5 },
199 {
"UXTH", 0xb280, 0xffc0, DATA_FORMAT5 },
201 {
"IT", 0xbf00, 0xff00, IT_BLOCK }
207 {
"ADR", 0xf2af0000, 0xfbff8000, ADR_THUMB2 },
208 {
"CMN", 0xf1100f00, 0xfff08f00, CMN_THUMB2 },
209 {
"CMN", 0xeb100f00, 0xfff08f00, ADD_IMM5_2REG },
210 {
"CMP", 0xf1a00f00, 0xfff08f00, CMN_THUMB2 },
211 {
"TEQ", 0xf0900f00, 0xfff08f00, CMN_THUMB2 },
212 {
"TEQ", 0xea900f00, 0xfff08f00, ADD_IMM5_2REG },
213 {
"TST", 0xf0100f00, 0xfff08f00, CMN_THUMB2 },
214 {
"TST", 0xea100f00, 0xfff08f00, ADD_IMM5_2REG },
216 {
"MOV", 0xf04f0000, 0xfbef8000, ADD_IMM12_1REG },
217 {
"MOVW", 0xf2400000, 0xfbe08000, THUMB2_IMM16 },
218 {
"MOVT", 0xf2c00000, 0xfbe08000, THUMB2_IMM16 },
220 {
"ADC", 0xf1400000, 0xfbe08000, ADD_IMM12 },
221 {
"ADC", 0xeb400000, 0xffe08000, ADD_IMM5 },
222 {
"ADD", 0xf1000000, 0xfbe08000, ADD_IMM12 },
223 {
"ADD", 0xeb000000, 0xffe08000, ADD_IMM5 },
224 {
"ADDW", 0xf2000000, 0xfbe08000, ADD_IMM12 },
225 {
"AND", 0xf0000000, 0xfbe08000, ADD_IMM12 },
226 {
"AND", 0xea000000, 0xffe08000, ADD_IMM5 },
227 {
"BIC", 0xf0200000, 0xfbe08000, ADD_IMM12 },
228 {
"BIC", 0xea200000, 0xffe08000, ADD_IMM5 },
229 {
"EOR", 0xf0800000, 0xfbe08000, ADD_IMM12 },
230 {
"EOR", 0xea800000, 0xffe08000, ADD_IMM5 },
231 {
"ORN", 0xf0600000, 0xfbe08000, ADD_IMM12 },
232 {
"ORN", 0xea600000, 0xffe08000, ADD_IMM5 },
233 {
"ORR", 0xf0400000, 0xfbe08000, ADD_IMM12 },
234 {
"ORR", 0xea400000, 0xffe08000, ADD_IMM5 },
235 {
"RSB", 0xf1c00000, 0xfbe08000, ADD_IMM12 },
236 {
"RSB", 0xebc00000, 0xffe08000, ADD_IMM5 },
237 {
"SBC", 0xf1600000, 0xfbe08000, ADD_IMM12 },
238 {
"SBC", 0xeb600000, 0xffe08000, ADD_IMM5 },
239 {
"SUB", 0xf1a00000, 0xfbe08000, ADD_IMM12 },
240 {
"SUB", 0xeba00000, 0xffe08000, ADD_IMM5 },
242 {
"ASR", 0xea4f0020, 0xffef8030, ASR_IMM5 },
243 {
"ASR", 0xfa40f000, 0xffe0f0f0, ASR_3REG },
244 {
"LSR", 0xea4f0010, 0xffef8030, ASR_IMM5 },
245 {
"LSR", 0xfa20f000, 0xffe0f0f0, ASR_3REG },
246 {
"ROR", 0xea4f0030, 0xffef8030, ASR_IMM5 },
247 {
"ROR", 0xfa60f000, 0xffe0f0f0, ASR_3REG },
249 {
"BFC", 0xf36f0000, 0xffff8010, BFC_THUMB2 },
250 {
"BIC", 0xf3600000, 0xfff08010, BFC_THUMB2 },
251 {
"SBFX", 0xf3400000, 0xfff08010, BFC_THUMB2 },
252 {
"UBFX", 0xf3c00000, 0xfff08010, BFC_THUMB2 },
254 {
"CPD", 0xee000000, 0xff000010, CPD_THUMB2 },
255 {
"CPD2", 0xfe000000, 0xff000010, CPD_THUMB2 },
257 {
"MRC", 0xee100000, 0xff100000, MRC_THUMB2 },
258 {
"MRC2", 0xfe100000, 0xff100000, MRC_THUMB2 },
259 {
"MRRC", 0xec500000, 0xfff00000, MRRC_THUMB2 },
260 {
"MRRC2", 0xfc500000, 0xfff00000, MRRC_THUMB2 },
262 {
"MRS", 0xf3ef8000, 0xfffff0ff, THUMB2_MRS },
263 {
"MSR", 0xf3808000, 0xfff0fcff, THUMB2_MSR },
265 {
"CLREX", 0xf3bf8f2f, 0xfffffff, THUMB2_NO_ARGS },
267 {
"CLZ", 0xfab0f080, 0xfff0f0f0, THUMB2_2REGS },
268 {
"MOV", 0xec4f0000, 0xfff0f0f0, THUMB2_2REGS },
269 {
"MOVS", 0xec5f0000, 0xfff0f0f0, THUMB2_2REGS },
270 {
"RBIT", 0xfb90f0a0, 0xfff0f0f0, THUMB2_2REGS },
271 {
"REV", 0xfb90f080, 0xfff0f0f0, THUMB2_2REGS },
272 {
"REV16", 0xfa90f090, 0xfff0f0f0, THUMB2_2REGS },
273 {
"REVSH", 0xfa90f0b0, 0xfff0f0f0, THUMB2_2REGS },
274 {
"RRX", 0xea4f0030, 0xfffff0f0, THUMB2_2REGS },
275 {
"RRXS", 0xea5f0030, 0xfffff0f0, THUMB2_2REGS },
277 {
"MLA", 0xfb000000, 0xfff000f0, THUMB2_4REGS },
278 {
"MLS", 0xfb000010, 0xfff000f0, THUMB2_4REGS },
280 {
"SMLABB", 0xfb100000, 0xfff000f0, THUMB2_4REGS },
281 {
"SMLABT", 0xfb100010, 0xfff000f0, THUMB2_4REGS },
282 {
"SMLABB", 0xfb100020, 0xfff000f0, THUMB2_4REGS },
283 {
"SMLATT", 0xfb100030, 0xfff000f0, THUMB2_4REGS },
284 {
"SMLAWB", 0xfb300000, 0xfff000f0, THUMB2_4REGS },
285 {
"SMLAWT", 0xfb300010, 0xfff000f0, THUMB2_4REGS },
286 {
"SMLSD", 0xfb400000, 0xfff000f0, THUMB2_4REGS },
287 {
"SMLSDX", 0xfb400010, 0xfff000f0, THUMB2_4REGS },
288 {
"SMMLA", 0xfb500000, 0xfff000f0, THUMB2_4REGS },
289 {
"SMMLAR", 0xfb500010, 0xfff000f0, THUMB2_4REGS },
290 {
"SMMLS", 0xfb600000, 0xfff000f0, THUMB2_4REGS },
291 {
"SMMLSR", 0xfb600010, 0xfff000f0, THUMB2_4REGS },
292 {
"USADA8", 0xfb700000, 0xfff000f0, THUMB2_4REGS },
293 {
"SMLAD", 0xfb200000, 0xfff000f0, THUMB2_4REGS },
294 {
"SMLADX", 0xfb200010, 0xfff000f0, THUMB2_4REGS },
296 {
"B", 0xf0008000, 0xf800d000, B_T3 },
297 {
"B", 0xf0009000, 0xf800d000, B_T4 },
298 {
"BL", 0xf000d000, 0xf800d000, B_T4 },
299 {
"BLX", 0xf000c000, 0xf800d000, BL_T2 },
301 {
"POP", 0xe8bd0000, 0xffff2000, POP_T2 },
302 {
"POP", 0xf85d0b04, 0xffff0fff, POP_T3 },
303 {
"PUSH", 0xe8ad0000, 0xffffa000, POP_T2 },
304 {
"PUSH", 0xf84d0d04, 0xffff0fff, POP_T3 },
305 {
"STM", 0xe8800000, 0xffd0a000, STM_FORMAT },
306 {
"STMDB", 0xe9800000, 0xffd0a000, STM_FORMAT },
307 {
"LDM", 0xe8900000, 0xffd02000, STM_FORMAT },
308 {
"LDMDB", 0xe9100000, 0xffd02000, STM_FORMAT },
310 {
"LDR", 0xf8d00000, 0xfff00000, LDM_REG_IMM12 },
311 {
"LDRB", 0xf8900000, 0xfff00000, LDM_REG_IMM12 },
312 {
"LDRH", 0xf8b00000, 0xfff00000, LDM_REG_IMM12 },
313 {
"LDRSB", 0xf9900000, 0xfff00000, LDM_REG_IMM12 },
314 {
"LDRSH", 0xf9b00000, 0xfff00000, LDM_REG_IMM12 },
316 {
"LDR", 0xf85f0000, 0xff7f0000, LDM_REG_IMM12_SIGNED },
317 {
"LDRB", 0xf81f0000, 0xff7f0000, LDM_REG_IMM12_SIGNED },
318 {
"LDRH", 0xf83f0000, 0xff7f0000, LDM_REG_IMM12_SIGNED },
319 {
"LDRSB", 0xf91f0000, 0xff7f0000, LDM_REG_IMM12_SIGNED },
320 {
"LDRSH", 0xf93f0000, 0xff7f0000, LDM_REG_IMM12_SIGNED },
322 {
"LDR", 0xf8500000, 0xfff00fc0, LDM_REG_INDIRECT_LSL },
323 {
"LDRB", 0xf8100000, 0xfff00fc0, LDM_REG_INDIRECT_LSL },
324 {
"LDRH", 0xf8300000, 0xfff00fc0, LDM_REG_INDIRECT_LSL },
325 {
"LDRSB", 0xf9100000, 0xfff00fc0, LDM_REG_INDIRECT_LSL },
326 {
"LDRSH", 0xf9300000, 0xfff00fc0, LDM_REG_INDIRECT_LSL },
328 {
"LDR", 0xf8500800, 0xfff00800, LDM_REG_IMM8 },
329 {
"LDRBT", 0xf8100e00, 0xfff00f00, LDM_REG_IMM8 },
330 {
"LDRHT", 0xf8300e00, 0xfff00f00, LDM_REG_IMM8 },
331 {
"LDRSB", 0xf9100800, 0xfff00800, LDM_REG_IMM8 },
332 {
"LDRSBT", 0xf9100e00, 0xfff00f00, LDM_REG_IMM8 },
333 {
"LDRSH", 0xf9300800, 0xfff00800, LDM_REG_IMM8 },
334 {
"LDRSHT", 0xf9300e00, 0xfff00f00, LDM_REG_IMM8 },
335 {
"LDRT", 0xf8500e00, 0xfff00f00, LDM_REG_IMM8 },
337 {
"LDRD", 0xe8500000, 0xfe500000, LDRD_REG_IMM8_SIGNED },
338 {
"LDRD", 0xe8500000, 0xfe500000, LDRD_REG_IMM8 },
340 {
"LDREX", 0xe8500f00, 0xfff00f00, LDM_REG_IMM8 },
341 {
"LDREXB", 0xe8d00f4f, 0xfff00fff, LDREXB },
342 {
"LDREXH", 0xe8d00f5f, 0xfff00fff, LDREXB },
344 {
"LDREXD", 0xe8d00f4f, 0xfff00fff, LDREXD },
346 {
"STR", 0xf8c00000, 0xfff00000, LDM_REG_IMM12 },
347 {
"STRB", 0xf8800000, 0xfff00000, LDM_REG_IMM12 },
348 {
"STRH", 0xf8a00000, 0xfff00000, LDM_REG_IMM12 },
350 {
"STR", 0xf8400000, 0xfff00fc0, LDM_REG_INDIRECT_LSL },
351 {
"STRB", 0xf8000000, 0xfff00fc0, LDM_REG_INDIRECT_LSL },
352 {
"STRH", 0xf8200000, 0xfff00fc0, LDM_REG_INDIRECT_LSL },
354 {
"STR", 0xf8400800, 0xfff00800, LDM_REG_IMM8 },
355 {
"STRH", 0xf8200800, 0xfff00800, LDM_REG_IMM8 },
356 {
"STRBT", 0xf8000e00, 0xfff00f00, LDM_REG_IMM8 },
357 {
"STRHT", 0xf8200e00, 0xfff00f00, LDM_REG_IMM8 },
358 {
"STRT", 0xf8400e00, 0xfff00f00, LDM_REG_IMM8 },
360 {
"STRD", 0xe8400000, 0xfe500000, LDRD_REG_IMM8_SIGNED },
362 {
"STREX", 0xe8400f00, 0xfff00f00, LDM_REG_IMM8 },
363 {
"STREXB", 0xe8c00f4f, 0xfff00fff, LDREXB },
364 {
"STREXH", 0xe8c00f5f, 0xfff00fff, LDREXB },
366 {
"STREXD", 0xe8d00f4f, 0xfff00fff, LDREXD },
368 {
"SRSDB", 0xe80dc000, 0xffdffff0, SRS_FORMAT },
369 {
"SRS", 0xe98dc000, 0xffdffff0, SRS_FORMAT },
370 {
"RFEDB", 0xe810c000, 0xffd0ffff, RFE_FORMAT },
371 {
"RFE", 0xe990c000, 0xffd0ffff, RFE_FORMAT }
374CHAR8 *gShiftType[] = {
381CHAR8 mThumbMregListStr[4*15 + 1];
388 UINTN Index, Start, End;
391 mThumbMregListStr[0] =
'\0';
392 AsciiStrCatS (mThumbMregListStr,
sizeof mThumbMregListStr,
"{");
394 for (Index = 0, First =
TRUE; Index <= 15; Index++) {
395 if ((RegBitMask & (1 << Index)) != 0) {
397 for (Index++; ((RegBitMask & (1 << Index)) != 0) && (Index <= 9); Index++) {
402 AsciiStrCatS (mThumbMregListStr,
sizeof mThumbMregListStr,
",");
408 AsciiStrCatS (mThumbMregListStr,
sizeof mThumbMregListStr, gReg[Start]);
410 AsciiStrCatS (mThumbMregListStr,
sizeof mThumbMregListStr, gReg[Start]);
411 AsciiStrCatS (mThumbMregListStr,
sizeof mThumbMregListStr,
"-");
412 AsciiStrCatS (mThumbMregListStr,
sizeof mThumbMregListStr, gReg[End]);
418 AsciiStrCatS (mThumbMregListStr,
sizeof mThumbMregListStr,
"ERROR");
421 AsciiStrCatS (mThumbMregListStr,
sizeof mThumbMregListStr,
"}");
424 return mThumbMregListStr;
433 if (((Data & TopBit) == 0) || (TopBit == BIT31)) {
440 }
while ((TopBit & BIT31) != BIT31);
455 return (Data + 4) & 0xfffffffc;
473 IN UINT16 **OpCodePtrPtr,
485 UINT16 Rd, Rn, Rm, Rt, Rt2;
490 UINT32 Pc, Target, MsBit, LsBit;
498 UINT32 Coproc, Opc1, Opc2, CRd, CRn, CRm;
501 OpCodePtr = *OpCodePtrPtr;
502 OpCode = **OpCodePtrPtr;
505 OpCode32 = (((UINT32)OpCode) << 16) | *(OpCodePtr + 1);
509 Rn = (OpCode >> 3) & 0x7;
510 Rm = (OpCode >> 6) & 0x7;
511 H1Bit = (OpCode & BIT7) != 0;
512 H2Bit = (OpCode & BIT6) != 0;
513 IMod = (OpCode & BIT4) != 0;
514 Pc = (UINT32)(
UINTN)OpCodePtr;
529 if ((OpCode & gOpThumb[Index].Mask) == gOpThumb[Index].OpCode) {
531 Offset =
AsciiSPrint (Buf, Size,
"0x%04x %-6a", OpCode, gOpThumb[Index].Start);
533 Offset =
AsciiSPrint (Buf, Size,
"%-6a", gOpThumb[Index].Start);
536 switch (gOpThumb[Index].AddressMode) {
537 case LOAD_STORE_FORMAT1:
539 AsciiSPrint (&Buf[Offset], Size - Offset,
" r%d, [r%d #0x%x]", Rd, Rn, (OpCode >> 4) & 0x7c);
541 case LOAD_STORE_FORMAT1_H:
543 AsciiSPrint (&Buf[Offset], Size - Offset,
" r%d, [r%d #0x%x]", Rd, Rn, (OpCode >> 5) & 0x3e);
545 case LOAD_STORE_FORMAT1_B:
547 AsciiSPrint (&Buf[Offset], Size - Offset,
" r%d, [r%d #0x%x]", Rd, Rn, (OpCode >> 6) & 0x1f);
550 case LOAD_STORE_FORMAT2:
552 AsciiSPrint (&Buf[Offset], Size - Offset,
" r%d, [r%d, r%d]", Rd, Rn, Rm);
554 case LOAD_STORE_FORMAT3:
556 Target = (OpCode & 0xff) << 2;
557 AsciiSPrint (&Buf[Offset], Size - Offset,
" r%d, [pc, #0x%x] ;0x%08x", (OpCode >> 8) & 7, Target, PcAlign4 (Pc) + Target);
559 case LOAD_STORE_FORMAT4:
561 Target = (OpCode & 0xff) << 2;
562 AsciiSPrint (&Buf[Offset], Size - Offset,
" r%d, [sp, #0x%x]", (OpCode >> 8) & 7, Target);
565 case LOAD_STORE_MULTIPLE_FORMAT1:
567 AsciiSPrint (&Buf[Offset], Size - Offset,
" r%d!, %a", (OpCode >> 8) & 7, ThumbMRegList (OpCode & 0xff));
572 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a", ThumbMRegList ((OpCode & 0xff) | ((OpCode & BIT8) == BIT8 ? BIT15 : 0)));
577 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a", ThumbMRegList ((OpCode & 0xff) | ((OpCode & BIT8) == BIT8 ? BIT14 : 0)));
582 AsciiSPrint (&Buf[Offset], Size - Offset,
" 0x%x", OpCode & 0xff);
585 case CONDITIONAL_BRANCH:
588 Cond = gCondition[(OpCode >> 8) & 0xf];
589 Buf[Offset-5] = *Cond++;
590 Buf[Offset-4] = *Cond;
591 AsciiSPrint (&Buf[Offset], Size - Offset,
" 0x%04x", Pc + 4 + SignExtend32 ((OpCode & 0xff) << 1, BIT8));
593 case UNCONDITIONAL_BRANCH_SHORT:
595 AsciiSPrint (&Buf[Offset], Size - Offset,
" 0x%04x", Pc + 4 + SignExtend32 ((OpCode & 0x3ff) << 1, BIT11));
598 case BRANCH_EXCHANGE:
600 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a", gReg[Rn | (H2Bit ? 8 : 0)]);
605 AsciiSPrint (&Buf[Offset], Size - Offset,
" r%d, r%d, r%d", Rd, Rn, Rm);
609 AsciiSPrint (&Buf[Offset], Size - Offset,
" r%d, r%d, 0x%x", Rd, Rn, Rm);
613 AsciiSPrint (&Buf[Offset], Size - Offset,
" r%d, #0x%x", (OpCode >> 8) & 7, OpCode & 0xff);
617 AsciiSPrint (&Buf[Offset], Size - Offset,
" r%d, r%d, 0x%x", Rn, Rd, (OpCode >> 6) & 0x1f);
621 AsciiSPrint (&Buf[Offset], Size - Offset,
" r%d, r%d", Rd, Rn);
623 case DATA_FORMAT6_SP:
625 AsciiSPrint (&Buf[Offset], Size - Offset,
" r%d, sp, 0x%x", (OpCode >> 8) & 7, (OpCode & 0xff) << 2);
627 case DATA_FORMAT6_PC:
629 AsciiSPrint (&Buf[Offset], Size - Offset,
" r%d, pc, 0x%x", (OpCode >> 8) & 7, (OpCode & 0xff) << 2);
633 AsciiSPrint (&Buf[Offset], Size - Offset,
" sp, sp, 0x%x", (OpCode & 0x7f)*4);
637 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %a", gReg[Rd | (H1Bit ? 8 : 0)], gReg[Rn | (H2Bit ? 8 : 0)]);
642 AsciiSPrint (&Buf[Offset], Size - Offset,
"%a %a%a%a", IMod ?
"ID" :
"IE", ((OpCode & BIT2) == 0) ?
"" :
"a", ((OpCode & BIT1) == 0) ?
"" :
"i", ((OpCode & BIT0) == 0) ?
"" :
"f");
647 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a", (OpCode & BIT3) == 0 ?
"LE" :
"BE");
652 Target = ((OpCode >> 2) & 0x3e) | (((OpCode & BIT9) == BIT9) ? BIT6 : 0);
653 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %08x", gReg[Rd], Pc + 4 + Target);
658 Target = (OpCode & 0xff) << 2;
659 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %08x", gReg[(OpCode >> 8) & 7], PcAlign4 (Pc) + Target);
671 Mask = (OpCode & 0xf);
672 if ((Mask & 0x1) == 0x1) {
674 Offset +=
AsciiSPrint (&Buf[Offset], Size - Offset,
"%a%a%a", (Mask & BIT3) ?
"T" :
"E", (Mask & BIT2) ?
"T" :
"E", (Mask & BIT1) ?
"T" :
"E");
675 }
else if ((OpCode & 0x3) == 0x2) {
677 Offset +=
AsciiSPrint (&Buf[Offset], Size - Offset,
"%a%a", (Mask & BIT3) ?
"T" :
"E", (Mask & BIT2) ?
"T" :
"E");
678 }
else if ((OpCode & 0x7) == 0x4) {
680 Offset +=
AsciiSPrint (&Buf[Offset], Size - Offset,
"%a", (Mask & BIT3) ?
"T" :
"E");
681 }
else if ((OpCode & 0xf) == 0x8) {
685 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a", gCondition[(OpCode >> 4) & 0xf]);
693 Rt = (OpCode32 >> 12) & 0xf;
694 Rt2 = (OpCode32 >> 8) & 0xf;
695 Rd = (OpCode32 >> 8) & 0xf;
696 Rm = (OpCode32 & 0xf);
697 Rn = (OpCode32 >> 16) & 0xf;
699 if ((OpCode32 & gOpThumb2[Index].Mask) == gOpThumb2[Index].OpCode) {
701 Offset =
AsciiSPrint (Buf, Size,
"0x%04x %-6a", OpCode32, gOpThumb2[Index].Start);
703 Offset =
AsciiSPrint (Buf, Size,
" %-6a", gOpThumb2[Index].Start);
706 switch (gOpThumb2[Index].AddressMode) {
708 Cond = gCondition[(OpCode32 >> 22) & 0xf];
709 Buf[Offset-5] = *Cond++;
710 Buf[Offset-4] = *Cond;
712 Target = ((OpCode32 << 1) & 0xffe) + ((OpCode32 >> 4) & 0x3f000);
713 Target |= ((OpCode32 & BIT11) == BIT11) ? BIT19 : 0;
714 Target |= ((OpCode32 & BIT13) == BIT13) ? BIT18 : 0;
715 Target |= ((OpCode32 & BIT26) == BIT26) ? BIT20 : 0;
716 Target = SignExtend32 (Target, BIT20);
717 AsciiSPrint (&Buf[Offset], Size - Offset,
" 0x%08x", Pc + 4 + Target);
721 Target = ((OpCode32 << 1) & 0xffe) + ((OpCode32 >> 4) & 0x3ff000);
722 Sign = (OpCode32 & BIT26) == BIT26;
723 J1Bit = (OpCode32 & BIT13) == BIT13;
724 J2Bit = (OpCode32 & BIT11) == BIT11;
725 Target |= (!(J2Bit ^ Sign) ? BIT22 : 0);
726 Target |= (!(J1Bit ^ Sign) ? BIT23 : 0);
727 Target |= (Sign ? BIT24 : 0);
728 Target = SignExtend32 (Target, BIT24);
729 AsciiSPrint (&Buf[Offset], Size - Offset,
" 0x%08x", Pc + 4 + Target);
734 Target = ((OpCode32 << 1) & 0xffc) + ((OpCode32 >> 4) & 0x3ff000);
735 Sign = (OpCode32 & BIT26) == BIT26;
736 J1Bit = (OpCode32 & BIT13) == BIT13;
737 J2Bit = (OpCode32 & BIT11) == BIT11;
738 Target |= (!(J2Bit ^ Sign) ? BIT23 : 0);
739 Target |= (!(J1Bit ^ Sign) ? BIT24 : 0);
740 Target |= (Sign ? BIT25 : 0);
741 Target = SignExtend32 (Target, BIT25);
742 AsciiSPrint (&Buf[Offset], Size - Offset,
" 0x%08x", PcAlign4 (Pc) + Target);
747 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a", ThumbMRegList (OpCode32 & 0xffff));
752 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a", gReg[(OpCode32 >> 12) & 0xf]);
757 WriteBack = (OpCode32 & BIT21) == BIT21;
758 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a%a, %a", gReg[(OpCode32 >> 16) & 0xf], WriteBack ?
"!" :
"", ThumbMRegList (OpCode32 & 0xffff));
761 case LDM_REG_IMM12_SIGNED:
763 Target = OpCode32 & 0xfff;
764 if ((OpCode32 & BIT23) == 0) {
769 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %a", gReg[(OpCode32 >> 12) & 0xf], PcAlign4 (Pc) + Target);
772 case LDM_REG_INDIRECT_LSL:
774 Offset +=
AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, [%a, %a", gReg[Rt], gReg[Rn], gReg[Rm]);
775 if (((OpCode32 >> 4) & 3) == 0) {
778 AsciiSPrint (&Buf[Offset], Size - Offset,
", LSL #%d]", (OpCode32 >> 4) & 3);
785 Offset +=
AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, [%a", gReg[Rt], gReg[Rn]);
786 if ((OpCode32 & 0xfff) == 0) {
789 AsciiSPrint (&Buf[Offset], Size - Offset,
", #0x%x]", OpCode32 & 0xfff);
796 WriteBack = (OpCode32 & BIT8) == BIT8;
797 UAdd = (OpCode32 & BIT9) == BIT9;
798 Pre = (OpCode32 & BIT10) == BIT10;
799 Offset +=
AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, [%a", gReg[Rt], gReg[Rn]);
801 if ((OpCode32 & 0xff) == 0) {
802 AsciiSPrint (&Buf[Offset], Size - Offset,
"]%a", WriteBack ?
"!" :
"");
804 AsciiSPrint (&Buf[Offset], Size - Offset,
", #%a0x%x]%a", UAdd ?
"" :
"-", OpCode32 & 0xff, WriteBack ?
"!" :
"");
807 AsciiSPrint (&Buf[Offset], Size - Offset,
"], #%a0x%x", UAdd ?
"" :
"-", OpCode32 & 0xff);
812 case LDRD_REG_IMM8_SIGNED:
814 Pre = (OpCode32 & BIT24) == BIT24;
815 UAdd = (OpCode32 & BIT23) == BIT23;
816 WriteBack = (OpCode32 & BIT21) == BIT21;
817 Offset +=
AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %a, [%a", gReg[Rt], gReg[Rt2], gReg[Rn]);
819 if ((OpCode32 & 0xff) == 0) {
822 AsciiSPrint (&Buf[Offset], Size - Offset,
", #%a0x%x]%a", UAdd ?
"" :
"-", (OpCode32 & 0xff) << 2, WriteBack ?
"!" :
"");
825 if ((OpCode32 & 0xff) != 0) {
826 AsciiSPrint (&Buf[Offset], Size - Offset,
", #%a0x%x", UAdd ?
"" :
"-", (OpCode32 & 0xff) << 2);
834 Target = (OpCode32 & 0xff) << 2;
835 if ((OpCode32 & BIT23) == 0) {
840 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %a, %a", gReg[Rt], gReg[Rt2], Pc + 4 + Target);
845 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, [%a]", gReg[Rt], gReg[Rn]);
850 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, ,%a, [%a]", gReg[Rt], gReg[Rt2], gReg[Rn]);
855 WriteBack = (OpCode32 & BIT21) == BIT21;
856 AsciiSPrint (&Buf[Offset], Size - Offset,
" SP%a, #0x%x", WriteBack ?
"!" :
"", OpCode32 & 0x1f);
861 WriteBack = (OpCode32 & BIT21) == BIT21;
862 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a%a, #0x%x", gReg[Rn], WriteBack ?
"!" :
"");
867 if ((OpCode32 & BIT20) == BIT20) {
868 Buf[Offset - 3] =
'S';
871 Target = (OpCode32 & 0xff) | ((OpCode32 >> 4) & 0x700) | ((OpCode & BIT26) == BIT26 ? BIT11 : 0);
872 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %a, #0x%x", gReg[Rd], gReg[Rn], Target);
877 if ((OpCode32 & BIT20) == BIT20) {
878 Buf[Offset - 3] =
'S';
881 Target = (OpCode32 & 0xff) | ((OpCode32 >> 4) & 0x700) | ((OpCode & BIT26) == BIT26 ? BIT11 : 0);
882 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, #0x%x", gReg[Rd], Target);
887 Target = (OpCode32 & 0xff) | ((OpCode32 >> 4) & 0x700) | ((OpCode & BIT26) == BIT26 ? BIT11 : 0);
888 Target |= ((OpCode32 >> 4) & 0xf0000);
889 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, #0x%x", gReg[Rd], Target);
894 if ((OpCode32 & BIT20) == BIT20) {
895 Buf[Offset - 3] =
'S';
898 Target = ((OpCode32 >> 6) & 3) | ((OpCode32 >> 10) & 0x1c0);
899 Offset +=
AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %a, %a", gReg[Rd], gReg[Rn], gReg[Rm]);
901 AsciiSPrint (&Buf[Offset], Size - Offset,
", LSL %d", gShiftType[(OpCode >> 5) & 3], Target);
908 Target = ((OpCode32 >> 6) & 3) | ((OpCode32 >> 10) & 0x1c0);
909 Offset +=
AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %a", gReg[Rn], gReg[Rm]);
911 AsciiSPrint (&Buf[Offset], Size - Offset,
", LSL %d", gShiftType[(OpCode >> 5) & 3], Target);
916 if ((OpCode32 & BIT20) == BIT20) {
917 Buf[Offset - 3] =
'S';
920 Target = ((OpCode32 >> 6) & 3) | ((OpCode32 >> 10) & 0x1c0);
921 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %a #%d", gReg[Rd], gReg[Rm], Target);
926 if ((OpCode32 & BIT20) == BIT20) {
927 Buf[Offset - 3] =
'S';
930 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %a %a", gReg[Rd], gReg[Rn], gReg[Rm]);
935 Target = (OpCode32 & 0xff) | ((OpCode32 >> 8) & 0x700) | ((OpCode & BIT26) == BIT26 ? BIT11 : 0);
936 if ((OpCode & (BIT23 | BIT21)) == (BIT23 | BIT21)) {
937 Target = PcAlign4 (Pc) - Target;
939 Target = PcAlign4 (Pc) + Target;
942 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, 0x%08x", gReg[Rd], Target);
947 Target = (OpCode32 & 0xff) | ((OpCode >> 4) & 0x700) | ((OpCode & BIT26) == BIT26 ? BIT11 : 0);
948 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, #0x%x", gReg[Rn], Target);
953 MsBit = OpCode32 & 0x1f;
954 LsBit = ((OpCode32 >> 6) & 3) | ((OpCode >> 10) & 0x1c);
955 if ((Rn == 0xf) & (
AsciiStrCmp (gOpThumb2[Index].Start,
"BFC") == 0)) {
957 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, #%d, #%d", gReg[Rd], LsBit, MsBit - LsBit + 1);
958 }
else if (
AsciiStrCmp (gOpThumb2[Index].Start,
"BFI") == 0) {
959 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %a, #%d, #%d", gReg[Rd], gReg[Rn], LsBit, MsBit - LsBit + 1);
961 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %a, #%d, #%d", gReg[Rd], gReg[Rn], LsBit, MsBit + 1);
968 Coproc = (OpCode32 >> 8) & 0xf;
969 Opc1 = (OpCode32 >> 20) & 0xf;
970 Opc2 = (OpCode32 >> 5) & 0x7;
971 CRd = (OpCode32 >> 12) & 0xf;
972 CRn = (OpCode32 >> 16) & 0xf;
973 CRm = OpCode32 & 0xf;
974 Offset +=
AsciiSPrint (&Buf[Offset], Size - Offset,
" p%d,#%d,c%d,c%d,c%d", Coproc, Opc1, CRd, CRn, CRm);
976 AsciiSPrint (&Buf[Offset], Size - Offset,
",#%d,", Opc2);
983 Coproc = (OpCode32 >> 8) & 0xf;
984 Opc1 = (OpCode32 >> 20) & 0xf;
985 Opc2 = (OpCode32 >> 5) & 0x7;
986 CRn = (OpCode32 >> 16) & 0xf;
987 CRm = OpCode32 & 0xf;
988 Offset +=
AsciiSPrint (&Buf[Offset], Size - Offset,
" p%d,#%d,%a,c%d,c%d", Coproc, Opc1, gReg[Rt], CRn, CRm);
990 AsciiSPrint (&Buf[Offset], Size - Offset,
",#%d,", Opc2);
997 Coproc = (OpCode32 >> 8) & 0xf;
998 Opc1 = (OpCode32 >> 20) & 0xf;
999 CRn = (OpCode32 >> 16) & 0xf;
1000 CRm = OpCode32 & 0xf;
1001 Offset +=
AsciiSPrint (&Buf[Offset], Size - Offset,
" p%d,#%d,%a,%a,c%d", Coproc, Opc1, gReg[Rt], gReg[Rt2], CRm);
1006 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %a", gReg[Rd], gReg[Rm]);
1011 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, %a, %a, %a", gReg[Rd], gReg[Rn], gReg[Rm], gReg[Rt]);
1016 AsciiSPrint (&Buf[Offset], Size - Offset,
" %a, CPSR", gReg[Rd]);
1021 Target = (OpCode32 >> 10) & 3;
1022 AsciiSPrint (&Buf[Offset], Size - Offset,
" CPSR_%a%a, %a", (Target & 2) == 0 ?
"" :
"f", (Target & 1) == 0 ?
"" :
"s", gReg[Rd]);
1025 case THUMB2_NO_ARGS:
1037 IN UINT32 **OpCodePtr,
1060 IN UINT8 **OpCodePtr,
1062 IN BOOLEAN Extended,
1063 IN OUT UINT32 *ItBlock,
RETURN_STATUS EFIAPI AsciiStrCatS(IN OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
VOID DisassembleArmInstruction(IN UINT32 **OpCodePtr, OUT CHAR8 *Buf, OUT UINTN Size, IN BOOLEAN Extended)
VOID DisassembleInstruction(IN UINT8 **OpCodePtr, IN BOOLEAN Thumb, IN BOOLEAN Extended, IN OUT UINT32 *ItBlock, OUT CHAR8 *Buf, OUT UINTN Size)
VOID DisassembleThumbInstruction(IN UINT16 **OpCodePtrPtr, OUT CHAR8 *Buf, OUT UINTN Size, OUT UINT32 *ItBlock, IN BOOLEAN Extended)