/src/capstonenext/arch/AArch64/AArch64BaseInfo.c
Line  | Count  | Source  | 
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  | 78.0k  | { | 
125  | 78.0k  |   char Buffer[22];  | 
126  | 78.0k  |   char *BufPtr = Buffer + 21;  | 
127  |  |  | 
128  | 78.0k  |   Buffer[21] = '\0';  | 
129  | 78.0k  |   if (X == 0)  | 
130  | 21.5k  |     *--BufPtr = '0'; // Handle special case...  | 
131  |  |  | 
132  | 141k  |   while (X) { | 
133  | 63.3k  |     *--BufPtr = X % 10 + '0';  | 
134  | 63.3k  |     X /= 10;  | 
135  | 63.3k  |   }  | 
136  |  |  | 
137  | 78.0k  |   if (isNeg)  | 
138  | 0  |     *--BufPtr = '-'; // Add negative sign...  | 
139  |  |  | 
140  |  |   // suppose that result is big enough  | 
141  | 78.0k  |   strncpy(result, BufPtr, sizeof(Buffer));  | 
142  | 78.0k  | }  | 
143  |  |  | 
144  |  | // NOTE: result must be big enough to contain the result  | 
145  |  | void AArch64SysReg_genericRegisterString(uint32_t Bits, char *result)  | 
146  | 8.35k  | { | 
147  | 8.35k  |   CS_ASSERT_RET(Bits < 0x10000);  | 
148  | 8.35k  |   char Op0Str[32], Op1Str[32], CRnStr[32], CRmStr[32], Op2Str[32];  | 
149  | 8.35k  |   int dummy;  | 
150  | 8.35k  |   uint32_t Op0 = (Bits >> 14) & 0x3;  | 
151  | 8.35k  |   uint32_t Op1 = (Bits >> 11) & 0x7;  | 
152  | 8.35k  |   uint32_t CRn = (Bits >> 7) & 0xf;  | 
153  | 8.35k  |   uint32_t CRm = (Bits >> 3) & 0xf;  | 
154  | 8.35k  |   uint32_t Op2 = Bits & 0x7;  | 
155  |  |  | 
156  | 8.35k  |   utostr(Op0, false, Op0Str);  | 
157  | 8.35k  |   utostr(Op1, false, Op1Str);  | 
158  | 8.35k  |   utostr(Op2, false, Op2Str);  | 
159  | 8.35k  |   utostr(CRn, false, CRnStr);  | 
160  | 8.35k  |   utostr(CRm, false, CRmStr);  | 
161  |  |  | 
162  | 8.35k  |   dummy = cs_snprintf(result, AARCH64_GRS_LEN, "s%s_%s_c%s_c%s_%s",  | 
163  | 8.35k  |           Op0Str, Op1Str, CRnStr, CRmStr, Op2Str);  | 
164  | 8.35k  |   (void)dummy;  | 
165  | 8.35k  | }  | 
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  |