]> git.proxmox.com Git - qemu.git/blame - target-s390x/cpu.c
cpu: Change qemu_init_vcpu() argument to CPUState
[qemu.git] / target-s390x / cpu.c
CommitLineData
29e4bcb2
AF
1/*
2 * QEMU S/390 CPU
3 *
1ac1a749
AF
4 * Copyright (c) 2009 Ulrich Hecht
5 * Copyright (c) 2011 Alexander Graf
29e4bcb2 6 * Copyright (c) 2012 SUSE LINUX Products GmbH
70bada03 7 * Copyright (c) 2012 IBM Corp.
29e4bcb2
AF
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>
70bada03
JF
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.
29e4bcb2
AF
24 */
25
564b863d 26#include "cpu.h"
29e4bcb2 27#include "qemu-common.h"
1de7afc9 28#include "qemu/timer.h"
70bada03 29#include "hw/hw.h"
c7396bbb 30#ifndef CONFIG_USER_ONLY
904e5fd5
VM
31#include "sysemu/arch_init.h"
32#endif
33
70bada03
JF
34#define CR0_RESET 0xE0UL
35#define CR14_RESET 0xC2000000UL;
36
904e5fd5
VM
37/* generate CPU information for cpu -? */
38void 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}
29e4bcb2 44
904e5fd5
VM
45#ifndef CONFIG_USER_ONLY
46CpuDefinitionInfoList *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
29e4bcb2 60
1ac1a749 61/* CPUClass::reset() */
29e4bcb2
AF
62static void s390_cpu_reset(CPUState *s)
63{
64 S390CPU *cpu = S390_CPU(s);
65 S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
66 CPUS390XState *env = &cpu->env;
67
1ac1a749 68 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
55e5c285 69 qemu_log("CPU Reset (CPU %d)\n", s->cpu_index);
1ac1a749
AF
70 log_cpu_state(env, 0);
71 }
72
49e15878 73 s390_del_running_cpu(cpu);
70bada03 74
29e4bcb2
AF
75 scc->parent_reset(s);
76
1ac1a749 77 memset(env, 0, offsetof(CPUS390XState, breakpoints));
70bada03
JF
78
79 /* architectured initial values for CR 0 and 14 */
80 env->cregs[0] = CR0_RESET;
81 env->cregs[14] = CR14_RESET;
82 /* set halted to 1 to make sure we can add the cpu in
259186a7 83 * s390_ipl_cpu code, where CPUState::halted is set back to 0
70bada03
JF
84 * after incrementing the cpu counter */
85#if !defined(CONFIG_USER_ONLY)
259186a7 86 s->halted = 1;
70bada03 87#endif
1ac1a749 88 tlb_flush(env, 1);
29e4bcb2
AF
89}
90
70bada03
JF
91#if !defined(CONFIG_USER_ONLY)
92static void s390_cpu_machine_reset_cb(void *opaque)
93{
94 S390CPU *cpu = opaque;
95
96 cpu_reset(CPU(cpu));
97}
98#endif
99
1f136632
AF
100static void s390_cpu_realizefn(DeviceState *dev, Error **errp)
101{
102 S390CPU *cpu = S390_CPU(dev);
103 S390CPUClass *scc = S390_CPU_GET_CLASS(dev);
104
1f136632
AF
105 cpu_reset(CPU(cpu));
106
107 scc->parent_realize(dev, errp);
108}
109
8f22e0df
AF
110static void s390_cpu_initfn(Object *obj)
111{
c05efcb1 112 CPUState *cs = CPU(obj);
8f22e0df
AF
113 S390CPU *cpu = S390_CPU(obj);
114 CPUS390XState *env = &cpu->env;
2b7ac767 115 static bool inited;
8f22e0df
AF
116 static int cpu_num = 0;
117#if !defined(CONFIG_USER_ONLY)
118 struct tm tm;
119#endif
120
c05efcb1 121 cs->env_ptr = env;
8f22e0df
AF
122 cpu_exec_init(env);
123#if !defined(CONFIG_USER_ONLY)
70bada03 124 qemu_register_reset(s390_cpu_machine_reset_cb, cpu);
8f22e0df
AF
125 qemu_get_timedate(&tm, 0);
126 env->tod_offset = TOD_UNIX_EPOCH +
127 (time2tod(mktimegm(&tm)) * 1000000000ULL);
128 env->tod_basetime = 0;
b8ba6799
AF
129 env->tod_timer = qemu_new_timer_ns(vm_clock, s390x_tod_timer, cpu);
130 env->cpu_timer = qemu_new_timer_ns(vm_clock, s390x_cpu_timer, cpu);
259186a7 131 /* set CPUState::halted state to 1 to avoid decrementing the running
70bada03
JF
132 * cpu counter in s390_cpu_reset to a negative number at
133 * initial ipl */
259186a7 134 cs->halted = 1;
8f22e0df
AF
135#endif
136 env->cpu_num = cpu_num++;
137 env->ext_index = -1;
2b7ac767
AF
138
139 if (tcg_enabled() && !inited) {
140 inited = true;
141 s390x_translate_init();
142 }
8f22e0df
AF
143}
144
d5627ce8
AF
145static void s390_cpu_finalize(Object *obj)
146{
147#if !defined(CONFIG_USER_ONLY)
148 S390CPU *cpu = S390_CPU(obj);
149
150 qemu_unregister_reset(s390_cpu_machine_reset_cb, cpu);
151#endif
152}
153
c7396bbb
AF
154static const VMStateDescription vmstate_s390_cpu = {
155 .name = "cpu",
156 .unmigratable = 1,
157};
158
29e4bcb2
AF
159static void s390_cpu_class_init(ObjectClass *oc, void *data)
160{
161 S390CPUClass *scc = S390_CPU_CLASS(oc);
162 CPUClass *cc = CPU_CLASS(scc);
c7396bbb 163 DeviceClass *dc = DEVICE_CLASS(oc);
29e4bcb2 164
1f136632
AF
165 scc->parent_realize = dc->realize;
166 dc->realize = s390_cpu_realizefn;
167
29e4bcb2
AF
168 scc->parent_reset = cc->reset;
169 cc->reset = s390_cpu_reset;
c7396bbb 170
97a8ea5a 171 cc->do_interrupt = s390_cpu_do_interrupt;
878096ee 172 cc->dump_state = s390_cpu_dump_state;
c7396bbb 173 dc->vmsd = &vmstate_s390_cpu;
29e4bcb2
AF
174}
175
176static const TypeInfo s390_cpu_type_info = {
177 .name = TYPE_S390_CPU,
178 .parent = TYPE_CPU,
179 .instance_size = sizeof(S390CPU),
8f22e0df 180 .instance_init = s390_cpu_initfn,
d5627ce8 181 .instance_finalize = s390_cpu_finalize,
29e4bcb2
AF
182 .abstract = false,
183 .class_size = sizeof(S390CPUClass),
184 .class_init = s390_cpu_class_init,
185};
186
187static void s390_cpu_register_types(void)
188{
189 type_register_static(&s390_cpu_type_info);
190}
191
192type_init(s390_cpu_register_types)