root / target-s390x / cpu.c @ 5b50e790
History | View | Annotate | Download (5.2 kB)
1 | 29e4bcb2 | Andreas Färber | /*
|
---|---|---|---|
2 | 29e4bcb2 | Andreas Färber | * QEMU S/390 CPU
|
3 | 29e4bcb2 | Andreas Färber | *
|
4 | 1ac1a749 | Andreas Färber | * Copyright (c) 2009 Ulrich Hecht
|
5 | 1ac1a749 | Andreas Färber | * Copyright (c) 2011 Alexander Graf
|
6 | 29e4bcb2 | Andreas Färber | * Copyright (c) 2012 SUSE LINUX Products GmbH
|
7 | 70bada03 | Jens Freimann | * Copyright (c) 2012 IBM Corp.
|
8 | 29e4bcb2 | Andreas Färber | *
|
9 | 29e4bcb2 | Andreas Färber | * This library is free software; you can redistribute it and/or
|
10 | 29e4bcb2 | Andreas Färber | * modify it under the terms of the GNU Lesser General Public
|
11 | 29e4bcb2 | Andreas Färber | * License as published by the Free Software Foundation; either
|
12 | 29e4bcb2 | Andreas Färber | * version 2.1 of the License, or (at your option) any later version.
|
13 | 29e4bcb2 | Andreas Färber | *
|
14 | 29e4bcb2 | Andreas Färber | * This library is distributed in the hope that it will be useful,
|
15 | 29e4bcb2 | Andreas Färber | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 | 29e4bcb2 | Andreas Färber | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
17 | 29e4bcb2 | Andreas Färber | * Lesser General Public License for more details.
|
18 | 29e4bcb2 | Andreas Färber | *
|
19 | 29e4bcb2 | Andreas Färber | * You should have received a copy of the GNU Lesser General Public
|
20 | 29e4bcb2 | Andreas Färber | * License along with this library; if not, see
|
21 | 29e4bcb2 | Andreas Färber | * <http://www.gnu.org/licenses/lgpl-2.1.html>
|
22 | 70bada03 | Jens Freimann | * Contributions after 2012-12-11 are licensed under the terms of the
|
23 | 70bada03 | Jens Freimann | * GNU GPL, version 2 or (at your option) any later version.
|
24 | 29e4bcb2 | Andreas Färber | */
|
25 | 29e4bcb2 | Andreas Färber | |
26 | 564b863d | Andreas Färber | #include "cpu.h" |
27 | 29e4bcb2 | Andreas Färber | #include "qemu-common.h" |
28 | 1de7afc9 | Paolo Bonzini | #include "qemu/timer.h" |
29 | 70bada03 | Jens Freimann | #include "hw/hw.h" |
30 | c7396bbb | Andreas Färber | #ifndef CONFIG_USER_ONLY
|
31 | 904e5fd5 | Viktor Mihajlovski | #include "sysemu/arch_init.h" |
32 | 904e5fd5 | Viktor Mihajlovski | #endif
|
33 | 904e5fd5 | Viktor Mihajlovski | |
34 | 70bada03 | Jens Freimann | #define CR0_RESET 0xE0UL |
35 | 70bada03 | Jens Freimann | #define CR14_RESET 0xC2000000UL; |
36 | 70bada03 | Jens Freimann | |
37 | 904e5fd5 | Viktor Mihajlovski | /* generate CPU information for cpu -? */
|
38 | 904e5fd5 | Viktor Mihajlovski | void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf)
|
39 | 904e5fd5 | Viktor Mihajlovski | { |
40 | 904e5fd5 | Viktor Mihajlovski | #ifdef CONFIG_KVM
|
41 | 904e5fd5 | Viktor Mihajlovski | (*cpu_fprintf)(f, "s390 %16s\n", "host"); |
42 | 904e5fd5 | Viktor Mihajlovski | #endif
|
43 | 904e5fd5 | Viktor Mihajlovski | } |
44 | 29e4bcb2 | Andreas Färber | |
45 | 904e5fd5 | Viktor Mihajlovski | #ifndef CONFIG_USER_ONLY
|
46 | 904e5fd5 | Viktor Mihajlovski | CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) |
47 | 904e5fd5 | Viktor Mihajlovski | { |
48 | 904e5fd5 | Viktor Mihajlovski | CpuDefinitionInfoList *entry; |
49 | 904e5fd5 | Viktor Mihajlovski | CpuDefinitionInfo *info; |
50 | 904e5fd5 | Viktor Mihajlovski | |
51 | 904e5fd5 | Viktor Mihajlovski | info = g_malloc0(sizeof(*info));
|
52 | 904e5fd5 | Viktor Mihajlovski | info->name = g_strdup("host");
|
53 | 904e5fd5 | Viktor Mihajlovski | |
54 | 904e5fd5 | Viktor Mihajlovski | entry = g_malloc0(sizeof(*entry));
|
55 | 904e5fd5 | Viktor Mihajlovski | entry->value = info; |
56 | 904e5fd5 | Viktor Mihajlovski | |
57 | 904e5fd5 | Viktor Mihajlovski | return entry;
|
58 | 904e5fd5 | Viktor Mihajlovski | } |
59 | 904e5fd5 | Viktor Mihajlovski | #endif
|
60 | 29e4bcb2 | Andreas Färber | |
61 | f45748f1 | Andreas Färber | static void s390_cpu_set_pc(CPUState *cs, vaddr value) |
62 | f45748f1 | Andreas Färber | { |
63 | f45748f1 | Andreas Färber | S390CPU *cpu = S390_CPU(cs); |
64 | f45748f1 | Andreas Färber | |
65 | f45748f1 | Andreas Färber | cpu->env.psw.addr = value; |
66 | f45748f1 | Andreas Färber | } |
67 | f45748f1 | Andreas Färber | |
68 | 1ac1a749 | Andreas Färber | /* CPUClass::reset() */
|
69 | 29e4bcb2 | Andreas Färber | static void s390_cpu_reset(CPUState *s) |
70 | 29e4bcb2 | Andreas Färber | { |
71 | 29e4bcb2 | Andreas Färber | S390CPU *cpu = S390_CPU(s); |
72 | 29e4bcb2 | Andreas Färber | S390CPUClass *scc = S390_CPU_GET_CLASS(cpu); |
73 | 29e4bcb2 | Andreas Färber | CPUS390XState *env = &cpu->env; |
74 | 29e4bcb2 | Andreas Färber | |
75 | 49e15878 | Andreas Färber | s390_del_running_cpu(cpu); |
76 | 70bada03 | Jens Freimann | |
77 | 29e4bcb2 | Andreas Färber | scc->parent_reset(s); |
78 | 29e4bcb2 | Andreas Färber | |
79 | 1ac1a749 | Andreas Färber | memset(env, 0, offsetof(CPUS390XState, breakpoints));
|
80 | 70bada03 | Jens Freimann | |
81 | 70bada03 | Jens Freimann | /* architectured initial values for CR 0 and 14 */
|
82 | 70bada03 | Jens Freimann | env->cregs[0] = CR0_RESET;
|
83 | 70bada03 | Jens Freimann | env->cregs[14] = CR14_RESET;
|
84 | 70bada03 | Jens Freimann | /* set halted to 1 to make sure we can add the cpu in
|
85 | 259186a7 | Andreas Färber | * s390_ipl_cpu code, where CPUState::halted is set back to 0
|
86 | 70bada03 | Jens Freimann | * after incrementing the cpu counter */
|
87 | 70bada03 | Jens Freimann | #if !defined(CONFIG_USER_ONLY)
|
88 | 259186a7 | Andreas Färber | s->halted = 1;
|
89 | 70bada03 | Jens Freimann | #endif
|
90 | 1ac1a749 | Andreas Färber | tlb_flush(env, 1);
|
91 | 29e4bcb2 | Andreas Färber | } |
92 | 29e4bcb2 | Andreas Färber | |
93 | 70bada03 | Jens Freimann | #if !defined(CONFIG_USER_ONLY)
|
94 | 70bada03 | Jens Freimann | static void s390_cpu_machine_reset_cb(void *opaque) |
95 | 70bada03 | Jens Freimann | { |
96 | 70bada03 | Jens Freimann | S390CPU *cpu = opaque; |
97 | 70bada03 | Jens Freimann | |
98 | 70bada03 | Jens Freimann | cpu_reset(CPU(cpu)); |
99 | 70bada03 | Jens Freimann | } |
100 | 70bada03 | Jens Freimann | #endif
|
101 | 70bada03 | Jens Freimann | |
102 | 1f136632 | Andreas Färber | static void s390_cpu_realizefn(DeviceState *dev, Error **errp) |
103 | 1f136632 | Andreas Färber | { |
104 | 1f136632 | Andreas Färber | S390CPU *cpu = S390_CPU(dev); |
105 | 1f136632 | Andreas Färber | S390CPUClass *scc = S390_CPU_GET_CLASS(dev); |
106 | 1f136632 | Andreas Färber | |
107 | 1f136632 | Andreas Färber | cpu_reset(CPU(cpu)); |
108 | 1f136632 | Andreas Färber | |
109 | 1f136632 | Andreas Färber | scc->parent_realize(dev, errp); |
110 | 1f136632 | Andreas Färber | } |
111 | 1f136632 | Andreas Färber | |
112 | 8f22e0df | Andreas Färber | static void s390_cpu_initfn(Object *obj) |
113 | 8f22e0df | Andreas Färber | { |
114 | c05efcb1 | Andreas Färber | CPUState *cs = CPU(obj); |
115 | 8f22e0df | Andreas Färber | S390CPU *cpu = S390_CPU(obj); |
116 | 8f22e0df | Andreas Färber | CPUS390XState *env = &cpu->env; |
117 | 2b7ac767 | Andreas Färber | static bool inited; |
118 | 8f22e0df | Andreas Färber | static int cpu_num = 0; |
119 | 8f22e0df | Andreas Färber | #if !defined(CONFIG_USER_ONLY)
|
120 | 8f22e0df | Andreas Färber | struct tm tm;
|
121 | 8f22e0df | Andreas Färber | #endif
|
122 | 8f22e0df | Andreas Färber | |
123 | c05efcb1 | Andreas Färber | cs->env_ptr = env; |
124 | 8f22e0df | Andreas Färber | cpu_exec_init(env); |
125 | 8f22e0df | Andreas Färber | #if !defined(CONFIG_USER_ONLY)
|
126 | 70bada03 | Jens Freimann | qemu_register_reset(s390_cpu_machine_reset_cb, cpu); |
127 | 8f22e0df | Andreas Färber | qemu_get_timedate(&tm, 0);
|
128 | 8f22e0df | Andreas Färber | env->tod_offset = TOD_UNIX_EPOCH + |
129 | 8f22e0df | Andreas Färber | (time2tod(mktimegm(&tm)) * 1000000000ULL);
|
130 | 8f22e0df | Andreas Färber | env->tod_basetime = 0;
|
131 | b8ba6799 | Andreas Färber | env->tod_timer = qemu_new_timer_ns(vm_clock, s390x_tod_timer, cpu); |
132 | b8ba6799 | Andreas Färber | env->cpu_timer = qemu_new_timer_ns(vm_clock, s390x_cpu_timer, cpu); |
133 | 259186a7 | Andreas Färber | /* set CPUState::halted state to 1 to avoid decrementing the running
|
134 | 70bada03 | Jens Freimann | * cpu counter in s390_cpu_reset to a negative number at
|
135 | 70bada03 | Jens Freimann | * initial ipl */
|
136 | 259186a7 | Andreas Färber | cs->halted = 1;
|
137 | 8f22e0df | Andreas Färber | #endif
|
138 | 8f22e0df | Andreas Färber | env->cpu_num = cpu_num++; |
139 | 8f22e0df | Andreas Färber | env->ext_index = -1;
|
140 | 2b7ac767 | Andreas Färber | |
141 | 2b7ac767 | Andreas Färber | if (tcg_enabled() && !inited) {
|
142 | 2b7ac767 | Andreas Färber | inited = true;
|
143 | 2b7ac767 | Andreas Färber | s390x_translate_init(); |
144 | 2b7ac767 | Andreas Färber | } |
145 | 8f22e0df | Andreas Färber | } |
146 | 8f22e0df | Andreas Färber | |
147 | d5627ce8 | Andreas Färber | static void s390_cpu_finalize(Object *obj) |
148 | d5627ce8 | Andreas Färber | { |
149 | d5627ce8 | Andreas Färber | #if !defined(CONFIG_USER_ONLY)
|
150 | d5627ce8 | Andreas Färber | S390CPU *cpu = S390_CPU(obj); |
151 | d5627ce8 | Andreas Färber | |
152 | d5627ce8 | Andreas Färber | qemu_unregister_reset(s390_cpu_machine_reset_cb, cpu); |
153 | d5627ce8 | Andreas Färber | #endif
|
154 | d5627ce8 | Andreas Färber | } |
155 | d5627ce8 | Andreas Färber | |
156 | c7396bbb | Andreas Färber | static const VMStateDescription vmstate_s390_cpu = { |
157 | c7396bbb | Andreas Färber | .name = "cpu",
|
158 | c7396bbb | Andreas Färber | .unmigratable = 1,
|
159 | c7396bbb | Andreas Färber | }; |
160 | c7396bbb | Andreas Färber | |
161 | 29e4bcb2 | Andreas Färber | static void s390_cpu_class_init(ObjectClass *oc, void *data) |
162 | 29e4bcb2 | Andreas Färber | { |
163 | 29e4bcb2 | Andreas Färber | S390CPUClass *scc = S390_CPU_CLASS(oc); |
164 | 29e4bcb2 | Andreas Färber | CPUClass *cc = CPU_CLASS(scc); |
165 | c7396bbb | Andreas Färber | DeviceClass *dc = DEVICE_CLASS(oc); |
166 | 29e4bcb2 | Andreas Färber | |
167 | 1f136632 | Andreas Färber | scc->parent_realize = dc->realize; |
168 | 1f136632 | Andreas Färber | dc->realize = s390_cpu_realizefn; |
169 | 1f136632 | Andreas Färber | |
170 | 29e4bcb2 | Andreas Färber | scc->parent_reset = cc->reset; |
171 | 29e4bcb2 | Andreas Färber | cc->reset = s390_cpu_reset; |
172 | c7396bbb | Andreas Färber | |
173 | 97a8ea5a | Andreas Färber | cc->do_interrupt = s390_cpu_do_interrupt; |
174 | 878096ee | Andreas Färber | cc->dump_state = s390_cpu_dump_state; |
175 | f45748f1 | Andreas Färber | cc->set_pc = s390_cpu_set_pc; |
176 | 5b50e790 | Andreas Färber | cc->gdb_read_register = s390_cpu_gdb_read_register; |
177 | 5b50e790 | Andreas Färber | cc->gdb_write_register = s390_cpu_gdb_write_register; |
178 | 00b941e5 | Andreas Färber | #ifndef CONFIG_USER_ONLY
|
179 | 00b941e5 | Andreas Färber | cc->get_phys_page_debug = s390_cpu_get_phys_page_debug; |
180 | 00b941e5 | Andreas Färber | #endif
|
181 | c7396bbb | Andreas Färber | dc->vmsd = &vmstate_s390_cpu; |
182 | a0e372f0 | Andreas Färber | cc->gdb_num_core_regs = S390_NUM_REGS; |
183 | 29e4bcb2 | Andreas Färber | } |
184 | 29e4bcb2 | Andreas Färber | |
185 | 29e4bcb2 | Andreas Färber | static const TypeInfo s390_cpu_type_info = { |
186 | 29e4bcb2 | Andreas Färber | .name = TYPE_S390_CPU, |
187 | 29e4bcb2 | Andreas Färber | .parent = TYPE_CPU, |
188 | 29e4bcb2 | Andreas Färber | .instance_size = sizeof(S390CPU),
|
189 | 8f22e0df | Andreas Färber | .instance_init = s390_cpu_initfn, |
190 | d5627ce8 | Andreas Färber | .instance_finalize = s390_cpu_finalize, |
191 | 29e4bcb2 | Andreas Färber | .abstract = false,
|
192 | 29e4bcb2 | Andreas Färber | .class_size = sizeof(S390CPUClass),
|
193 | 29e4bcb2 | Andreas Färber | .class_init = s390_cpu_class_init, |
194 | 29e4bcb2 | Andreas Färber | }; |
195 | 29e4bcb2 | Andreas Färber | |
196 | 29e4bcb2 | Andreas Färber | static void s390_cpu_register_types(void) |
197 | 29e4bcb2 | Andreas Färber | { |
198 | 29e4bcb2 | Andreas Färber | type_register_static(&s390_cpu_type_info); |
199 | 29e4bcb2 | Andreas Färber | } |
200 | 29e4bcb2 | Andreas Färber | |
201 | 29e4bcb2 | Andreas Färber | type_init(s390_cpu_register_types) |