2013-07-07 14:54:12 +04:00
|
|
|
/*
|
|
|
|
* s390x gdb server stub
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2005 Fabrice Bellard
|
|
|
|
* Copyright (c) 2013 SUSE LINUX Products GmbH
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2019-01-29 16:37:47 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2013-07-07 14:54:12 +04:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2019-05-23 17:35:05 +03:00
|
|
|
|
2016-01-26 21:17:00 +03:00
|
|
|
#include "qemu/osdep.h"
|
2016-03-15 18:58:45 +03:00
|
|
|
#include "cpu.h"
|
2021-07-07 13:53:16 +03:00
|
|
|
#include "s390x-internal.h"
|
2016-03-15 15:18:37 +03:00
|
|
|
#include "exec/exec-all.h"
|
2013-06-29 06:18:45 +04:00
|
|
|
#include "exec/gdbstub.h"
|
2023-03-03 05:57:56 +03:00
|
|
|
#include "gdbstub/helpers.h"
|
2013-06-29 06:18:45 +04:00
|
|
|
#include "qemu/bitops.h"
|
2017-01-10 13:59:55 +03:00
|
|
|
#include "sysemu/hw_accel.h"
|
2019-05-23 17:35:05 +03:00
|
|
|
#include "sysemu/tcg.h"
|
2013-07-07 14:54:12 +04:00
|
|
|
|
2020-03-16 20:21:41 +03:00
|
|
|
int s390_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
|
2013-07-07 14:54:12 +04:00
|
|
|
{
|
2013-06-29 06:18:45 +04:00
|
|
|
S390CPU *cpu = S390_CPU(cs);
|
|
|
|
CPUS390XState *env = &cpu->env;
|
2013-07-07 14:54:12 +04:00
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
case S390_PSWM_REGNUM:
|
2021-06-15 06:07:43 +03:00
|
|
|
return gdb_get_regl(mem_buf, s390_cpu_get_psw_mask(env));
|
2013-07-07 14:54:12 +04:00
|
|
|
case S390_PSWA_REGNUM:
|
2013-07-07 15:05:05 +04:00
|
|
|
return gdb_get_regl(mem_buf, env->psw.addr);
|
2013-07-07 14:54:12 +04:00
|
|
|
case S390_R0_REGNUM ... S390_R15_REGNUM:
|
2014-08-29 17:52:17 +04:00
|
|
|
return gdb_get_regl(mem_buf, env->regs[n - S390_R0_REGNUM]);
|
2013-07-07 14:54:12 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-29 06:18:45 +04:00
|
|
|
int s390_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
|
2013-07-07 14:54:12 +04:00
|
|
|
{
|
2013-06-29 06:18:45 +04:00
|
|
|
S390CPU *cpu = S390_CPU(cs);
|
|
|
|
CPUS390XState *env = &cpu->env;
|
2014-08-29 17:52:16 +04:00
|
|
|
target_ulong tmpl = ldtul_p(mem_buf);
|
2013-07-07 14:54:12 +04:00
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
case S390_PSWM_REGNUM:
|
2021-06-15 06:07:43 +03:00
|
|
|
s390_cpu_set_psw(env, tmpl, env->psw.addr);
|
2013-07-07 14:54:12 +04:00
|
|
|
break;
|
|
|
|
case S390_PSWA_REGNUM:
|
|
|
|
env->psw.addr = tmpl;
|
|
|
|
break;
|
|
|
|
case S390_R0_REGNUM ... S390_R15_REGNUM:
|
2014-08-29 17:52:17 +04:00
|
|
|
env->regs[n - S390_R0_REGNUM] = tmpl;
|
2013-07-07 14:54:12 +04:00
|
|
|
break;
|
2014-08-29 17:52:16 +04:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the values represent the positions in s390-acr.xml */
|
|
|
|
#define S390_A0_REGNUM 0
|
|
|
|
#define S390_A15_REGNUM 15
|
|
|
|
/* total number of registers in s390-acr.xml */
|
|
|
|
#define S390_NUM_AC_REGS 16
|
|
|
|
|
2020-03-16 20:21:41 +03:00
|
|
|
static int cpu_read_ac_reg(CPUS390XState *env, GByteArray *buf, int n)
|
2014-08-29 17:52:16 +04:00
|
|
|
{
|
|
|
|
switch (n) {
|
2013-07-07 14:54:12 +04:00
|
|
|
case S390_A0_REGNUM ... S390_A15_REGNUM:
|
2020-03-16 20:21:41 +03:00
|
|
|
return gdb_get_reg32(buf, env->aregs[n]);
|
2014-08-29 17:52:16 +04:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpu_write_ac_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
|
|
|
|
{
|
|
|
|
switch (n) {
|
|
|
|
case S390_A0_REGNUM ... S390_A15_REGNUM:
|
|
|
|
env->aregs[n] = ldl_p(mem_buf);
|
2019-03-23 02:07:18 +03:00
|
|
|
cpu_synchronize_post_init(env_cpu(env));
|
2014-08-29 17:52:16 +04:00
|
|
|
return 4;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the values represent the positions in s390-fpr.xml */
|
|
|
|
#define S390_FPC_REGNUM 0
|
|
|
|
#define S390_F0_REGNUM 1
|
|
|
|
#define S390_F15_REGNUM 16
|
|
|
|
/* total number of registers in s390-fpr.xml */
|
|
|
|
#define S390_NUM_FP_REGS 17
|
|
|
|
|
2020-03-16 20:21:41 +03:00
|
|
|
static int cpu_read_fp_reg(CPUS390XState *env, GByteArray *buf, int n)
|
2014-08-29 17:52:16 +04:00
|
|
|
{
|
|
|
|
switch (n) {
|
2013-07-07 14:54:12 +04:00
|
|
|
case S390_FPC_REGNUM:
|
2020-03-16 20:21:41 +03:00
|
|
|
return gdb_get_reg32(buf, env->fpc);
|
2013-07-07 14:54:12 +04:00
|
|
|
case S390_F0_REGNUM ... S390_F15_REGNUM:
|
2020-03-16 20:21:41 +03:00
|
|
|
return gdb_get_reg64(buf, *get_freg(env, n - S390_F0_REGNUM));
|
2013-07-07 14:54:12 +04:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2014-08-29 17:52:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int cpu_write_fp_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
|
|
|
|
{
|
|
|
|
switch (n) {
|
|
|
|
case S390_FPC_REGNUM:
|
|
|
|
env->fpc = ldl_p(mem_buf);
|
|
|
|
return 4;
|
|
|
|
case S390_F0_REGNUM ... S390_F15_REGNUM:
|
2019-05-29 10:15:38 +03:00
|
|
|
*get_freg(env, n - S390_F0_REGNUM) = ldtul_p(mem_buf);
|
2014-08-29 17:52:16 +04:00
|
|
|
return 8;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-03 16:42:18 +04:00
|
|
|
/* the values represent the positions in s390-vx.xml */
|
|
|
|
#define S390_V0L_REGNUM 0
|
|
|
|
#define S390_V15L_REGNUM 15
|
|
|
|
#define S390_V16_REGNUM 16
|
|
|
|
#define S390_V31_REGNUM 31
|
|
|
|
/* total number of registers in s390-vx.xml */
|
|
|
|
#define S390_NUM_VREGS 32
|
|
|
|
|
2020-03-16 20:21:41 +03:00
|
|
|
static int cpu_read_vreg(CPUS390XState *env, GByteArray *buf, int n)
|
2014-06-03 16:42:18 +04:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
switch (n) {
|
|
|
|
case S390_V0L_REGNUM ... S390_V15L_REGNUM:
|
2020-03-16 20:21:41 +03:00
|
|
|
ret = gdb_get_reg64(buf, env->vregs[n][1]);
|
2014-06-03 16:42:18 +04:00
|
|
|
break;
|
|
|
|
case S390_V16_REGNUM ... S390_V31_REGNUM:
|
2020-03-16 20:21:41 +03:00
|
|
|
ret = gdb_get_reg64(buf, env->vregs[n][0]);
|
|
|
|
ret += gdb_get_reg64(buf, env->vregs[n][1]);
|
2014-06-03 16:42:18 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpu_write_vreg(CPUS390XState *env, uint8_t *mem_buf, int n)
|
|
|
|
{
|
|
|
|
switch (n) {
|
|
|
|
case S390_V0L_REGNUM ... S390_V15L_REGNUM:
|
2019-05-29 10:15:38 +03:00
|
|
|
env->vregs[n][1] = ldtul_p(mem_buf + 8);
|
2014-06-03 16:42:18 +04:00
|
|
|
return 8;
|
|
|
|
case S390_V16_REGNUM ... S390_V31_REGNUM:
|
2019-05-29 10:15:38 +03:00
|
|
|
env->vregs[n][0] = ldtul_p(mem_buf);
|
|
|
|
env->vregs[n][1] = ldtul_p(mem_buf + 8);
|
2014-06-03 16:42:18 +04:00
|
|
|
return 16;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-23 12:00:09 +03:00
|
|
|
/* the values represent the positions in s390-cr.xml */
|
|
|
|
#define S390_C0_REGNUM 0
|
|
|
|
#define S390_C15_REGNUM 15
|
|
|
|
/* total number of registers in s390-cr.xml */
|
|
|
|
#define S390_NUM_C_REGS 16
|
|
|
|
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
2020-03-16 20:21:41 +03:00
|
|
|
static int cpu_read_c_reg(CPUS390XState *env, GByteArray *buf, int n)
|
2015-06-23 12:00:09 +03:00
|
|
|
{
|
|
|
|
switch (n) {
|
|
|
|
case S390_C0_REGNUM ... S390_C15_REGNUM:
|
2020-03-16 20:21:41 +03:00
|
|
|
return gdb_get_regl(buf, env->cregs[n]);
|
2015-06-23 12:00:09 +03:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpu_write_c_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
|
|
|
|
{
|
|
|
|
switch (n) {
|
|
|
|
case S390_C0_REGNUM ... S390_C15_REGNUM:
|
|
|
|
env->cregs[n] = ldtul_p(mem_buf);
|
|
|
|
if (tcg_enabled()) {
|
2019-03-23 02:07:18 +03:00
|
|
|
tlb_flush(env_cpu(env));
|
2015-06-23 12:00:09 +03:00
|
|
|
}
|
2019-03-23 02:07:18 +03:00
|
|
|
cpu_synchronize_post_init(env_cpu(env));
|
2015-06-23 12:00:09 +03:00
|
|
|
return 8;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2015-10-01 11:49:44 +03:00
|
|
|
|
|
|
|
/* the values represent the positions in s390-virt.xml */
|
|
|
|
#define S390_VIRT_CKC_REGNUM 0
|
|
|
|
#define S390_VIRT_CPUTM_REGNUM 1
|
|
|
|
#define S390_VIRT_BEA_REGNUM 2
|
|
|
|
#define S390_VIRT_PREFIX_REGNUM 3
|
|
|
|
/* total number of registers in s390-virt.xml */
|
2023-03-14 13:18:13 +03:00
|
|
|
#define S390_NUM_VIRT_REGS 4
|
2015-10-01 11:49:44 +03:00
|
|
|
|
2020-03-16 20:21:41 +03:00
|
|
|
static int cpu_read_virt_reg(CPUS390XState *env, GByteArray *mem_buf, int n)
|
2015-10-01 11:49:44 +03:00
|
|
|
{
|
|
|
|
switch (n) {
|
|
|
|
case S390_VIRT_CKC_REGNUM:
|
|
|
|
return gdb_get_regl(mem_buf, env->ckc);
|
|
|
|
case S390_VIRT_CPUTM_REGNUM:
|
|
|
|
return gdb_get_regl(mem_buf, env->cputm);
|
|
|
|
case S390_VIRT_BEA_REGNUM:
|
|
|
|
return gdb_get_regl(mem_buf, env->gbea);
|
|
|
|
case S390_VIRT_PREFIX_REGNUM:
|
|
|
|
return gdb_get_regl(mem_buf, env->psa);
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpu_write_virt_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
|
|
|
|
{
|
|
|
|
switch (n) {
|
|
|
|
case S390_VIRT_CKC_REGNUM:
|
|
|
|
env->ckc = ldtul_p(mem_buf);
|
2019-03-23 02:07:18 +03:00
|
|
|
cpu_synchronize_post_init(env_cpu(env));
|
2015-10-01 11:49:44 +03:00
|
|
|
return 8;
|
|
|
|
case S390_VIRT_CPUTM_REGNUM:
|
|
|
|
env->cputm = ldtul_p(mem_buf);
|
2019-03-23 02:07:18 +03:00
|
|
|
cpu_synchronize_post_init(env_cpu(env));
|
2015-10-01 11:49:44 +03:00
|
|
|
return 8;
|
|
|
|
case S390_VIRT_BEA_REGNUM:
|
|
|
|
env->gbea = ldtul_p(mem_buf);
|
2019-03-23 02:07:18 +03:00
|
|
|
cpu_synchronize_post_init(env_cpu(env));
|
2015-10-01 11:49:44 +03:00
|
|
|
return 8;
|
|
|
|
case S390_VIRT_PREFIX_REGNUM:
|
|
|
|
env->psa = ldtul_p(mem_buf);
|
2019-03-23 02:07:18 +03:00
|
|
|
cpu_synchronize_post_init(env_cpu(env));
|
2015-10-01 11:49:44 +03:00
|
|
|
return 8;
|
2023-03-14 13:18:13 +03:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the values represent the positions in s390-virt-kvm.xml */
|
|
|
|
#define S390_VIRT_KVM_PP_REGNUM 0
|
|
|
|
#define S390_VIRT_KVM_PFT_REGNUM 1
|
|
|
|
#define S390_VIRT_KVM_PFS_REGNUM 2
|
|
|
|
#define S390_VIRT_KVM_PFC_REGNUM 3
|
|
|
|
/* total number of registers in s390-virt-kvm.xml */
|
|
|
|
#define S390_NUM_VIRT_KVM_REGS 4
|
|
|
|
|
|
|
|
static int cpu_read_virt_kvm_reg(CPUS390XState *env, GByteArray *mem_buf, int n)
|
|
|
|
{
|
|
|
|
switch (n) {
|
|
|
|
case S390_VIRT_KVM_PP_REGNUM:
|
|
|
|
return gdb_get_regl(mem_buf, env->pp);
|
|
|
|
case S390_VIRT_KVM_PFT_REGNUM:
|
|
|
|
return gdb_get_regl(mem_buf, env->pfault_token);
|
|
|
|
case S390_VIRT_KVM_PFS_REGNUM:
|
|
|
|
return gdb_get_regl(mem_buf, env->pfault_select);
|
|
|
|
case S390_VIRT_KVM_PFC_REGNUM:
|
|
|
|
return gdb_get_regl(mem_buf, env->pfault_compare);
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpu_write_virt_kvm_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
|
|
|
|
{
|
|
|
|
switch (n) {
|
|
|
|
case S390_VIRT_KVM_PP_REGNUM:
|
2015-10-01 11:49:44 +03:00
|
|
|
env->pp = ldtul_p(mem_buf);
|
2019-03-23 02:07:18 +03:00
|
|
|
cpu_synchronize_post_init(env_cpu(env));
|
2015-10-01 11:49:44 +03:00
|
|
|
return 8;
|
2023-03-14 13:18:13 +03:00
|
|
|
case S390_VIRT_KVM_PFT_REGNUM:
|
2015-10-01 11:49:44 +03:00
|
|
|
env->pfault_token = ldtul_p(mem_buf);
|
2019-03-23 02:07:18 +03:00
|
|
|
cpu_synchronize_post_init(env_cpu(env));
|
2015-10-01 11:49:44 +03:00
|
|
|
return 8;
|
2023-03-14 13:18:13 +03:00
|
|
|
case S390_VIRT_KVM_PFS_REGNUM:
|
2015-10-01 11:49:44 +03:00
|
|
|
env->pfault_select = ldtul_p(mem_buf);
|
2019-03-23 02:07:18 +03:00
|
|
|
cpu_synchronize_post_init(env_cpu(env));
|
2015-10-01 11:49:44 +03:00
|
|
|
return 8;
|
2023-03-14 13:18:13 +03:00
|
|
|
case S390_VIRT_KVM_PFC_REGNUM:
|
2015-10-01 11:49:44 +03:00
|
|
|
env->pfault_compare = ldtul_p(mem_buf);
|
2019-03-23 02:07:18 +03:00
|
|
|
cpu_synchronize_post_init(env_cpu(env));
|
2015-10-01 11:49:44 +03:00
|
|
|
return 8;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2015-06-23 12:00:09 +03:00
|
|
|
#endif
|
|
|
|
|
2017-03-08 14:41:14 +03:00
|
|
|
/* the values represent the positions in s390-gs.xml */
|
|
|
|
#define S390_GS_RESERVED_REGNUM 0
|
|
|
|
#define S390_GS_GSD_REGNUM 1
|
|
|
|
#define S390_GS_GSSM_REGNUM 2
|
|
|
|
#define S390_GS_GSEPLA_REGNUM 3
|
|
|
|
/* total number of registers in s390-gs.xml */
|
|
|
|
#define S390_NUM_GS_REGS 4
|
|
|
|
|
2020-03-16 20:21:41 +03:00
|
|
|
static int cpu_read_gs_reg(CPUS390XState *env, GByteArray *buf, int n)
|
2017-03-08 14:41:14 +03:00
|
|
|
{
|
2020-03-16 20:21:41 +03:00
|
|
|
return gdb_get_regl(buf, env->gscb[n]);
|
2017-03-08 14:41:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int cpu_write_gs_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
|
|
|
|
{
|
|
|
|
env->gscb[n] = ldtul_p(mem_buf);
|
2019-03-23 02:07:18 +03:00
|
|
|
cpu_synchronize_post_init(env_cpu(env));
|
2017-03-08 14:41:14 +03:00
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
2014-08-29 17:52:16 +04:00
|
|
|
void s390_cpu_gdb_init(CPUState *cs)
|
|
|
|
{
|
|
|
|
gdb_register_coprocessor(cs, cpu_read_ac_reg,
|
|
|
|
cpu_write_ac_reg,
|
|
|
|
S390_NUM_AC_REGS, "s390-acr.xml", 0);
|
|
|
|
|
|
|
|
gdb_register_coprocessor(cs, cpu_read_fp_reg,
|
|
|
|
cpu_write_fp_reg,
|
|
|
|
S390_NUM_FP_REGS, "s390-fpr.xml", 0);
|
2014-06-03 16:42:18 +04:00
|
|
|
|
|
|
|
gdb_register_coprocessor(cs, cpu_read_vreg,
|
|
|
|
cpu_write_vreg,
|
|
|
|
S390_NUM_VREGS, "s390-vx.xml", 0);
|
2015-06-23 12:00:09 +03:00
|
|
|
|
2017-03-08 14:41:14 +03:00
|
|
|
gdb_register_coprocessor(cs, cpu_read_gs_reg,
|
|
|
|
cpu_write_gs_reg,
|
|
|
|
S390_NUM_GS_REGS, "s390-gs.xml", 0);
|
|
|
|
|
2015-06-23 12:00:09 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
gdb_register_coprocessor(cs, cpu_read_c_reg,
|
|
|
|
cpu_write_c_reg,
|
|
|
|
S390_NUM_C_REGS, "s390-cr.xml", 0);
|
2015-10-01 11:49:44 +03:00
|
|
|
|
2023-03-14 13:18:13 +03:00
|
|
|
gdb_register_coprocessor(cs, cpu_read_virt_reg,
|
|
|
|
cpu_write_virt_reg,
|
|
|
|
S390_NUM_VIRT_REGS, "s390-virt.xml", 0);
|
|
|
|
|
2015-10-01 11:49:44 +03:00
|
|
|
if (kvm_enabled()) {
|
2023-03-14 13:18:13 +03:00
|
|
|
gdb_register_coprocessor(cs, cpu_read_virt_kvm_reg,
|
|
|
|
cpu_write_virt_kvm_reg,
|
|
|
|
S390_NUM_VIRT_KVM_REGS, "s390-virt-kvm.xml",
|
|
|
|
0);
|
2015-10-01 11:49:44 +03:00
|
|
|
}
|
2015-06-23 12:00:09 +03:00
|
|
|
#endif
|
2013-07-07 14:54:12 +04:00
|
|
|
}
|