2 * s390x gdb server stub
4 * Copyright (c) 2003-2005 Fabrice Bellard
5 * Copyright (c) 2013 SUSE LINUX Products GmbH
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.
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.
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/>.
21 #include "qemu-common.h"
22 #include "exec/gdbstub.h"
23 #include "qemu/bitops.h"
25 int s390_cpu_gdb_read_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
27 S390CPU
*cpu
= S390_CPU(cs
);
28 CPUS390XState
*env
= &cpu
->env
;
33 case S390_PSWM_REGNUM
:
35 cc_op
= calc_cc(env
, env
->cc_op
, env
->cc_src
, env
->cc_dst
,
37 val
= deposit64(env
->psw
.mask
, 44, 2, cc_op
);
38 return gdb_get_regl(mem_buf
, val
);
40 return gdb_get_regl(mem_buf
, env
->psw
.mask
);
41 case S390_PSWA_REGNUM
:
42 return gdb_get_regl(mem_buf
, env
->psw
.addr
);
43 case S390_R0_REGNUM
... S390_R15_REGNUM
:
44 return gdb_get_regl(mem_buf
, env
->regs
[n
- S390_R0_REGNUM
]);
49 int s390_cpu_gdb_write_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
51 S390CPU
*cpu
= S390_CPU(cs
);
52 CPUS390XState
*env
= &cpu
->env
;
53 target_ulong tmpl
= ldtul_p(mem_buf
);
56 case S390_PSWM_REGNUM
:
59 env
->cc_op
= extract64(tmpl
, 44, 2);
62 case S390_PSWA_REGNUM
:
65 case S390_R0_REGNUM
... S390_R15_REGNUM
:
66 env
->regs
[n
- S390_R0_REGNUM
] = tmpl
;
74 /* the values represent the positions in s390-acr.xml */
75 #define S390_A0_REGNUM 0
76 #define S390_A15_REGNUM 15
77 /* total number of registers in s390-acr.xml */
78 #define S390_NUM_AC_REGS 16
80 static int cpu_read_ac_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
83 case S390_A0_REGNUM
... S390_A15_REGNUM
:
84 return gdb_get_reg32(mem_buf
, env
->aregs
[n
]);
90 static int cpu_write_ac_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
93 case S390_A0_REGNUM
... S390_A15_REGNUM
:
94 env
->aregs
[n
] = ldl_p(mem_buf
);
95 cpu_synchronize_post_init(ENV_GET_CPU(env
));
102 /* the values represent the positions in s390-fpr.xml */
103 #define S390_FPC_REGNUM 0
104 #define S390_F0_REGNUM 1
105 #define S390_F15_REGNUM 16
106 /* total number of registers in s390-fpr.xml */
107 #define S390_NUM_FP_REGS 17
109 static int cpu_read_fp_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
112 case S390_FPC_REGNUM
:
113 return gdb_get_reg32(mem_buf
, env
->fpc
);
114 case S390_F0_REGNUM
... S390_F15_REGNUM
:
115 return gdb_get_reg64(mem_buf
, get_freg(env
, n
- S390_F0_REGNUM
)->ll
);
121 static int cpu_write_fp_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
124 case S390_FPC_REGNUM
:
125 env
->fpc
= ldl_p(mem_buf
);
127 case S390_F0_REGNUM
... S390_F15_REGNUM
:
128 get_freg(env
, n
- S390_F0_REGNUM
)->ll
= ldtul_p(mem_buf
);
135 /* the values represent the positions in s390-vx.xml */
136 #define S390_V0L_REGNUM 0
137 #define S390_V15L_REGNUM 15
138 #define S390_V16_REGNUM 16
139 #define S390_V31_REGNUM 31
140 /* total number of registers in s390-vx.xml */
141 #define S390_NUM_VREGS 32
143 static int cpu_read_vreg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
148 case S390_V0L_REGNUM
... S390_V15L_REGNUM
:
149 ret
= gdb_get_reg64(mem_buf
, env
->vregs
[n
][1].ll
);
151 case S390_V16_REGNUM
... S390_V31_REGNUM
:
152 ret
= gdb_get_reg64(mem_buf
, env
->vregs
[n
][0].ll
);
153 ret
+= gdb_get_reg64(mem_buf
+ 8, env
->vregs
[n
][1].ll
);
162 static int cpu_write_vreg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
165 case S390_V0L_REGNUM
... S390_V15L_REGNUM
:
166 env
->vregs
[n
][1].ll
= ldtul_p(mem_buf
+ 8);
168 case S390_V16_REGNUM
... S390_V31_REGNUM
:
169 env
->vregs
[n
][0].ll
= ldtul_p(mem_buf
);
170 env
->vregs
[n
][1].ll
= ldtul_p(mem_buf
+ 8);
177 void s390_cpu_gdb_init(CPUState
*cs
)
179 gdb_register_coprocessor(cs
, cpu_read_ac_reg
,
181 S390_NUM_AC_REGS
, "s390-acr.xml", 0);
183 gdb_register_coprocessor(cs
, cpu_read_fp_reg
,
185 S390_NUM_FP_REGS
, "s390-fpr.xml", 0);
187 gdb_register_coprocessor(cs
, cpu_read_vreg
,
189 S390_NUM_VREGS
, "s390-vx.xml", 0);