Coverage Report

Created: 2023-09-25 06:24

/src/capstonenext/arch/PowerPC/PPCDisassembler.c
Line
Count
Source (jump to first uncovered line)
1
/* Capstone Disassembly Engine, http://www.capstone-engine.org */
2
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2022, */
3
/*    Rot127 <unisono@quyllur.org> 2022-2023 */
4
/* Automatically translated source file from LLVM. */
5
6
/* LLVM-commit: <commit> */
7
/* LLVM-tag: <tag> */
8
9
/* Only small edits allowed. */
10
/* For multiple similar edits, please create a Patch for the translator. */
11
12
/* Capstone's C++ file translator: */
13
/* https://github.com/capstone-engine/capstone/tree/next/suite/auto-sync */
14
15
//===------ PPCDisassembler.cpp - Disassembler for PowerPC ------*- C++ -*-===//
16
//
17
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
18
// See https://llvm.org/LICENSE.txt for license information.
19
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
20
//
21
//===----------------------------------------------------------------------===//
22
23
#include <capstone/platform.h>
24
#include <stdio.h>
25
#include <stdlib.h>
26
#include <string.h>
27
28
#include "../../LEB128.h"
29
#include "../../MCDisassembler.h"
30
#include "../../MCFixedLenDisassembler.h"
31
#include "../../MCInst.h"
32
#include "../../MCInstPrinter.h"
33
#include "../../MCInstrDesc.h"
34
#include "../../MCRegisterInfo.h"
35
#include "../../SStream.h"
36
#include "../../utils.h"
37
#include "PPCLinkage.h"
38
#include "PPCMapping.h"
39
#include "PPCMCTargetDesc.h"
40
#include "PPCPredicates.h"
41
42
#define CONCAT(a, b) CONCAT_(a, b)
43
#define CONCAT_(a, b) a##_##b
44
45
DEFINE_PPC_REGCLASSES
46
47
#define DEBUG_TYPE "ppc-disassembler"
48
49
DecodeStatus getInstruction(csh ud, const uint8_t *Bytes, size_t BytesLen,
50
          MCInst *MI, uint16_t *Size, uint64_t Address,
51
          void *Info);
52
// end anonymous namespace
53
54
static DecodeStatus decodeCondBrTarget(MCInst *Inst, unsigned Imm,
55
               uint64_t Address, const void *Decoder)
56
1.70k
{
57
1.70k
  MCOperand_CreateImm0(Inst, (SignExtend32((Imm), 14)));
58
1.70k
  return MCDisassembler_Success;
59
1.70k
}
60
61
static DecodeStatus decodeDirectBrTarget(MCInst *Inst, unsigned Imm,
62
           uint64_t Address, const void *Decoder)
63
432
{
64
432
  int32_t Offset = SignExtend32((Imm), 24);
65
432
  MCOperand_CreateImm0(Inst, (Offset));
66
432
  return MCDisassembler_Success;
67
432
}
68
69
// FIXME: These can be generated by TableGen from the existing register
70
// encoding values!
71
72
static DecodeStatus decodeRegisterClass(MCInst *Inst, uint64_t RegNo,
73
          const MCPhysReg *Regs)
74
121k
{
75
121k
  MCOperand_CreateReg0(Inst, (Regs[RegNo]));
76
121k
  return MCDisassembler_Success;
77
121k
}
78
79
static DecodeStatus DecodeCRRCRegisterClass(MCInst *Inst, uint64_t RegNo,
80
              uint64_t Address,
81
              const void *Decoder)
82
3.68k
{
83
3.68k
  return decodeRegisterClass(Inst, RegNo, CRRegs);
84
3.68k
}
85
86
static DecodeStatus DecodeCRBITRCRegisterClass(MCInst *Inst, uint64_t RegNo,
87
                 uint64_t Address,
88
                 const void *Decoder)
89
4.71k
{
90
4.71k
  return decodeRegisterClass(Inst, RegNo, CRBITRegs);
91
4.71k
}
92
93
static DecodeStatus DecodeF4RCRegisterClass(MCInst *Inst, uint64_t RegNo,
94
              uint64_t Address,
95
              const void *Decoder)
