Statistics
| Branch: | Revision:

root / target-s390x / cpu.c @ 5b50e790

History | View | Annotate | Download (5.2 kB)

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

    
26
#include "cpu.h"
27
#include "qemu-common.h"
28
#include "qemu/timer.h"
29
#include "hw/hw.h"
30
#ifndef CONFIG_USER_ONLY
31
#include "sysemu/arch_init.h"
32
#endif
33

    
34
#define CR0_RESET       0xE0UL
35
#define CR14_RESET      0xC2000000UL;
36

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

    
45
#ifndef CONFIG_USER_ONLY
46
CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
47
{
48
    CpuDefinitionInfoList *entry;
49
    CpuDefinitionInfo *info;
50

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

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

    
57
    return entry;
58
}
59
#endif
60

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

    
65
    cpu->env.psw.addr = value;
66
}
67

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

    
75
    s390_del_running_cpu(cpu);
76

    
77
    scc->parent_reset(s);
78

    
79
    memset(env, 0, offsetof(CPUS390XState, breakpoints));
80

    
81
    /* architectured initial values for CR 0 and 14 */
82
    env->cregs[0] = CR0_RESET;
83
    env->cregs[14] = CR14_RESET;
84
    /* 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
86
     * after incrementing the cpu counter */
87
#if !defined(CONFIG_USER_ONLY)
88
    s->halted = 1;
89
#endif
90
    tlb_flush(env, 1);
91
}
92

    
93
#if !defined(CONFIG_USER_ONLY)
94
static void s390_cpu_machine_reset_cb(void *opaque)
95
{
96
    S390CPU *cpu = opaque;
97

    
98
    cpu_reset(CPU(cpu));
99
}
100
#endif
101

    
102
static void s390_cpu_realizefn(DeviceState *dev, Error **errp)
103
{
104
    S390CPU *cpu = S390_CPU(dev);
105
    S390CPUClass *scc = S390_CPU_GET_CLASS(dev);
106

    
107
    cpu_reset(CPU(cpu));
108

    
109
    scc->parent_realize(dev, errp);
110
}
111

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

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

    
141
    if (tcg_enabled() && !inited) {
142
        inited = true;
143
        s390x_translate_init();
144
    }
145
}
146

    
147
static void s390_cpu_finalize(Object *obj)
148
{
149
#if !defined(CONFIG_USER_ONLY)
150
    S390CPU *cpu = S390_CPU(obj);
151

    
152
    qemu_unregister_reset(s390_cpu_machine_reset_cb, cpu);
153
#endif
154
}
155

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

    
161
static void s390_cpu_class_init(ObjectClass *oc, void *data)
162
{
163
    S390CPUClass *scc = S390_CPU_CLASS(oc);
164
    CPUClass *cc = CPU_CLASS(scc);
165
    DeviceClass *dc = DEVICE_CLASS(oc);
166

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

    
170
    scc->parent_reset = cc->reset;
171
    cc->reset = s390_cpu_reset;
172

    
173
    cc->do_interrupt = s390_cpu_do_interrupt;
174
    cc->dump_state = s390_cpu_dump_state;
175
    cc->set_pc = s390_cpu_set_pc;
176
    cc->gdb_read_register = s390_cpu_gdb_read_register;
177
    cc->gdb_write_register = s390_cpu_gdb_write_register;
178
#ifndef CONFIG_USER_ONLY
179
    cc->get_phys_page_debug = s390_cpu_get_phys_page_debug;
180
#endif
181
    dc->vmsd = &vmstate_s390_cpu;
182
    cc->gdb_num_core_regs = S390_NUM_REGS;
183
}
184

    
185
static const TypeInfo s390_cpu_type_info = {
186
    .name = TYPE_S390_CPU,
187
    .parent = TYPE_CPU,
188
    .instance_size = sizeof(S390CPU),
189
    .instance_init = s390_cpu_initfn,
190
    .instance_finalize = s390_cpu_finalize,
191
    .abstract = false,
192
    .class_size = sizeof(S390CPUClass),
193
    .class_init = s390_cpu_class_init,
194
};
195

    
196
static void s390_cpu_register_types(void)
197
{
198
    type_register_static(&s390_cpu_type_info);
199
}
200

    
201
type_init(s390_cpu_register_types)