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"
22 #include "exec/gdbstub.h"
24 static int ppc_gdb_register_len_apple(int n
)
40 case 70+32: /* fpscr */
49 static int ppc_gdb_register_len(int n
)
54 return sizeof(target_ulong
);
74 return sizeof(target_ulong
);
80 return sizeof(target_ulong
);
86 /* We need to present the registers to gdb in the "current" memory ordering.
87 For user-only mode we get this for free; TARGET_WORDS_BIGENDIAN is set to
88 the proper ordering for the binary, and cannot be changed.
89 For system mode, TARGET_WORDS_BIGENDIAN is always set, and we must check
90 the current mode of the chip to see if we're running in little-endian. */
91 void ppc_maybe_bswap_register(CPUPPCState
*env
, uint8_t *mem_buf
, int len
)
93 #ifndef CONFIG_USER_ONLY
96 } else if (len
== 4) {
97 bswap32s((uint32_t *)mem_buf
);
98 } else if (len
== 8) {
99 bswap64s((uint64_t *)mem_buf
);
101 g_assert_not_reached();
106 /* Old gdb always expects FP registers. Newer (xml-aware) gdb only
107 * expects whatever the target description contains. Due to a
108 * historical mishap the FP registers appear in between core integer
109 * regs and PC, MSR, CR, and so forth. We hack round this by giving the
110 * FP regs zero size when talking to a newer gdb.
113 int ppc_cpu_gdb_read_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
115 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
116 CPUPPCState
*env
= &cpu
->env
;
117 int r
= ppc_gdb_register_len(n
);
125 gdb_get_regl(mem_buf
, env
->gpr
[n
]);
128 stfq_p(mem_buf
, env
->fpr
[n
-32]);
132 gdb_get_regl(mem_buf
, env
->nip
);
135 gdb_get_regl(mem_buf
, env
->msr
);
141 for (i
= 0; i
< 8; i
++) {
142 cr
|= env
->crf
[i
] << (32 - ((i
+ 1) * 4));
144 gdb_get_reg32(mem_buf
, cr
);
148 gdb_get_regl(mem_buf
, env
->lr
);
151 gdb_get_regl(mem_buf
, env
->ctr
);
154 gdb_get_regl(mem_buf
, env
->xer
);
157 gdb_get_reg32(mem_buf
, env
->fpscr
);
161 ppc_maybe_bswap_register(env
, mem_buf
, r
);
165 int ppc_cpu_gdb_read_register_apple(CPUState
*cs
, uint8_t *mem_buf
, int n
)
167 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
168 CPUPPCState
*env
= &cpu
->env
;
169 int r
= ppc_gdb_register_len_apple(n
);
177 gdb_get_reg64(mem_buf
, env
->gpr
[n
]);
180 stfq_p(mem_buf
, env
->fpr
[n
-32]);
183 stq_p(mem_buf
, n
- 64);
184 stq_p(mem_buf
+ 8, 0);
188 gdb_get_reg64(mem_buf
, env
->nip
);
191 gdb_get_reg64(mem_buf
, env
->msr
);
197 for (i
= 0; i
< 8; i
++) {
198 cr
|= env
->crf
[i
] << (32 - ((i
+ 1) * 4));
200 gdb_get_reg32(mem_buf
, cr
);
204 gdb_get_reg64(mem_buf
, env
->lr
);
207 gdb_get_reg64(mem_buf
, env
->ctr
);
210 gdb_get_reg64(mem_buf
, env
->xer
);
213 gdb_get_reg64(mem_buf
, env
->fpscr
);
217 ppc_maybe_bswap_register(env
, mem_buf
, r
);
221 int ppc_cpu_gdb_write_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
223 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
224 CPUPPCState
*env
= &cpu
->env
;
225 int r
= ppc_gdb_register_len(n
);
230 ppc_maybe_bswap_register(env
, mem_buf
, r
);
233 env
->gpr
[n
] = ldtul_p(mem_buf
);
236 env
->fpr
[n
-32] = ldfq_p(mem_buf
);
240 env
->nip
= ldtul_p(mem_buf
);
243 ppc_store_msr(env
, ldtul_p(mem_buf
));
247 uint32_t cr
= ldl_p(mem_buf
);
249 for (i
= 0; i
< 8; i
++) {
250 env
->crf
[i
] = (cr
>> (32 - ((i
+ 1) * 4))) & 0xF;
255 env
->lr
= ldtul_p(mem_buf
);
258 env
->ctr
= ldtul_p(mem_buf
);
261 env
->xer
= ldtul_p(mem_buf
);
265 store_fpscr(env
, ldtul_p(mem_buf
), 0xffffffff);
271 int ppc_cpu_gdb_write_register_apple(CPUState
*cs
, uint8_t *mem_buf
, int n
)
273 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
274 CPUPPCState
*env
= &cpu
->env
;
275 int r
= ppc_gdb_register_len_apple(n
);
280 ppc_maybe_bswap_register(env
, mem_buf
, r
);
283 env
->gpr
[n
] = ldq_p(mem_buf
);
286 env
->fpr
[n
-32] = ldfq_p(mem_buf
);
290 env
->nip
= ldq_p(mem_buf
);
293 ppc_store_msr(env
, ldq_p(mem_buf
));
297 uint32_t cr
= ldl_p(mem_buf
);
299 for (i
= 0; i
< 8; i
++) {
300 env
->crf
[i
] = (cr
>> (32 - ((i
+ 1) * 4))) & 0xF;
305 env
->lr
= ldq_p(mem_buf
);
308 env
->ctr
= ldq_p(mem_buf
);
311 env
->xer
= ldq_p(mem_buf
);
315 store_fpscr(env
, ldq_p(mem_buf
), 0xffffffff);