96
3.77k
{
97
3.77k
  return decodeRegisterClass(Inst, RegNo, FRegs);
98
3.77k
}
99
100
static DecodeStatus DecodeF8RCRegisterClass(MCInst *Inst, uint64_t RegNo,
101
              uint64_t Address,
102
              const void *Decoder)
103
5.16k
{
104
5.16k
  return decodeRegisterClass(Inst, RegNo, FRegs);
105
5.16k
}
106
107
static DecodeStatus DecodeVFRCRegisterClass(MCInst *Inst, uint64_t RegNo,
108
              uint64_t Address,
109
              const void *Decoder)
110
569
{
111
569
  return decodeRegisterClass(Inst, RegNo, VFRegs);
112
569
}
113
114
static DecodeStatus DecodeVRRCRegisterClass(MCInst *Inst, uint64_t RegNo,
115
              uint64_t Address,
116
              const void *Decoder)
117
10.7k
{
118
10.7k
  return decodeRegisterClass(Inst, RegNo, VRegs);
119
10.7k
}
120
121
static DecodeStatus DecodeVSRCRegisterClass(MCInst *Inst, uint64_t RegNo,
122
              uint64_t Address,
123
              const void *Decoder)
124
7.32k
{
125
7.32k
  return decodeRegisterClass(Inst, RegNo, VSRegs);
126
7.32k
}
127
128
static DecodeStatus DecodeVSFRCRegisterClass(MCInst *Inst, uint64_t RegNo,
129
               uint64_t Address,
130
               const void *Decoder)
131
2.23k
{
132
2.23k
  return decodeRegisterClass(Inst, RegNo, VSFRegs);
133
2.23k
}
134
135
static DecodeStatus DecodeVSSRCRegisterClass(MCInst *Inst, uint64_t RegNo,
136
               uint64_t Address,
137
               const void *Decoder)
138
2.72k
{
139
2.72k
  return decodeRegisterClass(Inst, RegNo, VSSRegs);
140
2.72k
}
141
142
static DecodeStatus DecodeGPRCRegisterClass(MCInst *Inst, uint64_t RegNo,
143
              uint64_t Address,
144
              const void *Decoder)
145
44.3k
{
146
44.3k
  return decodeRegisterClass(Inst, RegNo, RRegs);
147
44.3k
}
148
149
static DecodeStatus DecodeGPRC_NOR0RegisterClass(MCInst *Inst, uint64_t RegNo,
150
             uint64_t Address,
151
             const void *Decoder)
152
8.48k
{
153
8.48k
  return decodeRegisterClass(Inst, RegNo, RRegsNoR0);
154
8.48k
}
155
156
static DecodeStatus DecodeG8RCRegisterClass(MCInst *Inst, uint64_t RegNo,
157
              uint64_t Address,
158
              const void *Decoder)
159
13.0k
{
160
13.0k
  return decodeRegisterClass(Inst, RegNo, XRegs);
161
13.0k
}
162
163
static DecodeStatus DecodeG8pRCRegisterClass(MCInst *Inst, uint64_t RegNo,
164
               uint64_t Address,
165
               const void *Decoder)
166
701
{
167
701
  return decodeRegisterClass(Inst, RegNo, XRegs);
168
701
}
169
170
static DecodeStatus DecodeG8RC_NOX0RegisterClass(MCInst *Inst, uint64_t RegNo,
171
             uint64_t Address,
172
             const void *Decoder)
173
34
{
174
34
  return decodeRegisterClass(Inst, RegNo, XRegsNoX0);
175
34
}
176
177
4.75k
#define DecodePointerLikeRegClass0 DecodeGPRCRegisterClass
178
7.11k
#define DecodePointerLikeRegClass1 DecodeGPRC_NOR0RegisterClass
179
180
static DecodeStatus DecodeSPERCRegisterClass(MCInst *Inst, uint64_t RegNo,
181
               uint64_t Address,
182
               const void *Decoder)
