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 typedef struct RegisterSysregXmlParam
{
28 } RegisterSysregXmlParam
;
30 /* Old gdb always expect FPA registers. Newer (xml-aware) gdb only expect
31 whatever the target description contains. Due to a historical mishap
32 the FPA registers appear in between core integer regs and the CPSR.
33 We hack round this by giving the FPA regs zero size when talking to a
36 int arm_cpu_gdb_read_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
38 ARMCPU
*cpu
= ARM_CPU(cs
);
39 CPUARMState
*env
= &cpu
->env
;
42 /* Core integer register. */
43 return gdb_get_reg32(mem_buf
, env
->regs
[n
]);
50 memset(mem_buf
, 0, 12);
55 /* FPA status register. */
59 return gdb_get_reg32(mem_buf
, 0);
62 return gdb_get_reg32(mem_buf
, cpsr_read(env
));
64 /* Unknown register. */
68 int arm_cpu_gdb_write_register(CPUState
*cs
, uint8_t *mem_buf
, int n
)
70 ARMCPU
*cpu
= ARM_CPU(cs
);
71 CPUARMState
*env
= &cpu
->env
;
76 /* Mask out low bit of PC to workaround gdb bugs. This will probably
77 cause problems if we ever implement the Jazelle DBX extensions. */
83 /* Core integer register. */
87 if (n
< 24) { /* 16-23 */
88 /* FPA registers (ignored). */
96 /* FPA status register (ignored). */
103 cpsr_write(env
, tmp
, 0xffffffff, CPSRWriteByGDBStub
);
106 /* Unknown register. */
110 static void arm_gen_one_xml_reg_tag(GString
*s
, DynamicGDBXMLInfo
*dyn_xml
,
111 ARMCPRegInfo
*ri
, uint32_t ri_key
,
114 g_string_append_printf(s
, "<reg name=\"%s\"", ri
->name
);
115 g_string_append_printf(s
, " bitsize=\"%d\"", bitsize
);
116 g_string_append_printf(s
, " group=\"cp_regs\"/>");
117 dyn_xml
->num_cpregs
++;
118 dyn_xml
->cpregs_keys
[dyn_xml
->num_cpregs
- 1] = ri_key
;
121 static void arm_register_sysreg_for_xml(gpointer key
, gpointer value
,
124 uint32_t ri_key
= *(uint32_t *)key
;
125 ARMCPRegInfo
*ri
= value
;
126 RegisterSysregXmlParam
*param
= (RegisterSysregXmlParam
*)p
;
127 GString
*s
= param
->s
;
128 ARMCPU
*cpu
= ARM_CPU(param
->cs
);
129 CPUARMState
*env
= &cpu
->env
;
130 DynamicGDBXMLInfo
*dyn_xml
= &cpu
->dyn_xml
;
132 if (!(ri
->type
& (ARM_CP_NO_RAW
| ARM_CP_NO_GDB
))) {
133 if (arm_feature(env
, ARM_FEATURE_AARCH64
)) {
134 if (ri
->state
== ARM_CP_STATE_AA64
) {
135 arm_gen_one_xml_reg_tag(s
, dyn_xml
, ri
, ri_key
, 64);
138 if (ri
->state
== ARM_CP_STATE_AA32
) {
139 if (!arm_feature(env
, ARM_FEATURE_EL3
) &&
140 (ri
->secure
& ARM_CP_SECSTATE_S
)) {
143 if (ri
->type
& ARM_CP_64BIT
) {
144 arm_gen_one_xml_reg_tag(s
, dyn_xml
, ri
, ri_key
, 64);
146 arm_gen_one_xml_reg_tag(s
, dyn_xml
, ri
, ri_key
, 32);
153 int arm_gen_dynamic_xml(CPUState
*cs
)
155 ARMCPU
*cpu
= ARM_CPU(cs
);
156 GString
*s
= g_string_new(NULL
);
157 RegisterSysregXmlParam param
= {cs
, s
};
159 cpu
->dyn_xml
.num_cpregs
= 0;
160 cpu
->dyn_xml
.cpregs_keys
= g_new(uint32_t, g_hash_table_size(cpu
->cp_regs
));
161 g_string_printf(s
, "<?xml version=\"1.0\"?>");
162 g_string_append_printf(s
, "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">");
163 g_string_append_printf(s
, "<feature name=\"org.qemu.gdb.arm.sys.regs\">");
164 g_hash_table_foreach(cpu
->cp_regs
, arm_register_sysreg_for_xml
, ¶m
);
165 g_string_append_printf(s
, "</feature>");
166 cpu
->dyn_xml
.desc
= g_string_free(s
, false);
167 return cpu
->dyn_xml
.num_cpregs
;
170 const char *arm_gdb_get_dynamic_xml(CPUState
*cs
, const char *xmlname
)
172 ARMCPU
*cpu
= ARM_CPU(cs
);
174 if (strcmp(xmlname
, "system-registers.xml") == 0) {
175 return cpu
->dyn_xml
.desc
;