cpu.c 5.3 KB
Newer Older
A
Andreas Färber 已提交
1 2 3
/*
 * QEMU S/390 CPU
 *
4 5
 * Copyright (c) 2009 Ulrich Hecht
 * Copyright (c) 2011 Alexander Graf
A
Andreas Färber 已提交
6
 * Copyright (c) 2012 SUSE LINUX Products GmbH
J
Jens Freimann 已提交
7
 * Copyright (c) 2012 IBM Corp.
A
Andreas Färber 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see
 * <http://www.gnu.org/licenses/lgpl-2.1.html>
J
Jens Freimann 已提交
22 23
 * Contributions after 2012-12-11 are licensed under the terms of the
 * GNU GPL, version 2 or (at your option) any later version.
A
Andreas Färber 已提交
24 25
 */

26
#include "cpu.h"
A
Andreas Färber 已提交
27
#include "qemu-common.h"
28
#include "qemu/timer.h"
J
Jens Freimann 已提交
29
#include "hw/hw.h"
30
#ifndef CONFIG_USER_ONLY
31 32 33
#include "sysemu/arch_init.h"
#endif

J
Jens Freimann 已提交
34 35 36
#define CR0_RESET       0xE0UL
#define CR14_RESET      0xC2000000UL;

37 38 39 40 41 42 43
/* generate CPU information for cpu -? */
void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf)
{
#ifdef CONFIG_KVM
    (*cpu_fprintf)(f, "s390 %16s\n", "host");
#endif
}
A
Andreas Färber 已提交
44

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#ifndef CONFIG_USER_ONLY
CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
{
    CpuDefinitionInfoList *entry;
    CpuDefinitionInfo *info;

    info = g_malloc0(sizeof(*info));
    info->name = g_strdup("host");

    entry = g_malloc0(sizeof(*entry));
    entry->value = info;

    return entry;
}
#endif
A
Andreas Färber 已提交
60

61 62 63 64 65 66 67
static void s390_cpu_set_pc(CPUState *cs, vaddr value)
{
    S390CPU *cpu = S390_CPU(cs);

    cpu->env.psw.addr = value;
}

68
/* CPUClass::reset() */
A
Andreas Färber 已提交
69 70 71 72 73 74
static void s390_cpu_reset(CPUState *s)
{
    S390CPU *cpu = S390_CPU(s);
    S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
    CPUS390XState *env = &cpu->env;

75
    s390_del_running_cpu(cpu);
J
Jens Freimann 已提交
76

A
Andreas Färber 已提交
77 78
    scc->parent_reset(s);

79
    memset(env, 0, offsetof(CPUS390XState, breakpoints));
J
Jens Freimann 已提交
80 81 82 83 84

    /* architectured initial values for CR 0 and 14 */
    env->cregs[0] = CR0_RESET;
    env->cregs[14] = CR14_RESET;
    /* set halted to 1 to make sure we can add the cpu in
85
     * s390_ipl_cpu code, where CPUState::halted is set back to 0
J
Jens Freimann 已提交
86 87
     * after incrementing the cpu counter */
#if !defined(CONFIG_USER_ONLY)
88
    s->halted = 1;
J
Jens Freimann 已提交
89
#endif
90
    tlb_flush(env, 1);
A
Andreas Färber 已提交
91 92
}

J
Jens Freimann 已提交
93 94 95 96 97 98 99 100 101
#if !defined(CONFIG_USER_ONLY)
static void s390_cpu_machine_reset_cb(void *opaque)
{
    S390CPU *cpu = opaque;

    cpu_reset(CPU(cpu));
}
#endif

102 103
static void s390_cpu_realizefn(DeviceState *dev, Error **errp)
{
104
    CPUState *cs = CPU(dev);
105 106
    S390CPUClass *scc = S390_CPU_GET_CLASS(dev);

107 108
    qemu_init_vcpu(cs);
    cpu_reset(cs);
109 110 111 112

    scc->parent_realize(dev, errp);
}

