blob: 4214c38d016bae9f190e1da3734ffbb474b6f714 [file] [log] [blame]
Jiang Liub11a64a2014-01-07 22:17:08 +08001/*
2 * Copyright (C) 2013 Huawei Ltd.
3 * Author: Jiang Liu <liuj97@gmail.com>
4 *
Zi Shen Lim617d2fb2014-08-27 05:15:17 +01005 * Copyright (C) 2014 Zi Shen Lim <zlim.lnx@gmail.com>
6 *
Jiang Liub11a64a2014-01-07 22:17:08 +08007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#ifndef __ASM_INSN_H
20#define __ASM_INSN_H
21#include <linux/types.h>
22
Jiang Liuae164802014-01-07 22:17:09 +080023/* A64 instructions are always 32 bits. */
24#define AARCH64_INSN_SIZE 4
25
AKASHI Takahiro26e9b832014-04-30 10:54:30 +010026#ifndef __ASSEMBLY__
Jiang Liub11a64a2014-01-07 22:17:08 +080027/*
28 * ARM Architecture Reference Manual for ARMv8 Profile-A, Issue A.a
29 * Section C3.1 "A64 instruction index by encoding":
30 * AArch64 main encoding table
31 * Bit position
32 * 28 27 26 25 Encoding Group
33 * 0 0 - - Unallocated
34 * 1 0 0 - Data processing, immediate
35 * 1 0 1 - Branch, exception generation and system instructions
36 * - 1 - 0 Loads and stores
37 * - 1 0 1 Data processing - register
38 * 0 1 1 1 Data processing - SIMD and floating point
39 * 1 1 1 1 Data processing - SIMD and floating point
40 * "-" means "don't care"
41 */
42enum aarch64_insn_encoding_class {
43 AARCH64_INSN_CLS_UNKNOWN, /* UNALLOCATED */
44 AARCH64_INSN_CLS_DP_IMM, /* Data processing - immediate */
45 AARCH64_INSN_CLS_DP_REG, /* Data processing - register */
46 AARCH64_INSN_CLS_DP_FPSIMD, /* Data processing - SIMD and FP */
47 AARCH64_INSN_CLS_LDST, /* Loads and stores */
48 AARCH64_INSN_CLS_BR_SYS, /* Branch, exception generation and
49 * system instructions */
50};
51
52enum aarch64_insn_hint_op {
53 AARCH64_INSN_HINT_NOP = 0x0 << 5,
54 AARCH64_INSN_HINT_YIELD = 0x1 << 5,
55 AARCH64_INSN_HINT_WFE = 0x2 << 5,
56 AARCH64_INSN_HINT_WFI = 0x3 << 5,
57 AARCH64_INSN_HINT_SEV = 0x4 << 5,
58 AARCH64_INSN_HINT_SEVL = 0x5 << 5,
59};
60
Jiang Liuc84fced2014-01-07 22:17:10 +080061enum aarch64_insn_imm_type {
62 AARCH64_INSN_IMM_ADR,
63 AARCH64_INSN_IMM_26,
64 AARCH64_INSN_IMM_19,
65 AARCH64_INSN_IMM_16,
66 AARCH64_INSN_IMM_14,
67 AARCH64_INSN_IMM_12,
68 AARCH64_INSN_IMM_9,
Zi Shen Lim1bba5672014-08-27 05:15:21 +010069 AARCH64_INSN_IMM_7,
Zi Shen Lim5fdc6392014-08-27 05:15:25 +010070 AARCH64_INSN_IMM_6,
Zi Shen Lim4a89d2c2014-08-27 05:15:23 +010071 AARCH64_INSN_IMM_S,
72 AARCH64_INSN_IMM_R,
Jiang Liuc84fced2014-01-07 22:17:10 +080073 AARCH64_INSN_IMM_MAX
74};
75
Zi Shen Lim617d2fb2014-08-27 05:15:17 +010076enum aarch64_insn_register_type {
77 AARCH64_INSN_REGTYPE_RT,
Zi Shen Limc0cafba2014-08-27 05:15:18 +010078 AARCH64_INSN_REGTYPE_RN,
Zi Shen Lim1bba5672014-08-27 05:15:21 +010079 AARCH64_INSN_REGTYPE_RT2,
Zi Shen Lim17cac172014-08-27 05:15:20 +010080 AARCH64_INSN_REGTYPE_RM,
Zi Shen Lim9951a152014-08-27 05:15:22 +010081 AARCH64_INSN_REGTYPE_RD,
Zi Shen Lim27f95ba2014-08-27 05:15:28 +010082 AARCH64_INSN_REGTYPE_RA,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +020083 AARCH64_INSN_REGTYPE_RS,
Zi Shen Lim617d2fb2014-08-27 05:15:17 +010084};
85
86enum aarch64_insn_register {
87 AARCH64_INSN_REG_0 = 0,
88 AARCH64_INSN_REG_1 = 1,
89 AARCH64_INSN_REG_2 = 2,
90 AARCH64_INSN_REG_3 = 3,
91 AARCH64_INSN_REG_4 = 4,
92 AARCH64_INSN_REG_5 = 5,
93 AARCH64_INSN_REG_6 = 6,
94 AARCH64_INSN_REG_7 = 7,
95 AARCH64_INSN_REG_8 = 8,
96 AARCH64_INSN_REG_9 = 9,
97 AARCH64_INSN_REG_10 = 10,
98 AARCH64_INSN_REG_11 = 11,
99 AARCH64_INSN_REG_12 = 12,
100 AARCH64_INSN_REG_13 = 13,
101 AARCH64_INSN_REG_14 = 14,
102 AARCH64_INSN_REG_15 = 15,
103 AARCH64_INSN_REG_16 = 16,
104 AARCH64_INSN_REG_17 = 17,
105 AARCH64_INSN_REG_18 = 18,
106 AARCH64_INSN_REG_19 = 19,
107 AARCH64_INSN_REG_20 = 20,
108 AARCH64_INSN_REG_21 = 21,
109 AARCH64_INSN_REG_22 = 22,
110 AARCH64_INSN_REG_23 = 23,
111 AARCH64_INSN_REG_24 = 24,
112 AARCH64_INSN_REG_25 = 25,
113 AARCH64_INSN_REG_26 = 26,
114 AARCH64_INSN_REG_27 = 27,
115 AARCH64_INSN_REG_28 = 28,
116 AARCH64_INSN_REG_29 = 29,
117 AARCH64_INSN_REG_FP = 29, /* Frame pointer */
118 AARCH64_INSN_REG_30 = 30,
119 AARCH64_INSN_REG_LR = 30, /* Link register */
120 AARCH64_INSN_REG_ZR = 31, /* Zero: as source register */
121 AARCH64_INSN_REG_SP = 31 /* Stack pointer: as load/store base reg */
122};
123
David A. Longd59bee82016-07-08 12:35:46 -0400124enum aarch64_insn_special_register {
125 AARCH64_INSN_SPCLREG_SPSR_EL1 = 0xC200,
126 AARCH64_INSN_SPCLREG_ELR_EL1 = 0xC201,
127 AARCH64_INSN_SPCLREG_SP_EL0 = 0xC208,
128 AARCH64_INSN_SPCLREG_SPSEL = 0xC210,
129 AARCH64_INSN_SPCLREG_CURRENTEL = 0xC212,
130 AARCH64_INSN_SPCLREG_DAIF = 0xDA11,
131 AARCH64_INSN_SPCLREG_NZCV = 0xDA10,
132 AARCH64_INSN_SPCLREG_FPCR = 0xDA20,
133 AARCH64_INSN_SPCLREG_DSPSR_EL0 = 0xDA28,
134 AARCH64_INSN_SPCLREG_DLR_EL0 = 0xDA29,
135 AARCH64_INSN_SPCLREG_SPSR_EL2 = 0xE200,
136 AARCH64_INSN_SPCLREG_ELR_EL2 = 0xE201,
137 AARCH64_INSN_SPCLREG_SP_EL1 = 0xE208,
138 AARCH64_INSN_SPCLREG_SPSR_INQ = 0xE218,
139 AARCH64_INSN_SPCLREG_SPSR_ABT = 0xE219,
140 AARCH64_INSN_SPCLREG_SPSR_UND = 0xE21A,
141 AARCH64_INSN_SPCLREG_SPSR_FIQ = 0xE21B,
142 AARCH64_INSN_SPCLREG_SPSR_EL3 = 0xF200,
143 AARCH64_INSN_SPCLREG_ELR_EL3 = 0xF201,
144 AARCH64_INSN_SPCLREG_SP_EL2 = 0xF210
145};
146
Zi Shen Lim617d2fb2014-08-27 05:15:17 +0100147enum aarch64_insn_variant {
148 AARCH64_INSN_VARIANT_32BIT,
149 AARCH64_INSN_VARIANT_64BIT
150};
151
Zi Shen Lim345e0d32014-08-27 05:15:19 +0100152enum aarch64_insn_condition {
153 AARCH64_INSN_COND_EQ = 0x0, /* == */
154 AARCH64_INSN_COND_NE = 0x1, /* != */
155 AARCH64_INSN_COND_CS = 0x2, /* unsigned >= */
156 AARCH64_INSN_COND_CC = 0x3, /* unsigned < */
157 AARCH64_INSN_COND_MI = 0x4, /* < 0 */
158 AARCH64_INSN_COND_PL = 0x5, /* >= 0 */
159 AARCH64_INSN_COND_VS = 0x6, /* overflow */
160 AARCH64_INSN_COND_VC = 0x7, /* no overflow */
161 AARCH64_INSN_COND_HI = 0x8, /* unsigned > */
162 AARCH64_INSN_COND_LS = 0x9, /* unsigned <= */
163 AARCH64_INSN_COND_GE = 0xa, /* signed >= */
164 AARCH64_INSN_COND_LT = 0xb, /* signed < */
165 AARCH64_INSN_COND_GT = 0xc, /* signed > */
166 AARCH64_INSN_COND_LE = 0xd, /* signed <= */
167 AARCH64_INSN_COND_AL = 0xe, /* always */
168};
169
Jiang Liu5c5bf252014-01-07 22:17:11 +0800170enum aarch64_insn_branch_type {
171 AARCH64_INSN_BRANCH_NOLINK,
172 AARCH64_INSN_BRANCH_LINK,
Zi Shen Limc0cafba2014-08-27 05:15:18 +0100173 AARCH64_INSN_BRANCH_RETURN,
Zi Shen Lim617d2fb2014-08-27 05:15:17 +0100174 AARCH64_INSN_BRANCH_COMP_ZERO,
175 AARCH64_INSN_BRANCH_COMP_NONZERO,
Jiang Liu5c5bf252014-01-07 22:17:11 +0800176};
177
Zi Shen Lim17cac172014-08-27 05:15:20 +0100178enum aarch64_insn_size_type {
179 AARCH64_INSN_SIZE_8,
180 AARCH64_INSN_SIZE_16,
181 AARCH64_INSN_SIZE_32,
182 AARCH64_INSN_SIZE_64,
183};
184
185enum aarch64_insn_ldst_type {
186 AARCH64_INSN_LDST_LOAD_REG_OFFSET,
187 AARCH64_INSN_LDST_STORE_REG_OFFSET,
Zi Shen Lim1bba5672014-08-27 05:15:21 +0100188 AARCH64_INSN_LDST_LOAD_PAIR_PRE_INDEX,
189 AARCH64_INSN_LDST_STORE_PAIR_PRE_INDEX,
190 AARCH64_INSN_LDST_LOAD_PAIR_POST_INDEX,
191 AARCH64_INSN_LDST_STORE_PAIR_POST_INDEX,
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200192 AARCH64_INSN_LDST_LOAD_EX,
193 AARCH64_INSN_LDST_STORE_EX,
Zi Shen Lim17cac172014-08-27 05:15:20 +0100194};
195
Zi Shen Lim9951a152014-08-27 05:15:22 +0100196enum aarch64_insn_adsb_type {
197 AARCH64_INSN_ADSB_ADD,
198 AARCH64_INSN_ADSB_SUB,
199 AARCH64_INSN_ADSB_ADD_SETFLAGS,
200 AARCH64_INSN_ADSB_SUB_SETFLAGS
201};
202
Zi Shen Lim6098f2d2014-08-27 05:15:24 +0100203enum aarch64_insn_movewide_type {
204 AARCH64_INSN_MOVEWIDE_ZERO,
205 AARCH64_INSN_MOVEWIDE_KEEP,
206 AARCH64_INSN_MOVEWIDE_INVERSE
207};
208
Zi Shen Lim4a89d2c2014-08-27 05:15:23 +0100209enum aarch64_insn_bitfield_type {
210 AARCH64_INSN_BITFIELD_MOVE,
211 AARCH64_INSN_BITFIELD_MOVE_UNSIGNED,
212 AARCH64_INSN_BITFIELD_MOVE_SIGNED
213};
214
Zi Shen Lim546dd362014-08-27 05:15:26 +0100215enum aarch64_insn_data1_type {
216 AARCH64_INSN_DATA1_REVERSE_16,
217 AARCH64_INSN_DATA1_REVERSE_32,
218 AARCH64_INSN_DATA1_REVERSE_64,
219};
220
Zi Shen Lim64810632014-08-27 05:15:27 +0100221enum aarch64_insn_data2_type {
222 AARCH64_INSN_DATA2_UDIV,
223 AARCH64_INSN_DATA2_SDIV,
224 AARCH64_INSN_DATA2_LSLV,
225 AARCH64_INSN_DATA2_LSRV,
226 AARCH64_INSN_DATA2_ASRV,
227 AARCH64_INSN_DATA2_RORV,
228};
229
Zi Shen Lim27f95ba2014-08-27 05:15:28 +0100230enum aarch64_insn_data3_type {
231 AARCH64_INSN_DATA3_MADD,
232 AARCH64_INSN_DATA3_MSUB,
233};
234
Zi Shen Lim5e6e15a2014-08-27 05:15:29 +0100235enum aarch64_insn_logic_type {
236 AARCH64_INSN_LOGIC_AND,
237 AARCH64_INSN_LOGIC_BIC,
238 AARCH64_INSN_LOGIC_ORR,
239 AARCH64_INSN_LOGIC_ORN,
240 AARCH64_INSN_LOGIC_EOR,
241 AARCH64_INSN_LOGIC_EON,
242 AARCH64_INSN_LOGIC_AND_SETFLAGS,
243 AARCH64_INSN_LOGIC_BIC_SETFLAGS
244};
245
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200246enum aarch64_insn_prfm_type {
247 AARCH64_INSN_PRFM_TYPE_PLD,
248 AARCH64_INSN_PRFM_TYPE_PLI,
249 AARCH64_INSN_PRFM_TYPE_PST,
250};
251
252enum aarch64_insn_prfm_target {
253 AARCH64_INSN_PRFM_TARGET_L1,
254 AARCH64_INSN_PRFM_TARGET_L2,
255 AARCH64_INSN_PRFM_TARGET_L3,
256};
257
258enum aarch64_insn_prfm_policy {
259 AARCH64_INSN_PRFM_POLICY_KEEP,
260 AARCH64_INSN_PRFM_POLICY_STRM,
261};
262
Jiang Liub11a64a2014-01-07 22:17:08 +0800263#define __AARCH64_INSN_FUNCS(abbr, mask, val) \
264static __always_inline bool aarch64_insn_is_##abbr(u32 code) \
265{ return (code & (mask)) == (val); } \
266static __always_inline u32 aarch64_insn_get_##abbr##_value(void) \
267{ return (val); }
268
Suzuki K Poulose46084bc2016-09-09 14:07:12 +0100269__AARCH64_INSN_FUNCS(adr, 0x9F000000, 0x10000000)
270__AARCH64_INSN_FUNCS(adrp, 0x9F000000, 0x90000000)
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200271__AARCH64_INSN_FUNCS(prfm, 0x3FC00000, 0x39800000)
David A. Longd59bee82016-07-08 12:35:46 -0400272__AARCH64_INSN_FUNCS(prfm_lit, 0xFF000000, 0xD8000000)
Zi Shen Lim17cac172014-08-27 05:15:20 +0100273__AARCH64_INSN_FUNCS(str_reg, 0x3FE0EC00, 0x38206800)
274__AARCH64_INSN_FUNCS(ldr_reg, 0x3FE0EC00, 0x38606800)
David A. Longd59bee82016-07-08 12:35:46 -0400275__AARCH64_INSN_FUNCS(ldr_lit, 0xBF000000, 0x18000000)
276__AARCH64_INSN_FUNCS(ldrsw_lit, 0xFF000000, 0x98000000)
277__AARCH64_INSN_FUNCS(exclusive, 0x3F800000, 0x08000000)
Sandeepa Prabhu2dd0e8d2016-07-08 12:35:48 -0400278__AARCH64_INSN_FUNCS(load_ex, 0x3F400000, 0x08400000)
279__AARCH64_INSN_FUNCS(store_ex, 0x3F400000, 0x08000000)
Zi Shen Lim1bba5672014-08-27 05:15:21 +0100280__AARCH64_INSN_FUNCS(stp_post, 0x7FC00000, 0x28800000)
281__AARCH64_INSN_FUNCS(ldp_post, 0x7FC00000, 0x28C00000)
282__AARCH64_INSN_FUNCS(stp_pre, 0x7FC00000, 0x29800000)
283__AARCH64_INSN_FUNCS(ldp_pre, 0x7FC00000, 0x29C00000)
Zi Shen Lim9951a152014-08-27 05:15:22 +0100284__AARCH64_INSN_FUNCS(add_imm, 0x7F000000, 0x11000000)
285__AARCH64_INSN_FUNCS(adds_imm, 0x7F000000, 0x31000000)
286__AARCH64_INSN_FUNCS(sub_imm, 0x7F000000, 0x51000000)
287__AARCH64_INSN_FUNCS(subs_imm, 0x7F000000, 0x71000000)
Zi Shen Lim6098f2d2014-08-27 05:15:24 +0100288__AARCH64_INSN_FUNCS(movn, 0x7F800000, 0x12800000)
Zi Shen Lim4a89d2c2014-08-27 05:15:23 +0100289__AARCH64_INSN_FUNCS(sbfm, 0x7F800000, 0x13000000)
290__AARCH64_INSN_FUNCS(bfm, 0x7F800000, 0x33000000)
Zi Shen Lim6098f2d2014-08-27 05:15:24 +0100291__AARCH64_INSN_FUNCS(movz, 0x7F800000, 0x52800000)
Zi Shen Lim4a89d2c2014-08-27 05:15:23 +0100292__AARCH64_INSN_FUNCS(ubfm, 0x7F800000, 0x53000000)
Zi Shen Lim6098f2d2014-08-27 05:15:24 +0100293__AARCH64_INSN_FUNCS(movk, 0x7F800000, 0x72800000)
Zi Shen Lim5fdc6392014-08-27 05:15:25 +0100294__AARCH64_INSN_FUNCS(add, 0x7F200000, 0x0B000000)
295__AARCH64_INSN_FUNCS(adds, 0x7F200000, 0x2B000000)
296__AARCH64_INSN_FUNCS(sub, 0x7F200000, 0x4B000000)
297__AARCH64_INSN_FUNCS(subs, 0x7F200000, 0x6B000000)
Zi Shen Lim27f95ba2014-08-27 05:15:28 +0100298__AARCH64_INSN_FUNCS(madd, 0x7FE08000, 0x1B000000)
299__AARCH64_INSN_FUNCS(msub, 0x7FE08000, 0x1B008000)
Zi Shen Lim64810632014-08-27 05:15:27 +0100300__AARCH64_INSN_FUNCS(udiv, 0x7FE0FC00, 0x1AC00800)
301__AARCH64_INSN_FUNCS(sdiv, 0x7FE0FC00, 0x1AC00C00)
302__AARCH64_INSN_FUNCS(lslv, 0x7FE0FC00, 0x1AC02000)
303__AARCH64_INSN_FUNCS(lsrv, 0x7FE0FC00, 0x1AC02400)
304__AARCH64_INSN_FUNCS(asrv, 0x7FE0FC00, 0x1AC02800)
305__AARCH64_INSN_FUNCS(rorv, 0x7FE0FC00, 0x1AC02C00)
Zi Shen Lim546dd362014-08-27 05:15:26 +0100306__AARCH64_INSN_FUNCS(rev16, 0x7FFFFC00, 0x5AC00400)
307__AARCH64_INSN_FUNCS(rev32, 0x7FFFFC00, 0x5AC00800)
308__AARCH64_INSN_FUNCS(rev64, 0x7FFFFC00, 0x5AC00C00)
Zi Shen Lim5e6e15a2014-08-27 05:15:29 +0100309__AARCH64_INSN_FUNCS(and, 0x7F200000, 0x0A000000)
310__AARCH64_INSN_FUNCS(bic, 0x7F200000, 0x0A200000)
311__AARCH64_INSN_FUNCS(orr, 0x7F200000, 0x2A000000)
312__AARCH64_INSN_FUNCS(orn, 0x7F200000, 0x2A200000)
313__AARCH64_INSN_FUNCS(eor, 0x7F200000, 0x4A000000)
314__AARCH64_INSN_FUNCS(eon, 0x7F200000, 0x4A200000)
315__AARCH64_INSN_FUNCS(ands, 0x7F200000, 0x6A000000)
316__AARCH64_INSN_FUNCS(bics, 0x7F200000, 0x6A200000)
Jiang Liub11a64a2014-01-07 22:17:08 +0800317__AARCH64_INSN_FUNCS(b, 0xFC000000, 0x14000000)
318__AARCH64_INSN_FUNCS(bl, 0xFC000000, 0x94000000)
Robin Murphy115386f2015-02-18 15:40:17 +0000319__AARCH64_INSN_FUNCS(cbz, 0x7F000000, 0x34000000)
320__AARCH64_INSN_FUNCS(cbnz, 0x7F000000, 0x35000000)
321__AARCH64_INSN_FUNCS(tbz, 0x7F000000, 0x36000000)
322__AARCH64_INSN_FUNCS(tbnz, 0x7F000000, 0x37000000)
Zi Shen Lim345e0d32014-08-27 05:15:19 +0100323__AARCH64_INSN_FUNCS(bcond, 0xFF000010, 0x54000000)
Jiang Liub11a64a2014-01-07 22:17:08 +0800324__AARCH64_INSN_FUNCS(svc, 0xFFE0001F, 0xD4000001)
325__AARCH64_INSN_FUNCS(hvc, 0xFFE0001F, 0xD4000002)
326__AARCH64_INSN_FUNCS(smc, 0xFFE0001F, 0xD4000003)
327__AARCH64_INSN_FUNCS(brk, 0xFFE0001F, 0xD4200000)
David A. Longd59bee82016-07-08 12:35:46 -0400328__AARCH64_INSN_FUNCS(exception, 0xFF000000, 0xD4000000)
Jiang Liub11a64a2014-01-07 22:17:08 +0800329__AARCH64_INSN_FUNCS(hint, 0xFFFFF01F, 0xD503201F)
Zi Shen Limc0cafba2014-08-27 05:15:18 +0100330__AARCH64_INSN_FUNCS(br, 0xFFFFFC1F, 0xD61F0000)
331__AARCH64_INSN_FUNCS(blr, 0xFFFFFC1F, 0xD63F0000)
332__AARCH64_INSN_FUNCS(ret, 0xFFFFFC1F, 0xD65F0000)
David A. Longd59bee82016-07-08 12:35:46 -0400333__AARCH64_INSN_FUNCS(eret, 0xFFFFFFFF, 0xD69F03E0)
334__AARCH64_INSN_FUNCS(mrs, 0xFFF00000, 0xD5300000)
335__AARCH64_INSN_FUNCS(msr_imm, 0xFFF8F01F, 0xD500401F)
336__AARCH64_INSN_FUNCS(msr_reg, 0xFFF00000, 0xD5100000)
Jiang Liub11a64a2014-01-07 22:17:08 +0800337
338#undef __AARCH64_INSN_FUNCS
339
340bool aarch64_insn_is_nop(u32 insn);
Marc Zyngier10b48f72015-06-01 10:47:39 +0100341bool aarch64_insn_is_branch_imm(u32 insn);
Jiang Liub11a64a2014-01-07 22:17:08 +0800342
Suzuki K Poulose46084bc2016-09-09 14:07:12 +0100343static inline bool aarch64_insn_is_adr_adrp(u32 insn)
344{
345 return aarch64_insn_is_adr(insn) || aarch64_insn_is_adrp(insn);
346}
347
Jiang Liuae164802014-01-07 22:17:09 +0800348int aarch64_insn_read(void *addr, u32 *insnp);
349int aarch64_insn_write(void *addr, u32 insn);
Jiang Liub11a64a2014-01-07 22:17:08 +0800350enum aarch64_insn_encoding_class aarch64_get_insn_class(u32 insn);
David A. Longd59bee82016-07-08 12:35:46 -0400351bool aarch64_insn_uses_literal(u32 insn);
352bool aarch64_insn_is_branch(u32 insn);
Marc Zyngier0978fb22015-03-27 13:09:21 +0000353u64 aarch64_insn_decode_immediate(enum aarch64_insn_imm_type type, u32 insn);
Jiang Liuc84fced2014-01-07 22:17:10 +0800354u32 aarch64_insn_encode_immediate(enum aarch64_insn_imm_type type,
355 u32 insn, u64 imm);
Suzuki K Poulose8c2dcbd2017-01-09 17:28:29 +0000356u32 aarch64_insn_decode_register(enum aarch64_insn_register_type type,
357 u32 insn);
Jiang Liu5c5bf252014-01-07 22:17:11 +0800358u32 aarch64_insn_gen_branch_imm(unsigned long pc, unsigned long addr,
359 enum aarch64_insn_branch_type type);
Zi Shen Lim617d2fb2014-08-27 05:15:17 +0100360u32 aarch64_insn_gen_comp_branch_imm(unsigned long pc, unsigned long addr,
361 enum aarch64_insn_register reg,
362 enum aarch64_insn_variant variant,
363 enum aarch64_insn_branch_type type);
Zi Shen Lim345e0d32014-08-27 05:15:19 +0100364u32 aarch64_insn_gen_cond_branch_imm(unsigned long pc, unsigned long addr,
365 enum aarch64_insn_condition cond);
Jiang Liu5c5bf252014-01-07 22:17:11 +0800366u32 aarch64_insn_gen_hint(enum aarch64_insn_hint_op op);
367u32 aarch64_insn_gen_nop(void);
Zi Shen Limc0cafba2014-08-27 05:15:18 +0100368u32 aarch64_insn_gen_branch_reg(enum aarch64_insn_register reg,
369 enum aarch64_insn_branch_type type);
Zi Shen Lim17cac172014-08-27 05:15:20 +0100370u32 aarch64_insn_gen_load_store_reg(enum aarch64_insn_register reg,
371 enum aarch64_insn_register base,
372 enum aarch64_insn_register offset,
373 enum aarch64_insn_size_type size,
374 enum aarch64_insn_ldst_type type);
Zi Shen Lim1bba5672014-08-27 05:15:21 +0100375u32 aarch64_insn_gen_load_store_pair(enum aarch64_insn_register reg1,
376 enum aarch64_insn_register reg2,
377 enum aarch64_insn_register base,
378 int offset,
379 enum aarch64_insn_variant variant,
380 enum aarch64_insn_ldst_type type);
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200381u32 aarch64_insn_gen_load_store_ex(enum aarch64_insn_register reg,
382 enum aarch64_insn_register base,
383 enum aarch64_insn_register state,
384 enum aarch64_insn_size_type size,
385 enum aarch64_insn_ldst_type type);
Zi Shen Lim9951a152014-08-27 05:15:22 +0100386u32 aarch64_insn_gen_add_sub_imm(enum aarch64_insn_register dst,
387 enum aarch64_insn_register src,
388 int imm, enum aarch64_insn_variant variant,
389 enum aarch64_insn_adsb_type type);
Zi Shen Lim4a89d2c2014-08-27 05:15:23 +0100390u32 aarch64_insn_gen_bitfield(enum aarch64_insn_register dst,
391 enum aarch64_insn_register src,
392 int immr, int imms,
393 enum aarch64_insn_variant variant,
394 enum aarch64_insn_bitfield_type type);
Zi Shen Lim6098f2d2014-08-27 05:15:24 +0100395u32 aarch64_insn_gen_movewide(enum aarch64_insn_register dst,
396 int imm, int shift,
397 enum aarch64_insn_variant variant,
398 enum aarch64_insn_movewide_type type);
Zi Shen Lim5fdc6392014-08-27 05:15:25 +0100399u32 aarch64_insn_gen_add_sub_shifted_reg(enum aarch64_insn_register dst,
400 enum aarch64_insn_register src,
401 enum aarch64_insn_register reg,
402 int shift,
403 enum aarch64_insn_variant variant,
404 enum aarch64_insn_adsb_type type);
Zi Shen Lim546dd362014-08-27 05:15:26 +0100405u32 aarch64_insn_gen_data1(enum aarch64_insn_register dst,
406 enum aarch64_insn_register src,
407 enum aarch64_insn_variant variant,
408 enum aarch64_insn_data1_type type);
Zi Shen Lim64810632014-08-27 05:15:27 +0100409u32 aarch64_insn_gen_data2(enum aarch64_insn_register dst,
410 enum aarch64_insn_register src,
411 enum aarch64_insn_register reg,
412 enum aarch64_insn_variant variant,
413 enum aarch64_insn_data2_type type);
Zi Shen Lim27f95ba2014-08-27 05:15:28 +0100414u32 aarch64_insn_gen_data3(enum aarch64_insn_register dst,
415 enum aarch64_insn_register src,
416 enum aarch64_insn_register reg1,
417 enum aarch64_insn_register reg2,
418 enum aarch64_insn_variant variant,
419 enum aarch64_insn_data3_type type);
Zi Shen Lim5e6e15a2014-08-27 05:15:29 +0100420u32 aarch64_insn_gen_logical_shifted_reg(enum aarch64_insn_register dst,
421 enum aarch64_insn_register src,
422 enum aarch64_insn_register reg,
423 int shift,
424 enum aarch64_insn_variant variant,
425 enum aarch64_insn_logic_type type);
Daniel Borkmann85f68fe2017-05-01 02:57:20 +0200426u32 aarch64_insn_gen_prefetch(enum aarch64_insn_register base,
427 enum aarch64_insn_prfm_type type,
428 enum aarch64_insn_prfm_target target,
429 enum aarch64_insn_prfm_policy policy);
Marc Zyngier10b48f72015-06-01 10:47:39 +0100430s32 aarch64_get_branch_offset(u32 insn);
431u32 aarch64_set_branch_offset(u32 insn, s32 offset);
Jiang Liu5c5bf252014-01-07 22:17:11 +0800432
Jiang Liub11a64a2014-01-07 22:17:08 +0800433bool aarch64_insn_hotpatch_safe(u32 old_insn, u32 new_insn);
434
Jiang Liuae164802014-01-07 22:17:09 +0800435int aarch64_insn_patch_text_nosync(void *addr, u32 insn);
Jiang Liuae164802014-01-07 22:17:09 +0800436int aarch64_insn_patch_text(void *addrs[], u32 insns[], int cnt);
Punit Agrawal9b79f522014-11-18 11:41:22 +0000437
Suzuki K Poulose46084bc2016-09-09 14:07:12 +0100438s32 aarch64_insn_adrp_get_offset(u32 insn);
439u32 aarch64_insn_adrp_set_offset(u32 insn, s32 offset);
440
Punit Agrawal9b79f522014-11-18 11:41:22 +0000441bool aarch32_insn_is_wide(u32 insn);
Punit Agrawalbd35a4a2014-11-18 11:41:25 +0000442
443#define A32_RN_OFFSET 16
444#define A32_RT_OFFSET 12
445#define A32_RT2_OFFSET 0
446
David A. Longd59bee82016-07-08 12:35:46 -0400447u32 aarch64_insn_extract_system_reg(u32 insn);
Punit Agrawalbd35a4a2014-11-18 11:41:25 +0000448u32 aarch32_insn_extract_reg_num(u32 insn, int offset);
Punit Agrawalc852f322014-11-18 11:41:26 +0000449u32 aarch32_insn_mcr_extract_opc2(u32 insn);
450u32 aarch32_insn_mcr_extract_crm(u32 insn);
David A. Long2af3ec02016-07-08 12:35:47 -0400451
452typedef bool (pstate_check_t)(unsigned long);
453extern pstate_check_t * const aarch32_opcode_cond_checks[16];
AKASHI Takahiro26e9b832014-04-30 10:54:30 +0100454#endif /* __ASSEMBLY__ */
Jiang Liuae164802014-01-07 22:17:09 +0800455
Jiang Liub11a64a2014-01-07 22:17:08 +0800456#endif /* __ASM_INSN_H */