183
0
{
184
0
  return decodeRegisterClass(Inst, RegNo, SPERegs);
185
0
}
186
187
static DecodeStatus DecodeACCRCRegisterClass(MCInst *Inst, uint64_t RegNo,
188
               uint64_t Address,
189
               const void *Decoder)
190
0
{
191
0
  return decodeRegisterClass(Inst, RegNo, ACCRegs);
192
0
}
193
194
static DecodeStatus DecodeWACCRCRegisterClass(MCInst *Inst, uint64_t RegNo,
195
                uint64_t Address,
196
                const void *Decoder)
197
144
{
198
144
  return decodeRegisterClass(Inst, RegNo, WACCRegs);
199
144
}
200
201
static DecodeStatus DecodeWACC_HIRCRegisterClass(MCInst *Inst, uint64_t RegNo,
202
             uint64_t Address,
203
             const void *Decoder)
204
86
{
205
86
  return decodeRegisterClass(Inst, RegNo, WACC_HIRegs);
206
86
}
207
208
// TODO: Make this function static when the register class is used by a new
209
//       instruction.
210
DecodeStatus DecodeDMRROWRCRegisterClass(MCInst *Inst, uint64_t RegNo,
211
           uint64_t Address, const void *Decoder)
212
0
{
213
0
  return decodeRegisterClass(Inst, RegNo, DMRROWRegs);
214
0
}
215
216
static DecodeStatus DecodeDMRROWpRCRegisterClass(MCInst *Inst, uint64_t RegNo,
217
             uint64_t Address,
218
             const void *Decoder)
219
28
{
220
28
  return decodeRegisterClass(Inst, RegNo, DMRROWpRegs);
221
28
}
222
223
static DecodeStatus DecodeDMRRCRegisterClass(MCInst *Inst, uint64_t RegNo,
224
               uint64_t Address,
225
               const void *Decoder)
226
100
{
227
100
  return decodeRegisterClass(Inst, RegNo, DMRRegs);
228
100
}
229
230
// TODO: Make this function static when the register class is used by a new
231
//       instruction.
232
DecodeStatus DecodeDMRpRCRegisterClass(MCInst *Inst, uint64_t RegNo,
233
               uint64_t Address, const void *Decoder)
234
0
{
235
0
  return decodeRegisterClass(Inst, RegNo, DMRpRegs);
236
0
}
237
238
static DecodeStatus DecodeVSRpRCRegisterClass(MCInst *Inst, uint64_t RegNo,
239
                uint64_t Address,
240
                const void *Decoder)
241
788
{
242
788
  return decodeRegisterClass(Inst, RegNo, VSRpRegs);
243
788
}
244
245
3.19k
#define DecodeQSRCRegisterClass DecodeQFRCRegisterClass
246
4.40k
#define DecodeQBRCRegisterClass DecodeQFRCRegisterClass
247
248
static DecodeStatus DecodeQFRCRegisterClass(MCInst *Inst, uint64_t RegNo,
249
              uint64_t Address,
250
              const void *Decoder)
251
12.7k
{
252
12.7k
  return decodeRegisterClass(Inst, RegNo, QFRegs);
253
12.7k
}
254
255
#define DEFINE_decodeUImmOperand(N) \
256
  static DecodeStatus CONCAT(decodeUImmOperand, \
257
           N)(MCInst * Inst, uint64_t Imm, \
258
              int64_t Address, const void *Decoder) \
259
24.1k
  { \
260
24.1k
    MCOperand_CreateImm0(Inst, (Imm)); \
261
24.1k
    return MCDisassembler_Success; \
262
24.1k
  }
PPCDisassembler.c:decodeUImmOperand_5
Line
Count
Source
259
13.9k
  { \
260
13.9k
    MCOperand_CreateImm0(Inst, (Imm)); \
261
13.9k
    return MCDisassembler_Success; \
262
13.9k
  }
PPCDisassembler.c:decodeUImmOperand_16
Line
Count
Source
259
5.64k
  { \
260
5.64k
    MCOperand_CreateImm0(Inst, (Imm)); \
261
5.64k
    return MCDisassembler_Success; \
262
5.64k
  }
