2 * PowerPC 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"
22 #include "exec/gdbstub.h"
24 static int ppc_gdb_register_len_apple(int n
)
35 case 64 + 32: /* nip */
36 case 65 + 32: /* msr */
37 case 67 + 32: /* lr */
38 case 68 + 32: /* ctr */
39 case 70 + 32: /* fpscr */
41 case 66 + 32: /* cr */
42 case 69 + 32: /* xer */
49 static int ppc_gdb_register_len(int n
)
54 return sizeof(target_ulong
);
74 return sizeof(target_ulong
);
80 return sizeof(target_ulong
);
87 * We need to present the registers to gdb in the "current" memory
88 * ordering. For user-only mode we get this for free;
89 * TARGET_WORDS_BIGENDIAN is set to the proper ordering for the
90 * binary, and cannot be changed. For system mode,
91 * TARGET_WORDS_BIGENDIAN is always set, and we must check the current
92 * mode of the chip to see if we're running in little-endian.
94 void ppc_maybe_bswap_register(CPUPPCState
*env
, uint8_t *mem_buf
, int len
)
96 #ifndef CONFIG_USER_ONLY
99 } else if (len
== 4) {
100 bswap32s((uint32_t *)mem_buf
);
101 } else if (len
== 8) {
102 bswap64s((uint64_t *)mem_buf
);
104 g_assert_not_reached();
110 * Old gdb always expects FP registers. Newer (xml-aware) gdb only
111 * expects whatever the target description contains. Due to a
112 * historical mishap the FP registers appear in between core integer
113 * regs and PC, MSR, CR, and so forth. We hack round this by giving
114 * the FP regs zero size when talking to a newer gdb.
117 int ppc_cpu_gdb_read_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
119 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
120 CPUPPCState
*env
= &cpu
->env
;
121 int r
= ppc_gdb_register_len(n
);
129 gdb_get_regl(mem_buf
, env
->gpr
[n
]);
132 stfq_p(mem_buf
, *cpu_fpr_ptr(env
, n
- 32));
136 gdb_get_regl(mem_buf
, env
->nip
);
139 gdb_get_regl(mem_buf
, env
->msr
);
145 for (i
= 0; i
< 8; i
++) {
146 cr
|= env
->crf
[i
] << (32 - ((i
+ 1) * 4));
148 gdb_get_reg32(mem_buf
, cr
);
152 gdb_get_regl(mem_buf
, env
->lr
);
155 gdb_get_regl(mem_buf
, env
->ctr
);
158 gdb_get_reg32(mem_buf
, env
->xer
);
161 gdb_get_reg32(mem_buf
, env
->fpscr
);
165 ppc_maybe_bswap_register(env
, mem_buf
, r
);
169 int ppc_cpu_gdb_read_register_apple(CPUState
*cs
, uint8_t *mem_buf
, int n
)
171 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
172 CPUPPCState
*env
= &cpu
->env
;
173 int r
= ppc_gdb_register_len_apple(n
);
181 gdb_get_reg64(mem_buf
, env
->gpr
[n
]);
184 stfq_p(mem_buf
, *cpu_fpr_ptr(env
, n
- 32));
187 stq_p(mem_buf
, n
- 64);
188 stq_p(mem_buf
+ 8, 0);
192 gdb_get_reg64(mem_buf
, env
->nip
);
195 gdb_get_reg64(mem_buf
, env
->msr
);
201 for (i
= 0; i
< 8; i
++) {
202 cr
|= env
->crf
[i
] << (32 - ((i
+ 1) * 4));
204 gdb_get_reg32(mem_buf
, cr
);
208 gdb_get_reg64(mem_buf
, env
->lr
);
211 gdb_get_reg64(mem_buf
, env
->ctr
);
214 gdb_get_reg32(mem_buf
, env
->xer
);
217 gdb_get_reg64(mem_buf
, env
->fpscr
);
221 ppc_maybe_bswap_register(env
, mem_buf
, r
);
225 int ppc_cpu_gdb_write_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
227 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
228 CPUPPCState
*env
= &cpu
->env
;
229 int r
= ppc_gdb_register_len(n
);
234 ppc_maybe_bswap_register(env
, mem_buf
, r
);
237 env
->gpr
[n
] = ldtul_p(mem_buf
);
240 *cpu_fpr_ptr(env
, n
- 32) = ldfq_p(mem_buf
);
244 env
->nip
= ldtul_p(mem_buf
);
247 ppc_store_msr(env
, ldtul_p(mem_buf
));
251 uint32_t cr
= ldl_p(mem_buf
);
253 for (i
= 0; i
< 8; i
++) {
254 env
->crf
[i
] = (cr
>> (32 - ((i
+ 1) * 4))) & 0xF;
259 env
->lr
= ldtul_p(mem_buf
);
262 env
->ctr
= ldtul_p(mem_buf
);
265 env
->xer
= ldl_p(mem_buf
);
269 store_fpscr(env
, ldtul_p(mem_buf
), 0xffffffff);
275 int ppc_cpu_gdb_write_register_apple(CPUState
*cs
, uint8_t *mem_buf
, int n
)
277 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
278 CPUPPCState
*env
= &cpu
->env
;
279 int r
= ppc_gdb_register_len_apple(n
);
284 ppc_maybe_bswap_register(env
, mem_buf
, r
);
287 env
->gpr
[n
] = ldq_p(mem_buf
);
290 *cpu_fpr_ptr(env
, n
- 32) = ldfq_p(mem_buf
);
294 env
->nip
= ldq_p(mem_buf
);
297 ppc_store_msr(env
, ldq_p(mem_buf
));
301 uint32_t cr
= ldl_p(mem_buf
);
303 for (i
= 0; i
< 8; i
++) {
304 env
->crf
[i
] = (cr
>> (32 - ((i
+ 1) * 4))) & 0xF;
309 env
->lr
= ldq_p(mem_buf
);
312 env
->ctr
= ldq_p(mem_buf
);
315 env
->xer
= ldl_p(mem_buf
);
319 store_fpscr(env
, ldq_p(mem_buf
), 0xffffffff);
326 #ifndef CONFIG_USER_ONLY
327 void ppc_gdb_gen_spr_xml(PowerPCCPU
*cpu
)
329 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cpu
);
330 CPUPPCState
*env
= &cpu
->env
;
333 unsigned int num_regs
= 0;
336 if (pcc
->gdb_spr_xml
) {
340 xml
= g_string_new("<?xml version=\"1.0\"?>");
341 g_string_append(xml
, "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">");
342 g_string_append(xml
, "<feature name=\"org.qemu.power.spr\">");
344 for (i
= 0; i
< ARRAY_SIZE(env
->spr_cb
); i
++) {
345 ppc_spr_t
*spr
= &env
->spr_cb
[i
];
351 spr_name
= g_ascii_strdown(spr
->name
, -1);
352 g_string_append_printf(xml
, "<reg name=\"%s\"", spr_name
);
355 g_string_append_printf(xml
, " bitsize=\"%d\"", TARGET_LONG_BITS
);
356 g_string_append(xml
, " group=\"spr\"/>");
359 * GDB identifies registers based on the order they are
360 * presented in the XML. These ids will not match QEMU's
361 * representation (which follows the PowerISA).
363 * Store the position of the current register description so
364 * we can make the correspondence later.
366 spr
->gdb_id
= num_regs
;
370 g_string_append(xml
, "</feature>");
372 pcc
->gdb_num_sprs
= num_regs
;
373 pcc
->gdb_spr_xml
= g_string_free(xml
, false);
376 const char *ppc_gdb_get_dynamic_xml(CPUState
*cs
, const char *xml_name
)
378 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cs
);
380 if (strcmp(xml_name
, "power-spr.xml") == 0) {
381 return pcc
->gdb_spr_xml
;