#include "qemu/error-report.h"
#include "trace.h"
#include "qapi/visitor.h"
+#include "qapi/qapi-visit-misc.h"
+#include "qapi/qapi-visit-run-state.h"
+#include "sysemu/hw_accel.h"
#include "exec/exec-all.h"
#include "hw/qdev-properties.h"
#ifndef CONFIG_USER_ONLY
#include "hw/hw.h"
#include "sysemu/arch_init.h"
#include "sysemu/sysemu.h"
-#include "hw/s390x/sclp.h"
#endif
+#include "fpu/softfloat.h"
#define CR0_RESET 0xE0UL
#define CR14_RESET 0xC2000000UL;
static bool s390_cpu_has_work(CPUState *cs)
{
S390CPU *cpu = S390_CPU(cs);
- CPUS390XState *env = &cpu->env;
- return (cs->interrupt_request & CPU_INTERRUPT_HARD) &&
- (env->psw.mask & PSW_MASK_EXT);
+ /* STOPPED cpus can never wake up */
+ if (s390_cpu_get_state(cpu) != S390_CPU_STATE_LOAD &&
+ s390_cpu_get_state(cpu) != S390_CPU_STATE_OPERATING) {
+ return false;
+ }
+
+ if (!(cs->interrupt_request & CPU_INTERRUPT_HARD)) {
+ return false;
+ }
+
+ return s390_cpu_has_int(cpu);
}
#if !defined(CONFIG_USER_ONLY)
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;
- s390_cpu_set_state(CPU_STATE_OPERATING, cpu);
+ s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
}
#endif
CPUS390XState *env = &cpu->env;
env->pfault_token = -1UL;
+ env->bpbc = false;
scc->parent_reset(s);
cpu->env.sigp_order = 0;
- s390_cpu_set_state(CPU_STATE_STOPPED, cpu);
+ s390_cpu_set_state(S390_CPU_STATE_STOPPED, cpu);
}
/* S390CPUClass::initial_reset() */
{
S390CPU *cpu = S390_CPU(s);
CPUS390XState *env = &cpu->env;
- int i;
s390_cpu_reset(s);
/* initial reset does not clear everything! */
env->gbea = 1;
env->pfault_token = -1UL;
- env->ext_index = -1;
- for (i = 0; i < ARRAY_SIZE(env->io_index); i++) {
- env->io_index[i] = -1;
- }
/* tininess for underflow is detected before rounding */
set_float_detect_tininess(float_tininess_before_rounding,
S390CPU *cpu = S390_CPU(s);
S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
CPUS390XState *env = &cpu->env;
- int i;
scc->parent_reset(s);
cpu->env.sigp_order = 0;
- s390_cpu_set_state(CPU_STATE_STOPPED, cpu);
+ s390_cpu_set_state(S390_CPU_STATE_STOPPED, cpu);
memset(env, 0, offsetof(CPUS390XState, end_reset_fields));
env->gbea = 1;
env->pfault_token = -1UL;
- env->ext_index = -1;
- for (i = 0; i < ARRAY_SIZE(env->io_index); i++) {
- env->io_index[i] = -1;
- }
/* tininess for underflow is detected before rounding */
set_float_detect_tininess(float_tininess_before_rounding,
{
CPUState *cs = CPU(dev);
S390CPUClass *scc = S390_CPU_GET_CLASS(dev);
+#if !defined(CONFIG_USER_ONLY)
S390CPU *cpu = S390_CPU(dev);
- CPUS390XState *env = &cpu->env;
+#endif
Error *err = NULL;
/* the model has to be realized before qemu_init_vcpu() due to kvm */
max_cpus - 1);
goto out;
}
-#else
- /* implicitly set for linux-user only */
- cpu->env.core_id = scc->next_core_id;
-#endif
if (cpu_exists(cpu->env.core_id)) {
error_setg(&err, "Unable to add CPU with core-id: %" PRIu32
", it already exists", cpu->env.core_id);
goto out;
}
- if (cpu->env.core_id != scc->next_core_id) {
- error_setg(&err, "Unable to add CPU with core-id: %" PRIu32
- ", the next available core-id is %" PRIu32, cpu->env.core_id,
- scc->next_core_id);
- goto out;
- }
/* sync cs->cpu_index and env->core_id. The latter is needed for TCG. */
- cs->cpu_index = env->core_id;
+ cs->cpu_index = cpu->env.core_id;
+#endif
+
cpu_exec_realizefn(cs, &err);
if (err != NULL) {
goto out;
}
- scc->next_core_id++;
#if !defined(CONFIG_USER_ONLY)
qemu_register_reset(s390_cpu_machine_reset_cb, cpu);
#endif
scc->parent_realize(dev, &err);
+out:
+ error_propagate(errp, err);
+}
+
+static GuestPanicInformation *s390_cpu_get_crash_info(CPUState *cs)
+{
+ GuestPanicInformation *panic_info;
+ S390CPU *cpu = S390_CPU(cs);
+
+ cpu_synchronize_state(cs);
+ panic_info = g_malloc0(sizeof(GuestPanicInformation));
+ panic_info->type = GUEST_PANIC_INFORMATION_TYPE_S390;
#if !defined(CONFIG_USER_ONLY)
- if (dev->hotplugged) {
- raise_irq_cpu_hotplug();
- }
+ panic_info->u.s390.core = cpu->env.core_id;
+#else
+ panic_info->u.s390.core = 0; /* sane default for non system emulation */
#endif
+ panic_info->u.s390.psw_mask = cpu->env.psw.mask;
+ panic_info->u.s390.psw_addr = cpu->env.psw.addr;
+ panic_info->u.s390.reason = cpu->env.crash_reason;
-out:
- error_propagate(errp, err);
+ return panic_info;
+}
+
+static void s390_cpu_get_crash_info_qom(Object *obj, Visitor *v,
+ const char *name, void *opaque,
+ Error **errp)
+{
+ CPUState *cs = CPU(obj);
+ GuestPanicInformation *panic_info;
+
+ if (!cs->crash_occurred) {
+ error_setg(errp, "No crash occurred");
+ return;
+ }
+
+ panic_info = s390_cpu_get_crash_info(cs);
+
+ visit_type_GuestPanicInformation(v, "crash-information", &panic_info,
+ errp);
+ qapi_free_GuestPanicInformation(panic_info);
}
static void s390_cpu_initfn(Object *obj)
CPUState *cs = CPU(obj);
S390CPU *cpu = S390_CPU(obj);
CPUS390XState *env = &cpu->env;
- static bool inited;
#if !defined(CONFIG_USER_ONLY)
struct tm tm;
#endif
cs->env_ptr = env;
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)
qemu_get_timedate(&tm, 0);
env->tod_basetime = 0;
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);
- s390_cpu_set_state(CPU_STATE_STOPPED, cpu);
+ s390_cpu_set_state(S390_CPU_STATE_STOPPED, cpu);
#endif
-
- if (tcg_enabled() && !inited) {
- inited = true;
- s390x_translate_init();
- }
}
static void s390_cpu_finalize(Object *obj)
CPU_FOREACH(cpu) {
uint8_t state = S390_CPU(cpu)->env.cpu_state;
- if (state == CPU_STATE_OPERATING ||
- state == CPU_STATE_LOAD) {
+ if (state == S390_CPU_STATE_OPERATING ||
+ state == S390_CPU_STATE_LOAD) {
if (!disabled_wait(cpu)) {
nr_running++;
}
trace_cpu_set_state(CPU(cpu)->cpu_index, cpu_state);
switch (cpu_state) {
- case CPU_STATE_STOPPED:
- case CPU_STATE_CHECK_STOP:
+ case S390_CPU_STATE_STOPPED:
+ case S390_CPU_STATE_CHECK_STOP:
/* halt the cpu for common infrastructure */
s390_cpu_halt(cpu);
break;
- case CPU_STATE_OPERATING:
- case CPU_STATE_LOAD:
- /* unhalt the cpu for common infrastructure */
- s390_cpu_unhalt(cpu);
+ case S390_CPU_STATE_OPERATING:
+ case S390_CPU_STATE_LOAD:
+ /*
+ * Starting a CPU with a PSW WAIT bit set:
+ * KVM: handles this internally and triggers another WAIT exit.
+ * TCG: will actually try to continue to run. Don't unhalt, will
+ * be done when the CPU actually has work (an interrupt).
+ */
+ if (!tcg_enabled() || !(cpu->env.psw.mask & PSW_MASK_WAIT)) {
+ s390_cpu_unhalt(cpu);
+ }
break;
default:
error_report("Requested CPU state is not a valid S390 CPU state: %u",
int s390_get_clock(uint8_t *tod_high, uint64_t *tod_low)
{
+ int r = 0;
+
if (kvm_enabled()) {
- return kvm_s390_get_clock(tod_high, tod_low);
+ r = kvm_s390_get_clock_ext(tod_high, tod_low);
+ if (r == -ENXIO) {
+ return kvm_s390_get_clock(tod_high, tod_low);
+ }
+ } else {
+ /* Fixme TCG */
+ *tod_high = 0;
+ *tod_low = 0;
}
- /* Fixme TCG */
- *tod_high = 0;
- *tod_low = 0;
- return 0;
+
+ return r;
}
int s390_set_clock(uint8_t *tod_high, uint64_t *tod_low)
{
+ int r = 0;
+
if (kvm_enabled()) {
- return kvm_s390_set_clock(tod_high, tod_low);
+ r = kvm_s390_set_clock_ext(tod_high, tod_low);
+ if (r == -ENXIO) {
+ return kvm_s390_set_clock(tod_high, tod_low);
+ }
}
/* Fixme TCG */
- return 0;
+ return r;
}
int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit)
}
}
-int s390_cpu_restart(S390CPU *cpu)
-{
- if (kvm_enabled()) {
- return kvm_s390_cpu_restart(cpu);
- }
- return -ENOSYS;
-}
-
-int s390_get_memslot_count(void)
-{
- if (kvm_enabled()) {
- return kvm_s390_get_memslot_count();
- } else {
- return MAX_AVAIL_SLOTS;
- }
-}
-
int s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch_id,
int vq, bool assign)
{
}
static Property s390x_cpu_properties[] = {
+#if !defined(CONFIG_USER_ONLY)
DEFINE_PROP_UINT32("core-id", S390CPU, env.core_id, 0),
+#endif
DEFINE_PROP_END_OF_LIST()
};
CPUClass *cc = CPU_CLASS(scc);
DeviceClass *dc = DEVICE_CLASS(oc);
- scc->parent_realize = dc->realize;
- dc->realize = s390_cpu_realizefn;
+ device_class_set_parent_realize(dc, s390_cpu_realizefn,
+ &scc->parent_realize);
dc->props = s390x_cpu_properties;
dc->user_creatable = true;
cc->do_interrupt = s390_cpu_do_interrupt;
#endif
cc->dump_state = s390_cpu_dump_state;
+ cc->get_crash_info = s390_cpu_get_crash_info;
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;
#endif
#endif
cc->disas_set_info = s390_cpu_disas_set_info;
+#ifdef CONFIG_TCG
+ cc->tcg_initialize = s390x_translate_init;
+#endif
cc->gdb_num_core_regs = S390_NUM_CORE_REGS;
cc->gdb_core_xml_file = "s390x-core64.xml";