PPCDisassembler.c:decodeUImmOperand_6
Line
Count
Source
259
2.60k
  { \
260
2.60k
    MCOperand_CreateImm0(Inst, (Imm)); \
261
2.60k
    return MCDisassembler_Success; \
262
2.60k
  }
PPCDisassembler.c:decodeUImmOperand_10
Line
Count
Source
259
66
  { \
260
66
    MCOperand_CreateImm0(Inst, (Imm)); \
261
66
    return MCDisassembler_Success; \
262
66
  }
PPCDisassembler.c:decodeUImmOperand_8
Line
Count
Source
259
91
  { \
260
91
    MCOperand_CreateImm0(Inst, (Imm)); \
261
91
    return MCDisassembler_Success; \
262
91
  }
PPCDisassembler.c:decodeUImmOperand_7
Line
Count
Source
259
279
  { \
260
279
    MCOperand_CreateImm0(Inst, (Imm)); \
261
279
    return MCDisassembler_Success; \
262
279
  }
PPCDisassembler.c:decodeUImmOperand_12
Line
Count
Source
259
1.42k
  { \
260
1.42k
    MCOperand_CreateImm0(Inst, (Imm)); \
261
1.42k
    return MCDisassembler_Success; \
262
1.42k
  }
263
DEFINE_decodeUImmOperand(5) DEFINE_decodeUImmOperand(16)
264
  DEFINE_decodeUImmOperand(6) DEFINE_decodeUImmOperand(10)
265
    DEFINE_decodeUImmOperand(8) DEFINE_decodeUImmOperand(7)
266
      DEFINE_decodeUImmOperand(12)
267
268
#define DEFINE_decodeSImmOperand(N) \
269
  static DecodeStatus CONCAT(decodeSImmOperand, \
270
           N)(MCInst * Inst, uint64_t Imm, \
271
              int64_t Address, const void *Decoder) \
272
8.02k
  { \
273
8.02k
    MCOperand_CreateImm0(Inst, (SignExtend64(Imm, N))); \
274
8.02k
    return MCDisassembler_Success; \
275
8.02k
  }
PPCDisassembler.c:decodeSImmOperand_16
Line
Count
Source
272
7.48k
  { \
273
7.48k
    MCOperand_CreateImm0(Inst, (SignExtend64(Imm, N))); \
274
7.48k
    return MCDisassembler_Success; \
275
7.48k
  }
PPCDisassembler.c:decodeSImmOperand_5
Line
Count
Source
272
45
  { \
273
45
    MCOperand_CreateImm0(Inst, (SignExtend64(Imm, N))); \
274
45
    return MCDisassembler_Success; \
275
45
  }
PPCDisassembler.c:decodeSImmOperand_34
Line
Count
Source
272
487
  { \
273
487
    MCOperand_CreateImm0(Inst, (SignExtend64(Imm, N))); \
274
487
    return MCDisassembler_Success; \
275
487
  }
276
        DEFINE_decodeSImmOperand(16)
277
          DEFINE_decodeSImmOperand(5)
278
            DEFINE_decodeSImmOperand(34)
279
280
              static DecodeStatus
281
  decodeImmZeroOperand(MCInst *Inst, uint64_t Imm, int64_t Address,
282
           const void *Decoder)
283
497
{
284
497
  if (Imm != 0)
285
23
    return MCDisassembler_Fail;
286
474
  MCOperand_CreateImm0(Inst, (Imm));
287
474
  return MCDisassembler_Success;
288
497
}
289
290
static DecodeStatus decodeVSRpEvenOperands(MCInst *Inst, uint64_t RegNo,
291
             uint64_t Address,
292
             const void *Decoder)
293
0
{
294
0
  if (RegNo & 1)
295
0
    return MCDisassembler_Fail;
296
0
  MCOperand_CreateReg0(Inst, (VSRpRegs[RegNo >> 1]));
297
0
  return MCDisassembler_Success;
298
0
}
299
300
static DecodeStatus decodeMemRIOperands(MCInst *Inst, uint64_t Imm,
301
          int64_t Address, const void *Decoder)
