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"
27 int s390_cpu_gdb_read_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
29 S390CPU
*cpu
= S390_CPU(cs
);
30 CPUS390XState
*env
= &cpu
->env
;
35 case S390_PSWM_REGNUM
:
37 cc_op
= calc_cc(env
, env
->cc_op
, env
->cc_src
, env
->cc_dst
,
39 val
= deposit64(env
->psw
.mask
, 44, 2, cc_op
);
40 return gdb_get_regl(mem_buf
, val
);
42 return gdb_get_regl(mem_buf
, env
->psw
.mask
);
43 case S390_PSWA_REGNUM
:
44 return gdb_get_regl(mem_buf
, env
->psw
.addr
);
45 case S390_R0_REGNUM
... S390_R15_REGNUM
:
46 return gdb_get_regl(mem_buf
, env
->regs
[n
- S390_R0_REGNUM
]);
51 int s390_cpu_gdb_write_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
53 S390CPU
*cpu
= S390_CPU(cs
);
54 CPUS390XState
*env
= &cpu
->env
;
55 target_ulong tmpl
= ldtul_p(mem_buf
);
58 case S390_PSWM_REGNUM
:
61 env
->cc_op
= extract64(tmpl
, 44, 2);
64 case S390_PSWA_REGNUM
:
67 case S390_R0_REGNUM
... S390_R15_REGNUM
:
68 env
->regs
[n
- S390_R0_REGNUM
] = tmpl
;
76 /* the values represent the positions in s390-acr.xml */
77 #define S390_A0_REGNUM 0
78 #define S390_A15_REGNUM 15
79 /* total number of registers in s390-acr.xml */
80 #define S390_NUM_AC_REGS 16
82 static int cpu_read_ac_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
85 case S390_A0_REGNUM
... S390_A15_REGNUM
:
86 return gdb_get_reg32(mem_buf
, env
->aregs
[n
]);
92 static int cpu_write_ac_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
95 case S390_A0_REGNUM
... S390_A15_REGNUM
:
96 env
->aregs
[n
] = ldl_p(mem_buf
);
97 cpu_synchronize_post_init(ENV_GET_CPU(env
));
104 /* the values represent the positions in s390-fpr.xml */
105 #define S390_FPC_REGNUM 0
106 #define S390_F0_REGNUM 1
107 #define S390_F15_REGNUM 16
108 /* total number of registers in s390-fpr.xml */
109 #define S390_NUM_FP_REGS 17
111 static int cpu_read_fp_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
114 case S390_FPC_REGNUM
:
115 return gdb_get_reg32(mem_buf
, env
->fpc
);
116 case S390_F0_REGNUM
... S390_F15_REGNUM
:
117 return gdb_get_reg64(mem_buf
, get_freg(env
, n
- S390_F0_REGNUM
)->ll
);
123 static int cpu_write_fp_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
126 case S390_FPC_REGNUM
:
127 env
->fpc
= ldl_p(mem_buf
);
129 case S390_F0_REGNUM
... S390_F15_REGNUM
:
130 get_freg(env
, n
- S390_F0_REGNUM
)->ll
= ldtul_p(mem_buf
);
137 /* the values represent the positions in s390-vx.xml */
138 #define S390_V0L_REGNUM 0
139 #define S390_V15L_REGNUM 15
140 #define S390_V16_REGNUM 16
141 #define S390_V31_REGNUM 31
142 /* total number of registers in s390-vx.xml */
143 #define S390_NUM_VREGS 32
145 static int cpu_read_vreg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
150 case S390_V0L_REGNUM
... S390_V15L_REGNUM
:
151 ret
= gdb_get_reg64(mem_buf
, env
->vregs
[n
][1].ll
);
153 case S390_V16_REGNUM
... S390_V31_REGNUM
:
154 ret
= gdb_get_reg64(mem_buf
, env
->vregs
[n
][0].ll
);
155 ret
+= gdb_get_reg64(mem_buf
+ 8, env
->vregs
[n
][1].ll
);
164 static int cpu_write_vreg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
167 case S390_V0L_REGNUM
... S390_V15L_REGNUM
:
168 env
->vregs
[n
][1].ll
= ldtul_p(mem_buf
+ 8);
170 case S390_V16_REGNUM
... S390_V31_REGNUM
:
171 env
->vregs
[n
][0].ll
= ldtul_p(mem_buf
);
172 env
->vregs
[n
][1].ll
= ldtul_p(mem_buf
+ 8);
179 /* the values represent the positions in s390-cr.xml */
180 #define S390_C0_REGNUM 0
181 #define S390_C15_REGNUM 15
182 /* total number of registers in s390-cr.xml */
183 #define S390_NUM_C_REGS 16
185 #ifndef CONFIG_USER_ONLY
186 static int cpu_read_c_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
189 case S390_C0_REGNUM
... S390_C15_REGNUM
:
190 return gdb_get_regl(mem_buf
, env
->cregs
[n
]);
196 static int cpu_write_c_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
199 case S390_C0_REGNUM
... S390_C15_REGNUM
:
200 env
->cregs
[n
] = ldtul_p(mem_buf
);
202 tlb_flush(ENV_GET_CPU(env
), 1);
204 cpu_synchronize_post_init(ENV_GET_CPU(env
));
211 /* the values represent the positions in s390-virt.xml */
212 #define S390_VIRT_CKC_REGNUM 0
213 #define S390_VIRT_CPUTM_REGNUM 1
214 #define S390_VIRT_BEA_REGNUM 2
215 #define S390_VIRT_PREFIX_REGNUM 3
216 #define S390_VIRT_PP_REGNUM 4
217 #define S390_VIRT_PFT_REGNUM 5
218 #define S390_VIRT_PFS_REGNUM 6
219 #define S390_VIRT_PFC_REGNUM 7
220 /* total number of registers in s390-virt.xml */
221 #define S390_NUM_VIRT_REGS 8
223 static int cpu_read_virt_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
226 case S390_VIRT_CKC_REGNUM
:
227 return gdb_get_regl(mem_buf
, env
->ckc
);
228 case S390_VIRT_CPUTM_REGNUM
:
229 return gdb_get_regl(mem_buf
, env
->cputm
);
230 case S390_VIRT_BEA_REGNUM
:
231 return gdb_get_regl(mem_buf
, env
->gbea
);
232 case S390_VIRT_PREFIX_REGNUM
:
233 return gdb_get_regl(mem_buf
, env
->psa
);
234 case S390_VIRT_PP_REGNUM
:
235 return gdb_get_regl(mem_buf
, env
->pp
);
236 case S390_VIRT_PFT_REGNUM
:
237 return gdb_get_regl(mem_buf
, env
->pfault_token
);
238 case S390_VIRT_PFS_REGNUM
:
239 return gdb_get_regl(mem_buf
, env
->pfault_select
);
240 case S390_VIRT_PFC_REGNUM
:
241 return gdb_get_regl(mem_buf
, env
->pfault_compare
);
247 static int cpu_write_virt_reg(CPUS390XState
*env
, uint8_t *mem_buf
, int n
)
250 case S390_VIRT_CKC_REGNUM
:
251 env
->ckc
= ldtul_p(mem_buf
);
252 cpu_synchronize_post_init(ENV_GET_CPU(env
));
254 case S390_VIRT_CPUTM_REGNUM
:
255 env
->cputm
= ldtul_p(mem_buf
);
256 cpu_synchronize_post_init(ENV_GET_CPU(env
));
258 case S390_VIRT_BEA_REGNUM
:
259 env
->gbea
= ldtul_p(mem_buf
);
260 cpu_synchronize_post_init(ENV_GET_CPU(env
));
262 case S390_VIRT_PREFIX_REGNUM
:
263 env
->psa
= ldtul_p(mem_buf
);
264 cpu_synchronize_post_init(ENV_GET_CPU(env
));
266 case S390_VIRT_PP_REGNUM
:
267 env
->pp
= ldtul_p(mem_buf
);
268 cpu_synchronize_post_init(ENV_GET_CPU(env
));
270 case S390_VIRT_PFT_REGNUM
:
271 env
->pfault_token
= ldtul_p(mem_buf
);
272 cpu_synchronize_post_init(ENV_GET_CPU(env
));
274 case S390_VIRT_PFS_REGNUM
:
275 env
->pfault_select
= ldtul_p(mem_buf
);
276 cpu_synchronize_post_init(ENV_GET_CPU(env
));
278 case S390_VIRT_PFC_REGNUM
:
279 env
->pfault_compare
= ldtul_p(mem_buf
);
280 cpu_synchronize_post_init(ENV_GET_CPU(env
));
288 void s390_cpu_gdb_init(CPUState
*cs
)
290 gdb_register_coprocessor(cs
, cpu_read_ac_reg
,
292 S390_NUM_AC_REGS
, "s390-acr.xml", 0);
294 gdb_register_coprocessor(cs
, cpu_read_fp_reg
,
296 S390_NUM_FP_REGS
, "s390-fpr.xml", 0);
298 gdb_register_coprocessor(cs
, cpu_read_vreg
,
300 S390_NUM_VREGS
, "s390-vx.xml", 0);
302 #ifndef CONFIG_USER_ONLY
303 gdb_register_coprocessor(cs
, cpu_read_c_reg
,
305 S390_NUM_C_REGS
, "s390-cr.xml", 0);
308 gdb_register_coprocessor(cs
, cpu_read_virt_reg
,
310 S390_NUM_VIRT_REGS
, "s390-virt.xml", 0);