Coverage Report

Created: 2024-08-21 06:24

/src/capstonenext/arch/AArch64/AArch64BaseInfo.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
//===-- AArch64BaseInfo.cpp - AArch64 Base encoding information------------===//
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
// This file provides basic encoding and assembly information for AArch64.
24
//
25
//===----------------------------------------------------------------------===//
26
#include <capstone/platform.h>
27
#include <stdio.h>
28
#include <stdlib.h>
29
#include <string.h>
30
31
#include "AArch64BaseInfo.h"
32
33
#define CONCAT(a, b) CONCAT_(a, b)
34
#define CONCAT_(a, b) a##_##b
35
36
#define GET_AT_IMPL
37
#include "AArch64GenSystemOperands.inc"
38
#undef GET_AT_IMPL
39
40
#define GET_DBNXS_IMPL
41
#include "AArch64GenSystemOperands.inc"
42
#undef GET_DBNXS_IMPL
43
44
#define GET_DB_IMPL
45
#include "AArch64GenSystemOperands.inc"
46
#undef GET_DB_IMPL
47
48
#define GET_DC_IMPL
49
#include "AArch64GenSystemOperands.inc"
50
#undef GET_DC_IMPL
51
52
#define GET_IC_IMPL
53
#include "AArch64GenSystemOperands.inc"
54
#undef GET_IC_IMPL
55
56
#define GET_ISB_IMPL
57
#include "AArch64GenSystemOperands.inc"
58
#undef GET_ISB_IMPL
59
60
#define GET_TSB_IMPL
61
#include "AArch64GenSystemOperands.inc"
62
#undef GET_TSB_IMPL
63
64
#define GET_PRCTX_IMPL
65
#include "AArch64GenSystemOperands.inc"
66
#undef GET_PRCTX_IMPL
67
68
#define GET_PRFM_IMPL
69
#include "AArch64GenSystemOperands.inc"
70
#undef GET_PRFM_IMPL
71
72
#define GET_SVEPRFM_IMPL
73
#include "AArch64GenSystemOperands.inc"
74
#undef GET_SVEPRFM_IMPL
75
76
#define GET_RPRFM_IMPL
77
#include "AArch64GenSystemOperands.inc"
78
#undef GET_RPRFM_IMPL
79
80
// namespace AArch64RPRFM
81
// namespace llvm
82
83
#define GET_SVEPREDPAT_IMPL
84
#include "AArch64GenSystemOperands.inc"
85
#undef GET_SVEPREDPAT_IMPL
86
87
#define GET_SVEVECLENSPECIFIER_IMPL
88
#include "AArch64GenSystemOperands.inc"
89
#undef GET_SVEVECLENSPECIFIER_IMPL
90
91
// namespace AArch64SVEVecLenSpecifier
92
// namespace llvm
93
94
#define GET_EXACTFPIMM_IMPL
95
#include "AArch64GenSystemOperands.inc"
96
#undef GET_EXACTFPIMM_IMPL
97
98
#define GET_PSTATEIMM0_15_IMPL
99
#include "AArch64GenSystemOperands.inc"
100
#undef GET_PSTATEIMM0_15_IMPL
101
102
#define GET_PSTATEIMM0_1_IMPL
103
#include "AArch64GenSystemOperands.inc"
104
#undef GET_PSTATEIMM0_1_IMPL
105
106
#define GET_PSB_IMPL
107
#include "AArch64GenSystemOperands.inc"
108
#undef GET_PSB_IMPL
109
110
#define GET_BTI_IMPL
111
#include "AArch64GenSystemOperands.inc"
112
#undef GET_BTI_IMPL
113
114
#define SysReg AArch64SysReg_SysReg
115
#define GET_SYSREG_IMPL
116
#include "AArch64GenSystemOperands.inc"
117
#undef GET_SYSREG_IMPL
118
119
#undef SysReg
120
121
// return a string representing the number X
122
// NOTE: result must be big enough to contain the data
123
static void utostr(uint64_t X, bool isNeg, char *result)
124
27.3k
{
125
27.3k
  char Buffer[22];
126
27.3k
  char *BufPtr = Buffer + 21;
127
128
27.3k
  Buffer[21] = '\0';
129
27.3k
  if (X == 0)
130
5.51k
    *--BufPtr = '0'; // Handle special case...
131
132
52.2k
  while (X) {
133
24.8k
    *--BufPtr = X % 10 + '0';
134
24.8k
    X /= 10;
135
24.8k
  }
136
137
27.3k
  if (isNeg)
138
0
    *--BufPtr = '-'; // Add negative sign...
139
140
  // suppose that result is big enough
141
27.3k
  strncpy(result, BufPtr, sizeof(Buffer));
142
27.3k
}
143
144
// NOTE: result must be big enough to contain the result
145
void AArch64SysReg_genericRegisterString(uint32_t Bits, char *result)
146
5.46k
{
147
  // assert(Bits < 0x10000);
148
5.46k
  char Op0Str[32], Op1Str[32], CRnStr[32], CRmStr[32], Op2Str[32];
149
5.46k
  int dummy;
150
5.46k
  uint32_t Op0 = (Bits >> 14) & 0x3;
151
5.46k
  uint32_t Op1 = (Bits >> 11) & 0x7;
152
5.46k
  uint32_t CRn = (Bits >> 7) & 0xf;
153
5.46k
  uint32_t CRm = (Bits >> 3) & 0xf;
154
5.46k
  uint32_t Op2 = Bits & 0x7;
155
156
5.46k
  utostr(Op0, false, Op0Str);
157
5.46k
  utostr(Op1, false, Op1Str);
158
5.46k
  utostr(Op2, false, Op2Str);
159
5.46k
  utostr(CRn, false, CRnStr);
160
5.46k
  utostr(CRm, false, CRmStr);
161
162
5.46k
  dummy = cs_snprintf(result, AARCH64_GRS_LEN, "s%s_%s_c%s_c%s_%s",
163
5.46k
          Op0Str, Op1Str, CRnStr, CRmStr, Op2Str);
164
5.46k
  (void)dummy;
165
5.46k
}
166
167
#define GET_TLBITable_IMPL
168
169
#include "AArch64GenSystemOperands.inc"
170
#undef GET_TLBITable_IMPL
171
172
#define GET_SVCR_IMPL
173
174
#include "AArch64GenSystemOperands.inc"
175
#undef GET_SVCR_IMPL