4 #include "host-utils.h"
7 #ifndef CONFIG_USER_ONLY
8 static inline int get_phys_addr(CPUARMState *env, uint32_t address,
9 int access_type, int is_user,
10 uint32_t *phys_ptr, int *prot,
11 target_ulong *page_size);
14 static int vfp_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg)
18 /* VFP data registers are always little-endian. */
19 nregs = arm_feature(env, ARM_FEATURE_VFP3) ? 32 : 16;
21 stfq_le_p(buf, env->vfp.regs[reg]);
24 if (arm_feature(env, ARM_FEATURE_NEON)) {
25 /* Aliases for Q regs. */
28 stfq_le_p(buf, env->vfp.regs[(reg - 32) * 2]);
29 stfq_le_p(buf + 8, env->vfp.regs[(reg - 32) * 2 + 1]);
33 switch (reg - nregs) {
34 case 0: stl_p(buf, env->vfp.xregs[ARM_VFP_FPSID]); return 4;
35 case 1: stl_p(buf, env->vfp.xregs[ARM_VFP_FPSCR]); return 4;
36 case 2: stl_p(buf, env->vfp.xregs[ARM_VFP_FPEXC]); return 4;
41 static int vfp_gdb_set_reg(CPUARMState *env, uint8_t *buf, int reg)
45 nregs = arm_feature(env, ARM_FEATURE_VFP3) ? 32 : 16;
47 env->vfp.regs[reg] = ldfq_le_p(buf);
50 if (arm_feature(env, ARM_FEATURE_NEON)) {
53 env->vfp.regs[(reg - 32) * 2] = ldfq_le_p(buf);
54 env->vfp.regs[(reg - 32) * 2 + 1] = ldfq_le_p(buf + 8);
58 switch (reg - nregs) {
59 case 0: env->vfp.xregs[ARM_VFP_FPSID] = ldl_p(buf); return 4;
60 case 1: env->vfp.xregs[ARM_VFP_FPSCR] = ldl_p(buf); return 4;
61 case 2: env->vfp.xregs[ARM_VFP_FPEXC] = ldl_p(buf) & (1 << 30); return 4;
66 static int dacr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
69 tlb_flush(env, 1); /* Flush TLB as domain not tracked in TLB */
73 static int fcse_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
75 if (env->cp15.c13_fcse != value) {
76 /* Unlike real hardware the qemu TLB uses virtual addresses,
77 * not modified virtual addresses, so this causes a TLB flush.
80 env->cp15.c13_fcse = value;
84 static int contextidr_write(CPUARMState *env, const ARMCPRegInfo *ri,
87 if (env->cp15.c13_context != value && !arm_feature(env, ARM_FEATURE_MPU)) {
88 /* For VMSA (when not using the LPAE long descriptor page table
89 * format) this register includes the ASID, so do a TLB flush.
90 * For PMSA it is purely a process ID and no action is needed.
94 env->cp15.c13_context = value;
98 static int tlbiall_write(CPUARMState *env, const ARMCPRegInfo *ri,
101 /* Invalidate all (TLBIALL) */
106 static int tlbimva_write(CPUARMState *env, const ARMCPRegInfo *ri,
109 /* Invalidate single TLB entry by MVA and ASID (TLBIMVA) */
110 tlb_flush_page(env, value & TARGET_PAGE_MASK);
114 static int tlbiasid_write(CPUARMState *env, const ARMCPRegInfo *ri,
117 /* Invalidate by ASID (TLBIASID) */
118 tlb_flush(env, value == 0);
122 static int tlbimvaa_write(CPUARMState *env, const ARMCPRegInfo *ri,
125 /* Invalidate single entry by MVA, all ASIDs (TLBIMVAA) */
126 tlb_flush_page(env, value & TARGET_PAGE_MASK);
130 static const ARMCPRegInfo cp_reginfo[] = {
131 /* DBGDIDR: just RAZ. In particular this means the "debug architecture
132 * version" bits will read as a reserved value, which should cause
133 * Linux to not try to use the debug hardware.
135 { .name = "DBGDIDR", .cp = 14, .crn = 0, .crm = 0, .opc1 = 0, .opc2 = 0,
136 .access = PL0_R, .type = ARM_CP_CONST, .resetvalue = 0 },
137 /* MMU Domain access control / MPU write buffer control */
138 { .name = "DACR", .cp = 15,
139 .crn = 3, .crm = CP_ANY, .opc1 = CP_ANY, .opc2 = CP_ANY,
140 .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.c3),
141 .resetvalue = 0, .writefn = dacr_write },
142 { .name = "FCSEIDR", .cp = 15, .crn = 13, .crm = 0, .opc1 = 0, .opc2 = 0,
143 .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.c13_fcse),
144 .resetvalue = 0, .writefn = fcse_write },
145 { .name = "CONTEXTIDR", .cp = 15, .crn = 13, .crm = 0, .opc1 = 0, .opc2 = 1,
146 .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.c13_fcse),
147 .resetvalue = 0, .writefn = contextidr_write },
148 /* ??? This covers not just the impdef TLB lockdown registers but also
149 * some v7VMSA registers relating to TEX remap, so it is overly broad.
151 { .name = "TLB_LOCKDOWN", .cp = 15, .crn = 10, .crm = CP_ANY,
152 .opc1 = CP_ANY, .opc2 = CP_ANY, .access = PL1_RW, .type = ARM_CP_NOP },
153 /* MMU TLB control. Note that the wildcarding means we cover not just
154 * the unified TLB ops but also the dside/iside/inner-shareable variants.
156 { .name = "TLBIALL", .cp = 15, .crn = 8, .crm = CP_ANY,
157 .opc1 = CP_ANY, .opc2 = 0, .access = PL1_W, .writefn = tlbiall_write, },
158 { .name = "TLBIMVA", .cp = 15, .crn = 8, .crm = CP_ANY,
159 .opc1 = CP_ANY, .opc2 = 1, .access = PL1_W, .writefn = tlbimva_write, },
160 { .name = "TLBIASID", .cp = 15, .crn = 8, .crm = CP_ANY,
161 .opc1 = CP_ANY, .opc2 = 2, .access = PL1_W, .writefn = tlbiasid_write, },
162 { .name = "TLBIMVAA", .cp = 15, .crn = 8, .crm = CP_ANY,
163 .opc1 = CP_ANY, .opc2 = 3, .access = PL1_W, .writefn = tlbimvaa_write, },
167 static const ARMCPRegInfo not_v6_cp_reginfo[] = {
168 /* Not all pre-v6 cores implemented this WFI, so this is slightly
171 { .name = "WFI_v5", .cp = 15, .crn = 7, .crm = 8, .opc1 = 0, .opc2 = 2,
172 .access = PL1_W, .type = ARM_CP_WFI },
176 static const ARMCPRegInfo not_v7_cp_reginfo[] = {
177 /* Standard v6 WFI (also used in some pre-v6 cores); not in v7 (which
178 * is UNPREDICTABLE; we choose to NOP as most implementations do).
180 { .name = "WFI_v6", .cp = 15, .crn = 7, .crm = 0, .opc1 = 0, .opc2 = 4,
181 .access = PL1_W, .type = ARM_CP_WFI },
185 static const ARMCPRegInfo v6_cp_reginfo[] = {
186 /* prefetch by MVA in v6, NOP in v7 */
187 { .name = "MVA_prefetch",
188 .cp = 15, .crn = 7, .crm = 13, .opc1 = 0, .opc2 = 1,
189 .access = PL1_W, .type = ARM_CP_NOP },
190 { .name = "ISB", .cp = 15, .crn = 7, .crm = 5, .opc1 = 0, .opc2 = 4,
191 .access = PL0_W, .type = ARM_CP_NOP },
192 { .name = "ISB", .cp = 15, .crn = 7, .crm = 10, .opc1 = 0, .opc2 = 4,
193 .access = PL0_W, .type = ARM_CP_NOP },
194 { .name = "ISB", .cp = 15, .crn = 7, .crm = 10, .opc1 = 0, .opc2 = 5,
195 .access = PL0_W, .type = ARM_CP_NOP },
199 static int pmreg_read(CPUARMState *env, const ARMCPRegInfo *ri,
202 /* Generic performance monitor register read function for where
203 * user access may be allowed by PMUSERENR.
205 if (arm_current_pl(env) == 0 && !env->cp15.c9_pmuserenr) {
208 *value = CPREG_FIELD32(env, ri);
212 static int pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
215 if (arm_current_pl(env) == 0 && !env->cp15.c9_pmuserenr) {
218 /* only the DP, X, D and E bits are writable */
219 env->cp15.c9_pmcr &= ~0x39;
220 env->cp15.c9_pmcr |= (value & 0x39);
224 static int pmcntenset_write(CPUARMState *env, const ARMCPRegInfo *ri,
227 if (arm_current_pl(env) == 0 && !env->cp15.c9_pmuserenr) {
231 env->cp15.c9_pmcnten |= value;
235 static int pmcntenclr_write(CPUARMState *env, const ARMCPRegInfo *ri,
238 if (arm_current_pl(env) == 0 && !env->cp15.c9_pmuserenr) {
242 env->cp15.c9_pmcnten &= ~value;
246 static int pmovsr_write(CPUARMState *env, const ARMCPRegInfo *ri,
249 if (arm_current_pl(env) == 0 && !env->cp15.c9_pmuserenr) {
252 env->cp15.c9_pmovsr &= ~value;
256 static int pmxevtyper_write(CPUARMState *env, const ARMCPRegInfo *ri,
259 if (arm_current_pl(env) == 0 && !env->cp15.c9_pmuserenr) {
262 env->cp15.c9_pmxevtyper = value & 0xff;
266 static int pmuserenr_write(CPUARMState *env, const ARMCPRegInfo *ri,
269 env->cp15.c9_pmuserenr = value & 1;
273 static int pmintenset_write(CPUARMState *env, const ARMCPRegInfo *ri,
276 /* We have no event counters so only the C bit can be changed */
278 env->cp15.c9_pminten |= value;
282 static int pmintenclr_write(CPUARMState *env, const ARMCPRegInfo *ri,
286 env->cp15.c9_pminten &= ~value;
290 static const ARMCPRegInfo v7_cp_reginfo[] = {
291 /* DBGDRAR, DBGDSAR: always RAZ since we don't implement memory mapped
294 { .name = "DBGDRAR", .cp = 14, .crn = 1, .crm = 0, .opc1 = 0, .opc2 = 0,
295 .access = PL0_R, .type = ARM_CP_CONST, .resetvalue = 0 },
296 { .name = "DBGDRAR", .cp = 14, .crn = 2, .crm = 0, .opc1 = 0, .opc2 = 0,
297 .access = PL0_R, .type = ARM_CP_CONST, .resetvalue = 0 },
298 /* the old v6 WFI, UNPREDICTABLE in v7 but we choose to NOP */
299 { .name = "NOP", .cp = 15, .crn = 7, .crm = 0, .opc1 = 0, .opc2 = 4,
300 .access = PL1_W, .type = ARM_CP_NOP },
301 /* Performance monitors are implementation defined in v7,
302 * but with an ARM recommended set of registers, which we
303 * follow (although we don't actually implement any counters)
305 * Performance registers fall into three categories:
306 * (a) always UNDEF in PL0, RW in PL1 (PMINTENSET, PMINTENCLR)
307 * (b) RO in PL0 (ie UNDEF on write), RW in PL1 (PMUSERENR)
308 * (c) UNDEF in PL0 if PMUSERENR.EN==0, otherwise accessible (all others)
309 * For the cases controlled by PMUSERENR we must set .access to PL0_RW
310 * or PL0_RO as appropriate and then check PMUSERENR in the helper fn.
312 { .name = "PMCNTENSET", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 1,
313 .access = PL0_RW, .resetvalue = 0,
314 .fieldoffset = offsetof(CPUARMState, cp15.c9_pmcnten),
315 .readfn = pmreg_read, .writefn = pmcntenset_write },
316 { .name = "PMCNTENCLR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 2,
317 .access = PL0_RW, .fieldoffset = offsetof(CPUARMState, cp15.c9_pmcnten),
318 .readfn = pmreg_read, .writefn = pmcntenclr_write },
319 { .name = "PMOVSR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 3,
320 .access = PL0_RW, .fieldoffset = offsetof(CPUARMState, cp15.c9_pmovsr),
321 .readfn = pmreg_read, .writefn = pmovsr_write },
322 /* Unimplemented so WI. Strictly speaking write accesses in PL0 should
325 { .name = "PMSWINC", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 4,
326 .access = PL0_W, .type = ARM_CP_NOP },
327 /* Since we don't implement any events, writing to PMSELR is UNPREDICTABLE.
328 * We choose to RAZ/WI. XXX should respect PMUSERENR.
330 { .name = "PMSELR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 5,
331 .access = PL0_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
332 /* Unimplemented, RAZ/WI. XXX PMUSERENR */
333 { .name = "PMCCNTR", .cp = 15, .crn = 9, .crm = 13, .opc1 = 0, .opc2 = 0,
334 .access = PL0_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
335 { .name = "PMXEVTYPER", .cp = 15, .crn = 9, .crm = 13, .opc1 = 0, .opc2 = 1,
337 .fieldoffset = offsetof(CPUARMState, cp15.c9_pmxevtyper),
338 .readfn = pmreg_read, .writefn = pmxevtyper_write },
339 /* Unimplemented, RAZ/WI. XXX PMUSERENR */
340 { .name = "PMXEVCNTR", .cp = 15, .crn = 9, .crm = 13, .opc1 = 0, .opc2 = 2,
341 .access = PL0_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
342 { .name = "PMUSERENR", .cp = 15, .crn = 9, .crm = 14, .opc1 = 0, .opc2 = 0,
343 .access = PL0_R | PL1_RW,
344 .fieldoffset = offsetof(CPUARMState, cp15.c9_pmuserenr),
346 .writefn = pmuserenr_write },
347 { .name = "PMINTENSET", .cp = 15, .crn = 9, .crm = 14, .opc1 = 0, .opc2 = 1,
349 .fieldoffset = offsetof(CPUARMState, cp15.c9_pminten),
351 .writefn = pmintenset_write },
352 { .name = "PMINTENCLR", .cp = 15, .crn = 9, .crm = 14, .opc1 = 0, .opc2 = 2,
354 .fieldoffset = offsetof(CPUARMState, cp15.c9_pminten),
356 .writefn = pmintenclr_write },
360 static int teecr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
367 static int teehbr_read(CPUARMState *env, const ARMCPRegInfo *ri,
370 /* This is a helper function because the user access rights
371 * depend on the value of the TEECR.
373 if (arm_current_pl(env) == 0 && (env->teecr & 1)) {
376 *value = env->teehbr;
380 static int teehbr_write(CPUARMState *env, const ARMCPRegInfo *ri,
383 if (arm_current_pl(env) == 0 && (env->teecr & 1)) {
390 static const ARMCPRegInfo t2ee_cp_reginfo[] = {
391 { .name = "TEECR", .cp = 14, .crn = 0, .crm = 0, .opc1 = 6, .opc2 = 0,
392 .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, teecr),
394 .writefn = teecr_write },
395 { .name = "TEEHBR", .cp = 14, .crn = 1, .crm = 0, .opc1 = 6, .opc2 = 0,
396 .access = PL0_RW, .fieldoffset = offsetof(CPUARMState, teehbr),
398 .readfn = teehbr_read, .writefn = teehbr_write },
402 static const ARMCPRegInfo v6k_cp_reginfo[] = {
403 { .name = "TPIDRURW", .cp = 15, .crn = 13, .crm = 0, .opc1 = 0, .opc2 = 2,
405 .fieldoffset = offsetof(CPUARMState, cp15.c13_tls1),
407 { .name = "TPIDRURO", .cp = 15, .crn = 13, .crm = 0, .opc1 = 0, .opc2 = 3,
408 .access = PL0_R|PL1_W,
409 .fieldoffset = offsetof(CPUARMState, cp15.c13_tls2),
411 { .name = "TPIDRPRW", .cp = 15, .crn = 13, .crm = 0, .opc1 = 0, .opc2 = 4,
413 .fieldoffset = offsetof(CPUARMState, cp15.c13_tls3),
418 static const ARMCPRegInfo generic_timer_cp_reginfo[] = {
419 /* Dummy implementation: RAZ/WI the whole crn=14 space */
420 { .name = "GENERIC_TIMER", .cp = 15, .crn = 14,
421 .crm = CP_ANY, .opc1 = CP_ANY, .opc2 = CP_ANY,
422 .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
426 static int par_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
428 if (arm_feature(env, ARM_FEATURE_V7)) {
429 env->cp15.c7_par = value & 0xfffff6ff;
431 env->cp15.c7_par = value & 0xfffff1ff;
436 #ifndef CONFIG_USER_ONLY
437 /* get_phys_addr() isn't present for user-mode-only targets */
438 static int ats_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
441 target_ulong page_size;
443 int ret, is_user = ri->opc2 & 2;
444 int access_type = ri->opc2 & 1;
447 /* Other states are only available with TrustZone */
450 ret = get_phys_addr(env, value, access_type, is_user,
451 &phys_addr, &prot, &page_size);
453 /* We do not set any attribute bits in the PAR */
454 if (page_size == (1 << 24)
455 && arm_feature(env, ARM_FEATURE_V7)) {
456 env->cp15.c7_par = (phys_addr & 0xff000000) | 1 << 1;
458 env->cp15.c7_par = phys_addr & 0xfffff000;
461 env->cp15.c7_par = ((ret & (10 << 1)) >> 5) |
462 ((ret & (12 << 1)) >> 6) |
463 ((ret & 0xf) << 1) | 1;
469 static const ARMCPRegInfo vapa_cp_reginfo[] = {
470 { .name = "PAR", .cp = 15, .crn = 7, .crm = 4, .opc1 = 0, .opc2 = 0,
471 .access = PL1_RW, .resetvalue = 0,
472 .fieldoffset = offsetof(CPUARMState, cp15.c7_par),
473 .writefn = par_write },
474 #ifndef CONFIG_USER_ONLY
475 { .name = "ATS", .cp = 15, .crn = 7, .crm = 8, .opc1 = 0, .opc2 = CP_ANY,
476 .access = PL1_W, .writefn = ats_write },
481 /* Return basic MPU access permission bits. */
482 static uint32_t simple_mpu_ap_bits(uint32_t val)
489 for (i = 0; i < 16; i += 2) {
490 ret |= (val >> i) & mask;
496 /* Pad basic MPU access permission bits to extended format. */
497 static uint32_t extended_mpu_ap_bits(uint32_t val)
504 for (i = 0; i < 16; i += 2) {
505 ret |= (val & mask) << i;
511 static int pmsav5_data_ap_write(CPUARMState *env, const ARMCPRegInfo *ri,
514 env->cp15.c5_data = extended_mpu_ap_bits(value);
518 static int pmsav5_data_ap_read(CPUARMState *env, const ARMCPRegInfo *ri,
521 *value = simple_mpu_ap_bits(env->cp15.c5_data);
525 static int pmsav5_insn_ap_write(CPUARMState *env, const ARMCPRegInfo *ri,
528 env->cp15.c5_insn = extended_mpu_ap_bits(value);
532 static int pmsav5_insn_ap_read(CPUARMState *env, const ARMCPRegInfo *ri,
535 *value = simple_mpu_ap_bits(env->cp15.c5_insn);
539 static const ARMCPRegInfo pmsav5_cp_reginfo[] = {
540 { .name = "DATA_AP", .cp = 15, .crn = 5, .crm = 0, .opc1 = 0, .opc2 = 0,
542 .fieldoffset = offsetof(CPUARMState, cp15.c5_data), .resetvalue = 0,
543 .readfn = pmsav5_data_ap_read, .writefn = pmsav5_data_ap_write, },
544 { .name = "INSN_AP", .cp = 15, .crn = 5, .crm = 0, .opc1 = 0, .opc2 = 1,
546 .fieldoffset = offsetof(CPUARMState, cp15.c5_insn), .resetvalue = 0,
547 .readfn = pmsav5_insn_ap_read, .writefn = pmsav5_insn_ap_write, },
548 { .name = "DATA_EXT_AP", .cp = 15, .crn = 5, .crm = 0, .opc1 = 0, .opc2 = 2,
550 .fieldoffset = offsetof(CPUARMState, cp15.c5_data), .resetvalue = 0, },
551 { .name = "INSN_EXT_AP", .cp = 15, .crn = 5, .crm = 0, .opc1 = 0, .opc2 = 3,
553 .fieldoffset = offsetof(CPUARMState, cp15.c5_insn), .resetvalue = 0, },
554 { .name = "DCACHE_CFG", .cp = 15, .crn = 2, .crm = 0, .opc1 = 0, .opc2 = 0,
556 .fieldoffset = offsetof(CPUARMState, cp15.c2_data), .resetvalue = 0, },
557 { .name = "ICACHE_CFG", .cp = 15, .crn = 2, .crm = 0, .opc1 = 0, .opc2 = 1,
559 .fieldoffset = offsetof(CPUARMState, cp15.c2_insn), .resetvalue = 0, },
563 static int vmsa_ttbcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
567 env->cp15.c2_control = value;
568 env->cp15.c2_mask = ~(((uint32_t)0xffffffffu) >> value);
569 env->cp15.c2_base_mask = ~((uint32_t)0x3fffu >> value);
573 static void vmsa_ttbcr_reset(CPUARMState *env, const ARMCPRegInfo *ri)
575 env->cp15.c2_base_mask = 0xffffc000u;
576 env->cp15.c2_control = 0;
577 env->cp15.c2_mask = 0;
580 static const ARMCPRegInfo vmsa_cp_reginfo[] = {
581 { .name = "DFSR", .cp = 15, .crn = 5, .crm = 0, .opc1 = 0, .opc2 = 0,
583 .fieldoffset = offsetof(CPUARMState, cp15.c5_data), .resetvalue = 0, },
584 { .name = "IFSR", .cp = 15, .crn = 5, .crm = 0, .opc1 = 0, .opc2 = 1,
586 .fieldoffset = offsetof(CPUARMState, cp15.c5_insn), .resetvalue = 0, },
587 { .name = "TTBR0", .cp = 15, .crn = 2, .crm = 0, .opc1 = 0, .opc2 = 0,
589 .fieldoffset = offsetof(CPUARMState, cp15.c2_base0), .resetvalue = 0, },
590 { .name = "TTBR1", .cp = 15, .crn = 2, .crm = 0, .opc1 = 0, .opc2 = 1,
592 .fieldoffset = offsetof(CPUARMState, cp15.c2_base0), .resetvalue = 0, },
593 { .name = "TTBCR", .cp = 15, .crn = 2, .crm = 0, .opc1 = 0, .opc2 = 2,
594 .access = PL1_RW, .writefn = vmsa_ttbcr_write,
595 .resetfn = vmsa_ttbcr_reset,
596 .fieldoffset = offsetof(CPUARMState, cp15.c2_control) },
600 static int omap_ticonfig_write(CPUARMState *env, const ARMCPRegInfo *ri,
603 env->cp15.c15_ticonfig = value & 0xe7;
604 /* The OS_TYPE bit in this register changes the reported CPUID! */
605 env->cp15.c0_cpuid = (value & (1 << 5)) ?
606 ARM_CPUID_TI915T : ARM_CPUID_TI925T;
610 static int omap_threadid_write(CPUARMState *env, const ARMCPRegInfo *ri,
613 env->cp15.c15_threadid = value & 0xffff;
617 static int omap_wfi_write(CPUARMState *env, const ARMCPRegInfo *ri,
620 /* Wait-for-interrupt (deprecated) */
621 cpu_interrupt(env, CPU_INTERRUPT_HALT);
625 static const ARMCPRegInfo omap_cp_reginfo[] = {
626 { .name = "DFSR", .cp = 15, .crn = 5, .crm = CP_ANY,
627 .opc1 = CP_ANY, .opc2 = CP_ANY, .access = PL1_RW, .type = ARM_CP_OVERRIDE,
628 .fieldoffset = offsetof(CPUARMState, cp15.c5_data), .resetvalue = 0, },
629 { .name = "", .cp = 15, .crn = 15, .crm = 0, .opc1 = 0, .opc2 = 0,
630 .access = PL1_RW, .type = ARM_CP_NOP },
631 { .name = "TICONFIG", .cp = 15, .crn = 15, .crm = 1, .opc1 = 0, .opc2 = 0,
633 .fieldoffset = offsetof(CPUARMState, cp15.c15_ticonfig), .resetvalue = 0,
634 .writefn = omap_ticonfig_write },
635 { .name = "IMAX", .cp = 15, .crn = 15, .crm = 2, .opc1 = 0, .opc2 = 0,
637 .fieldoffset = offsetof(CPUARMState, cp15.c15_i_max), .resetvalue = 0, },
638 { .name = "IMIN", .cp = 15, .crn = 15, .crm = 3, .opc1 = 0, .opc2 = 0,
639 .access = PL1_RW, .resetvalue = 0xff0,
640 .fieldoffset = offsetof(CPUARMState, cp15.c15_i_min) },
641 { .name = "THREADID", .cp = 15, .crn = 15, .crm = 4, .opc1 = 0, .opc2 = 0,
643 .fieldoffset = offsetof(CPUARMState, cp15.c15_threadid), .resetvalue = 0,
644 .writefn = omap_threadid_write },
645 { .name = "TI925T_STATUS", .cp = 15, .crn = 15,
646 .crm = 8, .opc1 = 0, .opc2 = 0, .access = PL1_RW,
647 .readfn = arm_cp_read_zero, .writefn = omap_wfi_write, },
648 /* TODO: Peripheral port remap register:
649 * On OMAP2 mcr p15, 0, rn, c15, c2, 4 sets up the interrupt controller
650 * base address at $rn & ~0xfff and map size of 0x200 << ($rn & 0xfff),
656 static int xscale_cpar_write(CPUARMState *env, const ARMCPRegInfo *ri,
660 if (env->cp15.c15_cpar != value) {
661 /* Changes cp0 to cp13 behavior, so needs a TB flush. */
663 env->cp15.c15_cpar = value;
668 static const ARMCPRegInfo xscale_cp_reginfo[] = {
669 { .name = "XSCALE_CPAR",
670 .cp = 15, .crn = 15, .crm = 1, .opc1 = 0, .opc2 = 0, .access = PL1_RW,
671 .fieldoffset = offsetof(CPUARMState, cp15.c15_cpar), .resetvalue = 0,
672 .writefn = xscale_cpar_write, },
676 static const ARMCPRegInfo dummy_c15_cp_reginfo[] = {
677 /* RAZ/WI the whole crn=15 space, when we don't have a more specific
678 * implementation of this implementation-defined space.
679 * Ideally this should eventually disappear in favour of actually
680 * implementing the correct behaviour for all cores.
682 { .name = "C15_IMPDEF", .cp = 15, .crn = 15,
683 .crm = CP_ANY, .opc1 = CP_ANY, .opc2 = CP_ANY,
684 .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
688 void register_cp_regs_for_features(ARMCPU *cpu)
690 /* Register all the coprocessor registers based on feature bits */
691 CPUARMState *env = &cpu->env;
692 if (arm_feature(env, ARM_FEATURE_M)) {
693 /* M profile has no coprocessor registers */
697 define_arm_cp_regs(cpu, cp_reginfo);
698 if (arm_feature(env, ARM_FEATURE_V6)) {
699 define_arm_cp_regs(cpu, v6_cp_reginfo);
701 define_arm_cp_regs(cpu, not_v6_cp_reginfo);
703 if (arm_feature(env, ARM_FEATURE_V6K)) {
704 define_arm_cp_regs(cpu, v6k_cp_reginfo);
706 if (arm_feature(env, ARM_FEATURE_V7)) {
707 /* v7 performance monitor control register: same implementor
708 * field as main ID register, and we implement no event counters.
710 ARMCPRegInfo pmcr = {
711 .name = "PMCR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 0,
712 .access = PL0_RW, .resetvalue = cpu->midr & 0xff000000,
713 .fieldoffset = offsetof(CPUARMState, cp15.c9_pmcr),
714 .readfn = pmreg_read, .writefn = pmcr_write
716 define_one_arm_cp_reg(cpu, &pmcr);
717 define_arm_cp_regs(cpu, v7_cp_reginfo);
719 define_arm_cp_regs(cpu, not_v7_cp_reginfo);
721 if (arm_feature(env, ARM_FEATURE_MPU)) {
722 /* These are the MPU registers prior to PMSAv6. Any new
723 * PMSA core later than the ARM946 will require that we
724 * implement the PMSAv6 or PMSAv7 registers, which are
725 * completely different.
727 assert(!arm_feature(env, ARM_FEATURE_V6));
728 define_arm_cp_regs(cpu, pmsav5_cp_reginfo);
730 define_arm_cp_regs(cpu, vmsa_cp_reginfo);
732 if (arm_feature(env, ARM_FEATURE_THUMB2EE)) {
733 define_arm_cp_regs(cpu, t2ee_cp_reginfo);
735 if (arm_feature(env, ARM_FEATURE_GENERIC_TIMER)) {
736 define_arm_cp_regs(cpu, generic_timer_cp_reginfo);
738 if (arm_feature(env, ARM_FEATURE_VAPA)) {
739 define_arm_cp_regs(cpu, vapa_cp_reginfo);
741 if (arm_feature(env, ARM_FEATURE_OMAPCP)) {
742 define_arm_cp_regs(cpu, omap_cp_reginfo);
744 if (arm_feature(env, ARM_FEATURE_XSCALE)) {
745 define_arm_cp_regs(cpu, xscale_cp_reginfo);
747 if (arm_feature(env, ARM_FEATURE_DUMMY_C15_REGS)) {
748 define_arm_cp_regs(cpu, dummy_c15_cp_reginfo);
752 ARMCPU *cpu_arm_init(const char *cpu_model)
756 static int inited = 0;
758 if (!object_class_by_name(cpu_model)) {
761 cpu = ARM_CPU(object_new(cpu_model));
763 env->cpu_model_str = cpu_model;
764 arm_cpu_realize(cpu);
766 if (tcg_enabled() && !inited) {
768 arm_translate_init();
772 if (arm_feature(env, ARM_FEATURE_NEON)) {
773 gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
774 51, "arm-neon.xml", 0);
775 } else if (arm_feature(env, ARM_FEATURE_VFP3)) {
776 gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
777 35, "arm-vfp3.xml", 0);
778 } else if (arm_feature(env, ARM_FEATURE_VFP)) {
779 gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
780 19, "arm-vfp.xml", 0);
786 typedef struct ARMCPUListState {
787 fprintf_function cpu_fprintf;
791 /* Sort alphabetically by type name, except for "any". */
792 static gint arm_cpu_list_compare(gconstpointer a, gconstpointer b)
794 ObjectClass *class_a = (ObjectClass *)a;
795 ObjectClass *class_b = (ObjectClass *)b;
796 const char *name_a, *name_b;
798 name_a = object_class_get_name(class_a);
799 name_b = object_class_get_name(class_b);
800 if (strcmp(name_a, "any") == 0) {
802 } else if (strcmp(name_b, "any") == 0) {
805 return strcmp(name_a, name_b);
809 static void arm_cpu_list_entry(gpointer data, gpointer user_data)
811 ObjectClass *oc = data;
812 ARMCPUListState *s = user_data;
814 (*s->cpu_fprintf)(s->file, " %s\n",
815 object_class_get_name(oc));
818 void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf)
820 ARMCPUListState s = {
822 .cpu_fprintf = cpu_fprintf,
826 list = object_class_get_list(TYPE_ARM_CPU, false);
827 list = g_slist_sort(list, arm_cpu_list_compare);
828 (*cpu_fprintf)(f, "Available CPUs:\n");
829 g_slist_foreach(list, arm_cpu_list_entry, &s);
833 void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,
834 const ARMCPRegInfo *r, void *opaque)
836 /* Define implementations of coprocessor registers.
837 * We store these in a hashtable because typically
838 * there are less than 150 registers in a space which
839 * is 16*16*16*8*8 = 262144 in size.
840 * Wildcarding is supported for the crm, opc1 and opc2 fields.
841 * If a register is defined twice then the second definition is
842 * used, so this can be used to define some generic registers and
843 * then override them with implementation specific variations.
844 * At least one of the original and the second definition should
845 * include ARM_CP_OVERRIDE in its type bits -- this is just a guard
846 * against accidental use.
849 int crmmin = (r->crm == CP_ANY) ? 0 : r->crm;
850 int crmmax = (r->crm == CP_ANY) ? 15 : r->crm;
851 int opc1min = (r->opc1 == CP_ANY) ? 0 : r->opc1;
852 int opc1max = (r->opc1 == CP_ANY) ? 7 : r->opc1;
853 int opc2min = (r->opc2 == CP_ANY) ? 0 : r->opc2;
854 int opc2max = (r->opc2 == CP_ANY) ? 7 : r->opc2;
855 /* 64 bit registers have only CRm and Opc1 fields */
856 assert(!((r->type & ARM_CP_64BIT) && (r->opc2 || r->crn)));
857 /* Check that the register definition has enough info to handle
858 * reads and writes if they are permitted.
860 if (!(r->type & (ARM_CP_SPECIAL|ARM_CP_CONST))) {
861 if (r->access & PL3_R) {
862 assert(r->fieldoffset || r->readfn);
864 if (r->access & PL3_W) {
865 assert(r->fieldoffset || r->writefn);
868 /* Bad type field probably means missing sentinel at end of reg list */
869 assert(cptype_valid(r->type));
870 for (crm = crmmin; crm <= crmmax; crm++) {
871 for (opc1 = opc1min; opc1 <= opc1max; opc1++) {
872 for (opc2 = opc2min; opc2 <= opc2max; opc2++) {
873 uint32_t *key = g_new(uint32_t, 1);
874 ARMCPRegInfo *r2 = g_memdup(r, sizeof(ARMCPRegInfo));
875 int is64 = (r->type & ARM_CP_64BIT) ? 1 : 0;
876 *key = ENCODE_CP_REG(r->cp, is64, r->crn, crm, opc1, opc2);
878 /* Make sure reginfo passed to helpers for wildcarded regs
879 * has the correct crm/opc1/opc2 for this reg, not CP_ANY:
884 /* Overriding of an existing definition must be explicitly
887 if (!(r->type & ARM_CP_OVERRIDE)) {
888 ARMCPRegInfo *oldreg;
889 oldreg = g_hash_table_lookup(cpu->cp_regs, key);
890 if (oldreg && !(oldreg->type & ARM_CP_OVERRIDE)) {
891 fprintf(stderr, "Register redefined: cp=%d %d bit "
892 "crn=%d crm=%d opc1=%d opc2=%d, "
893 "was %s, now %s\n", r2->cp, 32 + 32 * is64,
894 r2->crn, r2->crm, r2->opc1, r2->opc2,
895 oldreg->name, r2->name);
899 g_hash_table_insert(cpu->cp_regs, key, r2);
905 void define_arm_cp_regs_with_opaque(ARMCPU *cpu,
906 const ARMCPRegInfo *regs, void *opaque)
908 /* Define a whole list of registers */
909 const ARMCPRegInfo *r;
910 for (r = regs; r->type != ARM_CP_SENTINEL; r++) {
911 define_one_arm_cp_reg_with_opaque(cpu, r, opaque);
915 const ARMCPRegInfo *get_arm_cp_reginfo(ARMCPU *cpu, uint32_t encoded_cp)
917 return g_hash_table_lookup(cpu->cp_regs, &encoded_cp);
920 int arm_cp_write_ignore(CPUARMState *env, const ARMCPRegInfo *ri,
923 /* Helper coprocessor write function for write-ignore registers */
927 int arm_cp_read_zero(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t *value)
929 /* Helper coprocessor write function for read-as-zero registers */
934 static int bad_mode_switch(CPUARMState *env, int mode)
936 /* Return true if it is not valid for us to switch to
937 * this CPU mode (ie all the UNPREDICTABLE cases in
938 * the ARM ARM CPSRWriteByInstr pseudocode).
941 case ARM_CPU_MODE_USR:
942 case ARM_CPU_MODE_SYS:
943 case ARM_CPU_MODE_SVC:
944 case ARM_CPU_MODE_ABT:
945 case ARM_CPU_MODE_UND:
946 case ARM_CPU_MODE_IRQ:
947 case ARM_CPU_MODE_FIQ:
954 uint32_t cpsr_read(CPUARMState *env)
958 return env->uncached_cpsr | (env->NF & 0x80000000) | (ZF << 30) |
959 (env->CF << 29) | ((env->VF & 0x80000000) >> 3) | (env->QF << 27)
960 | (env->thumb << 5) | ((env->condexec_bits & 3) << 25)
961 | ((env->condexec_bits & 0xfc) << 8)
965 void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)
967 if (mask & CPSR_NZCV) {
968 env->ZF = (~val) & CPSR_Z;
970 env->CF = (val >> 29) & 1;
971 env->VF = (val << 3) & 0x80000000;
974 env->QF = ((val & CPSR_Q) != 0);
976 env->thumb = ((val & CPSR_T) != 0);
977 if (mask & CPSR_IT_0_1) {
978 env->condexec_bits &= ~3;
979 env->condexec_bits |= (val >> 25) & 3;
981 if (mask & CPSR_IT_2_7) {
982 env->condexec_bits &= 3;
983 env->condexec_bits |= (val >> 8) & 0xfc;
985 if (mask & CPSR_GE) {
986 env->GE = (val >> 16) & 0xf;
989 if ((env->uncached_cpsr ^ val) & mask & CPSR_M) {
990 if (bad_mode_switch(env, val & CPSR_M)) {
991 /* Attempt to switch to an invalid mode: this is UNPREDICTABLE.
992 * We choose to ignore the attempt and leave the CPSR M field
997 switch_mode(env, val & CPSR_M);
1000 mask &= ~CACHED_CPSR_BITS;
1001 env->uncached_cpsr = (env->uncached_cpsr & ~mask) | (val & mask);
1004 /* Sign/zero extend */
1005 uint32_t HELPER(sxtb16)(uint32_t x)
1008 res = (uint16_t)(int8_t)x;
1009 res |= (uint32_t)(int8_t)(x >> 16) << 16;
1013 uint32_t HELPER(uxtb16)(uint32_t x)
1016 res = (uint16_t)(uint8_t)x;
1017 res |= (uint32_t)(uint8_t)(x >> 16) << 16;
1021 uint32_t HELPER(clz)(uint32_t x)
1026 int32_t HELPER(sdiv)(int32_t num, int32_t den)
1030 if (num == INT_MIN && den == -1)
1035 uint32_t HELPER(udiv)(uint32_t num, uint32_t den)
1042 uint32_t HELPER(rbit)(uint32_t x)
1044 x = ((x & 0xff000000) >> 24)
1045 | ((x & 0x00ff0000) >> 8)
1046 | ((x & 0x0000ff00) << 8)
1047 | ((x & 0x000000ff) << 24);
1048 x = ((x & 0xf0f0f0f0) >> 4)
1049 | ((x & 0x0f0f0f0f) << 4);
1050 x = ((x & 0x88888888) >> 3)
1051 | ((x & 0x44444444) >> 1)
1052 | ((x & 0x22222222) << 1)
1053 | ((x & 0x11111111) << 3);
1057 uint32_t HELPER(abs)(uint32_t x)
1059 return ((int32_t)x < 0) ? -x : x;
1062 #if defined(CONFIG_USER_ONLY)
1064 void do_interrupt (CPUARMState *env)
1066 env->exception_index = -1;
1069 int cpu_arm_handle_mmu_fault (CPUARMState *env, target_ulong address, int rw,
1073 env->exception_index = EXCP_PREFETCH_ABORT;
1074 env->cp15.c6_insn = address;
1076 env->exception_index = EXCP_DATA_ABORT;
1077 env->cp15.c6_data = address;
1082 void HELPER(set_cp15)(CPUARMState *env, uint32_t insn, uint32_t val)
1084 cpu_abort(env, "cp15 insn %08x\n", insn);
1087 uint32_t HELPER(get_cp15)(CPUARMState *env, uint32_t insn)
1089 cpu_abort(env, "cp15 insn %08x\n", insn);
1092 /* These should probably raise undefined insn exceptions. */
1093 void HELPER(v7m_msr)(CPUARMState *env, uint32_t reg, uint32_t val)
1095 cpu_abort(env, "v7m_mrs %d\n", reg);
1098 uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg)
1100 cpu_abort(env, "v7m_mrs %d\n", reg);
1104 void switch_mode(CPUARMState *env, int mode)
1106 if (mode != ARM_CPU_MODE_USR)
1107 cpu_abort(env, "Tried to switch out of user mode\n");
1110 void HELPER(set_r13_banked)(CPUARMState *env, uint32_t mode, uint32_t val)
1112 cpu_abort(env, "banked r13 write\n");
1115 uint32_t HELPER(get_r13_banked)(CPUARMState *env, uint32_t mode)
1117 cpu_abort(env, "banked r13 read\n");
1123 /* Map CPU modes onto saved register banks. */
1124 static inline int bank_number(CPUARMState *env, int mode)
1127 case ARM_CPU_MODE_USR:
1128 case ARM_CPU_MODE_SYS:
1130 case ARM_CPU_MODE_SVC:
1132 case ARM_CPU_MODE_ABT:
1134 case ARM_CPU_MODE_UND:
1136 case ARM_CPU_MODE_IRQ:
1138 case ARM_CPU_MODE_FIQ:
1141 cpu_abort(env, "Bad mode %x\n", mode);
1145 void switch_mode(CPUARMState *env, int mode)
1150 old_mode = env->uncached_cpsr & CPSR_M;
1151 if (mode == old_mode)
1154 if (old_mode == ARM_CPU_MODE_FIQ) {
1155 memcpy (env->fiq_regs, env->regs + 8, 5 * sizeof(uint32_t));
1156 memcpy (env->regs + 8, env->usr_regs, 5 * sizeof(uint32_t));
1157 } else if (mode == ARM_CPU_MODE_FIQ) {
1158 memcpy (env->usr_regs, env->regs + 8, 5 * sizeof(uint32_t));
1159 memcpy (env->regs + 8, env->fiq_regs, 5 * sizeof(uint32_t));
1162 i = bank_number(env, old_mode);
1163 env->banked_r13[i] = env->regs[13];
1164 env->banked_r14[i] = env->regs[14];
1165 env->banked_spsr[i] = env->spsr;
1167 i = bank_number(env, mode);
1168 env->regs[13] = env->banked_r13[i];
1169 env->regs[14] = env->banked_r14[i];
1170 env->spsr = env->banked_spsr[i];
1173 static void v7m_push(CPUARMState *env, uint32_t val)
1176 stl_phys(env->regs[13], val);
1179 static uint32_t v7m_pop(CPUARMState *env)
1182 val = ldl_phys(env->regs[13]);
1187 /* Switch to V7M main or process stack pointer. */
1188 static void switch_v7m_sp(CPUARMState *env, int process)
1191 if (env->v7m.current_sp != process) {
1192 tmp = env->v7m.other_sp;
1193 env->v7m.other_sp = env->regs[13];
1194 env->regs[13] = tmp;
1195 env->v7m.current_sp = process;
1199 static void do_v7m_exception_exit(CPUARMState *env)
1204 type = env->regs[15];
1205 if (env->v7m.exception != 0)
1206 armv7m_nvic_complete_irq(env->nvic, env->v7m.exception);
1208 /* Switch to the target stack. */
1209 switch_v7m_sp(env, (type & 4) != 0);
1210 /* Pop registers. */
1211 env->regs[0] = v7m_pop(env);
1212 env->regs[1] = v7m_pop(env);
1213 env->regs[2] = v7m_pop(env);
1214 env->regs[3] = v7m_pop(env);
1215 env->regs[12] = v7m_pop(env);
1216 env->regs[14] = v7m_pop(env);
1217 env->regs[15] = v7m_pop(env);
1218 xpsr = v7m_pop(env);
1219 xpsr_write(env, xpsr, 0xfffffdff);
1220 /* Undo stack alignment. */
1223 /* ??? The exception return type specifies Thread/Handler mode. However
1224 this is also implied by the xPSR value. Not sure what to do
1225 if there is a mismatch. */
1226 /* ??? Likewise for mismatches between the CONTROL register and the stack
1230 static void do_interrupt_v7m(CPUARMState *env)
1232 uint32_t xpsr = xpsr_read(env);
1237 if (env->v7m.current_sp)
1239 if (env->v7m.exception == 0)
1242 /* For exceptions we just mark as pending on the NVIC, and let that
1244 /* TODO: Need to escalate if the current priority is higher than the
1245 one we're raising. */
1246 switch (env->exception_index) {
1248 armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE);
1252 armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SVC);
1254 case EXCP_PREFETCH_ABORT:
1255 case EXCP_DATA_ABORT:
1256 armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_MEM);
1259 if (semihosting_enabled) {
1261 nr = arm_lduw_code(env->regs[15], env->bswap_code) & 0xff;
1264 env->regs[0] = do_arm_semihosting(env);
1268 armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_DEBUG);
1271 env->v7m.exception = armv7m_nvic_acknowledge_irq(env->nvic);
1273 case EXCP_EXCEPTION_EXIT:
1274 do_v7m_exception_exit(env);
1277 cpu_abort(env, "Unhandled exception 0x%x\n", env->exception_index);
1278 return; /* Never happens. Keep compiler happy. */
1281 /* Align stack pointer. */
1282 /* ??? Should only do this if Configuration Control Register
1283 STACKALIGN bit is set. */
1284 if (env->regs[13] & 4) {
1288 /* Switch to the handler mode. */
1289 v7m_push(env, xpsr);
1290 v7m_push(env, env->regs[15]);
1291 v7m_push(env, env->regs[14]);
1292 v7m_push(env, env->regs[12]);
1293 v7m_push(env, env->regs[3]);
1294 v7m_push(env, env->regs[2]);
1295 v7m_push(env, env->regs[1]);
1296 v7m_push(env, env->regs[0]);
1297 switch_v7m_sp(env, 0);
1299 env->condexec_bits = 0;
1301 addr = ldl_phys(env->v7m.vecbase + env->v7m.exception * 4);
1302 env->regs[15] = addr & 0xfffffffe;
1303 env->thumb = addr & 1;
1306 /* Handle a CPU exception. */
1307 void do_interrupt(CPUARMState *env)
1315 do_interrupt_v7m(env);
1318 /* TODO: Vectored interrupt controller. */
1319 switch (env->exception_index) {
1321 new_mode = ARM_CPU_MODE_UND;
1330 if (semihosting_enabled) {
1331 /* Check for semihosting interrupt. */
1333 mask = arm_lduw_code(env->regs[15] - 2, env->bswap_code) & 0xff;
1335 mask = arm_ldl_code(env->regs[15] - 4, env->bswap_code)
1338 /* Only intercept calls from privileged modes, to provide some
1339 semblance of security. */
1340 if (((mask == 0x123456 && !env->thumb)
1341 || (mask == 0xab && env->thumb))
1342 && (env->uncached_cpsr & CPSR_M) != ARM_CPU_MODE_USR) {
1343 env->regs[0] = do_arm_semihosting(env);
1347 new_mode = ARM_CPU_MODE_SVC;
1350 /* The PC already points to the next instruction. */
1354 /* See if this is a semihosting syscall. */
1355 if (env->thumb && semihosting_enabled) {
1356 mask = arm_lduw_code(env->regs[15], env->bswap_code) & 0xff;
1358 && (env->uncached_cpsr & CPSR_M) != ARM_CPU_MODE_USR) {
1360 env->regs[0] = do_arm_semihosting(env);
1364 env->cp15.c5_insn = 2;
1365 /* Fall through to prefetch abort. */
1366 case EXCP_PREFETCH_ABORT:
1367 new_mode = ARM_CPU_MODE_ABT;
1369 mask = CPSR_A | CPSR_I;
1372 case EXCP_DATA_ABORT:
1373 new_mode = ARM_CPU_MODE_ABT;
1375 mask = CPSR_A | CPSR_I;
1379 new_mode = ARM_CPU_MODE_IRQ;
1381 /* Disable IRQ and imprecise data aborts. */
1382 mask = CPSR_A | CPSR_I;
1386 new_mode = ARM_CPU_MODE_FIQ;
1388 /* Disable FIQ, IRQ and imprecise data aborts. */
1389 mask = CPSR_A | CPSR_I | CPSR_F;
1393 cpu_abort(env, "Unhandled exception 0x%x\n", env->exception_index);
1394 return; /* Never happens. Keep compiler happy. */
1397 if (env->cp15.c1_sys & (1 << 13)) {
1400 switch_mode (env, new_mode);
1401 env->spsr = cpsr_read(env);
1402 /* Clear IT bits. */
1403 env->condexec_bits = 0;
1404 /* Switch to the new mode, and to the correct instruction set. */
1405 env->uncached_cpsr = (env->uncached_cpsr & ~CPSR_M) | new_mode;
1406 env->uncached_cpsr |= mask;
1407 /* this is a lie, as the was no c1_sys on V4T/V5, but who cares
1408 * and we should just guard the thumb mode on V4 */
1409 if (arm_feature(env, ARM_FEATURE_V4T)) {
1410 env->thumb = (env->cp15.c1_sys & (1 << 30)) != 0;
1412 env->regs[14] = env->regs[15] + offset;
1413 env->regs[15] = addr;
1414 env->interrupt_request |= CPU_INTERRUPT_EXITTB;
1417 /* Check section/page access permissions.
1418 Returns the page protection flags, or zero if the access is not
1420 static inline int check_ap(CPUARMState *env, int ap, int domain_prot,
1421 int access_type, int is_user)
1425 if (domain_prot == 3) {
1426 return PAGE_READ | PAGE_WRITE;
1429 if (access_type == 1)
1432 prot_ro = PAGE_READ;
1436 if (access_type == 1)
1438 switch ((env->cp15.c1_sys >> 8) & 3) {
1440 return is_user ? 0 : PAGE_READ;
1447 return is_user ? 0 : PAGE_READ | PAGE_WRITE;
1452 return PAGE_READ | PAGE_WRITE;
1454 return PAGE_READ | PAGE_WRITE;
1455 case 4: /* Reserved. */
1458 return is_user ? 0 : prot_ro;
1462 if (!arm_feature (env, ARM_FEATURE_V6K))
1470 static uint32_t get_level1_table_address(CPUARMState *env, uint32_t address)
1474 if (address & env->cp15.c2_mask)
1475 table = env->cp15.c2_base1 & 0xffffc000;
1477 table = env->cp15.c2_base0 & env->cp15.c2_base_mask;
1479 table |= (address >> 18) & 0x3ffc;
1483 static int get_phys_addr_v5(CPUARMState *env, uint32_t address, int access_type,
1484 int is_user, uint32_t *phys_ptr, int *prot,
1485 target_ulong *page_size)
1496 /* Pagetable walk. */
1497 /* Lookup l1 descriptor. */
1498 table = get_level1_table_address(env, address);
1499 desc = ldl_phys(table);
1501 domain = (desc >> 5) & 0x0f;
1502 domain_prot = (env->cp15.c3 >> (domain * 2)) & 3;
1504 /* Section translation fault. */
1508 if (domain_prot == 0 || domain_prot == 2) {
1510 code = 9; /* Section domain fault. */
1512 code = 11; /* Page domain fault. */
1517 phys_addr = (desc & 0xfff00000) | (address & 0x000fffff);
1518 ap = (desc >> 10) & 3;
1520 *page_size = 1024 * 1024;
1522 /* Lookup l2 entry. */
1524 /* Coarse pagetable. */
1525 table = (desc & 0xfffffc00) | ((address >> 10) & 0x3fc);
1527 /* Fine pagetable. */
1528 table = (desc & 0xfffff000) | ((address >> 8) & 0xffc);
1530 desc = ldl_phys(table);
1532 case 0: /* Page translation fault. */
1535 case 1: /* 64k page. */
1536 phys_addr = (desc & 0xffff0000) | (address & 0xffff);
1537 ap = (desc >> (4 + ((address >> 13) & 6))) & 3;
1538 *page_size = 0x10000;
1540 case 2: /* 4k page. */
1541 phys_addr = (desc & 0xfffff000) | (address & 0xfff);
1542 ap = (desc >> (4 + ((address >> 13) & 6))) & 3;
1543 *page_size = 0x1000;
1545 case 3: /* 1k page. */
1547 if (arm_feature(env, ARM_FEATURE_XSCALE)) {
1548 phys_addr = (desc & 0xfffff000) | (address & 0xfff);
1550 /* Page translation fault. */
1555 phys_addr = (desc & 0xfffffc00) | (address & 0x3ff);
1557 ap = (desc >> 4) & 3;
1561 /* Never happens, but compiler isn't smart enough to tell. */
1566 *prot = check_ap(env, ap, domain_prot, access_type, is_user);
1568 /* Access permission fault. */
1572 *phys_ptr = phys_addr;
1575 return code | (domain << 4);
1578 static int get_phys_addr_v6(CPUARMState *env, uint32_t address, int access_type,
1579 int is_user, uint32_t *phys_ptr, int *prot,
1580 target_ulong *page_size)
1592 /* Pagetable walk. */
1593 /* Lookup l1 descriptor. */
1594 table = get_level1_table_address(env, address);
1595 desc = ldl_phys(table);
1598 /* Section translation fault. */
1602 } else if (type == 2 && (desc & (1 << 18))) {
1606 /* Section or page. */
1607 domain = (desc >> 5) & 0x0f;
1609 domain_prot = (env->cp15.c3 >> (domain * 2)) & 3;
1610 if (domain_prot == 0 || domain_prot == 2) {
1612 code = 9; /* Section domain fault. */
1614 code = 11; /* Page domain fault. */
1618 if (desc & (1 << 18)) {
1620 phys_addr = (desc & 0xff000000) | (address & 0x00ffffff);
1621 *page_size = 0x1000000;
1624 phys_addr = (desc & 0xfff00000) | (address & 0x000fffff);
1625 *page_size = 0x100000;
1627 ap = ((desc >> 10) & 3) | ((desc >> 13) & 4);
1628 xn = desc & (1 << 4);
1631 /* Lookup l2 entry. */
1632 table = (desc & 0xfffffc00) | ((address >> 10) & 0x3fc);
1633 desc = ldl_phys(table);
1634 ap = ((desc >> 4) & 3) | ((desc >> 7) & 4);
1636 case 0: /* Page translation fault. */
1639 case 1: /* 64k page. */
1640 phys_addr = (desc & 0xffff0000) | (address & 0xffff);
1641 xn = desc & (1 << 15);
1642 *page_size = 0x10000;
1644 case 2: case 3: /* 4k page. */
1645 phys_addr = (desc & 0xfffff000) | (address & 0xfff);
1647 *page_size = 0x1000;
1650 /* Never happens, but compiler isn't smart enough to tell. */
1655 if (domain_prot == 3) {
1656 *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
1658 if (xn && access_type == 2)
1661 /* The simplified model uses AP[0] as an access control bit. */
1662 if ((env->cp15.c1_sys & (1 << 29)) && (ap & 1) == 0) {
1663 /* Access flag fault. */
1664 code = (code == 15) ? 6 : 3;
1667 *prot = check_ap(env, ap, domain_prot, access_type, is_user);
1669 /* Access permission fault. */
1676 *phys_ptr = phys_addr;
1679 return code | (domain << 4);
1682 static int get_phys_addr_mpu(CPUARMState *env, uint32_t address, int access_type,
1683 int is_user, uint32_t *phys_ptr, int *prot)
1689 *phys_ptr = address;
1690 for (n = 7; n >= 0; n--) {
1691 base = env->cp15.c6_region[n];
1692 if ((base & 1) == 0)
1694 mask = 1 << ((base >> 1) & 0x1f);
1695 /* Keep this shift separate from the above to avoid an
1696 (undefined) << 32. */
1697 mask = (mask << 1) - 1;
1698 if (((base ^ address) & ~mask) == 0)
1704 if (access_type == 2) {
1705 mask = env->cp15.c5_insn;
1707 mask = env->cp15.c5_data;
1709 mask = (mask >> (n * 4)) & 0xf;
1716 *prot = PAGE_READ | PAGE_WRITE;
1721 *prot |= PAGE_WRITE;
1724 *prot = PAGE_READ | PAGE_WRITE;
1735 /* Bad permission. */
1742 static inline int get_phys_addr(CPUARMState *env, uint32_t address,
1743 int access_type, int is_user,
1744 uint32_t *phys_ptr, int *prot,
1745 target_ulong *page_size)
1747 /* Fast Context Switch Extension. */
1748 if (address < 0x02000000)
1749 address += env->cp15.c13_fcse;
1751 if ((env->cp15.c1_sys & 1) == 0) {
1752 /* MMU/MPU disabled. */
1753 *phys_ptr = address;
1754 *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
1755 *page_size = TARGET_PAGE_SIZE;
1757 } else if (arm_feature(env, ARM_FEATURE_MPU)) {
1758 *page_size = TARGET_PAGE_SIZE;
1759 return get_phys_addr_mpu(env, address, access_type, is_user, phys_ptr,
1761 } else if (env->cp15.c1_sys & (1 << 23)) {
1762 return get_phys_addr_v6(env, address, access_type, is_user, phys_ptr,
1765 return get_phys_addr_v5(env, address, access_type, is_user, phys_ptr,
1770 int cpu_arm_handle_mmu_fault (CPUARMState *env, target_ulong address,
1771 int access_type, int mmu_idx)
1774 target_ulong page_size;
1778 is_user = mmu_idx == MMU_USER_IDX;
1779 ret = get_phys_addr(env, address, access_type, is_user, &phys_addr, &prot,
1782 /* Map a single [sub]page. */
1783 phys_addr &= ~(uint32_t)0x3ff;
1784 address &= ~(uint32_t)0x3ff;
1785 tlb_set_page (env, address, phys_addr, prot, mmu_idx, page_size);
1789 if (access_type == 2) {
1790 env->cp15.c5_insn = ret;
1791 env->cp15.c6_insn = address;
1792 env->exception_index = EXCP_PREFETCH_ABORT;
1794 env->cp15.c5_data = ret;
1795 if (access_type == 1 && arm_feature(env, ARM_FEATURE_V6))
1796 env->cp15.c5_data |= (1 << 11);
1797 env->cp15.c6_data = address;
1798 env->exception_index = EXCP_DATA_ABORT;
1803 target_phys_addr_t cpu_get_phys_page_debug(CPUARMState *env, target_ulong addr)
1806 target_ulong page_size;
1810 ret = get_phys_addr(env, addr, 0, 0, &phys_addr, &prot, &page_size);
1818 void HELPER(set_cp15)(CPUARMState *env, uint32_t insn, uint32_t val)
1824 op1 = (insn >> 21) & 7;
1825 op2 = (insn >> 5) & 7;
1827 switch ((insn >> 16) & 0xf) {
1830 if (arm_feature(env, ARM_FEATURE_XSCALE))
1832 if (arm_feature(env, ARM_FEATURE_OMAPCP))
1834 if (arm_feature(env, ARM_FEATURE_V7)
1835 && op1 == 2 && crm == 0 && op2 == 0) {
1836 env->cp15.c0_cssel = val & 0xf;
1840 case 1: /* System configuration. */
1841 if (arm_feature(env, ARM_FEATURE_V7)
1842 && op1 == 0 && crm == 1 && op2 == 0) {
1843 env->cp15.c1_scr = val;
1846 if (arm_feature(env, ARM_FEATURE_OMAPCP))
1850 if (!arm_feature(env, ARM_FEATURE_XSCALE) || crm == 0)
1851 env->cp15.c1_sys = val;
1852 /* ??? Lots of these bits are not implemented. */
1853 /* This may enable/disable the MMU, so do a TLB flush. */
1856 case 1: /* Auxiliary control register. */
1857 if (arm_feature(env, ARM_FEATURE_XSCALE)) {
1858 env->cp15.c1_xscaleauxcr = val;
1861 /* Not implemented. */
1864 if (arm_feature(env, ARM_FEATURE_XSCALE))
1866 if (env->cp15.c1_coproc != val) {
1867 env->cp15.c1_coproc = val;
1868 /* ??? Is this safe when called from within a TB? */
1876 case 4: /* Reserved. */
1878 case 6: /* MMU Fault address / MPU base/size. */
1879 if (arm_feature(env, ARM_FEATURE_MPU)) {
1882 env->cp15.c6_region[crm] = val;
1884 if (arm_feature(env, ARM_FEATURE_OMAPCP))
1888 env->cp15.c6_data = val;
1890 case 1: /* ??? This is WFAR on armv6 */
1892 env->cp15.c6_insn = val;
1899 case 7: /* Cache control. */
1900 env->cp15.c15_i_max = 0x000;
1901 env->cp15.c15_i_min = 0xff0;
1907 if (arm_feature(env, ARM_FEATURE_OMAPCP))
1909 if (arm_feature(env, ARM_FEATURE_STRONGARM))
1910 break; /* Ignore ReadBuffer access */
1912 case 0: /* Cache lockdown. */
1914 case 0: /* L1 cache. */
1917 env->cp15.c9_data = val;
1920 env->cp15.c9_insn = val;
1926 case 1: /* L2 cache. */
1927 /* Ignore writes to L2 lockdown/auxiliary registers. */
1933 case 1: /* TCM memory region registers. */
1934 /* Not implemented. */
1940 case 12: /* Reserved. */
1945 /* ??? For debugging only. Should raise illegal instruction exception. */
1946 cpu_abort(env, "Unimplemented cp15 register write (c%d, c%d, {%d, %d})\n",
1947 (insn >> 16) & 0xf, crm, op1, op2);
1950 uint32_t HELPER(get_cp15)(CPUARMState *env, uint32_t insn)
1956 op1 = (insn >> 21) & 7;
1957 op2 = (insn >> 5) & 7;
1959 switch ((insn >> 16) & 0xf) {
1960 case 0: /* ID codes. */
1966 case 0: /* Device ID. */
1967 return env->cp15.c0_cpuid;
1968 case 1: /* Cache Type. */
1969 return env->cp15.c0_cachetype;
1970 case 2: /* TCM status. */
1972 case 3: /* TLB type register. */
1973 return 0; /* No lockable TLB entries. */
1975 /* The MPIDR was standardised in v7; prior to
1976 * this it was implemented only in the 11MPCore.
1977 * For all other pre-v7 cores it does not exist.
1979 if (arm_feature(env, ARM_FEATURE_V7) ||
1980 ARM_CPUID(env) == ARM_CPUID_ARM11MPCORE) {
1981 int mpidr = env->cpu_index;
1982 /* We don't support setting cluster ID ([8..11])
1983 * so these bits always RAZ.
1985 if (arm_feature(env, ARM_FEATURE_V7MP)) {
1987 /* Cores which are uniprocessor (non-coherent)
1988 * but still implement the MP extensions set
1989 * bit 30. (For instance, A9UP.) However we do
1990 * not currently model any of those cores.
1995 /* otherwise fall through to the unimplemented-reg case */
2000 if (!arm_feature(env, ARM_FEATURE_V6))
2002 return env->cp15.c0_c1[op2];
2004 if (!arm_feature(env, ARM_FEATURE_V6))
2006 return env->cp15.c0_c2[op2];
2007 case 3: case 4: case 5: case 6: case 7:
2013 /* These registers aren't documented on arm11 cores. However
2014 Linux looks at them anyway. */
2015 if (!arm_feature(env, ARM_FEATURE_V6))
2019 if (!arm_feature(env, ARM_FEATURE_V7))
2024 return env->cp15.c0_ccsid[env->cp15.c0_cssel];
2026 return env->cp15.c0_clid;
2032 if (op2 != 0 || crm != 0)
2034 return env->cp15.c0_cssel;
2038 case 1: /* System configuration. */
2039 if (arm_feature(env, ARM_FEATURE_V7)
2040 && op1 == 0 && crm == 1 && op2 == 0) {
2041 return env->cp15.c1_scr;
2043 if (arm_feature(env, ARM_FEATURE_OMAPCP))
2046 case 0: /* Control register. */
2047 return env->cp15.c1_sys;
2048 case 1: /* Auxiliary control register. */
2049 if (arm_feature(env, ARM_FEATURE_XSCALE))
2050 return env->cp15.c1_xscaleauxcr;
2051 if (!arm_feature(env, ARM_FEATURE_AUXCR))
2053 switch (ARM_CPUID(env)) {
2054 case ARM_CPUID_ARM1026:
2056 case ARM_CPUID_ARM1136:
2057 case ARM_CPUID_ARM1136_R2:
2058 case ARM_CPUID_ARM1176:
2060 case ARM_CPUID_ARM11MPCORE:
2062 case ARM_CPUID_CORTEXA8:
2064 case ARM_CPUID_CORTEXA9:
2065 case ARM_CPUID_CORTEXA15:
2070 case 2: /* Coprocessor access register. */
2071 if (arm_feature(env, ARM_FEATURE_XSCALE))
2073 return env->cp15.c1_coproc;
2077 case 4: /* Reserved. */
2079 case 6: /* MMU Fault address. */
2080 if (arm_feature(env, ARM_FEATURE_MPU)) {
2083 return env->cp15.c6_region[crm];
2085 if (arm_feature(env, ARM_FEATURE_OMAPCP))
2089 return env->cp15.c6_data;
2091 if (arm_feature(env, ARM_FEATURE_V6)) {
2092 /* Watchpoint Fault Adrress. */
2093 return 0; /* Not implemented. */
2095 /* Instruction Fault Adrress. */
2096 /* Arm9 doesn't have an IFAR, but implementing it anyway
2097 shouldn't do any harm. */
2098 return env->cp15.c6_insn;
2101 if (arm_feature(env, ARM_FEATURE_V6)) {
2102 /* Instruction Fault Adrress. */
2103 return env->cp15.c6_insn;
2111 case 7: /* Cache control. */
2112 /* FIXME: Should only clear Z flag if destination is r15. */
2117 case 0: /* Cache lockdown */
2119 case 0: /* L1 cache. */
2120 if (arm_feature(env, ARM_FEATURE_OMAPCP)) {
2125 return env->cp15.c9_data;
2127 return env->cp15.c9_insn;
2131 case 1: /* L2 cache */
2132 /* L2 Lockdown and Auxiliary control. */
2135 /* L2 cache lockdown (A8 only) */
2138 /* L2 cache auxiliary control (A8) or control (A15) */
2139 if (ARM_CPUID(env) == ARM_CPUID_CORTEXA15) {
2140 /* Linux wants the number of processors from here.
2141 * Might as well set the interrupt-controller bit too.
2143 return ((smp_cpus - 1) << 24) | (1 << 23);
2147 /* L2 cache extended control (A15) */
2160 case 11: /* TCM DMA control. */
2161 case 12: /* Reserved. */
2165 /* ??? For debugging only. Should raise illegal instruction exception. */
2166 cpu_abort(env, "Unimplemented cp15 register read (c%d, c%d, {%d, %d})\n",
2167 (insn >> 16) & 0xf, crm, op1, op2);
2171 void HELPER(set_r13_banked)(CPUARMState *env, uint32_t mode, uint32_t val)
2173 if ((env->uncached_cpsr & CPSR_M) == mode) {
2174 env->regs[13] = val;
2176 env->banked_r13[bank_number(env, mode)] = val;
2180 uint32_t HELPER(get_r13_banked)(CPUARMState *env, uint32_t mode)
2182 if ((env->uncached_cpsr & CPSR_M) == mode) {
2183 return env->regs[13];
2185 return env->banked_r13[bank_number(env, mode)];
2189 uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg)
2193 return xpsr_read(env) & 0xf8000000;
2195 return xpsr_read(env) & 0xf80001ff;
2197 return xpsr_read(env) & 0xff00fc00;
2199 return xpsr_read(env) & 0xff00fdff;
2201 return xpsr_read(env) & 0x000001ff;
2203 return xpsr_read(env) & 0x0700fc00;
2205 return xpsr_read(env) & 0x0700edff;
2207 return env->v7m.current_sp ? env->v7m.other_sp : env->regs[13];
2209 return env->v7m.current_sp ? env->regs[13] : env->v7m.other_sp;
2210 case 16: /* PRIMASK */
2211 return (env->uncached_cpsr & CPSR_I) != 0;
2212 case 17: /* BASEPRI */
2213 case 18: /* BASEPRI_MAX */
2214 return env->v7m.basepri;
2215 case 19: /* FAULTMASK */
2216 return (env->uncached_cpsr & CPSR_F) != 0;
2217 case 20: /* CONTROL */
2218 return env->v7m.control;
2220 /* ??? For debugging only. */
2221 cpu_abort(env, "Unimplemented system register read (%d)\n", reg);
2226 void HELPER(v7m_msr)(CPUARMState *env, uint32_t reg, uint32_t val)
2230 xpsr_write(env, val, 0xf8000000);
2233 xpsr_write(env, val, 0xf8000000);
2236 xpsr_write(env, val, 0xfe00fc00);
2239 xpsr_write(env, val, 0xfe00fc00);
2242 /* IPSR bits are readonly. */
2245 xpsr_write(env, val, 0x0600fc00);
2248 xpsr_write(env, val, 0x0600fc00);
2251 if (env->v7m.current_sp)
2252 env->v7m.other_sp = val;
2254 env->regs[13] = val;
2257 if (env->v7m.current_sp)
2258 env->regs[13] = val;
2260 env->v7m.other_sp = val;
2262 case 16: /* PRIMASK */
2264 env->uncached_cpsr |= CPSR_I;
2266 env->uncached_cpsr &= ~CPSR_I;
2268 case 17: /* BASEPRI */
2269 env->v7m.basepri = val & 0xff;
2271 case 18: /* BASEPRI_MAX */
2273 if (val != 0 && (val < env->v7m.basepri || env->v7m.basepri == 0))
2274 env->v7m.basepri = val;
2276 case 19: /* FAULTMASK */
2278 env->uncached_cpsr |= CPSR_F;
2280 env->uncached_cpsr &= ~CPSR_F;
2282 case 20: /* CONTROL */
2283 env->v7m.control = val & 3;
2284 switch_v7m_sp(env, (val & 2) != 0);
2287 /* ??? For debugging only. */
2288 cpu_abort(env, "Unimplemented system register write (%d)\n", reg);
2295 /* Note that signed overflow is undefined in C. The following routines are
2296 careful to use unsigned types where modulo arithmetic is required.
2297 Failure to do so _will_ break on newer gcc. */
2299 /* Signed saturating arithmetic. */
2301 /* Perform 16-bit signed saturating addition. */
2302 static inline uint16_t add16_sat(uint16_t a, uint16_t b)
2307 if (((res ^ a) & 0x8000) && !((a ^ b) & 0x8000)) {
2316 /* Perform 8-bit signed saturating addition. */
2317 static inline uint8_t add8_sat(uint8_t a, uint8_t b)
2322 if (((res ^ a) & 0x80) && !((a ^ b) & 0x80)) {
2331 /* Perform 16-bit signed saturating subtraction. */
2332 static inline uint16_t sub16_sat(uint16_t a, uint16_t b)
2337 if (((res ^ a) & 0x8000) && ((a ^ b) & 0x8000)) {
2346 /* Perform 8-bit signed saturating subtraction. */
2347 static inline uint8_t sub8_sat(uint8_t a, uint8_t b)
2352 if (((res ^ a) & 0x80) && ((a ^ b) & 0x80)) {
2361 #define ADD16(a, b, n) RESULT(add16_sat(a, b), n, 16);
2362 #define SUB16(a, b, n) RESULT(sub16_sat(a, b), n, 16);
2363 #define ADD8(a, b, n) RESULT(add8_sat(a, b), n, 8);
2364 #define SUB8(a, b, n) RESULT(sub8_sat(a, b), n, 8);
2367 #include "op_addsub.h"
2369 /* Unsigned saturating arithmetic. */
2370 static inline uint16_t add16_usat(uint16_t a, uint16_t b)
2379 static inline uint16_t sub16_usat(uint16_t a, uint16_t b)
2387 static inline uint8_t add8_usat(uint8_t a, uint8_t b)
2396 static inline uint8_t sub8_usat(uint8_t a, uint8_t b)
2404 #define ADD16(a, b, n) RESULT(add16_usat(a, b), n, 16);
2405 #define SUB16(a, b, n) RESULT(sub16_usat(a, b), n, 16);
2406 #define ADD8(a, b, n) RESULT(add8_usat(a, b), n, 8);
2407 #define SUB8(a, b, n) RESULT(sub8_usat(a, b), n, 8);
2410 #include "op_addsub.h"
2412 /* Signed modulo arithmetic. */
2413 #define SARITH16(a, b, n, op) do { \
2415 sum = (int32_t)(int16_t)(a) op (int32_t)(int16_t)(b); \
2416 RESULT(sum, n, 16); \
2418 ge |= 3 << (n * 2); \
2421 #define SARITH8(a, b, n, op) do { \
2423 sum = (int32_t)(int8_t)(a) op (int32_t)(int8_t)(b); \
2424 RESULT(sum, n, 8); \
2430 #define ADD16(a, b, n) SARITH16(a, b, n, +)
2431 #define SUB16(a, b, n) SARITH16(a, b, n, -)
2432 #define ADD8(a, b, n) SARITH8(a, b, n, +)
2433 #define SUB8(a, b, n) SARITH8(a, b, n, -)
2437 #include "op_addsub.h"
2439 /* Unsigned modulo arithmetic. */
2440 #define ADD16(a, b, n) do { \
2442 sum = (uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b); \
2443 RESULT(sum, n, 16); \
2444 if ((sum >> 16) == 1) \
2445 ge |= 3 << (n * 2); \
2448 #define ADD8(a, b, n) do { \
2450 sum = (uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b); \
2451 RESULT(sum, n, 8); \
2452 if ((sum >> 8) == 1) \
2456 #define SUB16(a, b, n) do { \
2458 sum = (uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b); \
2459 RESULT(sum, n, 16); \
2460 if ((sum >> 16) == 0) \
2461 ge |= 3 << (n * 2); \
2464 #define SUB8(a, b, n) do { \
2466 sum = (uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b); \
2467 RESULT(sum, n, 8); \
2468 if ((sum >> 8) == 0) \
2475 #include "op_addsub.h"
2477 /* Halved signed arithmetic. */
2478 #define ADD16(a, b, n) \
2479 RESULT(((int32_t)(int16_t)(a) + (int32_t)(int16_t)(b)) >> 1, n, 16)
2480 #define SUB16(a, b, n) \
2481 RESULT(((int32_t)(int16_t)(a) - (int32_t)(int16_t)(b)) >> 1, n, 16)
2482 #define ADD8(a, b, n) \
2483 RESULT(((int32_t)(int8_t)(a) + (int32_t)(int8_t)(b)) >> 1, n, 8)
2484 #define SUB8(a, b, n) \
2485 RESULT(((int32_t)(int8_t)(a) - (int32_t)(int8_t)(b)) >> 1, n, 8)
2488 #include "op_addsub.h"
2490 /* Halved unsigned arithmetic. */
2491 #define ADD16(a, b, n) \
2492 RESULT(((uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b)) >> 1, n, 16)
2493 #define SUB16(a, b, n) \
2494 RESULT(((uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b)) >> 1, n, 16)
2495 #define ADD8(a, b, n) \
2496 RESULT(((uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b)) >> 1, n, 8)
2497 #define SUB8(a, b, n) \
2498 RESULT(((uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b)) >> 1, n, 8)
2501 #include "op_addsub.h"
2503 static inline uint8_t do_usad(uint8_t a, uint8_t b)
2511 /* Unsigned sum of absolute byte differences. */
2512 uint32_t HELPER(usad8)(uint32_t a, uint32_t b)
2515 sum = do_usad(a, b);
2516 sum += do_usad(a >> 8, b >> 8);
2517 sum += do_usad(a >> 16, b >>16);
2518 sum += do_usad(a >> 24, b >> 24);
2522 /* For ARMv6 SEL instruction. */
2523 uint32_t HELPER(sel_flags)(uint32_t flags, uint32_t a, uint32_t b)
2536 return (a & mask) | (b & ~mask);
2539 uint32_t HELPER(logicq_cc)(uint64_t val)
2541 return (val >> 32) | (val != 0);
2544 /* VFP support. We follow the convention used for VFP instrunctions:
2545 Single precition routines have a "s" suffix, double precision a
2548 /* Convert host exception flags to vfp form. */
2549 static inline int vfp_exceptbits_from_host(int host_bits)
2551 int target_bits = 0;
2553 if (host_bits & float_flag_invalid)
2555 if (host_bits & float_flag_divbyzero)
2557 if (host_bits & float_flag_overflow)
2559 if (host_bits & (float_flag_underflow | float_flag_output_denormal))
2561 if (host_bits & float_flag_inexact)
2562 target_bits |= 0x10;
2563 if (host_bits & float_flag_input_denormal)
2564 target_bits |= 0x80;
2568 uint32_t HELPER(vfp_get_fpscr)(CPUARMState *env)
2573 fpscr = (env->vfp.xregs[ARM_VFP_FPSCR] & 0xffc8ffff)
2574 | (env->vfp.vec_len << 16)
2575 | (env->vfp.vec_stride << 20);
2576 i = get_float_exception_flags(&env->vfp.fp_status);
2577 i |= get_float_exception_flags(&env->vfp.standard_fp_status);
2578 fpscr |= vfp_exceptbits_from_host(i);
2582 uint32_t vfp_get_fpscr(CPUARMState *env)
2584 return HELPER(vfp_get_fpscr)(env);
2587 /* Convert vfp exception flags to target form. */
2588 static inline int vfp_exceptbits_to_host(int target_bits)
2592 if (target_bits & 1)
2593 host_bits |= float_flag_invalid;
2594 if (target_bits & 2)
2595 host_bits |= float_flag_divbyzero;
2596 if (target_bits & 4)
2597 host_bits |= float_flag_overflow;
2598 if (target_bits & 8)
2599 host_bits |= float_flag_underflow;
2600 if (target_bits & 0x10)
2601 host_bits |= float_flag_inexact;
2602 if (target_bits & 0x80)
2603 host_bits |= float_flag_input_denormal;
2607 void HELPER(vfp_set_fpscr)(CPUARMState *env, uint32_t val)
2612 changed = env->vfp.xregs[ARM_VFP_FPSCR];
2613 env->vfp.xregs[ARM_VFP_FPSCR] = (val & 0xffc8ffff);
2614 env->vfp.vec_len = (val >> 16) & 7;
2615 env->vfp.vec_stride = (val >> 20) & 3;
2618 if (changed & (3 << 22)) {
2619 i = (val >> 22) & 3;
2622 i = float_round_nearest_even;
2628 i = float_round_down;
2631 i = float_round_to_zero;
2634 set_float_rounding_mode(i, &env->vfp.fp_status);
2636 if (changed & (1 << 24)) {
2637 set_flush_to_zero((val & (1 << 24)) != 0, &env->vfp.fp_status);
2638 set_flush_inputs_to_zero((val & (1 << 24)) != 0, &env->vfp.fp_status);
2640 if (changed & (1 << 25))
2641 set_default_nan_mode((val & (1 << 25)) != 0, &env->vfp.fp_status);
2643 i = vfp_exceptbits_to_host(val);
2644 set_float_exception_flags(i, &env->vfp.fp_status);
2645 set_float_exception_flags(0, &env->vfp.standard_fp_status);
2648 void vfp_set_fpscr(CPUARMState *env, uint32_t val)
2650 HELPER(vfp_set_fpscr)(env, val);
2653 #define VFP_HELPER(name, p) HELPER(glue(glue(vfp_,name),p))
2655 #define VFP_BINOP(name) \
2656 float32 VFP_HELPER(name, s)(float32 a, float32 b, void *fpstp) \
2658 float_status *fpst = fpstp; \
2659 return float32_ ## name(a, b, fpst); \
2661 float64 VFP_HELPER(name, d)(float64 a, float64 b, void *fpstp) \
2663 float_status *fpst = fpstp; \
2664 return float64_ ## name(a, b, fpst); \
2672 float32 VFP_HELPER(neg, s)(float32 a)
2674 return float32_chs(a);
2677 float64 VFP_HELPER(neg, d)(float64 a)
2679 return float64_chs(a);
2682 float32 VFP_HELPER(abs, s)(float32 a)
2684 return float32_abs(a);
2687 float64 VFP_HELPER(abs, d)(float64 a)
2689 return float64_abs(a);
2692 float32 VFP_HELPER(sqrt, s)(float32 a, CPUARMState *env)
2694 return float32_sqrt(a, &env->vfp.fp_status);
2697 float64 VFP_HELPER(sqrt, d)(float64 a, CPUARMState *env)
2699 return float64_sqrt(a, &env->vfp.fp_status);
2702 /* XXX: check quiet/signaling case */
2703 #define DO_VFP_cmp(p, type) \
2704 void VFP_HELPER(cmp, p)(type a, type b, CPUARMState *env) \
2707 switch(type ## _compare_quiet(a, b, &env->vfp.fp_status)) { \
2708 case 0: flags = 0x6; break; \
2709 case -1: flags = 0x8; break; \
2710 case 1: flags = 0x2; break; \
2711 default: case 2: flags = 0x3; break; \
2713 env->vfp.xregs[ARM_VFP_FPSCR] = (flags << 28) \
2714 | (env->vfp.xregs[ARM_VFP_FPSCR] & 0x0fffffff); \
2716 void VFP_HELPER(cmpe, p)(type a, type b, CPUARMState *env) \
2719 switch(type ## _compare(a, b, &env->vfp.fp_status)) { \
2720 case 0: flags = 0x6; break; \
2721 case -1: flags = 0x8; break; \
2722 case 1: flags = 0x2; break; \
2723 default: case 2: flags = 0x3; break; \
2725 env->vfp.xregs[ARM_VFP_FPSCR] = (flags << 28) \
2726 | (env->vfp.xregs[ARM_VFP_FPSCR] & 0x0fffffff); \
2728 DO_VFP_cmp(s, float32)
2729 DO_VFP_cmp(d, float64)
2732 /* Integer to float and float to integer conversions */
2734 #define CONV_ITOF(name, fsz, sign) \
2735 float##fsz HELPER(name)(uint32_t x, void *fpstp) \
2737 float_status *fpst = fpstp; \
2738 return sign##int32_to_##float##fsz((sign##int32_t)x, fpst); \
2741 #define CONV_FTOI(name, fsz, sign, round) \
2742 uint32_t HELPER(name)(float##fsz x, void *fpstp) \
2744 float_status *fpst = fpstp; \
2745 if (float##fsz##_is_any_nan(x)) { \
2746 float_raise(float_flag_invalid, fpst); \
2749 return float##fsz##_to_##sign##int32##round(x, fpst); \
2752 #define FLOAT_CONVS(name, p, fsz, sign) \
2753 CONV_ITOF(vfp_##name##to##p, fsz, sign) \
2754 CONV_FTOI(vfp_to##name##p, fsz, sign, ) \
2755 CONV_FTOI(vfp_to##name##z##p, fsz, sign, _round_to_zero)
2757 FLOAT_CONVS(si, s, 32, )
2758 FLOAT_CONVS(si, d, 64, )
2759 FLOAT_CONVS(ui, s, 32, u)
2760 FLOAT_CONVS(ui, d, 64, u)
2766 /* floating point conversion */
2767 float64 VFP_HELPER(fcvtd, s)(float32 x, CPUARMState *env)
2769 float64 r = float32_to_float64(x, &env->vfp.fp_status);
2770 /* ARM requires that S<->D conversion of any kind of NaN generates
2771 * a quiet NaN by forcing the most significant frac bit to 1.
2773 return float64_maybe_silence_nan(r);
2776 float32 VFP_HELPER(fcvts, d)(float64 x, CPUARMState *env)
2778 float32 r = float64_to_float32(x, &env->vfp.fp_status);
2779 /* ARM requires that S<->D conversion of any kind of NaN generates
2780 * a quiet NaN by forcing the most significant frac bit to 1.
2782 return float32_maybe_silence_nan(r);
2785 /* VFP3 fixed point conversion. */
2786 #define VFP_CONV_FIX(name, p, fsz, itype, sign) \
2787 float##fsz HELPER(vfp_##name##to##p)(uint##fsz##_t x, uint32_t shift, \
2790 float_status *fpst = fpstp; \
2792 tmp = sign##int32_to_##float##fsz((itype##_t)x, fpst); \
2793 return float##fsz##_scalbn(tmp, -(int)shift, fpst); \
2795 uint##fsz##_t HELPER(vfp_to##name##p)(float##fsz x, uint32_t shift, \
2798 float_status *fpst = fpstp; \
2800 if (float##fsz##_is_any_nan(x)) { \
2801 float_raise(float_flag_invalid, fpst); \
2804 tmp = float##fsz##_scalbn(x, shift, fpst); \
2805 return float##fsz##_to_##itype##_round_to_zero(tmp, fpst); \
2808 VFP_CONV_FIX(sh, d, 64, int16, )
2809 VFP_CONV_FIX(sl, d, 64, int32, )
2810 VFP_CONV_FIX(uh, d, 64, uint16, u)
2811 VFP_CONV_FIX(ul, d, 64, uint32, u)
2812 VFP_CONV_FIX(sh, s, 32, int16, )
2813 VFP_CONV_FIX(sl, s, 32, int32, )
2814 VFP_CONV_FIX(uh, s, 32, uint16, u)
2815 VFP_CONV_FIX(ul, s, 32, uint32, u)
2818 /* Half precision conversions. */
2819 static float32 do_fcvt_f16_to_f32(uint32_t a, CPUARMState *env, float_status *s)
2821 int ieee = (env->vfp.xregs[ARM_VFP_FPSCR] & (1 << 26)) == 0;
2822 float32 r = float16_to_float32(make_float16(a), ieee, s);
2824 return float32_maybe_silence_nan(r);
2829 static uint32_t do_fcvt_f32_to_f16(float32 a, CPUARMState *env, float_status *s)
2831 int ieee = (env->vfp.xregs[ARM_VFP_FPSCR] & (1 << 26)) == 0;
2832 float16 r = float32_to_float16(a, ieee, s);
2834 r = float16_maybe_silence_nan(r);
2836 return float16_val(r);
2839 float32 HELPER(neon_fcvt_f16_to_f32)(uint32_t a, CPUARMState *env)
2841 return do_fcvt_f16_to_f32(a, env, &env->vfp.standard_fp_status);
2844 uint32_t HELPER(neon_fcvt_f32_to_f16)(float32 a, CPUARMState *env)
2846 return do_fcvt_f32_to_f16(a, env, &env->vfp.standard_fp_status);
2849 float32 HELPER(vfp_fcvt_f16_to_f32)(uint32_t a, CPUARMState *env)
2851 return do_fcvt_f16_to_f32(a, env, &env->vfp.fp_status);
2854 uint32_t HELPER(vfp_fcvt_f32_to_f16)(float32 a, CPUARMState *env)
2856 return do_fcvt_f32_to_f16(a, env, &env->vfp.fp_status);
2859 #define float32_two make_float32(0x40000000)
2860 #define float32_three make_float32(0x40400000)
2861 #define float32_one_point_five make_float32(0x3fc00000)
2863 float32 HELPER(recps_f32)(float32 a, float32 b, CPUARMState *env)
2865 float_status *s = &env->vfp.standard_fp_status;
2866 if ((float32_is_infinity(a) && float32_is_zero_or_denormal(b)) ||
2867 (float32_is_infinity(b) && float32_is_zero_or_denormal(a))) {
2868 if (!(float32_is_zero(a) || float32_is_zero(b))) {
2869 float_raise(float_flag_input_denormal, s);
2873 return float32_sub(float32_two, float32_mul(a, b, s), s);
2876 float32 HELPER(rsqrts_f32)(float32 a, float32 b, CPUARMState *env)
2878 float_status *s = &env->vfp.standard_fp_status;
2880 if ((float32_is_infinity(a) && float32_is_zero_or_denormal(b)) ||
2881 (float32_is_infinity(b) && float32_is_zero_or_denormal(a))) {
2882 if (!(float32_is_zero(a) || float32_is_zero(b))) {
2883 float_raise(float_flag_input_denormal, s);
2885 return float32_one_point_five;
2887 product = float32_mul(a, b, s);
2888 return float32_div(float32_sub(float32_three, product, s), float32_two, s);
2893 /* Constants 256 and 512 are used in some helpers; we avoid relying on
2894 * int->float conversions at run-time. */
2895 #define float64_256 make_float64(0x4070000000000000LL)
2896 #define float64_512 make_float64(0x4080000000000000LL)
2898 /* The algorithm that must be used to calculate the estimate
2899 * is specified by the ARM ARM.
2901 static float64 recip_estimate(float64 a, CPUARMState *env)
2903 /* These calculations mustn't set any fp exception flags,
2904 * so we use a local copy of the fp_status.
2906 float_status dummy_status = env->vfp.standard_fp_status;
2907 float_status *s = &dummy_status;
2908 /* q = (int)(a * 512.0) */
2909 float64 q = float64_mul(float64_512, a, s);
2910 int64_t q_int = float64_to_int64_round_to_zero(q, s);
2912 /* r = 1.0 / (((double)q + 0.5) / 512.0) */
2913 q = int64_to_float64(q_int, s);
2914 q = float64_add(q, float64_half, s);
2915 q = float64_div(q, float64_512, s);
2916 q = float64_div(float64_one, q, s);
2918 /* s = (int)(256.0 * r + 0.5) */
2919 q = float64_mul(q, float64_256, s);
2920 q = float64_add(q, float64_half, s);
2921 q_int = float64_to_int64_round_to_zero(q, s);
2923 /* return (double)s / 256.0 */
2924 return float64_div(int64_to_float64(q_int, s), float64_256, s);
2927 float32 HELPER(recpe_f32)(float32 a, CPUARMState *env)
2929 float_status *s = &env->vfp.standard_fp_status;
2931 uint32_t val32 = float32_val(a);
2934 int a_exp = (val32 & 0x7f800000) >> 23;
2935 int sign = val32 & 0x80000000;
2937 if (float32_is_any_nan(a)) {
2938 if (float32_is_signaling_nan(a)) {
2939 float_raise(float_flag_invalid, s);
2941 return float32_default_nan;
2942 } else if (float32_is_infinity(a)) {
2943 return float32_set_sign(float32_zero, float32_is_neg(a));
2944 } else if (float32_is_zero_or_denormal(a)) {
2945 if (!float32_is_zero(a)) {
2946 float_raise(float_flag_input_denormal, s);
2948 float_raise(float_flag_divbyzero, s);
2949 return float32_set_sign(float32_infinity, float32_is_neg(a));
2950 } else if (a_exp >= 253) {
2951 float_raise(float_flag_underflow, s);
2952 return float32_set_sign(float32_zero, float32_is_neg(a));
2955 f64 = make_float64((0x3feULL << 52)
2956 | ((int64_t)(val32 & 0x7fffff) << 29));
2958 result_exp = 253 - a_exp;
2960 f64 = recip_estimate(f64, env);
2963 | ((result_exp & 0xff) << 23)
2964 | ((float64_val(f64) >> 29) & 0x7fffff);
2965 return make_float32(val32);
2968 /* The algorithm that must be used to calculate the estimate
2969 * is specified by the ARM ARM.
2971 static float64 recip_sqrt_estimate(float64 a, CPUARMState *env)
2973 /* These calculations mustn't set any fp exception flags,
2974 * so we use a local copy of the fp_status.
2976 float_status dummy_status = env->vfp.standard_fp_status;
2977 float_status *s = &dummy_status;
2981 if (float64_lt(a, float64_half, s)) {
2982 /* range 0.25 <= a < 0.5 */
2984 /* a in units of 1/512 rounded down */
2985 /* q0 = (int)(a * 512.0); */
2986 q = float64_mul(float64_512, a, s);
2987 q_int = float64_to_int64_round_to_zero(q, s);
2989 /* reciprocal root r */
2990 /* r = 1.0 / sqrt(((double)q0 + 0.5) / 512.0); */
2991 q = int64_to_float64(q_int, s);
2992 q = float64_add(q, float64_half, s);
2993 q = float64_div(q, float64_512, s);
2994 q = float64_sqrt(q, s);
2995 q = float64_div(float64_one, q, s);
2997 /* range 0.5 <= a < 1.0 */
2999 /* a in units of 1/256 rounded down */
3000 /* q1 = (int)(a * 256.0); */
3001 q = float64_mul(float64_256, a, s);
3002 int64_t q_int = float64_to_int64_round_to_zero(q, s);
3004 /* reciprocal root r */
3005 /* r = 1.0 /sqrt(((double)q1 + 0.5) / 256); */
3006 q = int64_to_float64(q_int, s);
3007 q = float64_add(q, float64_half, s);
3008 q = float64_div(q, float64_256, s);
3009 q = float64_sqrt(q, s);
3010 q = float64_div(float64_one, q, s);
3012 /* r in units of 1/256 rounded to nearest */
3013 /* s = (int)(256.0 * r + 0.5); */
3015 q = float64_mul(q, float64_256,s );
3016 q = float64_add(q, float64_half, s);
3017 q_int = float64_to_int64_round_to_zero(q, s);
3019 /* return (double)s / 256.0;*/
3020 return float64_div(int64_to_float64(q_int, s), float64_256, s);
3023 float32 HELPER(rsqrte_f32)(float32 a, CPUARMState *env)
3025 float_status *s = &env->vfp.standard_fp_status;
3031 val = float32_val(a);
3033 if (float32_is_any_nan(a)) {
3034 if (float32_is_signaling_nan(a)) {
3035 float_raise(float_flag_invalid, s);
3037 return float32_default_nan;
3038 } else if (float32_is_zero_or_denormal(a)) {
3039 if (!float32_is_zero(a)) {
3040 float_raise(float_flag_input_denormal, s);
3042 float_raise(float_flag_divbyzero, s);
3043 return float32_set_sign(float32_infinity, float32_is_neg(a));
3044 } else if (float32_is_neg(a)) {
3045 float_raise(float_flag_invalid, s);
3046 return float32_default_nan;
3047 } else if (float32_is_infinity(a)) {
3048 return float32_zero;
3051 /* Normalize to a double-precision value between 0.25 and 1.0,
3052 * preserving the parity of the exponent. */
3053 if ((val & 0x800000) == 0) {
3054 f64 = make_float64(((uint64_t)(val & 0x80000000) << 32)
3056 | ((uint64_t)(val & 0x7fffff) << 29));
3058 f64 = make_float64(((uint64_t)(val & 0x80000000) << 32)
3060 | ((uint64_t)(val & 0x7fffff) << 29));
3063 result_exp = (380 - ((val & 0x7f800000) >> 23)) / 2;
3065 f64 = recip_sqrt_estimate(f64, env);
3067 val64 = float64_val(f64);
3069 val = ((result_exp & 0xff) << 23)
3070 | ((val64 >> 29) & 0x7fffff);
3071 return make_float32(val);
3074 uint32_t HELPER(recpe_u32)(uint32_t a, CPUARMState *env)
3078 if ((a & 0x80000000) == 0) {
3082 f64 = make_float64((0x3feULL << 52)
3083 | ((int64_t)(a & 0x7fffffff) << 21));
3085 f64 = recip_estimate (f64, env);
3087 return 0x80000000 | ((float64_val(f64) >> 21) & 0x7fffffff);
3090 uint32_t HELPER(rsqrte_u32)(uint32_t a, CPUARMState *env)
3094 if ((a & 0xc0000000) == 0) {
3098 if (a & 0x80000000) {
3099 f64 = make_float64((0x3feULL << 52)
3100 | ((uint64_t)(a & 0x7fffffff) << 21));
3101 } else { /* bits 31-30 == '01' */
3102 f64 = make_float64((0x3fdULL << 52)
3103 | ((uint64_t)(a & 0x3fffffff) << 22));
3106 f64 = recip_sqrt_estimate(f64, env);
3108 return 0x80000000 | ((float64_val(f64) >> 21) & 0x7fffffff);
3111 /* VFPv4 fused multiply-accumulate */
3112 float32 VFP_HELPER(muladd, s)(float32 a, float32 b, float32 c, void *fpstp)
3114 float_status *fpst = fpstp;
3115 return float32_muladd(a, b, c, 0, fpst);
3118 float64 VFP_HELPER(muladd, d)(float64 a, float64 b, float64 c, void *fpstp)
3120 float_status *fpst = fpstp;
3121 return float64_muladd(a, b, c, 0, fpst);