slirp: Common lhost/fhost union
[qemu.git] / target / s390x / gdbstub.c
blob94ab74d58f67a7e980e06ddaae3048da748395e9
1 /*
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/>.
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"
28 int s390_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
30 S390CPU *cpu = S390_CPU(cs);
31 CPUS390XState *env = &cpu->env;
32 uint64_t val;
33 int cc_op;
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);
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]);
49 return 0;
52 int s390_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
54 S390CPU *cpu = S390_CPU(cs);
55 CPUS390XState *env = &cpu->env;
56 target_ulong tmpl = ldtul_p(mem_buf);
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);
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;
74 return 8;
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
83 static int cpu_read_ac_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
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;
93 static int cpu_write_ac_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
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;
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
112 static int cpu_read_fp_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
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;
124 static int cpu_write_fp_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
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;
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
146 static int cpu_read_vreg(CPUS390XState *env, uint8_t *mem_buf, int n)
148 int ret;
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;
162 return ret;
165 static int cpu_write_vreg(CPUS390XState *env, uint8_t *mem_buf, int n)
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;
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
186 #ifndef CONFIG_USER_ONLY
187 static int cpu_read_c_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
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;
197 static int cpu_write_c_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
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));
205 cpu_synchronize_post_init(ENV_GET_CPU(env));
206 return 8;
207 default:
208 return 0;
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
224 static int cpu_read_virt_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
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;
248 static int cpu_write_virt_reg(CPUS390XState *env, uint8_t *mem_buf, int n)
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;
287 #endif
289 void s390_cpu_gdb_init(CPUState *cs)
291 gdb_register_coprocessor(cs, cpu_read_ac_reg,
292 cpu_write_ac_reg,
293 S390_NUM_AC_REGS, "s390-acr.xml", 0);
295 gdb_register_coprocessor(cs, cpu_read_fp_reg,
296 cpu_write_fp_reg,
297 S390_NUM_FP_REGS, "s390-fpr.xml", 0);
299 gdb_register_coprocessor(cs, cpu_read_vreg,
300 cpu_write_vreg,
301 S390_NUM_VREGS, "s390-vx.xml", 0);
303 #ifndef CONFIG_USER_ONLY
304 gdb_register_coprocessor(cs, cpu_read_c_reg,
305 cpu_write_c_reg,
306 S390_NUM_C_REGS, "s390-cr.xml", 0);
308 if (kvm_enabled()) {
309 gdb_register_coprocessor(cs, cpu_read_virt_reg,
310 cpu_write_virt_reg,
311 S390_NUM_VIRT_REGS, "s390-virt.xml", 0);
313 #endif