A
Andreas Färber 已提交
113 114
static void s390_cpu_initfn(Object *obj)
{
115
    CPUState *cs = CPU(obj);
A
Andreas Färber 已提交
116 117
    S390CPU *cpu = S390_CPU(obj);
    CPUS390XState *env = &cpu->env;
118
    static bool inited;
A
Andreas Färber 已提交
119 120 121 122 123
    static int cpu_num = 0;
#if !defined(CONFIG_USER_ONLY)
    struct tm tm;
#endif

124
    cs->env_ptr = env;
A
Andreas Färber 已提交
125 126
    cpu_exec_init(env);
#if !defined(CONFIG_USER_ONLY)
J
Jens Freimann 已提交
127
    qemu_register_reset(s390_cpu_machine_reset_cb, cpu);
A
Andreas Färber 已提交
128 129 130 131
    qemu_get_timedate(&tm, 0);
    env->tod_offset = TOD_UNIX_EPOCH +
                      (time2tod(mktimegm(&tm)) * 1000000000ULL);
    env->tod_basetime = 0;
132 133
    env->tod_timer = qemu_new_timer_ns(vm_clock, s390x_tod_timer, cpu);
    env->cpu_timer = qemu_new_timer_ns(vm_clock, s390x_cpu_timer, cpu);
134
    /* set CPUState::halted state to 1 to avoid decrementing the running
J
Jens Freimann 已提交
135 136
     * cpu counter in s390_cpu_reset to a negative number at
     * initial ipl */
137
    cs->halted = 1;
A
Andreas Färber 已提交
138 139 140
#endif
    env->cpu_num = cpu_num++;
    env->ext_index = -1;
141 142 143 144 145

    if (tcg_enabled() && !inited) {
        inited = true;
        s390x_translate_init();
    }
A
Andreas Färber 已提交
146 147
}

148 149 150 151 152 153 154 155 156
static void s390_cpu_finalize(Object *obj)
{
#if !defined(CONFIG_USER_ONLY)
    S390CPU *cpu = S390_CPU(obj);

    qemu_unregister_reset(s390_cpu_machine_reset_cb, cpu);
#endif
}

157 158 159 160 161
static const VMStateDescription vmstate_s390_cpu = {
    .name = "cpu",
    .unmigratable = 1,
};

A
Andreas Färber 已提交
162 163 164 165
static void s390_cpu_class_init(ObjectClass *oc, void *data)
{
    S390CPUClass *scc = S390_CPU_CLASS(oc);
    CPUClass *cc = CPU_CLASS(scc);
166
    DeviceClass *dc = DEVICE_CLASS(oc);
A
Andreas Färber 已提交
167

168 169 170
    scc->parent_realize = dc->realize;
    dc->realize = s390_cpu_realizefn;

A
Andreas Färber 已提交
171 172
    scc->parent_reset = cc->reset;
    cc->reset = s390_cpu_reset;
173

174
    cc->do_interrupt = s390_cpu_do_interrupt;
175
    cc->dump_state = s390_cpu_dump_state;
176
    cc->set_pc = s390_cpu_set_pc;
177 178
    cc->gdb_read_register = s390_cpu_gdb_read_register;
    cc->gdb_write_register = s390_cpu_gdb_write_register;
179 180 181
#ifndef CONFIG_USER_ONLY
    cc->get_phys_page_debug = s390_cpu_get_phys_page_debug;
#endif
182
    dc->vmsd = &vmstate_s390_cpu;
183
    cc->gdb_num_core_regs = S390_NUM_REGS;
A
Andreas Färber 已提交
184 185 186 187 188 189
}

static const TypeInfo s390_cpu_type_info = {
    .name = TYPE_S390_CPU,
    .parent = TYPE_CPU,
    .instance_size = sizeof(S390CPU),
A
Andreas Färber 已提交
190
    .instance_init = s390_cpu_initfn,
191
    .instance_finalize = s390_cpu_finalize,
A
Andreas Färber 已提交
192 193 194 195 196 197 198 199 200 201 202
    .abstract = false,
    .class_size = sizeof(S390CPUClass),
    .class_init = s390_cpu_class_init,
};

static void s390_cpu_register_types(void)
{
    type_register_static(&s390_cpu_type_info);
}

type_init(s390_cpu_register_types)