translate.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. #ifndef TARGET_ARM_TRANSLATE_H
  2. #define TARGET_ARM_TRANSLATE_H
  3. #include "exec/translator.h"
  4. #include "internals.h"
  5. /* internal defines */
  6. /*
  7. * Save pc_save across a branch, so that we may restore the value from
  8. * before the branch at the point the label is emitted.
  9. */
  10. typedef struct DisasLabel {
  11. TCGLabel *label;
  12. target_ulong pc_save;
  13. } DisasLabel;
  14. typedef struct DisasContext {
  15. DisasContextBase base;
  16. const ARMISARegisters *isar;
  17. /* The address of the current instruction being translated. */
  18. target_ulong pc_curr;
  19. /*
  20. * For TARGET_TB_PCREL, the full value of cpu_pc is not known
  21. * (although the page offset is known). For convenience, the
  22. * translation loop uses the full virtual address that triggered
  23. * the translation, from base.pc_start through pc_curr.
  24. * For efficiency, we do not update cpu_pc for every instruction.
  25. * Instead, pc_save has the value of pc_curr at the time of the
  26. * last update to cpu_pc, which allows us to compute the addend
  27. * needed to bring cpu_pc current: pc_curr - pc_save.
  28. * If cpu_pc now contains the destination of an indirect branch,
  29. * pc_save contains -1 to indicate that relative updates are no
  30. * longer possible.
  31. */
  32. target_ulong pc_save;
  33. target_ulong page_start;
  34. uint32_t insn;
  35. /* Nonzero if this instruction has been conditionally skipped. */
  36. int condjmp;
  37. /* The label that will be jumped to when the instruction is skipped. */
  38. DisasLabel condlabel;
  39. /* Thumb-2 conditional execution bits. */
  40. int condexec_mask;
  41. int condexec_cond;
  42. /* M-profile ECI/ICI exception-continuable instruction state */
  43. int eci;
  44. /*
  45. * trans_ functions for insns which are continuable should set this true
  46. * after decode (ie after any UNDEF checks)
  47. */
  48. bool eci_handled;
  49. int sctlr_b;
  50. MemOp be_data;
  51. #if !defined(CONFIG_USER_ONLY)
  52. int user;
  53. #endif
  54. ARMMMUIdx mmu_idx; /* MMU index to use for normal loads/stores */
  55. uint8_t tbii; /* TBI1|TBI0 for insns */
  56. uint8_t tbid; /* TBI1|TBI0 for data */
  57. uint8_t tcma; /* TCMA1|TCMA0 for MTE */
  58. bool ns; /* Use non-secure CPREG bank on access */
  59. int fp_excp_el; /* FP exception EL or 0 if enabled */
  60. int sve_excp_el; /* SVE exception EL or 0 if enabled */
  61. int sme_excp_el; /* SME exception EL or 0 if enabled */
  62. int vl; /* current vector length in bytes */
  63. int svl; /* current streaming vector length in bytes */
  64. bool vfp_enabled; /* FP enabled via FPSCR.EN */
  65. int vec_len;
  66. int vec_stride;
  67. bool v7m_handler_mode;
  68. bool v8m_secure; /* true if v8M and we're in Secure mode */
  69. bool v8m_stackcheck; /* true if we need to perform v8M stack limit checks */
  70. bool v8m_fpccr_s_wrong; /* true if v8M FPCCR.S != v8m_secure */
  71. bool v7m_new_fp_ctxt_needed; /* ASPEN set but no active FP context */
  72. bool v7m_lspact; /* FPCCR.LSPACT set */
  73. /* Immediate value in AArch32 SVC insn; must be set if is_jmp == DISAS_SWI
  74. * so that top level loop can generate correct syndrome information.
  75. */
  76. uint32_t svc_imm;
  77. int current_el;
  78. GHashTable *cp_regs;
  79. uint64_t features; /* CPU features bits */
  80. bool aarch64;
  81. bool thumb;
  82. /* Because unallocated encodings generate different exception syndrome
  83. * information from traps due to FP being disabled, we can't do a single
  84. * "is fp access disabled" check at a high level in the decode tree.
  85. * To help in catching bugs where the access check was forgotten in some
  86. * code path, we set this flag when the access check is done, and assert
  87. * that it is set at the point where we actually touch the FP regs.
  88. */
  89. bool fp_access_checked;
  90. bool sve_access_checked;
  91. /* ARMv8 single-step state (this is distinct from the QEMU gdbstub
  92. * single-step support).
  93. */
  94. bool ss_active;
  95. bool pstate_ss;
  96. /* True if the insn just emitted was a load-exclusive instruction
  97. * (necessary for syndrome information for single step exceptions),
  98. * ie A64 LDX*, LDAX*, A32/T32 LDREX*, LDAEX*.
  99. */
  100. bool is_ldex;
  101. /* True if AccType_UNPRIV should be used for LDTR et al */
  102. bool unpriv;
  103. /* True if v8.3-PAuth is active. */
  104. bool pauth_active;
  105. /* True if v8.5-MTE access to tags is enabled. */
  106. bool ata;
  107. /* True if v8.5-MTE tag checks affect the PE; index with is_unpriv. */
  108. bool mte_active[2];
  109. /* True with v8.5-BTI and SCTLR_ELx.BT* set. */
  110. bool bt;
  111. /* True if any CP15 access is trapped by HSTR_EL2 */
  112. bool hstr_active;
  113. /* True if memory operations require alignment */
  114. bool align_mem;
  115. /* True if PSTATE.IL is set */
  116. bool pstate_il;
  117. /* True if PSTATE.SM is set. */
  118. bool pstate_sm;
  119. /* True if PSTATE.ZA is set. */
  120. bool pstate_za;
  121. /* True if non-streaming insns should raise an SME Streaming exception. */
  122. bool sme_trap_nonstreaming;
  123. /* True if the current instruction is non-streaming. */
  124. bool is_nonstreaming;
  125. /* True if MVE insns are definitely not predicated by VPR or LTPSIZE */
  126. bool mve_no_pred;
  127. /*
  128. * >= 0, a copy of PSTATE.BTYPE, which will be 0 without v8.5-BTI.
  129. * < 0, set by the current instruction.
  130. */
  131. int8_t btype;
  132. /* A copy of cpu->dcz_blocksize. */
  133. uint8_t dcz_blocksize;
  134. /* True if this page is guarded. */
  135. bool guarded_page;
  136. /* Bottom two bits of XScale c15_cpar coprocessor access control reg */
  137. int c15_cpar;
  138. /* TCG op of the current insn_start. */
  139. TCGOp *insn_start;
  140. #define TMP_A64_MAX 16
  141. int tmp_a64_count;
  142. TCGv_i64 tmp_a64[TMP_A64_MAX];
  143. } DisasContext;
  144. typedef struct DisasCompare {
  145. TCGCond cond;
  146. TCGv_i32 value;
  147. bool value_global;
  148. } DisasCompare;
  149. /* Share the TCG temporaries common between 32 and 64 bit modes. */
  150. extern TCGv_i32 cpu_NF, cpu_ZF, cpu_CF, cpu_VF;
  151. extern TCGv_i64 cpu_exclusive_addr;
  152. extern TCGv_i64 cpu_exclusive_val;
  153. /*
  154. * Constant expanders for the decoders.
  155. */
  156. static inline int negate(DisasContext *s, int x)
  157. {
  158. return -x;
  159. }
  160. static inline int plus_1(DisasContext *s, int x)
  161. {
  162. return x + 1;
  163. }
  164. static inline int plus_2(DisasContext *s, int x)
  165. {
  166. return x + 2;
  167. }
  168. static inline int plus_12(DisasContext *s, int x)
  169. {
  170. return x + 12;
  171. }
  172. static inline int times_2(DisasContext *s, int x)
  173. {
  174. return x * 2;
  175. }
  176. static inline int times_4(DisasContext *s, int x)
  177. {
  178. return x * 4;
  179. }
  180. static inline int times_2_plus_1(DisasContext *s, int x)
  181. {
  182. return x * 2 + 1;
  183. }
  184. static inline int rsub_64(DisasContext *s, int x)
  185. {
  186. return 64 - x;
  187. }
  188. static inline int rsub_32(DisasContext *s, int x)
  189. {
  190. return 32 - x;
  191. }
  192. static inline int rsub_16(DisasContext *s, int x)
  193. {
  194. return 16 - x;
  195. }
  196. static inline int rsub_8(DisasContext *s, int x)
  197. {
  198. return 8 - x;
  199. }
  200. static inline int neon_3same_fp_size(DisasContext *s, int x)
  201. {
  202. /* Convert 0==fp32, 1==fp16 into a MO_* value */
  203. return MO_32 - x;
  204. }
  205. static inline int arm_dc_feature(DisasContext *dc, int feature)
  206. {
  207. return (dc->features & (1ULL << feature)) != 0;
  208. }
  209. static inline int get_mem_index(DisasContext *s)
  210. {
  211. return arm_to_core_mmu_idx(s->mmu_idx);
  212. }
  213. static inline void disas_set_insn_syndrome(DisasContext *s, uint32_t syn)
  214. {
  215. /* We don't need to save all of the syndrome so we mask and shift
  216. * out unneeded bits to help the sleb128 encoder do a better job.
  217. */
  218. syn &= ARM_INSN_START_WORD2_MASK;
  219. syn >>= ARM_INSN_START_WORD2_SHIFT;
  220. /* We check and clear insn_start_idx to catch multiple updates. */
  221. assert(s->insn_start != NULL);
  222. tcg_set_insn_start_param(s->insn_start, 2, syn);
  223. s->insn_start = NULL;
  224. }
  225. static inline int curr_insn_len(DisasContext *s)
  226. {
  227. return s->base.pc_next - s->pc_curr;
  228. }
  229. /* is_jmp field values */
  230. #define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */
  231. /* CPU state was modified dynamically; exit to main loop for interrupts. */
  232. #define DISAS_UPDATE_EXIT DISAS_TARGET_1
  233. /* These instructions trap after executing, so the A32/T32 decoder must
  234. * defer them until after the conditional execution state has been updated.
  235. * WFI also needs special handling when single-stepping.
  236. */
  237. #define DISAS_WFI DISAS_TARGET_2
  238. #define DISAS_SWI DISAS_TARGET_3
  239. /* WFE */
  240. #define DISAS_WFE DISAS_TARGET_4
  241. #define DISAS_HVC DISAS_TARGET_5
  242. #define DISAS_SMC DISAS_TARGET_6
  243. #define DISAS_YIELD DISAS_TARGET_7
  244. /* M profile branch which might be an exception return (and so needs
  245. * custom end-of-TB code)
  246. */
  247. #define DISAS_BX_EXCRET DISAS_TARGET_8
  248. /*
  249. * For instructions which want an immediate exit to the main loop, as opposed
  250. * to attempting to use lookup_and_goto_ptr. Unlike DISAS_UPDATE_EXIT, this
  251. * doesn't write the PC on exiting the translation loop so you need to ensure
  252. * something (gen_a64_update_pc or runtime helper) has done so before we reach
  253. * return from cpu_tb_exec.
  254. */
  255. #define DISAS_EXIT DISAS_TARGET_9
  256. /* CPU state was modified dynamically; no need to exit, but do not chain. */
  257. #define DISAS_UPDATE_NOCHAIN DISAS_TARGET_10
  258. #ifdef TARGET_AARCH64
  259. void a64_translate_init(void);
  260. void gen_a64_update_pc(DisasContext *s, target_long diff);
  261. extern const TranslatorOps aarch64_translator_ops;
  262. #else
  263. static inline void a64_translate_init(void)
  264. {
  265. }
  266. static inline void gen_a64_update_pc(DisasContext *s, target_long diff)
  267. {
  268. }
  269. #endif
  270. void arm_test_cc(DisasCompare *cmp, int cc);
  271. void arm_free_cc(DisasCompare *cmp);
  272. void arm_jump_cc(DisasCompare *cmp, TCGLabel *label);
  273. void arm_gen_test_cc(int cc, TCGLabel *label);
  274. MemOp pow2_align(unsigned i);
  275. void unallocated_encoding(DisasContext *s);
  276. void gen_exception_insn_el(DisasContext *s, target_long pc_diff, int excp,
  277. uint32_t syn, uint32_t target_el);
  278. void gen_exception_insn(DisasContext *s, target_long pc_diff,
  279. int excp, uint32_t syn);
  280. /* Return state of Alternate Half-precision flag, caller frees result */
  281. static inline TCGv_i32 get_ahp_flag(void)
  282. {
  283. TCGv_i32 ret = tcg_temp_new_i32();
  284. tcg_gen_ld_i32(ret, cpu_env,
  285. offsetof(CPUARMState, vfp.xregs[ARM_VFP_FPSCR]));
  286. tcg_gen_extract_i32(ret, ret, 26, 1);
  287. return ret;
  288. }
  289. /* Set bits within PSTATE. */
  290. static inline void set_pstate_bits(uint32_t bits)
  291. {
  292. TCGv_i32 p = tcg_temp_new_i32();
  293. tcg_debug_assert(!(bits & CACHED_PSTATE_BITS));
  294. tcg_gen_ld_i32(p, cpu_env, offsetof(CPUARMState, pstate));
  295. tcg_gen_ori_i32(p, p, bits);
  296. tcg_gen_st_i32(p, cpu_env, offsetof(CPUARMState, pstate));
  297. tcg_temp_free_i32(p);
  298. }
  299. /* Clear bits within PSTATE. */
  300. static inline void clear_pstate_bits(uint32_t bits)
  301. {
  302. TCGv_i32 p = tcg_temp_new_i32();
  303. tcg_debug_assert(!(bits & CACHED_PSTATE_BITS));
  304. tcg_gen_ld_i32(p, cpu_env, offsetof(CPUARMState, pstate));
  305. tcg_gen_andi_i32(p, p, ~bits);
  306. tcg_gen_st_i32(p, cpu_env, offsetof(CPUARMState, pstate));
  307. tcg_temp_free_i32(p);
  308. }
  309. /* If the singlestep state is Active-not-pending, advance to Active-pending. */
  310. static inline void gen_ss_advance(DisasContext *s)
  311. {
  312. if (s->ss_active) {
  313. s->pstate_ss = 0;
  314. clear_pstate_bits(PSTATE_SS);
  315. }
  316. }
  317. /* Generate an architectural singlestep exception */
  318. static inline void gen_swstep_exception(DisasContext *s, int isv, int ex)
  319. {
  320. /* Fill in the same_el field of the syndrome in the helper. */
  321. uint32_t syn = syn_swstep(false, isv, ex);
  322. gen_helper_exception_swstep(cpu_env, tcg_constant_i32(syn));
  323. }
  324. /*
  325. * Given a VFP floating point constant encoded into an 8 bit immediate in an
  326. * instruction, expand it to the actual constant value of the specified
  327. * size, as per the VFPExpandImm() pseudocode in the Arm ARM.
  328. */
  329. uint64_t vfp_expand_imm(int size, uint8_t imm8);
  330. /* Vector operations shared between ARM and AArch64. */
  331. void gen_gvec_ceq0(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
  332. uint32_t opr_sz, uint32_t max_sz);
  333. void gen_gvec_clt0(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
  334. uint32_t opr_sz, uint32_t max_sz);
  335. void gen_gvec_cgt0(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
  336. uint32_t opr_sz, uint32_t max_sz);
  337. void gen_gvec_cle0(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
  338. uint32_t opr_sz, uint32_t max_sz);
  339. void gen_gvec_cge0(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
  340. uint32_t opr_sz, uint32_t max_sz);
  341. void gen_gvec_mla(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  342. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  343. void gen_gvec_mls(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  344. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  345. void gen_gvec_cmtst(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  346. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  347. void gen_gvec_sshl(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  348. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  349. void gen_gvec_ushl(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  350. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  351. void gen_cmtst_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b);
  352. void gen_ushl_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b);
  353. void gen_sshl_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b);
  354. void gen_ushl_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b);
  355. void gen_sshl_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b);
  356. void gen_gvec_uqadd_qc(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  357. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  358. void gen_gvec_sqadd_qc(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  359. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  360. void gen_gvec_uqsub_qc(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  361. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  362. void gen_gvec_sqsub_qc(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  363. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  364. void gen_gvec_ssra(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
  365. int64_t shift, uint32_t opr_sz, uint32_t max_sz);
  366. void gen_gvec_usra(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
  367. int64_t shift, uint32_t opr_sz, uint32_t max_sz);
  368. void gen_gvec_srshr(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
  369. int64_t shift, uint32_t opr_sz, uint32_t max_sz);
  370. void gen_gvec_urshr(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
  371. int64_t shift, uint32_t opr_sz, uint32_t max_sz);
  372. void gen_gvec_srsra(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
  373. int64_t shift, uint32_t opr_sz, uint32_t max_sz);
  374. void gen_gvec_ursra(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
  375. int64_t shift, uint32_t opr_sz, uint32_t max_sz);
  376. void gen_gvec_sri(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
  377. int64_t shift, uint32_t opr_sz, uint32_t max_sz);
  378. void gen_gvec_sli(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
  379. int64_t shift, uint32_t opr_sz, uint32_t max_sz);
  380. void gen_gvec_sqrdmlah_qc(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  381. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  382. void gen_gvec_sqrdmlsh_qc(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  383. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  384. void gen_gvec_sabd(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  385. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  386. void gen_gvec_uabd(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  387. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  388. void gen_gvec_saba(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  389. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  390. void gen_gvec_uaba(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
  391. uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz);
  392. /*
  393. * Forward to the isar_feature_* tests given a DisasContext pointer.
  394. */
  395. #define dc_isar_feature(name, ctx) \
  396. ({ DisasContext *ctx_ = (ctx); isar_feature_##name(ctx_->isar); })
  397. /* Note that the gvec expanders operate on offsets + sizes. */
  398. typedef void GVecGen2Fn(unsigned, uint32_t, uint32_t, uint32_t, uint32_t);
  399. typedef void GVecGen2iFn(unsigned, uint32_t, uint32_t, int64_t,
  400. uint32_t, uint32_t);
  401. typedef void GVecGen3Fn(unsigned, uint32_t, uint32_t,
  402. uint32_t, uint32_t, uint32_t);
  403. typedef void GVecGen4Fn(unsigned, uint32_t, uint32_t, uint32_t,
  404. uint32_t, uint32_t, uint32_t);
  405. /* Function prototype for gen_ functions for calling Neon helpers */
  406. typedef void NeonGenOneOpFn(TCGv_i32, TCGv_i32);
  407. typedef void NeonGenOneOpEnvFn(TCGv_i32, TCGv_ptr, TCGv_i32);
  408. typedef void NeonGenTwoOpFn(TCGv_i32, TCGv_i32, TCGv_i32);
  409. typedef void NeonGenTwoOpEnvFn(TCGv_i32, TCGv_ptr, TCGv_i32, TCGv_i32);
  410. typedef void NeonGenThreeOpEnvFn(TCGv_i32, TCGv_env, TCGv_i32,
  411. TCGv_i32, TCGv_i32);
  412. typedef void NeonGenTwo64OpFn(TCGv_i64, TCGv_i64, TCGv_i64);
  413. typedef void NeonGenTwo64OpEnvFn(TCGv_i64, TCGv_ptr, TCGv_i64, TCGv_i64);
  414. typedef void NeonGenNarrowFn(TCGv_i32, TCGv_i64);
  415. typedef void NeonGenNarrowEnvFn(TCGv_i32, TCGv_ptr, TCGv_i64);
  416. typedef void NeonGenWidenFn(TCGv_i64, TCGv_i32);
  417. typedef void NeonGenTwoOpWidenFn(TCGv_i64, TCGv_i32, TCGv_i32);
  418. typedef void NeonGenOneSingleOpFn(TCGv_i32, TCGv_i32, TCGv_ptr);
  419. typedef void NeonGenTwoSingleOpFn(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_ptr);
  420. typedef void NeonGenTwoDoubleOpFn(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_ptr);
  421. typedef void NeonGenOne64OpFn(TCGv_i64, TCGv_i64);
  422. typedef void CryptoTwoOpFn(TCGv_ptr, TCGv_ptr);
  423. typedef void CryptoThreeOpIntFn(TCGv_ptr, TCGv_ptr, TCGv_i32);
  424. typedef void CryptoThreeOpFn(TCGv_ptr, TCGv_ptr, TCGv_ptr);
  425. typedef void AtomicThreeOpFn(TCGv_i64, TCGv_i64, TCGv_i64, TCGArg, MemOp);
  426. typedef void WideShiftImmFn(TCGv_i64, TCGv_i64, int64_t shift);
  427. typedef void WideShiftFn(TCGv_i64, TCGv_ptr, TCGv_i64, TCGv_i32);
  428. typedef void ShiftImmFn(TCGv_i32, TCGv_i32, int32_t shift);
  429. typedef void ShiftFn(TCGv_i32, TCGv_ptr, TCGv_i32, TCGv_i32);
  430. /**
  431. * arm_tbflags_from_tb:
  432. * @tb: the TranslationBlock
  433. *
  434. * Extract the flag values from @tb.
  435. */
  436. static inline CPUARMTBFlags arm_tbflags_from_tb(const TranslationBlock *tb)
  437. {
  438. return (CPUARMTBFlags){ tb->flags, tb->cs_base };
  439. }
  440. /*
  441. * Enum for argument to fpstatus_ptr().
  442. */
  443. typedef enum ARMFPStatusFlavour {
  444. FPST_FPCR,
  445. FPST_FPCR_F16,
  446. FPST_STD,
  447. FPST_STD_F16,
  448. } ARMFPStatusFlavour;
  449. /**
  450. * fpstatus_ptr: return TCGv_ptr to the specified fp_status field
  451. *
  452. * We have multiple softfloat float_status fields in the Arm CPU state struct
  453. * (see the comment in cpu.h for details). Return a TCGv_ptr which has
  454. * been set up to point to the requested field in the CPU state struct.
  455. * The options are:
  456. *
  457. * FPST_FPCR
  458. * for non-FP16 operations controlled by the FPCR
  459. * FPST_FPCR_F16
  460. * for operations controlled by the FPCR where FPCR.FZ16 is to be used
  461. * FPST_STD
  462. * for A32/T32 Neon operations using the "standard FPSCR value"
  463. * FPST_STD_F16
  464. * as FPST_STD, but where FPCR.FZ16 is to be used
  465. */
  466. static inline TCGv_ptr fpstatus_ptr(ARMFPStatusFlavour flavour)
  467. {
  468. TCGv_ptr statusptr = tcg_temp_new_ptr();
  469. int offset;
  470. switch (flavour) {
  471. case FPST_FPCR:
  472. offset = offsetof(CPUARMState, vfp.fp_status);
  473. break;
  474. case FPST_FPCR_F16:
  475. offset = offsetof(CPUARMState, vfp.fp_status_f16);
  476. break;
  477. case FPST_STD:
  478. offset = offsetof(CPUARMState, vfp.standard_fp_status);
  479. break;
  480. case FPST_STD_F16:
  481. offset = offsetof(CPUARMState, vfp.standard_fp_status_f16);
  482. break;
  483. default:
  484. g_assert_not_reached();
  485. }
  486. tcg_gen_addi_ptr(statusptr, cpu_env, offset);
  487. return statusptr;
  488. }
  489. /**
  490. * finalize_memop:
  491. * @s: DisasContext
  492. * @opc: size+sign+align of the memory operation
  493. *
  494. * Build the complete MemOp for a memory operation, including alignment
  495. * and endianness.
  496. *
  497. * If (op & MO_AMASK) then the operation already contains the required
  498. * alignment, e.g. for AccType_ATOMIC. Otherwise, this an optionally
  499. * unaligned operation, e.g. for AccType_NORMAL.
  500. *
  501. * In the latter case, there are configuration bits that require alignment,
  502. * and this is applied here. Note that there is no way to indicate that
  503. * no alignment should ever be enforced; this must be handled manually.
  504. */
  505. static inline MemOp finalize_memop(DisasContext *s, MemOp opc)
  506. {
  507. if (s->align_mem && !(opc & MO_AMASK)) {
  508. opc |= MO_ALIGN;
  509. }
  510. return opc | s->be_data;
  511. }
  512. /**
  513. * asimd_imm_const: Expand an encoded SIMD constant value
  514. *
  515. * Expand a SIMD constant value. This is essentially the pseudocode
  516. * AdvSIMDExpandImm, except that we also perform the boolean NOT needed for
  517. * VMVN and VBIC (when cmode < 14 && op == 1).
  518. *
  519. * The combination cmode == 15 op == 1 is a reserved encoding for AArch32;
  520. * callers must catch this; we return the 64-bit constant value defined
  521. * for AArch64.
  522. *
  523. * cmode = 2,3,4,5,6,7,10,11,12,13 imm=0 was UNPREDICTABLE in v7A but
  524. * is either not unpredictable or merely CONSTRAINED UNPREDICTABLE in v8A;
  525. * we produce an immediate constant value of 0 in these cases.
  526. */
  527. uint64_t asimd_imm_const(uint32_t imm, int cmode, int op);
  528. /*
  529. * gen_disas_label:
  530. * Create a label and cache a copy of pc_save.
  531. */
  532. static inline DisasLabel gen_disas_label(DisasContext *s)
  533. {
  534. return (DisasLabel){
  535. .label = gen_new_label(),
  536. .pc_save = s->pc_save,
  537. };
  538. }
  539. /*
  540. * set_disas_label:
  541. * Emit a label and restore the cached copy of pc_save.
  542. */
  543. static inline void set_disas_label(DisasContext *s, DisasLabel l)
  544. {
  545. gen_set_label(l.label);
  546. s->pc_save = l.pc_save;
  547. }
  548. /*
  549. * Helpers for implementing sets of trans_* functions.
  550. * Defer the implementation of NAME to FUNC, with optional extra arguments.
  551. */
  552. #define TRANS(NAME, FUNC, ...) \
  553. static bool trans_##NAME(DisasContext *s, arg_##NAME *a) \
  554. { return FUNC(s, __VA_ARGS__); }
  555. #define TRANS_FEAT(NAME, FEAT, FUNC, ...) \
  556. static bool trans_##NAME(DisasContext *s, arg_##NAME *a) \
  557. { return dc_isar_feature(FEAT, s) && FUNC(s, __VA_ARGS__); }
  558. #define TRANS_FEAT_NONSTREAMING(NAME, FEAT, FUNC, ...) \
  559. static bool trans_##NAME(DisasContext *s, arg_##NAME *a) \
  560. { \
  561. s->is_nonstreaming = true; \
  562. return dc_isar_feature(FEAT, s) && FUNC(s, __VA_ARGS__); \
  563. }
  564. #endif /* TARGET_ARM_TRANSLATE_H */