Rizin
unix-like reverse engineering framework and cli tools
MCRegisterInfo.c
Go to the documentation of this file.
1 //=== MC/MCRegisterInfo.cpp - Target Register Description -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements MCRegisterInfo functions.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 /* Capstone Disassembly Engine */
15 /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */
16 
17 #include "MCRegisterInfo.h"
18 
23 typedef struct DiffListIterator {
25  const MCPhysReg *List;
27 
29  const MCRegisterDesc *D, unsigned NR,
30  unsigned RA, unsigned PC,
31  const MCRegisterClass *C, unsigned NC,
32  uint16_t (*RURoots)[2], unsigned NRU,
33  const MCPhysReg *DL,
34  const char *Strings,
35  const uint16_t *SubIndices, unsigned NumIndices,
36  const uint16_t *RET)
37 {
38  RI->Desc = D;
39  RI->NumRegs = NR;
40  RI->RAReg = RA;
41  RI->PCReg = PC;
42  RI->Classes = C;
43  RI->DiffLists = DL;
44  RI->RegStrings = Strings;
45  RI->NumClasses = NC;
46  RI->RegUnitRoots = RURoots;
47  RI->NumRegUnits = NRU;
48  RI->SubRegIndices = SubIndices;
49  RI->NumSubRegIndices = NumIndices;
50  RI->RegEncodingTable = RET;
51 }
52 
53 static void DiffListIterator_init(DiffListIterator *d, MCPhysReg InitVal, const MCPhysReg *DiffList)
54 {
55  d->Val = InitVal;
56  d->List = DiffList;
57 }
58 
60 {
61  return d->Val;
62 }
63 
65 {
66  MCPhysReg D;
67 
68  if (d->List == 0)
69  return false;
70 
71  D = *d->List;
72  d->List++;
73  d->Val += D;
74 
75  if (!D)
76  d->List = 0;
77 
78  return (D != 0);
79 }
80 
82 {
83  return (d->List != 0);
84 }
85 
86 unsigned MCRegisterInfo_getMatchingSuperReg(const MCRegisterInfo *RI, unsigned Reg, unsigned SubIdx, const MCRegisterClass *RC)
87 {
89 
90  if (Reg >= RI->NumRegs) {
91  return 0;
92  }
93 
96 
99  if (MCRegisterClass_contains(RC, val) && Reg == MCRegisterInfo_getSubReg(RI, val, SubIdx))
100  return val;
101 
103  }
104 
105  return 0;
106 }
107 
108 unsigned MCRegisterInfo_getSubReg(const MCRegisterInfo *RI, unsigned Reg, unsigned Idx)
109 {
111  const uint16_t *SRI = RI->SubRegIndices + RI->Desc[Reg].SubRegIndices;
112 
115 
116  while(DiffListIterator_isValid(&iter)) {
117  if (*SRI == Idx)
118  return DiffListIterator_getVal(&iter);
120  ++SRI;
121  }
122 
123  return 0;
124 }
125 
127 {
128  //assert(i < getNumRegClasses() && "Register Class ID out of range");
129  if (i >= RI->NumClasses)
130  return 0;
131  return &(RI->Classes[i]);
132 }
133 
135 {
136  unsigned InByte = Reg % 8;
137  unsigned Byte = Reg / 8;
138 
139  if (Byte >= c->RegSetSize)
140  return false;
141 
142  return (c->RegSet[Byte] & (1 << InByte)) != 0;
143 }
static uint16_t DiffListIterator_getVal(DiffListIterator *d)
unsigned MCRegisterInfo_getMatchingSuperReg(const MCRegisterInfo *RI, unsigned Reg, unsigned SubIdx, const MCRegisterClass *RC)
static bool DiffListIterator_isValid(DiffListIterator *d)
const MCRegisterClass * MCRegisterInfo_getRegClass(const MCRegisterInfo *RI, unsigned i)
void MCRegisterInfo_InitMCRegisterInfo(MCRegisterInfo *RI, const MCRegisterDesc *D, unsigned NR, unsigned RA, unsigned PC, const MCRegisterClass *C, unsigned NC, uint16_t(*RURoots)[2], unsigned NRU, const MCPhysReg *DL, const char *Strings, const uint16_t *SubIndices, unsigned NumIndices, const uint16_t *RET)
static void DiffListIterator_init(DiffListIterator *d, MCPhysReg InitVal, const MCPhysReg *DiffList)
bool MCRegisterClass_contains(const MCRegisterClass *c, unsigned Reg)
struct DiffListIterator DiffListIterator
static bool DiffListIterator_next(DiffListIterator *d)
unsigned MCRegisterInfo_getSubReg(const MCRegisterInfo *RI, unsigned Reg, unsigned Idx)
uint16_t MCPhysReg
lzma_index ** i
Definition: index.h:629
#define RET
#define C(x)
Definition: arc.h:167
#define PC(addr, is_thumb)
Definition: arm_il32.c:108
ut16 val
Definition: armass64_const.h:6
#define D
Definition: block.c:38
#define NC
Definition: utils.h:42
unsigned short uint16_t
Definition: sftypes.h:30
#define d(i)
Definition: sha256.c:44
#define c(i)
Definition: sha256.c:43
const MCPhysReg * List
uint32_t SubRegIndices
uint32_t SubRegs
uint32_t SuperRegs
unsigned NumClasses
const MCRegisterDesc * Desc
const uint16_t * SubRegIndices
const char * RegStrings
unsigned NumRegUnits
const MCRegisterClass * Classes
uint16_t(* RegUnitRoots)[2]
const MCPhysReg * DiffLists
unsigned NumSubRegIndices
const uint16_t * RegEncodingTable
unsigned NumRegs
unsigned char Byte
Definition: zconf.h:391