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.1 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
, GByteArray
*buf
, int n
)
119 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
120 CPUPPCState
*env
= &cpu
->env
;
122 int r
= ppc_gdb_register_len(n
);
130 gdb_get_regl(buf
, env
->gpr
[n
]);
133 gdb_get_float64(buf
, *cpu_fpr_ptr(env
, n
- 32));
137 gdb_get_regl(buf
, env
->nip
);
140 gdb_get_regl(buf
, env
->msr
);
146 for (i
= 0; i
< 8; i
++) {
147 cr
|= env
->crf
[i
] << (32 - ((i
+ 1) * 4));
149 gdb_get_reg32(buf
, cr
);
153 gdb_get_regl(buf
, env
->lr
);
156 gdb_get_regl(buf
, env
->ctr
);
159 gdb_get_reg32(buf
, env
->xer
);
162 gdb_get_reg32(buf
, env
->fpscr
);
166 mem_buf
= buf
->data
+ buf
->len
- r
;
167 ppc_maybe_bswap_register(env
, mem_buf
, r
);
171 int ppc_cpu_gdb_read_register_apple(CPUState
*cs
, GByteArray
*buf
, int n
)
173 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
174 CPUPPCState
*env
= &cpu
->env
;
176 int r
= ppc_gdb_register_len_apple(n
);
184 gdb_get_reg64(buf
, env
->gpr
[n
]);
187 gdb_get_float64(buf
, *cpu_fpr_ptr(env
, n
- 32));
190 gdb_get_reg64(buf
, n
- 64);
191 gdb_get_reg64(buf
, 0);
195 gdb_get_reg64(buf
, env
->nip
);
198 gdb_get_reg64(buf
, env
->msr
);
204 for (i
= 0; i
< 8; i
++) {
205 cr
|= env
->crf
[i
] << (32 - ((i
+ 1) * 4));
207 gdb_get_reg32(buf
, cr
);
211 gdb_get_reg64(buf
, env
->lr
);
214 gdb_get_reg64(buf
, env
->ctr
);
217 gdb_get_reg32(buf
, env
->xer
);
220 gdb_get_reg64(buf
, env
->fpscr
);
224 mem_buf
= buf
->data
+ buf
->len
- r
;
225 ppc_maybe_bswap_register(env
, mem_buf
, r
);
229 int ppc_cpu_gdb_write_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
231 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
232 CPUPPCState
*env
= &cpu
->env
;
233 int r
= ppc_gdb_register_len(n
);
238 ppc_maybe_bswap_register(env
, mem_buf
, r
);
241 env
->gpr
[n
] = ldtul_p(mem_buf
);
244 *cpu_fpr_ptr(env
, n
- 32) = ldfq_p(mem_buf
);
248 env
->nip
= ldtul_p(mem_buf
);
251 ppc_store_msr(env
, ldtul_p(mem_buf
));
255 uint32_t cr
= ldl_p(mem_buf
);
257 for (i
= 0; i
< 8; i
++) {
258 env
->crf
[i
] = (cr
>> (32 - ((i
+ 1) * 4))) & 0xF;
263 env
->lr
= ldtul_p(mem_buf
);
266 env
->ctr
= ldtul_p(mem_buf
);
269 env
->xer
= ldl_p(mem_buf
);
273 store_fpscr(env
, ldtul_p(mem_buf
), 0xffffffff);
279 int ppc_cpu_gdb_write_register_apple(CPUState
*cs
, uint8_t *mem_buf
, int n
)
281 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
282 CPUPPCState
*env
= &cpu
->env
;
283 int r
= ppc_gdb_register_len_apple(n
);
288 ppc_maybe_bswap_register(env
, mem_buf
, r
);
291 env
->gpr
[n
] = ldq_p(mem_buf
);
294 *cpu_fpr_ptr(env
, n
- 32) = ldfq_p(mem_buf
);
298 env
->nip
= ldq_p(mem_buf
);
301 ppc_store_msr(env
, ldq_p(mem_buf
));
305 uint32_t cr
= ldl_p(mem_buf
);
307 for (i
= 0; i
< 8; i
++) {
308 env
->crf
[i
] = (cr
>> (32 - ((i
+ 1) * 4))) & 0xF;
313 env
->lr
= ldq_p(mem_buf
);
316 env
->ctr
= ldq_p(mem_buf
);
319 env
->xer
= ldl_p(mem_buf
);
323 store_fpscr(env
, ldq_p(mem_buf
), 0xffffffff);
330 #ifndef CONFIG_USER_ONLY
331 void ppc_gdb_gen_spr_xml(PowerPCCPU
*cpu
)
333 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cpu
);
334 CPUPPCState
*env
= &cpu
->env
;
337 unsigned int num_regs
= 0;
340 if (pcc
->gdb_spr_xml
) {
344 xml
= g_string_new("<?xml version=\"1.0\"?>");
345 g_string_append(xml
, "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">");
346 g_string_append(xml
, "<feature name=\"org.qemu.power.spr\">");
348 for (i
= 0; i
< ARRAY_SIZE(env
->spr_cb
); i
++) {
349 ppc_spr_t
*spr
= &env
->spr_cb
[i
];
355 spr_name
= g_ascii_strdown(spr
->name
, -1);
356 g_string_append_printf(xml
, "<reg name=\"%s\"", spr_name
);
359 g_string_append_printf(xml
, " bitsize=\"%d\"", TARGET_LONG_BITS
);
360 g_string_append(xml
, " group=\"spr\"/>");
363 * GDB identifies registers based on the order they are
364 * presented in the XML. These ids will not match QEMU's
365 * representation (which follows the PowerISA).
367 * Store the position of the current register description so
368 * we can make the correspondence later.
370 spr
->gdb_id
= num_regs
;
374 g_string_append(xml
, "</feature>");
376 pcc
->gdb_num_sprs
= num_regs
;
377 pcc
->gdb_spr_xml
= g_string_free(xml
, false);
380 const char *ppc_gdb_get_dynamic_xml(CPUState
*cs
, const char *xml_name
)
382 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cs
);
384 if (strcmp(xml_name
, "power-spr.xml") == 0) {
385 return pcc
->gdb_spr_xml
;