302
8.90k
{
303
  // Decode the memri field (imm, reg), which has the low 16-bits as the
304
  // displacement and the next 5 bits as the register #.
305
306
8.90k
  uint64_t Base = Imm >> 16;
307
8.90k
  uint64_t Disp = Imm & 0xFFFF;
308
309
8.90k
  switch (MCInst_getOpcode(Inst)) {
310
3.57k
  default:
311
3.57k
    break;
312
3.57k
  case PPC_LBZU:
313
1.82k
  case PPC_LHAU:
314
2.19k
  case PPC_LHZU:
315
2.97k
  case PPC_LWZU:
316
3.28k
  case PPC_LFSU:
317
3.60k
  case PPC_LFDU:
318
    // Add the tied output operand.
319
3.60k
    MCOperand_CreateReg0(Inst, (RRegsNoR0[Base]));
320
3.60k
    break;
321
339
  case PPC_STBU:
322
824
  case PPC_STHU:
323
1.22k
  case PPC_STWU:
324
1.46k
  case PPC_STFSU:
325
1.72k
  case PPC_STFDU:
326
1.72k
    MCInst_insert0(Inst, 0,
327
1.72k
             MCOperand_CreateReg1(Inst, RRegsNoR0[Base]));
328
1.72k
    break;
329
8.90k
  }
330
331
8.90k
  MCOperand_CreateImm0(Inst, (SignExtend64(Disp, 16)));
332
8.90k
  MCOperand_CreateReg0(Inst, (RRegsNoR0[Base]));
333
8.90k
  return MCDisassembler_Success;
334
8.90k
}
335
336
static DecodeStatus decodeMemRIXOperands(MCInst *Inst, uint64_t Imm,
337
           int64_t Address, const void *Decoder)
338
1.36k
{
339
  // Decode the memrix field (imm, reg), which has the low 14-bits as the
340
  // displacement and the next 5 bits as the register #.
341
342
1.36k
  uint64_t Base = Imm >> 14;
343
1.36k
  uint64_t Disp = Imm & 0x3FFF;
344
345
1.36k
  if (MCInst_getOpcode(Inst) == PPC_LDU)
346
    // Add the tied output operand.
347
222
    MCOperand_CreateReg0(Inst, (RRegsNoR0[Base]));
348
1.14k
  else if (MCInst_getOpcode(Inst) == PPC_STDU)
349
204
    MCInst_insert0(Inst, 0,
350
204
             MCOperand_CreateReg1(Inst, RRegsNoR0[Base]));
351
352
1.36k
  MCOperand_CreateImm0(Inst, (SignExtend64(Disp << 2, 16)));
353
1.36k
  MCOperand_CreateReg0(Inst, (RRegsNoR0[Base]));
354
1.36k
  return MCDisassembler_Success;
355
1.36k
}
356
357
static DecodeStatus decodeMemRIHashOperands(MCInst *Inst, uint64_t Imm,
358
              int64_t Address,
359
              const void *Decoder)
360
162
{
361
  // Decode the memrix field for a hash store or hash check operation.
362
  // The field is composed of a register and an immediate value that is 6 bits
363
  // and covers the range -8 to -512. The immediate is always negative and 2s
364
  // complement which is why we sign extend a 7 bit value.
365
162
  const uint64_t Base = Imm >> 6;
366
162
  const int64_t Disp = SignExtend64((Imm & 0x3F) + 64, 7) * 8;
367
368
162
  MCOperand_CreateImm0(Inst, (Disp));
369
162
  MCOperand_CreateReg0(Inst, (RRegs[Base]));
370
162
  return MCDisassembler_Success;
371
162
}
372
373
static DecodeStatus decodeMemRIX16Operands(MCInst *Inst, uint64_t Imm,
374
             int64_t Address, const void *Decoder)
