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