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/>.
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
);
87 static void ppc_gdb_swap_register(uint8_t *mem_buf
, int n
, int len
)
90 bswap32s((uint32_t *)mem_buf
);
91 } else if (len
== 8) {
92 bswap64s((uint64_t *)mem_buf
);
94 g_assert_not_reached();
98 /* Old gdb always expects FP registers. Newer (xml-aware) gdb only
99 * expects whatever the target description contains. Due to a
100 * historical mishap the FP registers appear in between core integer
101 * regs and PC, MSR, CR, and so forth. We hack round this by giving the
102 * FP regs zero size when talking to a newer gdb.
105 int ppc_cpu_gdb_read_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
107 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
108 CPUPPCState
*env
= &cpu
->env
;
109 int r
= ppc_gdb_register_len(n
);
117 gdb_get_regl(mem_buf
, env
->gpr
[n
]);
120 stfq_p(mem_buf
, env
->fpr
[n
-32]);
124 gdb_get_regl(mem_buf
, env
->nip
);
127 gdb_get_regl(mem_buf
, env
->msr
);
133 for (i
= 0; i
< 8; i
++) {
134 cr
|= env
->crf
[i
] << (32 - ((i
+ 1) * 4));
136 gdb_get_reg32(mem_buf
, cr
);
140 gdb_get_regl(mem_buf
, env
->lr
);
143 gdb_get_regl(mem_buf
, env
->ctr
);
146 gdb_get_regl(mem_buf
, env
->xer
);
149 gdb_get_reg32(mem_buf
, env
->fpscr
);
154 /* If cpu is in LE mode, convert memory contents to LE. */
155 ppc_gdb_swap_register(mem_buf
, n
, r
);
160 int ppc_cpu_gdb_read_register_apple(CPUState
*cs
, uint8_t *mem_buf
, int n
)
162 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
163 CPUPPCState
*env
= &cpu
->env
;
164 int r
= ppc_gdb_register_len_apple(n
);
172 gdb_get_reg64(mem_buf
, env
->gpr
[n
]);
175 stfq_p(mem_buf
, env
->fpr
[n
-32]);
178 stq_p(mem_buf
, n
- 64);
179 stq_p(mem_buf
+ 8, 0);
183 gdb_get_reg64(mem_buf
, env
->nip
);
186 gdb_get_reg64(mem_buf
, env
->msr
);
192 for (i
= 0; i
< 8; i
++) {
193 cr
|= env
->crf
[i
] << (32 - ((i
+ 1) * 4));
195 gdb_get_reg32(mem_buf
, cr
);
199 gdb_get_reg64(mem_buf
, env
->lr
);
202 gdb_get_reg64(mem_buf
, env
->ctr
);
205 gdb_get_reg64(mem_buf
, env
->xer
);
208 gdb_get_reg64(mem_buf
, env
->fpscr
);
213 /* If cpu is in LE mode, convert memory contents to LE. */
214 ppc_gdb_swap_register(mem_buf
, n
, r
);
219 int ppc_cpu_gdb_write_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
221 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
222 CPUPPCState
*env
= &cpu
->env
;
223 int r
= ppc_gdb_register_len(n
);
229 /* If cpu is in LE mode, convert memory contents to LE. */
230 ppc_gdb_swap_register(mem_buf
, n
, 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
);
282 /* If cpu is in LE mode, convert memory contents to LE. */
283 ppc_gdb_swap_register(mem_buf
, n
, r
);
287 env
->gpr
[n
] = ldq_p(mem_buf
);
290 env
->fpr
[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
= ldq_p(mem_buf
);
319 store_fpscr(env
, ldq_p(mem_buf
), 0xffffffff);