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"
21 #include "qemu-common.h"
23 #include "exec/gdbstub.h"
25 static int ppc_gdb_register_len_apple(int n)
41 case 70+32: /* fpscr */
50 static int ppc_gdb_register_len(int n)
55 return sizeof(target_ulong);
75 return sizeof(target_ulong);
81 return sizeof(target_ulong);
87 /* We need to present the registers to gdb in the "current" memory ordering.
88 For user-only mode we get this for free; TARGET_WORDS_BIGENDIAN is set to
89 the proper ordering for the binary, and cannot be changed.
90 For system mode, TARGET_WORDS_BIGENDIAN is always set, and we must check
91 the current mode of the chip to see if we're running in little-endian. */
92 void ppc_maybe_bswap_register(CPUPPCState *env, uint8_t *mem_buf, int len)
94 #ifndef CONFIG_USER_ONLY
97 } else if (len == 4) {
98 bswap32s((uint32_t *)mem_buf);
99 } else if (len == 8) {
100 bswap64s((uint64_t *)mem_buf);
102 g_assert_not_reached();
107 /* Old gdb always expects FP registers. Newer (xml-aware) gdb only
108 * expects whatever the target description contains. Due to a
109 * historical mishap the FP registers appear in between core integer
110 * regs and PC, MSR, CR, and so forth. We hack round this by giving the
111 * FP regs zero size when talking to a newer gdb.
114 int ppc_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
116 PowerPCCPU *cpu = POWERPC_CPU(cs);
117 CPUPPCState *env = &cpu->env;
118 int r = ppc_gdb_register_len(n);
126 gdb_get_regl(mem_buf, env->gpr[n]);
129 stfq_p(mem_buf, env->fpr[n-32]);
133 gdb_get_regl(mem_buf, env->nip);
136 gdb_get_regl(mem_buf, env->msr);
142 for (i = 0; i < 8; i++) {
143 cr |= env->crf[i] << (32 - ((i + 1) * 4));
145 gdb_get_reg32(mem_buf, cr);
149 gdb_get_regl(mem_buf, env->lr);
152 gdb_get_regl(mem_buf, env->ctr);
155 gdb_get_regl(mem_buf, env->xer);
158 gdb_get_reg32(mem_buf, env->fpscr);
162 ppc_maybe_bswap_register(env, mem_buf, r);
166 int ppc_cpu_gdb_read_register_apple(CPUState *cs, uint8_t *mem_buf, int n)
168 PowerPCCPU *cpu = POWERPC_CPU(cs);
169 CPUPPCState *env = &cpu->env;
170 int r = ppc_gdb_register_len_apple(n);
178 gdb_get_reg64(mem_buf, env->gpr[n]);
181 stfq_p(mem_buf, env->fpr[n-32]);
184 stq_p(mem_buf, n - 64);
185 stq_p(mem_buf + 8, 0);
189 gdb_get_reg64(mem_buf, env->nip);
192 gdb_get_reg64(mem_buf, env->msr);
198 for (i = 0; i < 8; i++) {
199 cr |= env->crf[i] << (32 - ((i + 1) * 4));
201 gdb_get_reg32(mem_buf, cr);
205 gdb_get_reg64(mem_buf, env->lr);
208 gdb_get_reg64(mem_buf, env->ctr);
211 gdb_get_reg64(mem_buf, env->xer);
214 gdb_get_reg64(mem_buf, env->fpscr);
218 ppc_maybe_bswap_register(env, mem_buf, r);
222 int ppc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
224 PowerPCCPU *cpu = POWERPC_CPU(cs);
225 CPUPPCState *env = &cpu->env;
226 int r = ppc_gdb_register_len(n);
231 ppc_maybe_bswap_register(env, mem_buf, r);
234 env->gpr[n] = ldtul_p(mem_buf);
237 env->fpr[n-32] = ldfq_p(mem_buf);
241 env->nip = ldtul_p(mem_buf);
244 ppc_store_msr(env, ldtul_p(mem_buf));
248 uint32_t cr = ldl_p(mem_buf);
250 for (i = 0; i < 8; i++) {
251 env->crf[i] = (cr >> (32 - ((i + 1) * 4))) & 0xF;
256 env->lr = ldtul_p(mem_buf);
259 env->ctr = ldtul_p(mem_buf);
262 env->xer = ldtul_p(mem_buf);
266 store_fpscr(env, ldtul_p(mem_buf), 0xffffffff);
272 int ppc_cpu_gdb_write_register_apple(CPUState *cs, uint8_t *mem_buf, int n)
274 PowerPCCPU *cpu = POWERPC_CPU(cs);
275 CPUPPCState *env = &cpu->env;
276 int r = ppc_gdb_register_len_apple(n);
281 ppc_maybe_bswap_register(env, mem_buf, r);
284 env->gpr[n] = ldq_p(mem_buf);
287 env->fpr[n-32] = ldfq_p(mem_buf);
291 env->nip = ldq_p(mem_buf);
294 ppc_store_msr(env, ldq_p(mem_buf));
298 uint32_t cr = ldl_p(mem_buf);
300 for (i = 0; i < 8; i++) {
301 env->crf[i] = (cr >> (32 - ((i + 1) * 4))) & 0xF;
306 env->lr = ldq_p(mem_buf);
309 env->ctr = ldq_p(mem_buf);
312 env->xer = ldq_p(mem_buf);
316 store_fpscr(env, ldq_p(mem_buf), 0xffffffff);