1 /* 2 * s390x gdb server stub 3 * 4 * Copyright (c) 2003-2005 Fabrice Bellard 5 * Copyright (c) 2013 SUSE LINUX Products GmbH 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 10 * version 2 of the License, or (at your option) any later version. 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 18 * License along with this library; if not, see <http://www.gnu.org/licenses/>. 19 */ 20 #include "qemu/osdep.h" 21 #include "qemu-common.h" 22 #include "cpu.h" 23 #include "exec/exec-all.h" 24 #include "exec/gdbstub.h" 25 #include "qemu/bitops.h" 26 #include "sysemu/hw_accel.h" 27 28 int s390_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) 29 { 30 S390CPU *cpu = S390_CPU(cs); 31 CPUS390XState *env = &cpu->env; 32 uint64_t val; 33 int cc_op; 34 35 switch (n) { 36 case S390_PSWM_REGNUM: 37 if (tcg_enabled()) { 38 cc_op = calc_cc(env, env->cc_op, env->cc_src, env->cc_dst, 39 env->cc_vr); 40 val = deposit64(env->psw.mask, 44, 2, cc_op); 41 return gdb_get_regl(mem_buf, val); 42 } 43 return gdb_get_regl(mem_buf, env->psw.mask); 44 case S390_PSWA_REGNUM: 45 return gdb_get_regl(mem_buf, env->psw.addr); 46 case S390_R0_REGNUM ... S390_R15_REGNUM: 47 return gdb_get_regl(mem_buf, env->regs[n - S390_R0_REGNUM]); 48 } 49 return 0; 50 } 51 52 int s390_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) 53 { 54 S390CPU *cpu = S390_CPU(cs); 55 CPUS390XState *env = &cpu->env; 56 target_ulong tmpl = ldtul_p(mem_buf); 57 58 switch (n) { 59 case S390_PSWM_REGNUM: 60 env->psw.mask = tmpl; 61 if (tcg_enabled()) { 62 env->cc_op = extract64(tmpl, 44, 2); 63 } 64 break; 65 case S390_PSWA_REGNUM: 66 env->psw.addr = tmpl; 67 break; 68 case S390_R0_REGNUM ... S390_R15_REGNUM: 69 env->regs[n - S390_R0_REGNUM] = tmpl; 70 break; 71 default: 72 return 0; 73 } 74 return 8; 75 } 76 77 /* the values represent the positions in s390-acr.xml */ 78 #define S390_A0_REGNUM 0 79 #define S390_A15_REGNUM 15 80 /* total number of registers in s390-acr.xml */ 81 #define S390_NUM_AC_REGS 16 82 83 static int cpu_read_ac_reg(CPUS390XState *env, uint8_t *mem_buf, int n) 84 { 85 switch (n) { 86 case S390_A0_REGNUM ... S390_A15_REGNUM: 87 return gdb_get_reg32(mem_buf, env->aregs[n]); 88 default: 89 return 0; 90 } 91 } 92 93 static int cpu_write_ac_reg(CPUS390XState *env, uint8_t *mem_buf, int n) 94 { 95 switch (n) { 96 case S390_A0_REGNUM ... S390_A15_REGNUM: 97 env->aregs[n] = ldl_p(mem_buf); 98 cpu_synchronize_post_init(ENV_GET_CPU(env)); 99 return 4; 100 default: 101 return 0; 102 } 103 } 104 105 /* the values represent the positions in s390-fpr.xml */ 106 #define S390_FPC_REGNUM 0 107 #define S390_F0_REGNUM 1 108 #define S390_F15_REGNUM 16 109 /* total number of registers in s390-fpr.xml */ 110 #define S390_NUM_FP_REGS 17 111 112 static int cpu_read_fp_reg(CPUS390XState *env, uint8_t *mem_buf, int n) 113 { 114 switch (n) { 115 case S390_FPC_REGNUM: 116 return gdb_get_reg32(mem_buf, env->fpc); 117 case S390_F0_REGNUM ... S390_F15_REGNUM: 118 return gdb_get_reg64(mem_buf, get_freg(env, n - S390_F0_REGNUM)->ll); 119 default: 120 return 0; 121 } 122 } 123 124 static int cpu_write_fp_reg(CPUS390XState *env, uint8_t *mem_buf, int n) 125 { 126 switch (n) { 127 case S390_FPC_REGNUM: 128 env->fpc = ldl_p(mem_buf); 129 return 4; 130 case S390_F0_REGNUM ... S390_F15_REGNUM: 131 get_freg(env, n - S390_F0_REGNUM)->ll = ldtul_p(mem_buf); 132 return 8; 133 default: 134 return 0; 135 } 136 } 137 138 /* the values represent the positions in s390-vx.xml */ 139 #define S390_V0L_REGNUM 0 140 #define S390_V15L_REGNUM 15 141 #define S390_V16_REGNUM 16 142 #define S390_V31_REGNUM 31 143 /* total number of registers in s390-vx.xml */ 144 #define S390_NUM_VREGS 32 145 146 static int cpu_read_vreg(CPUS390XState *env, uint8_t *mem_buf, int n) 147 { 148 int ret; 149 150 switch (n) { 151 case S390_V0L_REGNUM ... S390_V15L_REGNUM: 152 ret = gdb_get_reg64(mem_buf, env->vregs[n][1].ll); 153 break; 154 case S390_V16_REGNUM ... S390_V31_REGNUM: 155 ret = gdb_get_reg64(mem_buf, env->vregs[n][0].ll); 156 ret += gdb_get_reg64(mem_buf + 8, env->vregs[n][1].ll); 157 break; 158 default: 159 ret = 0; 160 } 161 162 return ret; 163 } 164 165 static int cpu_write_vreg(CPUS390XState *env, uint8_t *mem_buf, int n) 166 { 167 switch (n) { 168 case S390_V0L_REGNUM ... S390_V15L_REGNUM: 169 env->vregs[n][1].ll = ldtul_p(mem_buf + 8); 170 return 8; 171 case S390_V16_REGNUM ... S390_V31_REGNUM: 172 env->vregs[n][0].ll = ldtul_p(mem_buf); 173 env->vregs[n][1].ll = ldtul_p(mem_buf + 8); 174 return 16; 175 default: 176 return 0; 177 } 178 } 179 180 /* the values represent the positions in s390-cr.xml */ 181 #define S390_C0_REGNUM 0 182 #define S390_C15_REGNUM 15 183 /* total number of registers in s390-cr.xml */ 184 #define S390_NUM_C_REGS 16 185 186 #ifndef CONFIG_USER_ONLY 187 static int cpu_read_c_reg(CPUS390XState *env, uint8_t *mem_buf, int n) 188 { 189 switch (n) { 190 case S390_C0_REGNUM ... S390_C15_REGNUM: 191 return gdb_get_regl(mem_buf, env->cregs[n]); 192 default: 193 return 0; 194 } 195 } 196 197 static int cpu_write_c_reg(CPUS390XState *env, uint8_t *mem_buf, int n) 198 { 199 switch (n) { 200 case S390_C0_REGNUM ... S390_C15_REGNUM: 201 env->cregs[n] = ldtul_p(mem_buf); 202 if (tcg_enabled()) { 203 tlb_flush(ENV_GET_CPU(env)); 204 } 205 cpu_synchronize_post_init(ENV_GET_CPU(env)); 206 return 8; 207 default: 208 return 0; 209 } 210 } 211 212 /* the values represent the positions in s390-virt.xml */ 213 #define S390_VIRT_CKC_REGNUM 0 214 #define S390_VIRT_CPUTM_REGNUM 1 215 #define S390_VIRT_BEA_REGNUM 2 216 #define S390_VIRT_PREFIX_REGNUM 3 217 #define S390_VIRT_PP_REGNUM 4 218 #define S390_VIRT_PFT_REGNUM 5 219 #define S390_VIRT_PFS_REGNUM 6 220 #define S390_VIRT_PFC_REGNUM 7 221 /* total number of registers in s390-virt.xml */ 222 #define S390_NUM_VIRT_REGS 8 223 224 static int cpu_read_virt_reg(CPUS390XState *env, uint8_t *mem_buf, int n) 225 { 226 switch (n) { 227 case S390_VIRT_CKC_REGNUM: 228 return gdb_get_regl(mem_buf, env->ckc); 229 case S390_VIRT_CPUTM_REGNUM: 230 return gdb_get_regl(mem_buf, env->cputm); 231 case S390_VIRT_BEA_REGNUM: 232 return gdb_get_regl(mem_buf, env->gbea); 233 case S390_VIRT_PREFIX_REGNUM: 234 return gdb_get_regl(mem_buf, env->psa); 235 case S390_VIRT_PP_REGNUM: 236 return gdb_get_regl(mem_buf, env->pp); 237 case S390_VIRT_PFT_REGNUM: 238 return gdb_get_regl(mem_buf, env->pfault_token); 239 case S390_VIRT_PFS_REGNUM: 240 return gdb_get_regl(mem_buf, env->pfault_select); 241 case S390_VIRT_PFC_REGNUM: 242 return gdb_get_regl(mem_buf, env->pfault_compare); 243 default: 244 return 0; 245 } 246 } 247 248 static int cpu_write_virt_reg(CPUS390XState *env, uint8_t *mem_buf, int n) 249 { 250 switch (n) { 251 case S390_VIRT_CKC_REGNUM: 252 env->ckc = ldtul_p(mem_buf); 253 cpu_synchronize_post_init(ENV_GET_CPU(env)); 254 return 8; 255 case S390_VIRT_CPUTM_REGNUM: 256 env->cputm = ldtul_p(mem_buf); 257 cpu_synchronize_post_init(ENV_GET_CPU(env)); 258 return 8; 259 case S390_VIRT_BEA_REGNUM: 260 env->gbea = ldtul_p(mem_buf); 261 cpu_synchronize_post_init(ENV_GET_CPU(env)); 262 return 8; 263 case S390_VIRT_PREFIX_REGNUM: 264 env->psa = ldtul_p(mem_buf); 265 cpu_synchronize_post_init(ENV_GET_CPU(env)); 266 return 8; 267 case S390_VIRT_PP_REGNUM: 268 env->pp = ldtul_p(mem_buf); 269 cpu_synchronize_post_init(ENV_GET_CPU(env)); 270 return 8; 271 case S390_VIRT_PFT_REGNUM: 272 env->pfault_token = ldtul_p(mem_buf); 273 cpu_synchronize_post_init(ENV_GET_CPU(env)); 274 return 8; 275 case S390_VIRT_PFS_REGNUM: 276 env->pfault_select = ldtul_p(mem_buf); 277 cpu_synchronize_post_init(ENV_GET_CPU(env)); 278 return 8; 279 case S390_VIRT_PFC_REGNUM: 280 env->pfault_compare = ldtul_p(mem_buf); 281 cpu_synchronize_post_init(ENV_GET_CPU(env)); 282 return 8; 283 default: 284 return 0; 285 } 286 } 287 #endif 288 289 /* the values represent the positions in s390-gs.xml */ 290 #define S390_GS_RESERVED_REGNUM 0 291 #define S390_GS_GSD_REGNUM 1 292 #define S390_GS_GSSM_REGNUM 2 293 #define S390_GS_GSEPLA_REGNUM 3 294 /* total number of registers in s390-gs.xml */ 295 #define S390_NUM_GS_REGS 4 296 297 static int cpu_read_gs_reg(CPUS390XState *env, uint8_t *mem_buf, int n) 298 { 299 return gdb_get_regl(mem_buf, env->gscb[n]); 300 } 301 302 static int cpu_write_gs_reg(CPUS390XState *env, uint8_t *mem_buf, int n) 303 { 304 env->gscb[n] = ldtul_p(mem_buf); 305 cpu_synchronize_post_init(ENV_GET_CPU(env)); 306 return 8; 307 } 308 309 void s390_cpu_gdb_init(CPUState *cs) 310 { 311 gdb_register_coprocessor(cs, cpu_read_ac_reg, 312 cpu_write_ac_reg, 313 S390_NUM_AC_REGS, "s390-acr.xml", 0); 314 315 gdb_register_coprocessor(cs, cpu_read_fp_reg, 316 cpu_write_fp_reg, 317 S390_NUM_FP_REGS, "s390-fpr.xml", 0); 318 319 gdb_register_coprocessor(cs, cpu_read_vreg, 320 cpu_write_vreg, 321 S390_NUM_VREGS, "s390-vx.xml", 0); 322 323 gdb_register_coprocessor(cs, cpu_read_gs_reg, 324 cpu_write_gs_reg, 325 S390_NUM_GS_REGS, "s390-gs.xml", 0); 326 327 #ifndef CONFIG_USER_ONLY 328 gdb_register_coprocessor(cs, cpu_read_c_reg, 329 cpu_write_c_reg, 330 S390_NUM_C_REGS, "s390-cr.xml", 0); 331 332 if (kvm_enabled()) { 333 gdb_register_coprocessor(cs, cpu_read_virt_reg, 334 cpu_write_virt_reg, 335 S390_NUM_VIRT_REGS, "s390-virt.xml", 0); 336 } 337 #endif 338 } 339