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"
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
;
36 case S390_PSWM_REGNUM
:
38 cc_op
= calc_cc(env
, env
->cc_op
, env
->cc_src
, env
->cc_dst
,
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
]);
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
);
59 case S390_PSWM_REGNUM
:
62 env
->cc_op
= extract64(tmpl
, 44, 2);
65 case S390_PSWA_REGNUM
:
68 case S390_R0_REGNUM
... S390_R15_REGNUM
:
69 env
->regs
[n
- S390_R0_REGNUM
] = tmpl
;
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
)
86 case S390_A0_REGNUM
... S390_A15_REGNUM
:
87 return gdb_get_reg32(mem_buf
, env
->aregs
[n
]);
93 static int cpu_write_ac_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int 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
));
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
)
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
);
124 static int cpu_write_fp_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
127 case S390_FPC_REGNUM
:
128 env
->fpc
= ldl_p(mem_buf
);
130 case S390_F0_REGNUM
... S390_F15_REGNUM
:
131 get_freg(env
, n
- S390_F0_REGNUM
)->ll
= ldtul_p(mem_buf
);
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
)
151 case S390_V0L_REGNUM
... S390_V15L_REGNUM
:
152 ret
= gdb_get_reg64(mem_buf
, env
->vregs
[n
][1].ll
);
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
);
165 static int cpu_write_vreg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
168 case S390_V0L_REGNUM
... S390_V15L_REGNUM
:
169 env
->vregs
[n
][1].ll
= ldtul_p(mem_buf
+ 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);
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
)
190 case S390_C0_REGNUM
... S390_C15_REGNUM
:
191 return gdb_get_regl(mem_buf
, env
->cregs
[n
]);
197 static int cpu_write_c_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
200 case S390_C0_REGNUM
... S390_C15_REGNUM
:
201 env
->cregs
[n
] = ldtul_p(mem_buf
);
203 tlb_flush(ENV_GET_CPU(env
));
205 cpu_synchronize_post_init(ENV_GET_CPU(env
));
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
)
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
);
248 static int cpu_write_virt_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
251 case S390_VIRT_CKC_REGNUM
:
252 env
->ckc
= ldtul_p(mem_buf
);
253 cpu_synchronize_post_init(ENV_GET_CPU(env
));
255 case S390_VIRT_CPUTM_REGNUM
:
256 env
->cputm
= ldtul_p(mem_buf
);
257 cpu_synchronize_post_init(ENV_GET_CPU(env
));
259 case S390_VIRT_BEA_REGNUM
:
260 env
->gbea
= ldtul_p(mem_buf
);
261 cpu_synchronize_post_init(ENV_GET_CPU(env
));
263 case S390_VIRT_PREFIX_REGNUM
:
264 env
->psa
= ldtul_p(mem_buf
);
265 cpu_synchronize_post_init(ENV_GET_CPU(env
));
267 case S390_VIRT_PP_REGNUM
:
268 env
->pp
= ldtul_p(mem_buf
);
269 cpu_synchronize_post_init(ENV_GET_CPU(env
));
271 case S390_VIRT_PFT_REGNUM
:
272 env
->pfault_token
= ldtul_p(mem_buf
);
273 cpu_synchronize_post_init(ENV_GET_CPU(env
));
275 case S390_VIRT_PFS_REGNUM
:
276 env
->pfault_select
= ldtul_p(mem_buf
);
277 cpu_synchronize_post_init(ENV_GET_CPU(env
));
279 case S390_VIRT_PFC_REGNUM
:
280 env
->pfault_compare
= ldtul_p(mem_buf
);
281 cpu_synchronize_post_init(ENV_GET_CPU(env
));
289 void s390_cpu_gdb_init(CPUState
*cs
)
291 gdb_register_coprocessor(cs
, cpu_read_ac_reg
,
293 S390_NUM_AC_REGS
, "s390-acr.xml", 0);
295 gdb_register_coprocessor(cs
, cpu_read_fp_reg
,
297 S390_NUM_FP_REGS
, "s390-fpr.xml", 0);
299 gdb_register_coprocessor(cs
, cpu_read_vreg
,
301 S390_NUM_VREGS
, "s390-vx.xml", 0);
303 #ifndef CONFIG_USER_ONLY
304 gdb_register_coprocessor(cs
, cpu_read_c_reg
,
306 S390_NUM_C_REGS
, "s390-cr.xml", 0);
309 gdb_register_coprocessor(cs
, cpu_read_virt_reg
,
311 S390_NUM_VIRT_REGS
, "s390-virt.xml", 0);