Alexander Graf | 10ec511 | 2009-12-05 12:44:21 +0100 | [diff] [blame] | 1 | /* |
| 2 | * S/390 helpers |
| 3 | * |
| 4 | * Copyright (c) 2009 Ulrich Hecht |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 5 | * Copyright (c) 2011 Alexander Graf |
Alexander Graf | 10ec511 | 2009-12-05 12:44:21 +0100 | [diff] [blame] | 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
Thomas Huth | 41c6a6d | 2019-01-29 14:37:47 +0100 | [diff] [blame] | 10 | * version 2.1 of the License, or (at your option) any later version. |
Alexander Graf | 10ec511 | 2009-12-05 12:44:21 +0100 | [diff] [blame] | 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
Blue Swirl | 70539e1 | 2010-03-07 15:48:43 +0000 | [diff] [blame] | 18 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
Alexander Graf | 10ec511 | 2009-12-05 12:44:21 +0100 | [diff] [blame] | 19 | */ |
| 20 | |
Peter Maydell | 9615495 | 2016-01-26 18:17:00 +0000 | [diff] [blame] | 21 | #include "qemu/osdep.h" |
Alexander Graf | 10ec511 | 2009-12-05 12:44:21 +0100 | [diff] [blame] | 22 | #include "cpu.h" |
David Hildenbrand | 4e58b83 | 2017-08-18 13:43:49 +0200 | [diff] [blame] | 23 | #include "internal.h" |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 24 | #include "exec/gdbstub.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 25 | #include "qemu/timer.h" |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 26 | #include "qemu/qemu-print.h" |
Paolo Bonzini | bd3f16a | 2015-12-04 12:06:26 +0100 | [diff] [blame] | 27 | #include "hw/s390x/ioinst.h" |
David Hildenbrand | 83f7f32 | 2017-09-28 22:36:46 +0200 | [diff] [blame] | 28 | #include "sysemu/hw_accel.h" |
Alexander Graf | ef81522 | 2011-10-07 09:51:50 +0200 | [diff] [blame] | 29 | #ifndef CONFIG_USER_ONLY |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 30 | #include "sysemu/sysemu.h" |
Alexander Graf | ef81522 | 2011-10-07 09:51:50 +0200 | [diff] [blame] | 31 | #endif |
Alexander Graf | 10ec511 | 2009-12-05 12:44:21 +0100 | [diff] [blame] | 32 | |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 33 | #ifndef CONFIG_USER_ONLY |
Andreas Färber | 8f22e0d | 2012-04-02 13:56:29 +0200 | [diff] [blame] | 34 | void s390x_tod_timer(void *opaque) |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 35 | { |
David Hildenbrand | 6482b0f | 2017-09-28 22:36:39 +0200 | [diff] [blame] | 36 | cpu_inject_clock_comparator((S390CPU *) opaque); |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 37 | } |
| 38 | |
Andreas Färber | 8f22e0d | 2012-04-02 13:56:29 +0200 | [diff] [blame] | 39 | void s390x_cpu_timer(void *opaque) |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 40 | { |
David Hildenbrand | 6482b0f | 2017-09-28 22:36:39 +0200 | [diff] [blame] | 41 | cpu_inject_cpu_timer((S390CPU *) opaque); |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 42 | } |
| 43 | #endif |
Alexander Graf | 10c339a | 2009-12-05 12:44:26 +0100 | [diff] [blame] | 44 | |
Thomas Huth | cded401 | 2017-07-24 10:52:49 +0200 | [diff] [blame] | 45 | #ifndef CONFIG_USER_ONLY |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 46 | |
Andreas Färber | 00b941e | 2013-06-29 18:55:54 +0200 | [diff] [blame] | 47 | hwaddr s390_cpu_get_phys_page_debug(CPUState *cs, vaddr vaddr) |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 48 | { |
Andreas Färber | 00b941e | 2013-06-29 18:55:54 +0200 | [diff] [blame] | 49 | S390CPU *cpu = S390_CPU(cs); |
| 50 | CPUS390XState *env = &cpu->env; |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 51 | target_ulong raddr; |
Thomas Huth | e3e09d8 | 2015-02-12 18:09:22 +0100 | [diff] [blame] | 52 | int prot; |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 53 | uint64_t asc = env->psw.mask & PSW_MASK_ASC; |
| 54 | |
| 55 | /* 31-Bit mode */ |
| 56 | if (!(env->psw.mask & PSW_MASK_64)) { |
| 57 | vaddr &= 0x7fffffff; |
| 58 | } |
| 59 | |
David Hildenbrand | 234779a | 2015-12-09 16:36:42 +0100 | [diff] [blame] | 60 | if (mmu_translate(env, vaddr, MMU_INST_FETCH, asc, &raddr, &prot, false)) { |
| 61 | return -1; |
| 62 | } |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 63 | return raddr; |
| 64 | } |
| 65 | |
David Hildenbrand | 770a637 | 2012-09-03 13:09:10 +0200 | [diff] [blame] | 66 | hwaddr s390_cpu_get_phys_addr_debug(CPUState *cs, vaddr vaddr) |
| 67 | { |
| 68 | hwaddr phys_addr; |
| 69 | target_ulong page; |
| 70 | |
| 71 | page = vaddr & TARGET_PAGE_MASK; |
| 72 | phys_addr = cpu_get_phys_page_debug(cs, page); |
| 73 | phys_addr += (vaddr & ~TARGET_PAGE_MASK); |
| 74 | |
| 75 | return phys_addr; |
| 76 | } |
| 77 | |
David Hildenbrand | 83f7f32 | 2017-09-28 22:36:46 +0200 | [diff] [blame] | 78 | static inline bool is_special_wait_psw(uint64_t psw_addr) |
| 79 | { |
| 80 | /* signal quiesce */ |
| 81 | return psw_addr == 0xfffUL; |
| 82 | } |
| 83 | |
| 84 | void s390_handle_wait(S390CPU *cpu) |
| 85 | { |
Christian Borntraeger | 4ada99a | 2018-02-09 12:25:43 +0000 | [diff] [blame] | 86 | CPUState *cs = CPU(cpu); |
| 87 | |
David Hildenbrand | 83f7f32 | 2017-09-28 22:36:46 +0200 | [diff] [blame] | 88 | if (s390_cpu_halt(cpu) == 0) { |
| 89 | #ifndef CONFIG_USER_ONLY |
| 90 | if (is_special_wait_psw(cpu->env.psw.addr)) { |
| 91 | qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); |
| 92 | } else { |
Christian Borntraeger | 4ada99a | 2018-02-09 12:25:43 +0000 | [diff] [blame] | 93 | cpu->env.crash_reason = S390_CRASH_REASON_DISABLED_WAIT; |
| 94 | qemu_system_guest_panicked(cpu_get_crash_info(cs)); |
David Hildenbrand | 83f7f32 | 2017-09-28 22:36:46 +0200 | [diff] [blame] | 95 | } |
| 96 | #endif |
| 97 | } |
| 98 | } |
| 99 | |
Andreas Färber | a4e3ad1 | 2012-03-14 01:38:22 +0100 | [diff] [blame] | 100 | void load_psw(CPUS390XState *env, uint64_t mask, uint64_t addr) |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 101 | { |
Aurelien Jarno | 311918b | 2015-06-13 00:46:00 +0200 | [diff] [blame] | 102 | uint64_t old_mask = env->psw.mask; |
| 103 | |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 104 | env->psw.addr = addr; |
| 105 | env->psw.mask = mask; |
David Hildenbrand | b3a184f | 2018-04-09 13:30:19 +0200 | [diff] [blame] | 106 | |
| 107 | /* KVM will handle all WAITs and trigger a WAIT exit on disabled_wait */ |
| 108 | if (!tcg_enabled()) { |
| 109 | return; |
David Hildenbrand | 3f10341 | 2015-02-24 14:15:29 +0100 | [diff] [blame] | 110 | } |
David Hildenbrand | b3a184f | 2018-04-09 13:30:19 +0200 | [diff] [blame] | 111 | env->cc_op = (mask >> 44) & 3; |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 112 | |
Aurelien Jarno | 311918b | 2015-06-13 00:46:00 +0200 | [diff] [blame] | 113 | if ((old_mask ^ mask) & PSW_MASK_PER) { |
Richard Henderson | dc79e92 | 2019-03-22 19:21:48 -0700 | [diff] [blame] | 114 | s390_cpu_recompute_watchpoints(env_cpu(env)); |
Aurelien Jarno | 311918b | 2015-06-13 00:46:00 +0200 | [diff] [blame] | 115 | } |
| 116 | |
David Hildenbrand | b3a184f | 2018-04-09 13:30:19 +0200 | [diff] [blame] | 117 | if (mask & PSW_MASK_WAIT) { |
Richard Henderson | dc79e92 | 2019-03-22 19:21:48 -0700 | [diff] [blame] | 118 | s390_handle_wait(env_archcpu(env)); |
David Hildenbrand | eb24f7c | 2014-09-30 10:57:29 +0200 | [diff] [blame] | 119 | } |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 120 | } |
| 121 | |
Thomas Huth | cded401 | 2017-07-24 10:52:49 +0200 | [diff] [blame] | 122 | uint64_t get_psw_mask(CPUS390XState *env) |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 123 | { |
David Hildenbrand | 3f10341 | 2015-02-24 14:15:29 +0100 | [diff] [blame] | 124 | uint64_t r = env->psw.mask; |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 125 | |
David Hildenbrand | 3f10341 | 2015-02-24 14:15:29 +0100 | [diff] [blame] | 126 | if (tcg_enabled()) { |
| 127 | env->cc_op = calc_cc(env, env->cc_op, env->cc_src, env->cc_dst, |
| 128 | env->cc_vr); |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 129 | |
David Hildenbrand | 3f10341 | 2015-02-24 14:15:29 +0100 | [diff] [blame] | 130 | r &= ~PSW_MASK_CC; |
| 131 | assert(!(env->cc_op & ~3)); |
| 132 | r |= (uint64_t)env->cc_op << 44; |
| 133 | } |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 134 | |
| 135 | return r; |
| 136 | } |
| 137 | |
Thomas Huth | cded401 | 2017-07-24 10:52:49 +0200 | [diff] [blame] | 138 | LowCore *cpu_map_lowcore(CPUS390XState *env) |
Cornelia Huck | 4782a23 | 2013-01-24 02:28:01 +0000 | [diff] [blame] | 139 | { |
| 140 | LowCore *lowcore; |
| 141 | hwaddr len = sizeof(LowCore); |
| 142 | |
| 143 | lowcore = cpu_physical_memory_map(env->psa, &len, 1); |
| 144 | |
| 145 | if (len < sizeof(LowCore)) { |
Richard Henderson | dc79e92 | 2019-03-22 19:21:48 -0700 | [diff] [blame] | 146 | cpu_abort(env_cpu(env), "Could not map lowcore\n"); |
Cornelia Huck | 4782a23 | 2013-01-24 02:28:01 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | return lowcore; |
| 150 | } |
| 151 | |
Thomas Huth | cded401 | 2017-07-24 10:52:49 +0200 | [diff] [blame] | 152 | void cpu_unmap_lowcore(LowCore *lowcore) |
Cornelia Huck | 4782a23 | 2013-01-24 02:28:01 +0000 | [diff] [blame] | 153 | { |
| 154 | cpu_physical_memory_unmap(lowcore, sizeof(LowCore), 1, sizeof(LowCore)); |
| 155 | } |
| 156 | |
David Hildenbrand | 3f10341 | 2015-02-24 14:15:29 +0100 | [diff] [blame] | 157 | void do_restart_interrupt(CPUS390XState *env) |
| 158 | { |
| 159 | uint64_t mask, addr; |
| 160 | LowCore *lowcore; |
| 161 | |
| 162 | lowcore = cpu_map_lowcore(env); |
| 163 | |
| 164 | lowcore->restart_old_psw.mask = cpu_to_be64(get_psw_mask(env)); |
| 165 | lowcore->restart_old_psw.addr = cpu_to_be64(env->psw.addr); |
| 166 | mask = be64_to_cpu(lowcore->restart_new_psw.mask); |
| 167 | addr = be64_to_cpu(lowcore->restart_new_psw.addr); |
| 168 | |
| 169 | cpu_unmap_lowcore(lowcore); |
David Hildenbrand | b1ab5f6 | 2017-09-28 22:37:02 +0200 | [diff] [blame] | 170 | env->pending_int &= ~INTERRUPT_RESTART; |
David Hildenbrand | 3f10341 | 2015-02-24 14:15:29 +0100 | [diff] [blame] | 171 | |
| 172 | load_psw(env, mask, addr); |
| 173 | } |
| 174 | |
Aurelien Jarno | 311918b | 2015-06-13 00:46:00 +0200 | [diff] [blame] | 175 | void s390_cpu_recompute_watchpoints(CPUState *cs) |
| 176 | { |
| 177 | const int wp_flags = BP_CPU | BP_MEM_WRITE | BP_STOP_BEFORE_ACCESS; |
| 178 | S390CPU *cpu = S390_CPU(cs); |
| 179 | CPUS390XState *env = &cpu->env; |
| 180 | |
| 181 | /* We are called when the watchpoints have changed. First |
| 182 | remove them all. */ |
| 183 | cpu_watchpoint_remove_all(cs, BP_CPU); |
| 184 | |
| 185 | /* Return if PER is not enabled */ |
| 186 | if (!(env->psw.mask & PSW_MASK_PER)) { |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | /* Return if storage-alteration event is not enabled. */ |
| 191 | if (!(env->cregs[9] & PER_CR9_EVENT_STORE)) { |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | if (env->cregs[10] == 0 && env->cregs[11] == -1LL) { |
| 196 | /* We can't create a watchoint spanning the whole memory range, so |
| 197 | split it in two parts. */ |
| 198 | cpu_watchpoint_insert(cs, 0, 1ULL << 63, wp_flags, NULL); |
| 199 | cpu_watchpoint_insert(cs, 1ULL << 63, 1ULL << 63, wp_flags, NULL); |
| 200 | } else if (env->cregs[10] > env->cregs[11]) { |
| 201 | /* The address range loops, create two watchpoints. */ |
| 202 | cpu_watchpoint_insert(cs, env->cregs[10], -env->cregs[10], |
| 203 | wp_flags, NULL); |
| 204 | cpu_watchpoint_insert(cs, 0, env->cregs[11] + 1, wp_flags, NULL); |
| 205 | |
| 206 | } else { |
| 207 | /* Default case, create a single watchpoint. */ |
| 208 | cpu_watchpoint_insert(cs, env->cregs[10], |
| 209 | env->cregs[11] - env->cregs[10] + 1, |
| 210 | wp_flags, NULL); |
| 211 | } |
| 212 | } |
| 213 | |
David Hildenbrand | 257619b | 2019-02-22 09:11:52 +0100 | [diff] [blame] | 214 | typedef struct SigpSaveArea { |
David Hildenbrand | cf729ba | 2017-09-28 22:36:51 +0200 | [diff] [blame] | 215 | uint64_t fprs[16]; /* 0x0000 */ |
| 216 | uint64_t grs[16]; /* 0x0080 */ |
| 217 | PSW psw; /* 0x0100 */ |
| 218 | uint8_t pad_0x0110[0x0118 - 0x0110]; /* 0x0110 */ |
| 219 | uint32_t prefix; /* 0x0118 */ |
| 220 | uint32_t fpc; /* 0x011c */ |
| 221 | uint8_t pad_0x0120[0x0124 - 0x0120]; /* 0x0120 */ |
| 222 | uint32_t todpr; /* 0x0124 */ |
| 223 | uint64_t cputm; /* 0x0128 */ |
| 224 | uint64_t ckc; /* 0x0130 */ |
| 225 | uint8_t pad_0x0138[0x0140 - 0x0138]; /* 0x0138 */ |
| 226 | uint32_t ars[16]; /* 0x0140 */ |
| 227 | uint64_t crs[16]; /* 0x0384 */ |
David Hildenbrand | 257619b | 2019-02-22 09:11:52 +0100 | [diff] [blame] | 228 | } SigpSaveArea; |
| 229 | QEMU_BUILD_BUG_ON(sizeof(SigpSaveArea) != 512); |
David Hildenbrand | cf729ba | 2017-09-28 22:36:51 +0200 | [diff] [blame] | 230 | |
| 231 | int s390_store_status(S390CPU *cpu, hwaddr addr, bool store_arch) |
| 232 | { |
| 233 | static const uint8_t ar_id = 1; |
David Hildenbrand | 257619b | 2019-02-22 09:11:52 +0100 | [diff] [blame] | 234 | SigpSaveArea *sa; |
David Hildenbrand | cf729ba | 2017-09-28 22:36:51 +0200 | [diff] [blame] | 235 | hwaddr len = sizeof(*sa); |
| 236 | int i; |
| 237 | |
| 238 | sa = cpu_physical_memory_map(addr, &len, 1); |
| 239 | if (!sa) { |
| 240 | return -EFAULT; |
| 241 | } |
| 242 | if (len != sizeof(*sa)) { |
| 243 | cpu_physical_memory_unmap(sa, len, 1, 0); |
| 244 | return -EFAULT; |
| 245 | } |
| 246 | |
| 247 | if (store_arch) { |
| 248 | cpu_physical_memory_write(offsetof(LowCore, ar_access_id), &ar_id, 1); |
| 249 | } |
| 250 | for (i = 0; i < 16; ++i) { |
David Hildenbrand | 4f83d7d | 2019-05-29 09:15:38 +0200 | [diff] [blame] | 251 | sa->fprs[i] = cpu_to_be64(*get_freg(&cpu->env, i)); |
David Hildenbrand | cf729ba | 2017-09-28 22:36:51 +0200 | [diff] [blame] | 252 | } |
| 253 | for (i = 0; i < 16; ++i) { |
| 254 | sa->grs[i] = cpu_to_be64(cpu->env.regs[i]); |
| 255 | } |
| 256 | sa->psw.addr = cpu_to_be64(cpu->env.psw.addr); |
| 257 | sa->psw.mask = cpu_to_be64(get_psw_mask(&cpu->env)); |
| 258 | sa->prefix = cpu_to_be32(cpu->env.psa); |
| 259 | sa->fpc = cpu_to_be32(cpu->env.fpc); |
| 260 | sa->todpr = cpu_to_be32(cpu->env.todpr); |
| 261 | sa->cputm = cpu_to_be64(cpu->env.cputm); |
| 262 | sa->ckc = cpu_to_be64(cpu->env.ckc >> 8); |
| 263 | for (i = 0; i < 16; ++i) { |
| 264 | sa->ars[i] = cpu_to_be32(cpu->env.aregs[i]); |
| 265 | } |
| 266 | for (i = 0; i < 16; ++i) { |
David Hildenbrand | dc0bbef | 2017-11-16 18:05:24 +0100 | [diff] [blame] | 267 | sa->crs[i] = cpu_to_be64(cpu->env.cregs[i]); |
David Hildenbrand | cf729ba | 2017-09-28 22:36:51 +0200 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | cpu_physical_memory_unmap(sa, len, 1, len); |
| 271 | |
| 272 | return 0; |
| 273 | } |
David Hildenbrand | f875cb0 | 2017-09-28 22:36:52 +0200 | [diff] [blame] | 274 | |
David Hildenbrand | 2cca53f | 2019-02-22 09:11:51 +0100 | [diff] [blame] | 275 | typedef struct SigpAdtlSaveArea { |
| 276 | uint64_t vregs[32][2]; /* 0x0000 */ |
| 277 | uint8_t pad_0x0200[0x0400 - 0x0200]; /* 0x0200 */ |
| 278 | uint64_t gscb[4]; /* 0x0400 */ |
| 279 | uint8_t pad_0x0420[0x1000 - 0x0420]; /* 0x0420 */ |
| 280 | } SigpAdtlSaveArea; |
| 281 | QEMU_BUILD_BUG_ON(sizeof(SigpAdtlSaveArea) != 4096); |
| 282 | |
David Hildenbrand | f875cb0 | 2017-09-28 22:36:52 +0200 | [diff] [blame] | 283 | #define ADTL_GS_MIN_SIZE 2048 /* minimal size of adtl save area for GS */ |
| 284 | int s390_store_adtl_status(S390CPU *cpu, hwaddr addr, hwaddr len) |
| 285 | { |
David Hildenbrand | 2cca53f | 2019-02-22 09:11:51 +0100 | [diff] [blame] | 286 | SigpAdtlSaveArea *sa; |
David Hildenbrand | f875cb0 | 2017-09-28 22:36:52 +0200 | [diff] [blame] | 287 | hwaddr save = len; |
David Hildenbrand | 2cca53f | 2019-02-22 09:11:51 +0100 | [diff] [blame] | 288 | int i; |
David Hildenbrand | f875cb0 | 2017-09-28 22:36:52 +0200 | [diff] [blame] | 289 | |
David Hildenbrand | 2cca53f | 2019-02-22 09:11:51 +0100 | [diff] [blame] | 290 | sa = cpu_physical_memory_map(addr, &save, 1); |
| 291 | if (!sa) { |
David Hildenbrand | f875cb0 | 2017-09-28 22:36:52 +0200 | [diff] [blame] | 292 | return -EFAULT; |
| 293 | } |
| 294 | if (save != len) { |
David Hildenbrand | 2cca53f | 2019-02-22 09:11:51 +0100 | [diff] [blame] | 295 | cpu_physical_memory_unmap(sa, len, 1, 0); |
David Hildenbrand | f875cb0 | 2017-09-28 22:36:52 +0200 | [diff] [blame] | 296 | return -EFAULT; |
| 297 | } |
| 298 | |
David Hildenbrand | f875cb0 | 2017-09-28 22:36:52 +0200 | [diff] [blame] | 299 | if (s390_has_feat(S390_FEAT_VECTOR)) { |
David Hildenbrand | 2cca53f | 2019-02-22 09:11:51 +0100 | [diff] [blame] | 300 | for (i = 0; i < 32; i++) { |
David Hildenbrand | 4f83d7d | 2019-05-29 09:15:38 +0200 | [diff] [blame] | 301 | sa->vregs[i][0] = cpu_to_be64(cpu->env.vregs[i][0]); |
| 302 | sa->vregs[i][1] = cpu_to_be64(cpu->env.vregs[i][1]); |
David Hildenbrand | 2cca53f | 2019-02-22 09:11:51 +0100 | [diff] [blame] | 303 | } |
David Hildenbrand | f875cb0 | 2017-09-28 22:36:52 +0200 | [diff] [blame] | 304 | } |
| 305 | if (s390_has_feat(S390_FEAT_GUARDED_STORAGE) && len >= ADTL_GS_MIN_SIZE) { |
David Hildenbrand | 2cca53f | 2019-02-22 09:11:51 +0100 | [diff] [blame] | 306 | for (i = 0; i < 4; i++) { |
| 307 | sa->gscb[i] = cpu_to_be64(cpu->env.gscb[i]); |
| 308 | } |
David Hildenbrand | f875cb0 | 2017-09-28 22:36:52 +0200 | [diff] [blame] | 309 | } |
| 310 | |
David Hildenbrand | 2cca53f | 2019-02-22 09:11:51 +0100 | [diff] [blame] | 311 | cpu_physical_memory_unmap(sa, len, 1, len); |
David Hildenbrand | f875cb0 | 2017-09-28 22:36:52 +0200 | [diff] [blame] | 312 | return 0; |
| 313 | } |
Alexander Graf | d5a4396 | 2011-03-23 10:58:07 +0100 | [diff] [blame] | 314 | #endif /* CONFIG_USER_ONLY */ |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 315 | |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 316 | void s390_cpu_dump_state(CPUState *cs, FILE *f, int flags) |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 317 | { |
| 318 | S390CPU *cpu = S390_CPU(cs); |
| 319 | CPUS390XState *env = &cpu->env; |
| 320 | int i; |
| 321 | |
| 322 | if (env->cc_op > 3) { |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 323 | qemu_fprintf(f, "PSW=mask %016" PRIx64 " addr %016" PRIx64 " cc %15s\n", |
| 324 | env->psw.mask, env->psw.addr, cc_name(env->cc_op)); |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 325 | } else { |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 326 | qemu_fprintf(f, "PSW=mask %016" PRIx64 " addr %016" PRIx64 " cc %02x\n", |
| 327 | env->psw.mask, env->psw.addr, env->cc_op); |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | for (i = 0; i < 16; i++) { |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 331 | qemu_fprintf(f, "R%02d=%016" PRIx64, i, env->regs[i]); |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 332 | if ((i % 4) == 3) { |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 333 | qemu_fprintf(f, "\n"); |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 334 | } else { |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 335 | qemu_fprintf(f, " "); |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | |
Richard Henderson | af6e5ea | 2018-05-10 20:38:23 -0700 | [diff] [blame] | 339 | if (flags & CPU_DUMP_FPU) { |
| 340 | if (s390_has_feat(S390_FEAT_VECTOR)) { |
| 341 | for (i = 0; i < 32; i++) { |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 342 | qemu_fprintf(f, "V%02d=%016" PRIx64 "%016" PRIx64 "%c", |
David Hildenbrand | 4f83d7d | 2019-05-29 09:15:38 +0200 | [diff] [blame] | 343 | i, env->vregs[i][0], env->vregs[i][1], |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 344 | i % 2 ? '\n' : ' '); |
Richard Henderson | af6e5ea | 2018-05-10 20:38:23 -0700 | [diff] [blame] | 345 | } |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 346 | } else { |
Richard Henderson | af6e5ea | 2018-05-10 20:38:23 -0700 | [diff] [blame] | 347 | for (i = 0; i < 16; i++) { |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 348 | qemu_fprintf(f, "F%02d=%016" PRIx64 "%c", |
David Hildenbrand | 4f83d7d | 2019-05-29 09:15:38 +0200 | [diff] [blame] | 349 | i, *get_freg(env, i), |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 350 | (i % 4) == 3 ? '\n' : ' '); |
Richard Henderson | af6e5ea | 2018-05-10 20:38:23 -0700 | [diff] [blame] | 351 | } |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 355 | #ifndef CONFIG_USER_ONLY |
| 356 | for (i = 0; i < 16; i++) { |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 357 | qemu_fprintf(f, "C%02d=%016" PRIx64, i, env->cregs[i]); |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 358 | if ((i % 4) == 3) { |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 359 | qemu_fprintf(f, "\n"); |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 360 | } else { |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 361 | qemu_fprintf(f, " "); |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | #endif |
| 365 | |
| 366 | #ifdef DEBUG_INLINE_BRANCHES |
| 367 | for (i = 0; i < CC_OP_MAX; i++) { |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 368 | qemu_fprintf(f, " %15s = %10ld\t%10ld\n", cc_name(i), |
| 369 | inline_branch_miss[i], inline_branch_hit[i]); |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 370 | } |
| 371 | #endif |
| 372 | |
Markus Armbruster | 90c84c5 | 2019-04-17 21:18:02 +0200 | [diff] [blame] | 373 | qemu_fprintf(f, "\n"); |
Thomas Huth | b5bd2e9 | 2017-07-24 10:52:46 +0200 | [diff] [blame] | 374 | } |
David Hildenbrand | c534055 | 2017-08-18 13:43:44 +0200 | [diff] [blame] | 375 | |
| 376 | const char *cc_name(enum cc_op cc_op) |
| 377 | { |
| 378 | static const char * const cc_names[] = { |
| 379 | [CC_OP_CONST0] = "CC_OP_CONST0", |
| 380 | [CC_OP_CONST1] = "CC_OP_CONST1", |
| 381 | [CC_OP_CONST2] = "CC_OP_CONST2", |
| 382 | [CC_OP_CONST3] = "CC_OP_CONST3", |
| 383 | [CC_OP_DYNAMIC] = "CC_OP_DYNAMIC", |
| 384 | [CC_OP_STATIC] = "CC_OP_STATIC", |
| 385 | [CC_OP_NZ] = "CC_OP_NZ", |
| 386 | [CC_OP_LTGT_32] = "CC_OP_LTGT_32", |
| 387 | [CC_OP_LTGT_64] = "CC_OP_LTGT_64", |
| 388 | [CC_OP_LTUGTU_32] = "CC_OP_LTUGTU_32", |
| 389 | [CC_OP_LTUGTU_64] = "CC_OP_LTUGTU_64", |
| 390 | [CC_OP_LTGT0_32] = "CC_OP_LTGT0_32", |
| 391 | [CC_OP_LTGT0_64] = "CC_OP_LTGT0_64", |
| 392 | [CC_OP_ADD_64] = "CC_OP_ADD_64", |
| 393 | [CC_OP_ADDU_64] = "CC_OP_ADDU_64", |
| 394 | [CC_OP_ADDC_64] = "CC_OP_ADDC_64", |
| 395 | [CC_OP_SUB_64] = "CC_OP_SUB_64", |
| 396 | [CC_OP_SUBU_64] = "CC_OP_SUBU_64", |
| 397 | [CC_OP_SUBB_64] = "CC_OP_SUBB_64", |
| 398 | [CC_OP_ABS_64] = "CC_OP_ABS_64", |
| 399 | [CC_OP_NABS_64] = "CC_OP_NABS_64", |
| 400 | [CC_OP_ADD_32] = "CC_OP_ADD_32", |
| 401 | [CC_OP_ADDU_32] = "CC_OP_ADDU_32", |
| 402 | [CC_OP_ADDC_32] = "CC_OP_ADDC_32", |
| 403 | [CC_OP_SUB_32] = "CC_OP_SUB_32", |
| 404 | [CC_OP_SUBU_32] = "CC_OP_SUBU_32", |
| 405 | [CC_OP_SUBB_32] = "CC_OP_SUBB_32", |
| 406 | [CC_OP_ABS_32] = "CC_OP_ABS_32", |
| 407 | [CC_OP_NABS_32] = "CC_OP_NABS_32", |
| 408 | [CC_OP_COMP_32] = "CC_OP_COMP_32", |
| 409 | [CC_OP_COMP_64] = "CC_OP_COMP_64", |
| 410 | [CC_OP_TM_32] = "CC_OP_TM_32", |
| 411 | [CC_OP_TM_64] = "CC_OP_TM_64", |
| 412 | [CC_OP_NZ_F32] = "CC_OP_NZ_F32", |
| 413 | [CC_OP_NZ_F64] = "CC_OP_NZ_F64", |
| 414 | [CC_OP_NZ_F128] = "CC_OP_NZ_F128", |
| 415 | [CC_OP_ICM] = "CC_OP_ICM", |
| 416 | [CC_OP_SLA_32] = "CC_OP_SLA_32", |
| 417 | [CC_OP_SLA_64] = "CC_OP_SLA_64", |
| 418 | [CC_OP_FLOGR] = "CC_OP_FLOGR", |
David Hildenbrand | 6d93033 | 2019-02-25 21:03:18 +0100 | [diff] [blame] | 419 | [CC_OP_LCBB] = "CC_OP_LCBB", |
David Hildenbrand | ff825c6 | 2019-04-11 10:00:25 +0200 | [diff] [blame] | 420 | [CC_OP_VC] = "CC_OP_VC", |
David Hildenbrand | c534055 | 2017-08-18 13:43:44 +0200 | [diff] [blame] | 421 | }; |
| 422 | |
| 423 | return cc_names[cc_op]; |
| 424 | } |