#include "internal.h"
#include "kvm_s390x.h"
#include "sysemu/kvm.h"
-#include "qemu-common.h"
+#include "sysemu/reset.h"
#include "qemu/timer.h"
#include "qemu/error-report.h"
+#include "qemu/module.h"
#include "trace.h"
#include "qapi/visitor.h"
-#include "qapi/qapi-visit-misc.h"
+#include "qapi/qapi-types-machine.h"
#include "qapi/qapi-visit-run-state.h"
#include "sysemu/hw_accel.h"
#include "hw/qdev-properties.h"
#ifndef CONFIG_USER_ONLY
-#include "hw/hw.h"
+#include "hw/boards.h"
#include "sysemu/arch_init.h"
#include "sysemu/sysemu.h"
+#include "sysemu/tcg.h"
#endif
-#include "fpu/softfloat.h"
+#include "fpu/softfloat-helpers.h"
#define CR0_RESET 0xE0UL
#define CR14_RESET 0xC2000000UL;
static void s390_cpu_load_normal(CPUState *s)
{
S390CPU *cpu = S390_CPU(s);
- cpu->env.psw.addr = ldl_phys(s->as, 4) & PSW_MASK_ESA_ADDR;
- cpu->env.psw.mask = PSW_MASK_32 | PSW_MASK_64;
+ uint64_t spsw = ldq_phys(s->as, 0);
+
+ cpu->env.psw.mask = spsw & 0xffffffff80000000ULL;
+ /*
+ * Invert short psw indication, so SIE will report a specification
+ * exception if it was not set.
+ */
+ cpu->env.psw.mask ^= PSW_MASK_SHORTPSW;
+ cpu->env.psw.addr = spsw & 0x7fffffffULL;
+
s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
}
#endif
-/* S390CPUClass::cpu_reset() */
-static void s390_cpu_reset(CPUState *s)
+/* S390CPUClass::reset() */
+static void s390_cpu_reset(CPUState *s, cpu_reset_type type)
{
S390CPU *cpu = S390_CPU(s);
S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
CPUS390XState *env = &cpu->env;
- env->pfault_token = -1UL;
- env->bpbc = false;
scc->parent_reset(s);
cpu->env.sigp_order = 0;
s390_cpu_set_state(S390_CPU_STATE_STOPPED, cpu);
-}
-
-/* S390CPUClass::initial_reset() */
-static void s390_cpu_initial_reset(CPUState *s)
-{
- S390CPU *cpu = S390_CPU(s);
- CPUS390XState *env = &cpu->env;
-
- s390_cpu_reset(s);
- /* initial reset does not clear everything! */
- memset(&env->start_initial_reset_fields, 0,
- offsetof(CPUS390XState, end_reset_fields) -
- offsetof(CPUS390XState, start_initial_reset_fields));
-
- /* architectured initial values for CR 0 and 14 */
- env->cregs[0] = CR0_RESET;
- env->cregs[14] = CR14_RESET;
- /* architectured initial value for Breaking-Event-Address register */
- env->gbea = 1;
+ switch (type) {
+ case S390_CPU_RESET_CLEAR:
+ memset(env, 0, offsetof(CPUS390XState, start_initial_reset_fields));
+ /* fall through */
+ case S390_CPU_RESET_INITIAL:
+ /* initial reset does not clear everything! */
+ memset(&env->start_initial_reset_fields, 0,
+ offsetof(CPUS390XState, start_normal_reset_fields) -
+ offsetof(CPUS390XState, start_initial_reset_fields));
- env->pfault_token = -1UL;
+ /* architectured initial value for Breaking-Event-Address register */
+ env->gbea = 1;
- /* tininess for underflow is detected before rounding */
- set_float_detect_tininess(float_tininess_before_rounding,
- &env->fpu_status);
-
- /* Reset state inside the kernel that we cannot access yet from QEMU. */
- if (kvm_enabled()) {
- kvm_s390_reset_vcpu(cpu);
- }
-}
-
-/* CPUClass:reset() */
-static void s390_cpu_full_reset(CPUState *s)
-{
- S390CPU *cpu = S390_CPU(s);
- S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
- CPUS390XState *env = &cpu->env;
-
- scc->parent_reset(s);
- cpu->env.sigp_order = 0;
- s390_cpu_set_state(S390_CPU_STATE_STOPPED, cpu);
-
- memset(env, 0, offsetof(CPUS390XState, end_reset_fields));
-
- /* architectured initial values for CR 0 and 14 */
- env->cregs[0] = CR0_RESET;
- env->cregs[14] = CR14_RESET;
+ /* architectured initial values for CR 0 and 14 */
+ env->cregs[0] = CR0_RESET;
+ env->cregs[14] = CR14_RESET;
#if defined(CONFIG_USER_ONLY)
- /* user mode should always be allowed to use the full FPU */
- env->cregs[0] |= CR0_AFP;
+ /* user mode should always be allowed to use the full FPU */
+ env->cregs[0] |= CR0_AFP;
+ if (s390_has_feat(S390_FEAT_VECTOR)) {
+ env->cregs[0] |= CR0_VECTOR;
+ }
#endif
- /* architectured initial value for Breaking-Event-Address register */
- env->gbea = 1;
-
- env->pfault_token = -1UL;
-
- /* tininess for underflow is detected before rounding */
- set_float_detect_tininess(float_tininess_before_rounding,
- &env->fpu_status);
+ /* tininess for underflow is detected before rounding */
+ set_float_detect_tininess(float_tininess_before_rounding,
+ &env->fpu_status);
+ /* fall through */
+ case S390_CPU_RESET_NORMAL:
+ env->psw.mask &= ~PSW_MASK_RI;
+ memset(&env->start_normal_reset_fields, 0,
+ offsetof(CPUS390XState, end_reset_fields) -
+ offsetof(CPUS390XState, start_normal_reset_fields));
+
+ env->pfault_token = -1UL;
+ env->bpbc = false;
+ break;
+ default:
+ g_assert_not_reached();
+ }
/* Reset state inside the kernel that we cannot access yet from QEMU. */
- if (kvm_enabled()) {
+ if (kvm_enabled() && type != S390_CPU_RESET_NORMAL) {
kvm_s390_reset_vcpu(cpu);
}
}
}
#if !defined(CONFIG_USER_ONLY)
+ MachineState *ms = MACHINE(qdev_get_machine());
+ unsigned int max_cpus = ms->smp.max_cpus;
if (cpu->env.core_id >= max_cpus) {
error_setg(&err, "Unable to add CPU with core-id: %" PRIu32
", maximum core-id: %d", cpu->env.core_id,
{
CPUState *cs = CPU(obj);
S390CPU *cpu = S390_CPU(obj);
- CPUS390XState *env = &cpu->env;
- cs->env_ptr = env;
+ cpu_set_cpustate_pointers(cpu);
cs->halted = 1;
cs->exception_index = EXCP_HLT;
object_property_add(obj, "crash-information", "GuestPanicInformation",
s390_cpu_get_crash_info_qom, NULL, NULL, NULL, NULL);
s390_cpu_model_register_props(obj);
#if !defined(CONFIG_USER_ONLY)
- env->tod_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_tod_timer, cpu);
- env->cpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_cpu_timer, cpu);
+ cpu->env.tod_timer =
+ timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_tod_timer, cpu);
+ cpu->env.cpu_timer =
+ timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_cpu_timer, cpu);
s390_cpu_set_state(S390_CPU_STATE_STOPPED, cpu);
#endif
}
DEFINE_PROP_END_OF_LIST()
};
+static void s390_cpu_reset_full(CPUState *s)
+{
+ return s390_cpu_reset(s, S390_CPU_RESET_CLEAR);
+}
+
static void s390_cpu_class_init(ObjectClass *oc, void *data)
{
S390CPUClass *scc = S390_CPU_CLASS(oc);
#if !defined(CONFIG_USER_ONLY)
scc->load_normal = s390_cpu_load_normal;
#endif
- scc->cpu_reset = s390_cpu_reset;
- scc->initial_cpu_reset = s390_cpu_initial_reset;
- cc->reset = s390_cpu_full_reset;
+ scc->reset = s390_cpu_reset;
+ cc->reset = s390_cpu_reset_full;
cc->class_by_name = s390_cpu_class_by_name,
cc->has_work = s390_cpu_has_work;
#ifdef CONFIG_TCG
cc->set_pc = s390_cpu_set_pc;
cc->gdb_read_register = s390_cpu_gdb_read_register;
cc->gdb_write_register = s390_cpu_gdb_write_register;
-#ifdef CONFIG_USER_ONLY
- cc->handle_mmu_fault = s390_cpu_handle_mmu_fault;
-#else
+#ifndef CONFIG_USER_ONLY
cc->get_phys_page_debug = s390_cpu_get_phys_page_debug;
cc->vmsd = &vmstate_s390_cpu;
cc->write_elf64_note = s390_cpu_write_elf64_note;
cc->disas_set_info = s390_cpu_disas_set_info;
#ifdef CONFIG_TCG
cc->tcg_initialize = s390x_translate_init;
+ cc->tlb_fill = s390_cpu_tlb_fill;
#endif
cc->gdb_num_core_regs = S390_NUM_CORE_REGS;