Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * QEMU S/390 CPU |
| 3 | * |
Andreas Färber | 1ac1a74 | 2012-04-02 13:31:59 +0200 | [diff] [blame] | 4 | * Copyright (c) 2009 Ulrich Hecht |
| 5 | * Copyright (c) 2011 Alexander Graf |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 6 | * Copyright (c) 2012 SUSE LINUX Products GmbH |
Jens Freimann | 70bada0 | 2013-01-07 05:27:14 +0000 | [diff] [blame] | 7 | * Copyright (c) 2012 IBM Corp. |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 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> |
Jens Freimann | 70bada0 | 2013-01-07 05:27:14 +0000 | [diff] [blame] | 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. |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 24 | */ |
| 25 | |
Andreas Färber | 564b863 | 2012-05-03 04:13:04 +0200 | [diff] [blame] | 26 | #include "cpu.h" |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 27 | #include "qemu-common.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 28 | #include "qemu/timer.h" |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 29 | #include "qemu/error-report.h" |
Jens Freimann | 70bada0 | 2013-01-07 05:27:14 +0000 | [diff] [blame] | 30 | #include "hw/hw.h" |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 31 | #include "trace.h" |
Andreas Färber | c7396bb | 2013-01-20 19:41:06 +0100 | [diff] [blame] | 32 | #ifndef CONFIG_USER_ONLY |
Viktor Mihajlovski | 904e5fd | 2012-12-18 07:50:59 +0000 | [diff] [blame] | 33 | #include "sysemu/arch_init.h" |
| 34 | #endif |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 35 | |
Jens Freimann | 70bada0 | 2013-01-07 05:27:14 +0000 | [diff] [blame] | 36 | #define CR0_RESET 0xE0UL |
| 37 | #define CR14_RESET 0xC2000000UL; |
| 38 | |
Viktor Mihajlovski | 904e5fd | 2012-12-18 07:50:59 +0000 | [diff] [blame] | 39 | /* generate CPU information for cpu -? */ |
| 40 | void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf) |
| 41 | { |
| 42 | #ifdef CONFIG_KVM |
| 43 | (*cpu_fprintf)(f, "s390 %16s\n", "host"); |
| 44 | #endif |
| 45 | } |
| 46 | |
| 47 | #ifndef CONFIG_USER_ONLY |
| 48 | CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp) |
| 49 | { |
| 50 | CpuDefinitionInfoList *entry; |
| 51 | CpuDefinitionInfo *info; |
| 52 | |
| 53 | info = g_malloc0(sizeof(*info)); |
| 54 | info->name = g_strdup("host"); |
| 55 | |
| 56 | entry = g_malloc0(sizeof(*entry)); |
| 57 | entry->value = info; |
| 58 | |
| 59 | return entry; |
| 60 | } |
| 61 | #endif |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 62 | |
Andreas Färber | f45748f | 2013-06-21 19:09:18 +0200 | [diff] [blame] | 63 | static void s390_cpu_set_pc(CPUState *cs, vaddr value) |
| 64 | { |
| 65 | S390CPU *cpu = S390_CPU(cs); |
| 66 | |
| 67 | cpu->env.psw.addr = value; |
| 68 | } |
| 69 | |
Andreas Färber | 8c2e1b0 | 2013-08-25 18:53:55 +0200 | [diff] [blame] | 70 | static bool s390_cpu_has_work(CPUState *cs) |
| 71 | { |
| 72 | S390CPU *cpu = S390_CPU(cs); |
| 73 | CPUS390XState *env = &cpu->env; |
| 74 | |
| 75 | return (cs->interrupt_request & CPU_INTERRUPT_HARD) && |
| 76 | (env->psw.mask & PSW_MASK_EXT); |
| 77 | } |
| 78 | |
Christian Borntraeger | 29c6157 | 2013-07-25 16:45:51 +0200 | [diff] [blame] | 79 | #if !defined(CONFIG_USER_ONLY) |
| 80 | /* S390CPUClass::load_normal() */ |
| 81 | static void s390_cpu_load_normal(CPUState *s) |
| 82 | { |
| 83 | S390CPU *cpu = S390_CPU(s); |
Edgar E. Iglesias | fdfba1a | 2013-11-15 14:46:38 +0100 | [diff] [blame] | 84 | cpu->env.psw.addr = ldl_phys(s->as, 4) & PSW_MASK_ESA_ADDR; |
Christian Borntraeger | 29c6157 | 2013-07-25 16:45:51 +0200 | [diff] [blame] | 85 | cpu->env.psw.mask = PSW_MASK_32 | PSW_MASK_64; |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 86 | s390_cpu_set_state(CPU_STATE_OPERATING, cpu); |
Christian Borntraeger | 29c6157 | 2013-07-25 16:45:51 +0200 | [diff] [blame] | 87 | } |
| 88 | #endif |
| 89 | |
Christian Borntraeger | f5ae2a4 | 2013-06-28 10:51:09 +0200 | [diff] [blame] | 90 | /* S390CPUClass::cpu_reset() */ |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 91 | static void s390_cpu_reset(CPUState *s) |
| 92 | { |
| 93 | S390CPU *cpu = S390_CPU(s); |
| 94 | S390CPUClass *scc = S390_CPU_GET_CLASS(cpu); |
| 95 | CPUS390XState *env = &cpu->env; |
| 96 | |
Dominik Dingel | 819bd30 | 2013-09-05 13:54:39 +0200 | [diff] [blame] | 97 | env->pfault_token = -1UL; |
Christian Borntraeger | f5ae2a4 | 2013-06-28 10:51:09 +0200 | [diff] [blame] | 98 | scc->parent_reset(s); |
David Hildenbrand | 18ff949 | 2015-02-24 14:15:27 +0100 | [diff] [blame] | 99 | cpu->env.sigp_order = 0; |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 100 | s390_cpu_set_state(CPU_STATE_STOPPED, cpu); |
Andreas Färber | 00c8cb0 | 2013-09-04 02:19:44 +0200 | [diff] [blame] | 101 | tlb_flush(s, 1); |
Christian Borntraeger | f5ae2a4 | 2013-06-28 10:51:09 +0200 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /* S390CPUClass::initial_reset() */ |
| 105 | static void s390_cpu_initial_reset(CPUState *s) |
| 106 | { |
| 107 | S390CPU *cpu = S390_CPU(s); |
| 108 | CPUS390XState *env = &cpu->env; |
Aurelien Jarno | cc0d079 | 2015-06-15 17:57:05 +0200 | [diff] [blame] | 109 | int i; |
Christian Borntraeger | f5ae2a4 | 2013-06-28 10:51:09 +0200 | [diff] [blame] | 110 | |
| 111 | s390_cpu_reset(s); |
| 112 | /* initial reset does not touch regs,fregs and aregs */ |
Andreas Färber | f0c3c50 | 2013-08-26 21:22:53 +0200 | [diff] [blame] | 113 | memset(&env->fpc, 0, offsetof(CPUS390XState, cpu_num) - |
Christian Borntraeger | f5ae2a4 | 2013-06-28 10:51:09 +0200 | [diff] [blame] | 114 | offsetof(CPUS390XState, fpc)); |
| 115 | |
| 116 | /* architectured initial values for CR 0 and 14 */ |
| 117 | env->cregs[0] = CR0_RESET; |
| 118 | env->cregs[14] = CR14_RESET; |
Dominik Dingel | 819bd30 | 2013-09-05 13:54:39 +0200 | [diff] [blame] | 119 | |
Aurelien Jarno | 3da0ab3 | 2015-06-13 00:46:03 +0200 | [diff] [blame] | 120 | /* architectured initial value for Breaking-Event-Address register */ |
| 121 | env->gbea = 1; |
| 122 | |
Dominik Dingel | 819bd30 | 2013-09-05 13:54:39 +0200 | [diff] [blame] | 123 | env->pfault_token = -1UL; |
Aurelien Jarno | 7107e5a | 2015-06-15 17:57:04 +0200 | [diff] [blame] | 124 | env->ext_index = -1; |
Aurelien Jarno | cc0d079 | 2015-06-15 17:57:05 +0200 | [diff] [blame] | 125 | for (i = 0; i < ARRAY_SIZE(env->io_index); i++) { |
| 126 | env->io_index[i] = -1; |
| 127 | } |
Thomas Huth | 49f5c9e | 2014-02-12 09:56:35 +0100 | [diff] [blame] | 128 | |
Aurelien Jarno | 4a33565 | 2015-05-25 01:47:26 +0200 | [diff] [blame] | 129 | /* tininess for underflow is detected before rounding */ |
| 130 | set_float_detect_tininess(float_tininess_before_rounding, |
| 131 | &env->fpu_status); |
| 132 | |
Thomas Huth | 49f5c9e | 2014-02-12 09:56:35 +0100 | [diff] [blame] | 133 | /* Reset state inside the kernel that we cannot access yet from QEMU. */ |
| 134 | if (kvm_enabled()) { |
David Hildenbrand | 9960714 | 2014-09-30 10:57:31 +0200 | [diff] [blame] | 135 | kvm_s390_reset_vcpu(cpu); |
Thomas Huth | 49f5c9e | 2014-02-12 09:56:35 +0100 | [diff] [blame] | 136 | } |
Aurelien Jarno | cbed0ba | 2015-06-15 17:57:06 +0200 | [diff] [blame] | 137 | tlb_flush(s, 1); |
Christian Borntraeger | f5ae2a4 | 2013-06-28 10:51:09 +0200 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /* CPUClass:reset() */ |
| 141 | static void s390_cpu_full_reset(CPUState *s) |
| 142 | { |
| 143 | S390CPU *cpu = S390_CPU(s); |
| 144 | S390CPUClass *scc = S390_CPU_GET_CLASS(cpu); |
| 145 | CPUS390XState *env = &cpu->env; |
Aurelien Jarno | cc0d079 | 2015-06-15 17:57:05 +0200 | [diff] [blame] | 146 | int i; |
Christian Borntraeger | f5ae2a4 | 2013-06-28 10:51:09 +0200 | [diff] [blame] | 147 | |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 148 | scc->parent_reset(s); |
David Hildenbrand | 18ff949 | 2015-02-24 14:15:27 +0100 | [diff] [blame] | 149 | cpu->env.sigp_order = 0; |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 150 | s390_cpu_set_state(CPU_STATE_STOPPED, cpu); |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 151 | |
Andreas Färber | f0c3c50 | 2013-08-26 21:22:53 +0200 | [diff] [blame] | 152 | memset(env, 0, offsetof(CPUS390XState, cpu_num)); |
Jens Freimann | 70bada0 | 2013-01-07 05:27:14 +0000 | [diff] [blame] | 153 | |
| 154 | /* architectured initial values for CR 0 and 14 */ |
| 155 | env->cregs[0] = CR0_RESET; |
| 156 | env->cregs[14] = CR14_RESET; |
Dominik Dingel | 819bd30 | 2013-09-05 13:54:39 +0200 | [diff] [blame] | 157 | |
Aurelien Jarno | 3da0ab3 | 2015-06-13 00:46:03 +0200 | [diff] [blame] | 158 | /* architectured initial value for Breaking-Event-Address register */ |
| 159 | env->gbea = 1; |
| 160 | |
Dominik Dingel | 819bd30 | 2013-09-05 13:54:39 +0200 | [diff] [blame] | 161 | env->pfault_token = -1UL; |
Aurelien Jarno | 7107e5a | 2015-06-15 17:57:04 +0200 | [diff] [blame] | 162 | env->ext_index = -1; |
Aurelien Jarno | cc0d079 | 2015-06-15 17:57:05 +0200 | [diff] [blame] | 163 | for (i = 0; i < ARRAY_SIZE(env->io_index); i++) { |
| 164 | env->io_index[i] = -1; |
| 165 | } |
Dominik Dingel | 819bd30 | 2013-09-05 13:54:39 +0200 | [diff] [blame] | 166 | |
Aurelien Jarno | 4a33565 | 2015-05-25 01:47:26 +0200 | [diff] [blame] | 167 | /* tininess for underflow is detected before rounding */ |
| 168 | set_float_detect_tininess(float_tininess_before_rounding, |
| 169 | &env->fpu_status); |
| 170 | |
David Hildenbrand | 9960714 | 2014-09-30 10:57:31 +0200 | [diff] [blame] | 171 | /* Reset state inside the kernel that we cannot access yet from QEMU. */ |
Paolo Bonzini | 50a2c6e | 2013-03-20 13:11:56 +0100 | [diff] [blame] | 172 | if (kvm_enabled()) { |
| 173 | kvm_s390_reset_vcpu(cpu); |
| 174 | } |
Andreas Färber | 00c8cb0 | 2013-09-04 02:19:44 +0200 | [diff] [blame] | 175 | tlb_flush(s, 1); |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Jens Freimann | 70bada0 | 2013-01-07 05:27:14 +0000 | [diff] [blame] | 178 | #if !defined(CONFIG_USER_ONLY) |
| 179 | static void s390_cpu_machine_reset_cb(void *opaque) |
| 180 | { |
| 181 | S390CPU *cpu = opaque; |
| 182 | |
David Hildenbrand | 1fad8b3 | 2014-08-28 13:58:51 +0200 | [diff] [blame] | 183 | run_on_cpu(CPU(cpu), s390_do_cpu_full_reset, CPU(cpu)); |
Jens Freimann | 70bada0 | 2013-01-07 05:27:14 +0000 | [diff] [blame] | 184 | } |
| 185 | #endif |
| 186 | |
Andreas Färber | 1f13663 | 2013-01-16 04:00:41 +0100 | [diff] [blame] | 187 | static void s390_cpu_realizefn(DeviceState *dev, Error **errp) |
| 188 | { |
Andreas Färber | 14a10fc | 2013-07-27 02:53:25 +0200 | [diff] [blame] | 189 | CPUState *cs = CPU(dev); |
Andreas Färber | 1f13663 | 2013-01-16 04:00:41 +0100 | [diff] [blame] | 190 | S390CPUClass *scc = S390_CPU_GET_CLASS(dev); |
| 191 | |
David Hildenbrand | 73d510c | 2014-08-29 15:52:16 +0200 | [diff] [blame] | 192 | s390_cpu_gdb_init(cs); |
Andreas Färber | 14a10fc | 2013-07-27 02:53:25 +0200 | [diff] [blame] | 193 | qemu_init_vcpu(cs); |
David Hildenbrand | 159855f | 2014-08-28 13:58:52 +0200 | [diff] [blame] | 194 | #if !defined(CONFIG_USER_ONLY) |
| 195 | run_on_cpu(cs, s390_do_cpu_full_reset, cs); |
| 196 | #else |
Andreas Färber | 14a10fc | 2013-07-27 02:53:25 +0200 | [diff] [blame] | 197 | cpu_reset(cs); |
David Hildenbrand | 159855f | 2014-08-28 13:58:52 +0200 | [diff] [blame] | 198 | #endif |
Andreas Färber | 1f13663 | 2013-01-16 04:00:41 +0100 | [diff] [blame] | 199 | |
| 200 | scc->parent_realize(dev, errp); |
| 201 | } |
| 202 | |
Andreas Färber | 8f22e0d | 2012-04-02 13:56:29 +0200 | [diff] [blame] | 203 | static void s390_cpu_initfn(Object *obj) |
| 204 | { |
Andreas Färber | c05efcb | 2013-01-17 12:13:41 +0100 | [diff] [blame] | 205 | CPUState *cs = CPU(obj); |
Andreas Färber | 8f22e0d | 2012-04-02 13:56:29 +0200 | [diff] [blame] | 206 | S390CPU *cpu = S390_CPU(obj); |
| 207 | CPUS390XState *env = &cpu->env; |
Andreas Färber | 2b7ac76 | 2013-01-19 22:43:32 +0100 | [diff] [blame] | 208 | static bool inited; |
Andreas Färber | 8f22e0d | 2012-04-02 13:56:29 +0200 | [diff] [blame] | 209 | static int cpu_num = 0; |
| 210 | #if !defined(CONFIG_USER_ONLY) |
| 211 | struct tm tm; |
| 212 | #endif |
| 213 | |
Andreas Färber | c05efcb | 2013-01-17 12:13:41 +0100 | [diff] [blame] | 214 | cs->env_ptr = env; |
Peter Crosthwaite | 4bad9e3 | 2015-06-23 19:31:18 -0700 | [diff] [blame] | 215 | cpu_exec_init(cs, &error_abort); |
Andreas Färber | 8f22e0d | 2012-04-02 13:56:29 +0200 | [diff] [blame] | 216 | #if !defined(CONFIG_USER_ONLY) |
Jens Freimann | 70bada0 | 2013-01-07 05:27:14 +0000 | [diff] [blame] | 217 | qemu_register_reset(s390_cpu_machine_reset_cb, cpu); |
Andreas Färber | 8f22e0d | 2012-04-02 13:56:29 +0200 | [diff] [blame] | 218 | qemu_get_timedate(&tm, 0); |
| 219 | env->tod_offset = TOD_UNIX_EPOCH + |
| 220 | (time2tod(mktimegm(&tm)) * 1000000000ULL); |
| 221 | env->tod_basetime = 0; |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 222 | env->tod_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_tod_timer, cpu); |
| 223 | env->cpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_cpu_timer, cpu); |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 224 | s390_cpu_set_state(CPU_STATE_STOPPED, cpu); |
Andreas Färber | 8f22e0d | 2012-04-02 13:56:29 +0200 | [diff] [blame] | 225 | #endif |
| 226 | env->cpu_num = cpu_num++; |
Andreas Färber | 2b7ac76 | 2013-01-19 22:43:32 +0100 | [diff] [blame] | 227 | |
| 228 | if (tcg_enabled() && !inited) { |
| 229 | inited = true; |
| 230 | s390x_translate_init(); |
| 231 | } |
Andreas Färber | 8f22e0d | 2012-04-02 13:56:29 +0200 | [diff] [blame] | 232 | } |
| 233 | |
Andreas Färber | d5627ce | 2013-01-07 06:14:16 +0000 | [diff] [blame] | 234 | static void s390_cpu_finalize(Object *obj) |
| 235 | { |
| 236 | #if !defined(CONFIG_USER_ONLY) |
| 237 | S390CPU *cpu = S390_CPU(obj); |
| 238 | |
| 239 | qemu_unregister_reset(s390_cpu_machine_reset_cb, cpu); |
Jens Freimann | 3cda44f | 2015-03-02 17:44:24 +0100 | [diff] [blame] | 240 | g_free(cpu->irqstate); |
Andreas Färber | d5627ce | 2013-01-07 06:14:16 +0000 | [diff] [blame] | 241 | #endif |
| 242 | } |
| 243 | |
David Hildenbrand | 75973bf | 2014-09-30 10:57:28 +0200 | [diff] [blame] | 244 | #if !defined(CONFIG_USER_ONLY) |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 245 | static bool disabled_wait(CPUState *cpu) |
| 246 | { |
| 247 | return cpu->halted && !(S390_CPU(cpu)->env.psw.mask & |
| 248 | (PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK)); |
| 249 | } |
| 250 | |
David Hildenbrand | 75973bf | 2014-09-30 10:57:28 +0200 | [diff] [blame] | 251 | static unsigned s390_count_running_cpus(void) |
| 252 | { |
| 253 | CPUState *cpu; |
| 254 | int nr_running = 0; |
| 255 | |
| 256 | CPU_FOREACH(cpu) { |
| 257 | uint8_t state = S390_CPU(cpu)->env.cpu_state; |
| 258 | if (state == CPU_STATE_OPERATING || |
| 259 | state == CPU_STATE_LOAD) { |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 260 | if (!disabled_wait(cpu)) { |
| 261 | nr_running++; |
| 262 | } |
David Hildenbrand | 75973bf | 2014-09-30 10:57:28 +0200 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
| 266 | return nr_running; |
| 267 | } |
| 268 | |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 269 | unsigned int s390_cpu_halt(S390CPU *cpu) |
David Hildenbrand | 75973bf | 2014-09-30 10:57:28 +0200 | [diff] [blame] | 270 | { |
| 271 | CPUState *cs = CPU(cpu); |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 272 | trace_cpu_halt(cs->cpu_index); |
| 273 | |
| 274 | if (!cs->halted) { |
| 275 | cs->halted = 1; |
| 276 | cs->exception_index = EXCP_HLT; |
| 277 | } |
| 278 | |
| 279 | return s390_count_running_cpus(); |
| 280 | } |
| 281 | |
| 282 | void s390_cpu_unhalt(S390CPU *cpu) |
| 283 | { |
| 284 | CPUState *cs = CPU(cpu); |
| 285 | trace_cpu_unhalt(cs->cpu_index); |
David Hildenbrand | 75973bf | 2014-09-30 10:57:28 +0200 | [diff] [blame] | 286 | |
| 287 | if (cs->halted) { |
David Hildenbrand | 75973bf | 2014-09-30 10:57:28 +0200 | [diff] [blame] | 288 | cs->halted = 0; |
| 289 | cs->exception_index = -1; |
| 290 | } |
| 291 | } |
| 292 | |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 293 | unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu) |
| 294 | { |
| 295 | trace_cpu_set_state(CPU(cpu)->cpu_index, cpu_state); |
David Hildenbrand | 75973bf | 2014-09-30 10:57:28 +0200 | [diff] [blame] | 296 | |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 297 | switch (cpu_state) { |
| 298 | case CPU_STATE_STOPPED: |
| 299 | case CPU_STATE_CHECK_STOP: |
| 300 | /* halt the cpu for common infrastructure */ |
| 301 | s390_cpu_halt(cpu); |
| 302 | break; |
| 303 | case CPU_STATE_OPERATING: |
| 304 | case CPU_STATE_LOAD: |
| 305 | /* unhalt the cpu for common infrastructure */ |
| 306 | s390_cpu_unhalt(cpu); |
| 307 | break; |
| 308 | default: |
| 309 | error_report("Requested CPU state is not a valid S390 CPU state: %u", |
| 310 | cpu_state); |
| 311 | exit(1); |
David Hildenbrand | 75973bf | 2014-09-30 10:57:28 +0200 | [diff] [blame] | 312 | } |
David Hildenbrand | c9e659c | 2014-09-30 10:57:30 +0200 | [diff] [blame] | 313 | if (kvm_enabled() && cpu->env.cpu_state != cpu_state) { |
| 314 | kvm_s390_set_cpu_state(cpu, cpu_state); |
| 315 | } |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 316 | cpu->env.cpu_state = cpu_state; |
David Hildenbrand | 75973bf | 2014-09-30 10:57:28 +0200 | [diff] [blame] | 317 | |
| 318 | return s390_count_running_cpus(); |
| 319 | } |
| 320 | #endif |
| 321 | |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 322 | static void s390_cpu_class_init(ObjectClass *oc, void *data) |
| 323 | { |
| 324 | S390CPUClass *scc = S390_CPU_CLASS(oc); |
| 325 | CPUClass *cc = CPU_CLASS(scc); |
Andreas Färber | c7396bb | 2013-01-20 19:41:06 +0100 | [diff] [blame] | 326 | DeviceClass *dc = DEVICE_CLASS(oc); |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 327 | |
Andreas Färber | 1f13663 | 2013-01-16 04:00:41 +0100 | [diff] [blame] | 328 | scc->parent_realize = dc->realize; |
| 329 | dc->realize = s390_cpu_realizefn; |
| 330 | |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 331 | scc->parent_reset = cc->reset; |
Christian Borntraeger | 29c6157 | 2013-07-25 16:45:51 +0200 | [diff] [blame] | 332 | #if !defined(CONFIG_USER_ONLY) |
| 333 | scc->load_normal = s390_cpu_load_normal; |
| 334 | #endif |
Christian Borntraeger | f5ae2a4 | 2013-06-28 10:51:09 +0200 | [diff] [blame] | 335 | scc->cpu_reset = s390_cpu_reset; |
| 336 | scc->initial_cpu_reset = s390_cpu_initial_reset; |
| 337 | cc->reset = s390_cpu_full_reset; |
Andreas Färber | 8c2e1b0 | 2013-08-25 18:53:55 +0200 | [diff] [blame] | 338 | cc->has_work = s390_cpu_has_work; |
Andreas Färber | 97a8ea5 | 2013-02-02 10:57:51 +0100 | [diff] [blame] | 339 | cc->do_interrupt = s390_cpu_do_interrupt; |
Andreas Färber | 878096e | 2013-05-27 01:33:50 +0200 | [diff] [blame] | 340 | cc->dump_state = s390_cpu_dump_state; |
Andreas Färber | f45748f | 2013-06-21 19:09:18 +0200 | [diff] [blame] | 341 | cc->set_pc = s390_cpu_set_pc; |
Andreas Färber | 5b50e79 | 2013-06-29 04:18:45 +0200 | [diff] [blame] | 342 | cc->gdb_read_register = s390_cpu_gdb_read_register; |
| 343 | cc->gdb_write_register = s390_cpu_gdb_write_register; |
Andreas Färber | 7510454 | 2013-08-26 03:01:33 +0200 | [diff] [blame] | 344 | #ifdef CONFIG_USER_ONLY |
| 345 | cc->handle_mmu_fault = s390_cpu_handle_mmu_fault; |
| 346 | #else |
Andreas Färber | 00b941e | 2013-06-29 18:55:54 +0200 | [diff] [blame] | 347 | cc->get_phys_page_debug = s390_cpu_get_phys_page_debug; |
Thomas Huth | ef1df13 | 2014-09-30 10:58:42 +0200 | [diff] [blame] | 348 | cc->vmsd = &vmstate_s390_cpu; |
Ekaterina Tumanova | 9b4f38e | 2013-07-10 15:26:46 +0200 | [diff] [blame] | 349 | cc->write_elf64_note = s390_cpu_write_elf64_note; |
| 350 | cc->write_elf64_qemunote = s390_cpu_write_elf64_qemunote; |
Richard Henderson | 02bb9bb | 2014-09-13 09:45:19 -0700 | [diff] [blame] | 351 | cc->cpu_exec_interrupt = s390_cpu_exec_interrupt; |
Aurelien Jarno | 311918b | 2015-06-13 00:46:00 +0200 | [diff] [blame] | 352 | cc->debug_excp_handler = s390x_cpu_debug_excp_handler; |
Andreas Färber | 00b941e | 2013-06-29 18:55:54 +0200 | [diff] [blame] | 353 | #endif |
David Hildenbrand | 73d510c | 2014-08-29 15:52:16 +0200 | [diff] [blame] | 354 | cc->gdb_num_core_regs = S390_NUM_CORE_REGS; |
| 355 | cc->gdb_core_xml_file = "s390x-core64.xml"; |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | static const TypeInfo s390_cpu_type_info = { |
| 359 | .name = TYPE_S390_CPU, |
| 360 | .parent = TYPE_CPU, |
| 361 | .instance_size = sizeof(S390CPU), |
Andreas Färber | 8f22e0d | 2012-04-02 13:56:29 +0200 | [diff] [blame] | 362 | .instance_init = s390_cpu_initfn, |
Andreas Färber | d5627ce | 2013-01-07 06:14:16 +0000 | [diff] [blame] | 363 | .instance_finalize = s390_cpu_finalize, |
Andreas Färber | 29e4bcb | 2012-04-02 11:39:23 +0200 | [diff] [blame] | 364 | .abstract = false, |
| 365 | .class_size = sizeof(S390CPUClass), |
| 366 | .class_init = s390_cpu_class_init, |
| 367 | }; |
| 368 | |
| 369 | static void s390_cpu_register_types(void) |
| 370 | { |
| 371 | type_register_static(&s390_cpu_type_info); |
| 372 | } |
| 373 | |
| 374 | type_init(s390_cpu_register_types) |