static int get_cpsr(QEMUFile *f, void *opaque, size_t size) { ARMCPU *cpu = opaque; CPUARMState *env = &cpu->env; uint32_t val = qemu_get_be32(f); /* Avoid mode switch when restoring CPSR */ env->uncached_cpsr = val & CPSR_M; cpsr_write(env, val, 0xffffffff); return 0; }
static int get_cpsr(QEMUFile *f, void *opaque, size_t size) { ARMCPU *cpu = opaque; CPUARMState *env = &cpu->env; uint32_t val = qemu_get_be32(f); env->aarch64 = ((val & PSTATE_nRW) == 0); if (is_a64(env)) { pstate_write(env, val); return 0; } cpsr_write(env, val, 0xffffffff, CPSRWriteRaw); return 0; }
static int get_cpsr(QEMUFile *f, void *opaque, size_t size) { ARMCPU *cpu = opaque; CPUARMState *env = &cpu->env; uint32_t val = qemu_get_be32(f); env->aarch64 = ((val & PSTATE_nRW) == 0); if (is_a64(env)) { pstate_write(env, val); return 0; } /* Avoid mode switch when restoring CPSR */ env->uncached_cpsr = val & CPSR_M; cpsr_write(env, val, 0xffffffff); return 0; }
int arm_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) { ARMCPU *cpu = ARM_CPU(cs); CPUARMState *env = &cpu->env; uint32_t tmp; tmp = ldl_p(mem_buf); /* Mask out low bit of PC to workaround gdb bugs. This will probably cause problems if we ever implement the Jazelle DBX extensions. */ if (n == 15) { tmp &= ~1; } if (n < 16) { /* Core integer register. */ env->regs[n] = tmp; return 4; } if (n < 24) { /* 16-23 */ /* FPA registers (ignored). */ if (gdb_has_xml) { return 0; } return 12; } switch (n) { case 24: /* FPA status register (ignored). */ if (gdb_has_xml) { return 0; } return 4; case 25: /* CPSR */ cpsr_write(env, tmp, 0xffffffff, CPSRWriteByGDBStub); return 4; } /* Unknown register. */ return 0; }
int cpu_load(QEMUFile *f, void *opaque, int version_id) { CPUARMState *env = (CPUARMState *)opaque; int i; uint32_t val; if (version_id != CPU_SAVE_VERSION) return -EINVAL; for (i = 0; i < 16; i++) { env->regs[i] = qemu_get_be32(f); } val = qemu_get_be32(f); /* Avoid mode switch when restoring CPSR. */ env->uncached_cpsr = val & CPSR_M; cpsr_write(env, val, 0xffffffff); env->spsr = qemu_get_be32(f); for (i = 0; i < 6; i++) { env->banked_spsr[i] = qemu_get_be32(f); env->banked_r13[i] = qemu_get_be32(f); env->banked_r14[i] = qemu_get_be32(f); } for (i = 0; i < 5; i++) { env->usr_regs[i] = qemu_get_be32(f); env->fiq_regs[i] = qemu_get_be32(f); } env->cp15.c0_cpuid = qemu_get_be32(f); env->cp15.c0_cachetype = qemu_get_be32(f); env->cp15.c0_cssel = qemu_get_be32(f); env->cp15.c1_sys = qemu_get_be32(f); env->cp15.c1_coproc = qemu_get_be32(f); env->cp15.c1_xscaleauxcr = qemu_get_be32(f); env->cp15.c1_scr = qemu_get_be32(f); env->cp15.c2_base0 = qemu_get_be32(f); env->cp15.c2_base1 = qemu_get_be32(f); env->cp15.c2_control = qemu_get_be32(f); env->cp15.c2_mask = qemu_get_be32(f); env->cp15.c2_base_mask = qemu_get_be32(f); env->cp15.c2_data = qemu_get_be32(f); env->cp15.c2_insn = qemu_get_be32(f); env->cp15.c3 = qemu_get_be32(f); env->cp15.c5_insn = qemu_get_be32(f); env->cp15.c5_data = qemu_get_be32(f); for (i = 0; i < 8; i++) { env->cp15.c6_region[i] = qemu_get_be32(f); } env->cp15.c6_insn = qemu_get_be32(f); env->cp15.c6_data = qemu_get_be32(f); env->cp15.c7_par = qemu_get_be32(f); env->cp15.c9_insn = qemu_get_be32(f); env->cp15.c9_data = qemu_get_be32(f); env->cp15.c9_pmcr = qemu_get_be32(f); env->cp15.c9_pmcnten = qemu_get_be32(f); env->cp15.c9_pmovsr = qemu_get_be32(f); env->cp15.c9_pmxevtyper = qemu_get_be32(f); env->cp15.c9_pmuserenr = qemu_get_be32(f); env->cp15.c9_pminten = qemu_get_be32(f); env->cp15.c13_fcse = qemu_get_be32(f); env->cp15.c13_context = qemu_get_be32(f); env->cp15.c13_tls1 = qemu_get_be32(f); env->cp15.c13_tls2 = qemu_get_be32(f); env->cp15.c13_tls3 = qemu_get_be32(f); env->cp15.c15_cpar = qemu_get_be32(f); env->cp15.c15_power_control = qemu_get_be32(f); env->cp15.c15_diagnostic = qemu_get_be32(f); env->cp15.c15_power_diagnostic = qemu_get_be32(f); env->features = qemu_get_be32(f); if (arm_feature(env, ARM_FEATURE_VFP)) { for (i = 0; i < 16; i++) { CPU_DoubleU u; u.l.upper = qemu_get_be32(f); u.l.lower = qemu_get_be32(f); env->vfp.regs[i] = u.d; } for (i = 0; i < 16; i++) { env->vfp.xregs[i] = qemu_get_be32(f); } /* TODO: Should use proper FPSCR access functions. */ env->vfp.vec_len = qemu_get_be32(f); env->vfp.vec_stride = qemu_get_be32(f); if (arm_feature(env, ARM_FEATURE_VFP3)) { for (i = 16; i < 32; i++) { CPU_DoubleU u; u.l.upper = qemu_get_be32(f); u.l.lower = qemu_get_be32(f); env->vfp.regs[i] = u.d; } } } if (arm_feature(env, ARM_FEATURE_IWMMXT)) { for (i = 0; i < 16; i++) { env->iwmmxt.regs[i] = qemu_get_be64(f); } for (i = 0; i < 16; i++) { env->iwmmxt.cregs[i] = qemu_get_be32(f); } } if (arm_feature(env, ARM_FEATURE_M)) { env->v7m.other_sp = qemu_get_be32(f); env->v7m.vecbase = qemu_get_be32(f); env->v7m.basepri = qemu_get_be32(f); env->v7m.control = qemu_get_be32(f); env->v7m.current_sp = qemu_get_be32(f); env->v7m.exception = qemu_get_be32(f); } if (arm_feature(env, ARM_FEATURE_THUMB2EE)) { env->teecr = qemu_get_be32(f); env->teehbr = qemu_get_be32(f); } return 0; }
int arm_set_cpu_on(uint64_t cpuid, uint64_t entry, uint64_t context_id, uint32_t target_el, bool target_aa64) { CPUState *target_cpu_state; ARMCPU *target_cpu; DPRINTF("cpu %" PRId64 " (EL %d, %s) @ 0x%" PRIx64 " with R0 = 0x%" PRIx64 "\n", cpuid, target_el, target_aa64 ? "aarch64" : "aarch32", entry, context_id); /* requested EL level need to be in the 1 to 3 range */ assert((target_el > 0) && (target_el < 4)); if (target_aa64 && (entry & 3)) { /* * if we are booting in AArch64 mode then "entry" needs to be 4 bytes * aligned. */ return QEMU_ARM_POWERCTL_INVALID_PARAM; } /* Retrieve the cpu we are powering up */ target_cpu_state = arm_get_cpu_by_id(cpuid); if (!target_cpu_state) { /* The cpu was not found */ return QEMU_ARM_POWERCTL_INVALID_PARAM; } target_cpu = ARM_CPU(target_cpu_state); if (!target_cpu->powered_off) { qemu_log_mask(LOG_GUEST_ERROR, "[ARM]%s: CPU %" PRId64 " is already on\n", __func__, cpuid); return QEMU_ARM_POWERCTL_ALREADY_ON; } /* * The newly brought CPU is requested to enter the exception level * "target_el" and be in the requested mode (AArch64 or AArch32). */ if (((target_el == 3) && !arm_feature(&target_cpu->env, ARM_FEATURE_EL3)) || ((target_el == 2) && !arm_feature(&target_cpu->env, ARM_FEATURE_EL2))) { /* * The CPU does not support requested level */ return QEMU_ARM_POWERCTL_INVALID_PARAM; } if (!target_aa64 && arm_feature(&target_cpu->env, ARM_FEATURE_AARCH64)) { /* * For now we don't support booting an AArch64 CPU in AArch32 mode * TODO: We should add this support later */ qemu_log_mask(LOG_UNIMP, "[ARM]%s: Starting AArch64 CPU %" PRId64 " in AArch32 mode is not supported yet\n", __func__, cpuid); return QEMU_ARM_POWERCTL_INVALID_PARAM; } /* Initialize the cpu we are turning on */ cpu_reset(target_cpu_state); target_cpu->powered_off = false; target_cpu_state->halted = 0; if (target_aa64) { if ((target_el < 3) && arm_feature(&target_cpu->env, ARM_FEATURE_EL3)) { /* * As target mode is AArch64, we need to set lower * exception level (the requested level 2) to AArch64 */ target_cpu->env.cp15.scr_el3 |= SCR_RW; } if ((target_el < 2) && arm_feature(&target_cpu->env, ARM_FEATURE_EL2)) { /* * As target mode is AArch64, we need to set lower * exception level (the requested level 1) to AArch64 */ target_cpu->env.cp15.hcr_el2 |= HCR_RW; } target_cpu->env.pstate = aarch64_pstate_mode(target_el, true); } else { /* We are requested to boot in AArch32 mode */ static uint32_t mode_for_el[] = { 0, ARM_CPU_MODE_SVC, ARM_CPU_MODE_HYP, ARM_CPU_MODE_SVC }; cpsr_write(&target_cpu->env, mode_for_el[target_el], CPSR_M, CPSRWriteRaw); } if (target_el == 3) { /* Processor is in secure mode */ target_cpu->env.cp15.scr_el3 &= ~SCR_NS; } else { /* Processor is not in secure mode */ target_cpu->env.cp15.scr_el3 |= SCR_NS; } /* We check if the started CPU is now at the correct level */ assert(target_el == arm_current_el(&target_cpu->env)); if (target_aa64) { target_cpu->env.xregs[0] = context_id; target_cpu->env.thumb = false; } else { target_cpu->env.regs[0] = context_id; target_cpu->env.thumb = entry & 1; entry &= 0xfffffffe; } /* Start the new CPU at the requested address */ cpu_set_pc(target_cpu_state, entry); /* We are good to go */ return QEMU_ARM_POWERCTL_RET_SUCCESS; }