375
639
{
376
  // Decode the memrix16 field (imm, reg), which has the low 12-bits as the
377
  // displacement with 16-byte aligned, and the next 5 bits as the register #.
378
379
639
  uint64_t Base = Imm >> 12;
380
639
  uint64_t Disp = Imm & 0xFFF;
381
382
639
  MCOperand_CreateImm0(Inst, (SignExtend64(Disp << 4, 16)));
383
639
  MCOperand_CreateReg0(Inst, (RRegsNoR0[Base]));
384
639
  return MCDisassembler_Success;
385
639
}
386
387
static DecodeStatus decodeMemRI34PCRelOperands(MCInst *Inst, uint64_t Imm,
388
                 int64_t Address,
389
                 const void *Decoder)
390
182
{
391
  // Decode the memri34_pcrel field (imm, reg), which has the low 34-bits as
392
  // the displacement, and the next 5 bits as an immediate 0.
393
182
  uint64_t Base = Imm >> 34;
394
182
  uint64_t Disp = Imm & 0x3FFFFFFFFUL;
395
396
182
  MCOperand_CreateImm0(Inst, (SignExtend64(Disp, 34)));
397
182
  return decodeImmZeroOperand(Inst, Base, Address, Decoder);
398
182
}
399
400
static DecodeStatus decodeMemRI34Operands(MCInst *Inst, uint64_t Imm,
401
            int64_t Address, const void *Decoder)
402
311
{
403
  // Decode the memri34 field (imm, reg), which has the low 34-bits as the
404
  // displacement, and the next 5 bits as the register #.
405
311
  uint64_t Base = Imm >> 34;
406
311
  uint64_t Disp = Imm & 0x3FFFFFFFFUL;
407
408
311
  MCOperand_CreateImm0(Inst, (SignExtend64(Disp, 34)));
409
311
  MCOperand_CreateReg0(Inst, (RRegsNoR0[Base]));
410
311
  return MCDisassembler_Success;
411
311
}
412
413
static DecodeStatus decodeSPE8Operands(MCInst *Inst, uint64_t Imm,
414
               int64_t Address, const void *Decoder)
415
0
{
416
  // Decode the spe8disp field (imm, reg), which has the low 5-bits as the
417
  // displacement with 8-byte aligned, and the next 5 bits as the register #.
418
419
0
  uint64_t Base = Imm >> 5;
420
0
  uint64_t Disp = Imm & 0x1F;
421
422
0
  MCOperand_CreateImm0(Inst, (Disp << 3));
423
0
  MCOperand_CreateReg0(Inst, (RRegsNoR0[Base]));
424
0
  return MCDisassembler_Success;
425
0
}
426
427
static DecodeStatus decodeSPE4Operands(MCInst *Inst, uint64_t Imm,
428
               int64_t Address, const void *Decoder)
429
0
{
430
  // Decode the spe4disp field (imm, reg), which has the low 5-bits as the
431
  // displacement with 4-byte aligned, and the next 5 bits as the register #.
432
433
0
  uint64_t Base = Imm >> 5;
434
0
  uint64_t Disp = Imm & 0x1F;
435
436
0
  MCOperand_CreateImm0(Inst, (Disp << 2));
437
0
  MCOperand_CreateReg0(Inst, (RRegsNoR0[Base]));
438
0
  return MCDisassembler_Success;
439
0
}
440
441
static DecodeStatus decodeSPE2Operands(MCInst *Inst, uint64_t Imm,
442
               int64_t Address, const void *Decoder)
443
0
{
444
  // Decode the spe2disp field (imm, reg), which has the low 5-bits as the
445
  // displacement with 2-byte aligned, and the next 5 bits as the register #.
446
447
0
  uint64_t Base = Imm >> 5;
448
0
  uint64_t Disp = Imm & 0x1F;
449
450
0
  MCOperand_CreateImm0(Inst, (Disp << 1));
451
0
  MCOperand_CreateReg0(Inst, (RRegsNoR0[Base]));
452
0
  return MCDisassembler_Success;
453
0
}
454
455
static DecodeStatus decodeCRBitMOperand(MCInst *Inst, uint64_t Imm,
456
          int64_t Address, const void *Decoder)
