]> git.proxmox.com Git - qemu.git/blame - target-s390x/cpu.c
hw/i386/Makefile.obj: use $(PYTHON) to run .py scripts consistently
[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
f45748f1
AF
61static 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
29c6157c
CB
68#if !defined(CONFIG_USER_ONLY)
69/* S390CPUClass::load_normal() */
70static void s390_cpu_load_normal(CPUState *s)
71{
72 S390CPU *cpu = S390_CPU(s);
73 cpu->env.psw.addr = ldl_phys(4) & PSW_MASK_ESA_ADDR;
74 cpu->env.psw.mask = PSW_MASK_32 | PSW_MASK_64;
75 s390_add_running_cpu(cpu);
76}
77#endif
78
f5ae2a4f 79/* S390CPUClass::cpu_reset() */
29e4bcb2
AF
80static void s390_cpu_reset(CPUState *s)
81{
82 S390CPU *cpu = S390_CPU(s);
83 S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
84 CPUS390XState *env = &cpu->env;
85
f5ae2a4f
CB
86 s390_del_running_cpu(cpu);
87 scc->parent_reset(s);
88#if !defined(CONFIG_USER_ONLY)
89 s->halted = 1;
90#endif
91 tlb_flush(env, 1);
92}
93
94/* S390CPUClass::initial_reset() */
95static void s390_cpu_initial_reset(CPUState *s)
96{
97 S390CPU *cpu = S390_CPU(s);
98 CPUS390XState *env = &cpu->env;
99
100 s390_cpu_reset(s);
101 /* initial reset does not touch regs,fregs and aregs */
102 memset(&env->fpc, 0, offsetof(CPUS390XState, breakpoints) -
103 offsetof(CPUS390XState, fpc));
104
105 /* architectured initial values for CR 0 and 14 */
106 env->cregs[0] = CR0_RESET;
107 env->cregs[14] = CR14_RESET;
108}
109
110/* CPUClass:reset() */
111static void s390_cpu_full_reset(CPUState *s)
112{
113 S390CPU *cpu = S390_CPU(s);
114 S390CPUClass *scc = S390_CPU_GET_CLASS(cpu);
115 CPUS390XState *env = &cpu->env;
116
49e15878 117 s390_del_running_cpu(cpu);
70bada03 118
29e4bcb2
AF
119 scc->parent_reset(s);
120
1ac1a749 121 memset(env, 0, offsetof(CPUS390XState, breakpoints));
70bada03
JF
122
123 /* architectured initial values for CR 0 and 14 */
124 env->cregs[0] = CR0_RESET;
125 env->cregs[14] = CR14_RESET;
126 /* set halted to 1 to make sure we can add the cpu in
259186a7 127 * s390_ipl_cpu code, where CPUState::halted is set back to 0
70bada03
JF
128 * after incrementing the cpu counter */
129#if !defined(CONFIG_USER_ONLY)
259186a7 130 s->halted = 1;
70bada03 131#endif
1ac1a749 132 tlb_flush(env, 1);
29e4bcb2
AF
133}
134
70bada03
JF
135#if !defined(CONFIG_USER_ONLY)
136static void s390_cpu_machine_reset_cb(void *opaque)
137{
138 S390CPU *cpu = opaque;
139
140 cpu_reset(CPU(cpu));
141}
142#endif
143
1f136632
AF
144static void s390_cpu_realizefn(DeviceState *dev, Error **errp)
145{
14a10fc3 146 CPUState *cs = CPU(dev);
1f136632
AF
147 S390CPUClass *scc = S390_CPU_GET_CLASS(dev);
148
14a10fc3
AF
149 qemu_init_vcpu(cs);
150 cpu_reset(cs);
1f136632
AF
151
152 scc->parent_realize(dev, errp);
153}
154
8f22e0df
AF
155static void s390_cpu_initfn(Object *obj)
156{
c05efcb1 157 CPUState *cs = CPU(obj);
8f22e0df
AF
158 S390CPU *cpu = S390_CPU(obj);
159 CPUS390XState *env = &cpu->env;
2b7ac767 160 static bool inited;
8f22e0df
AF
161 static int cpu_num = 0;
162#if !defined(CONFIG_USER_ONLY)
163 struct tm tm;
164#endif
165
c05efcb1 166 cs->env_ptr = env;
8f22e0df
AF
167 cpu_exec_init(env);
168#if !defined(CONFIG_USER_ONLY)
70bada03 169 qemu_register_reset(s390_cpu_machine_reset_cb, cpu);
8f22e0df
AF
170 qemu_get_timedate(&tm, 0);
171 env->tod_offset = TOD_UNIX_EPOCH +
172 (time2tod(mktimegm(&tm)) * 1000000000ULL);
173 env->tod_basetime = 0;
bc72ad67
AB
174 env->tod_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_tod_timer, cpu);
175 env->cpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_cpu_timer, cpu);
259186a7 176 /* set CPUState::halted state to 1 to avoid decrementing the running
70bada03
JF
177 * cpu counter in s390_cpu_reset to a negative number at
178 * initial ipl */
259186a7 179 cs->halted = 1;
8f22e0df
AF
180#endif
181 env->cpu_num = cpu_num++;
182 env->ext_index = -1;
2b7ac767
AF
183
184 if (tcg_enabled() && !inited) {
185 inited = true;
186 s390x_translate_init();
187 }
8f22e0df
AF
188}
189
d5627ce8
AF
190static void s390_cpu_finalize(Object *obj)
191{
192#if !defined(CONFIG_USER_ONLY)
193 S390CPU *cpu = S390_CPU(obj);
194
195 qemu_unregister_reset(s390_cpu_machine_reset_cb, cpu);
196#endif
197}
198
c7396bbb
AF
199static const VMStateDescription vmstate_s390_cpu = {
200 .name = "cpu",
201 .unmigratable = 1,
202};
203
29e4bcb2
AF
204static void s390_cpu_class_init(ObjectClass *oc, void *data)
205{
206 S390CPUClass *scc = S390_CPU_CLASS(oc);
207 CPUClass *cc = CPU_CLASS(scc);
c7396bbb 208 DeviceClass *dc = DEVICE_CLASS(oc);
29e4bcb2 209
1f136632
AF
210 scc->parent_realize = dc->realize;
211 dc->realize = s390_cpu_realizefn;
212
29e4bcb2 213 scc->parent_reset = cc->reset;
29c6157c
CB
214#if !defined(CONFIG_USER_ONLY)
215 scc->load_normal = s390_cpu_load_normal;
216#endif
f5ae2a4f
CB
217 scc->cpu_reset = s390_cpu_reset;
218 scc->initial_cpu_reset = s390_cpu_initial_reset;
219 cc->reset = s390_cpu_full_reset;
97a8ea5a 220 cc->do_interrupt = s390_cpu_do_interrupt;
878096ee 221 cc->dump_state = s390_cpu_dump_state;
f45748f1 222 cc->set_pc = s390_cpu_set_pc;
5b50e790
AF
223 cc->gdb_read_register = s390_cpu_gdb_read_register;
224 cc->gdb_write_register = s390_cpu_gdb_write_register;
00b941e5
AF
225#ifndef CONFIG_USER_ONLY
226 cc->get_phys_page_debug = s390_cpu_get_phys_page_debug;
9b4f38e1
ET
227 cc->write_elf64_note = s390_cpu_write_elf64_note;
228 cc->write_elf64_qemunote = s390_cpu_write_elf64_qemunote;
00b941e5 229#endif
c7396bbb 230 dc->vmsd = &vmstate_s390_cpu;
a0e372f0 231 cc->gdb_num_core_regs = S390_NUM_REGS;
29e4bcb2
AF
232}
233
234static const TypeInfo s390_cpu_type_info = {
235 .name = TYPE_S390_CPU,
236 .parent = TYPE_CPU,
237 .instance_size = sizeof(S390CPU),
8f22e0df 238 .instance_init = s390_cpu_initfn,
d5627ce8 239 .instance_finalize = s390_cpu_finalize,
29e4bcb2
AF
240 .abstract = false,
241 .class_size = sizeof(S390CPUClass),
242 .class_init = s390_cpu_class_init,
243};
244
245static void s390_cpu_register_types(void)
246{
247 type_register_static(&s390_cpu_type_info);
248}
249
250type_init(s390_cpu_register_types)