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(int n
)
29 return sizeof(target_ulong
);
49 return sizeof(target_ulong
);
55 return sizeof(target_ulong
);
62 static void ppc_gdb_swap_register(uint8_t *mem_buf
, int n
, int len
)
65 bswap32s((uint32_t *)mem_buf
);
66 } else if (len
== 8) {
67 bswap64s((uint64_t *)mem_buf
);
69 g_assert_not_reached();
73 /* Old gdb always expects FP registers. Newer (xml-aware) gdb only
74 * expects whatever the target description contains. Due to a
75 * historical mishap the FP registers appear in between core integer
76 * regs and PC, MSR, CR, and so forth. We hack round this by giving the
77 * FP regs zero size when talking to a newer gdb.
80 int ppc_cpu_gdb_read_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
82 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
83 CPUPPCState
*env
= &cpu
->env
;
84 int r
= ppc_gdb_register_len(n
);
92 gdb_get_regl(mem_buf
, env
->gpr
[n
]);
95 stfq_p(mem_buf
, env
->fpr
[n
-32]);
99 gdb_get_regl(mem_buf
, env
->nip
);
102 gdb_get_regl(mem_buf
, env
->msr
);
108 for (i
= 0; i
< 8; i
++) {
109 cr
|= env
->crf
[i
] << (32 - ((i
+ 1) * 4));
111 gdb_get_reg32(mem_buf
, cr
);
115 gdb_get_regl(mem_buf
, env
->lr
);
118 gdb_get_regl(mem_buf
, env
->ctr
);
121 gdb_get_regl(mem_buf
, env
->xer
);
124 gdb_get_reg32(mem_buf
, env
->fpscr
);
129 /* If cpu is in LE mode, convert memory contents to LE. */
130 ppc_gdb_swap_register(mem_buf
, n
, r
);
135 int ppc_cpu_gdb_write_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
137 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
138 CPUPPCState
*env
= &cpu
->env
;
139 int r
= ppc_gdb_register_len(n
);
145 /* If cpu is in LE mode, convert memory contents to LE. */
146 ppc_gdb_swap_register(mem_buf
, n
, r
);
150 env
->gpr
[n
] = ldtul_p(mem_buf
);
153 env
->fpr
[n
-32] = ldfq_p(mem_buf
);
157 env
->nip
= ldtul_p(mem_buf
);
160 ppc_store_msr(env
, ldtul_p(mem_buf
));
164 uint32_t cr
= ldl_p(mem_buf
);
166 for (i
= 0; i
< 8; i
++) {
167 env
->crf
[i
] = (cr
>> (32 - ((i
+ 1) * 4))) & 0xF;
172 env
->lr
= ldtul_p(mem_buf
);
175 env
->ctr
= ldtul_p(mem_buf
);
178 env
->xer
= ldtul_p(mem_buf
);
182 store_fpscr(env
, ldtul_p(mem_buf
), 0xffffffff);