457
1.25k
{
458
  // The cr bit encoding is 0x80 >> cr_reg_num.
459
460
1.25k
  unsigned Zeros = CountTrailingZeros_32(Imm);
461
1.25k
  if (Zeros >= 8)
462
3
    return MCDisassembler_Fail;
463
464
1.25k
  MCOperand_CreateReg0(Inst, (CRRegs[7 - Zeros]));
465
1.25k
  return MCDisassembler_Success;
466
1.25k
}
467
468
#include "PPCGenDisassemblerTables.inc"
469
470
DecodeStatus getInstruction(csh ud, const uint8_t *Bytes, size_t BytesLen,
471
          MCInst *MI, uint16_t *Size, uint64_t Address,
472
          void *Info)
473
64.9k
{
474
  // If this is an 8-byte prefixed instruction, handle it here.
475
  // Note: prefixed instructions aren't technically 8-byte entities - the
476
  // prefix
477
  //       appears in memory at an address 4 bytes prior to that of the base
478
  //       instruction regardless of endianness. So we read the two pieces and
479
  //       rebuild the 8-byte instruction.
480
  // TODO: In this function we call decodeInstruction several times with
481
  //       different decoder tables. It may be possible to only call once by
482
  //       looking at the top 6 bits of the instruction.
483
64.9k
  if (PPC_getFeatureBits(MI->csh->mode, PPC_FeaturePrefixInstrs) &&
484
64.9k
      BytesLen >= 8) {
485
62.2k
    uint32_t Prefix = readBytes32(MI, Bytes);
486
62.2k
    uint32_t BaseInst = readBytes32(MI, Bytes + 4);
487
62.2k
    uint64_t Inst = BaseInst | (uint64_t)Prefix << 32;
488
62.2k
    DecodeStatus result =
489
62.2k
      decodeInstruction_4(DecoderTable64, MI, Inst, Address);
490
62.2k
    if (result != MCDisassembler_Fail) {
491
1.04k
      *Size = 8;
492
1.04k
      return result;
493
1.04k
    }
494
62.2k
  }
495
496
  // Get the four bytes of the instruction.
497
63.8k
  *Size = 4;
498
63.8k
  if (BytesLen < 4) {
499
772
    *Size = 0;
500
772
    return MCDisassembler_Fail;
501
772
  }
502
503
  // Read the instruction in the proper endianness.
504
63.1k
  uint64_t Inst = readBytes32(MI, Bytes);
505
506
63.1k
  if (PPC_getFeatureBits(MI->csh->mode, PPC_FeatureQPX)) {
507
32.4k
    DecodeStatus result = decodeInstruction_4(DecoderTableQPX32, MI,
508
32.4k
                Inst, Address);
509
32.4k
    if (result != MCDisassembler_Fail)
510
4.11k
      return result;
511
32.4k
  } else if (PPC_getFeatureBits(MI->csh->mode, PPC_FeatureSPE)) {
512
0
    DecodeStatus result = decodeInstruction_4(DecoderTableSPE32, MI,
513
0
                Inst, Address);
514
0
    if (result != MCDisassembler_Fail)
515
0
      return result;
516
30.7k
  } else if (PPC_getFeatureBits(MI->csh->mode, PPC_FeaturePS)) {
517
7.90k
    DecodeStatus result = decodeInstruction_4(DecoderTablePS32, MI,
518
7.90k
                Inst, Address);
519
7.90k
    if (result != MCDisassembler_Fail)
520
622
      return result;
521
7.90k
  }
522
523
58.3k
  return decodeInstruction_4(DecoderTable32, MI, Inst, Address);
524
63.1k
}
525
526
DecodeStatus PPC_LLVM_getInstruction(csh handle, const uint8_t *Bytes,
527
             size_t BytesLen, MCInst *MI,
528
             uint16_t *Size, uint64_t Address,
529
             void *Info)
530
64.9k
{
531
64.9k
  return getInstruction(handle, Bytes, BytesLen, MI, Size, Address, Info);
532
64.9k
}