Skip to content

Commit 96c0421

Browse files
agrafpm215
authored andcommitted
target-arm: Add AArch64 gdbstub support
We want to be able to debug AArch64 guests. So let's add the respective gdb stub functions and xml descriptions that allow us to do so. Signed-off-by: Alexander Graf <[email protected]> Signed-off-by: John Rigby <[email protected]> Signed-off-by: Peter Maydell <[email protected]> Message-id: [email protected] Message-id: [email protected] [PMM: dropped unused fp regs XML for now; moved 64 bit only functions to new gdbstub64.c; these are hooked up in AArch64CPU, not via ifdefs in ARMCPU] Signed-off-by: Peter Maydell <[email protected]>
1 parent 14ade10 commit 96c0421

File tree

5 files changed

+126
-1
lines changed

5 files changed

+126
-1
lines changed

gdb-xml/aarch64-core.xml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0"?>
2+
<!-- Copyright (C) 2009-2012 Free Software Foundation, Inc.
3+
Contributed by ARM Ltd.
4+
5+
Copying and distribution of this file, with or without modification,
6+
are permitted in any medium without royalty provided the copyright
7+
notice and this notice are preserved. -->
8+
9+
<!DOCTYPE feature SYSTEM "gdb-target.dtd">
10+
<feature name="org.gnu.gdb.aarch64.core">
11+
<reg name="x0" bitsize="64"/>
12+
<reg name="x1" bitsize="64"/>
13+
<reg name="x2" bitsize="64"/>
14+
<reg name="x3" bitsize="64"/>
15+
<reg name="x4" bitsize="64"/>
16+
<reg name="x5" bitsize="64"/>
17+
<reg name="x6" bitsize="64"/>
18+
<reg name="x7" bitsize="64"/>
19+
<reg name="x8" bitsize="64"/>
20+
<reg name="x9" bitsize="64"/>
21+
<reg name="x10" bitsize="64"/>
22+
<reg name="x11" bitsize="64"/>
23+
<reg name="x12" bitsize="64"/>
24+
<reg name="x13" bitsize="64"/>
25+
<reg name="x14" bitsize="64"/>
26+
<reg name="x15" bitsize="64"/>
27+
<reg name="x16" bitsize="64"/>
28+
<reg name="x17" bitsize="64"/>
29+
<reg name="x18" bitsize="64"/>
30+
<reg name="x19" bitsize="64"/>
31+
<reg name="x20" bitsize="64"/>
32+
<reg name="x21" bitsize="64"/>
33+
<reg name="x22" bitsize="64"/>
34+
<reg name="x23" bitsize="64"/>
35+
<reg name="x24" bitsize="64"/>
36+
<reg name="x25" bitsize="64"/>
37+
<reg name="x26" bitsize="64"/>
38+
<reg name="x27" bitsize="64"/>
39+
<reg name="x28" bitsize="64"/>
40+
<reg name="x29" bitsize="64"/>
41+
<reg name="x30" bitsize="64"/>
42+
<reg name="sp" bitsize="64" type="data_ptr"/>
43+
44+
<reg name="pc" bitsize="64" type="code_ptr"/>
45+
<reg name="cpsr" bitsize="32"/>
46+
</feature>

target-arm/Makefile.objs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ obj-$(CONFIG_NO_KVM) += kvm-stub.o
55
obj-y += translate.o op_helper.o helper.o cpu.o
66
obj-y += neon_helper.o iwmmxt_helper.o
77
obj-y += gdbstub.o
8-
obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o
8+
obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o gdbstub64.o

target-arm/cpu-qom.h

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ void arm_gt_vtimer_cb(void *opaque);
176176
#ifdef TARGET_AARCH64
177177
void aarch64_cpu_dump_state(CPUState *cs, FILE *f,
178178
fprintf_function cpu_fprintf, int flags);
179+
int aarch64_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);
180+
int aarch64_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
179181
#endif
180182

181183
#endif

target-arm/cpu64.c

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ static void aarch64_cpu_class_init(ObjectClass *oc, void *data)
7373
CPUClass *cc = CPU_CLASS(oc);
7474

7575
cc->dump_state = aarch64_cpu_dump_state;
76+
cc->gdb_read_register = aarch64_cpu_gdb_read_register;
77+
cc->gdb_write_register = aarch64_cpu_gdb_write_register;
78+
cc->gdb_num_core_regs = 34;
79+
cc->gdb_core_xml_file = "aarch64-core.xml";
7680
}
7781

7882
static void aarch64_cpu_register(const ARMCPUInfo *info)

target-arm/gdbstub64.c

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* ARM gdb server stub: AArch64 specific functions.
3+
*
4+
* Copyright (c) 2013 SUSE LINUX Products GmbH
5+
*
6+
* This library is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 2 of the License, or (at your option) any later version.
10+
*
11+
* This library is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public
17+
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
#include "config.h"
20+
#include "qemu-common.h"
21+
#include "exec/gdbstub.h"
22+
23+
int aarch64_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
24+
{
25+
ARMCPU *cpu = ARM_CPU(cs);
26+
CPUARMState *env = &cpu->env;
27+
28+
if (n < 31) {
29+
/* Core integer register. */
30+
return gdb_get_reg64(mem_buf, env->xregs[n]);
31+
}
32+
switch (n) {
33+
case 31:
34+
return gdb_get_reg64(mem_buf, env->xregs[31]);
35+
break;
36+
case 32:
37+
return gdb_get_reg64(mem_buf, env->pc);
38+
break;
39+
case 33:
40+
return gdb_get_reg32(mem_buf, env->pstate);
41+
}
42+
/* Unknown register. */
43+
return 0;
44+
}
45+
46+
int aarch64_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
47+
{
48+
ARMCPU *cpu = ARM_CPU(cs);
49+
CPUARMState *env = &cpu->env;
50+
uint64_t tmp;
51+
52+
tmp = ldq_p(mem_buf);
53+
54+
if (n < 31) {
55+
/* Core integer register. */
56+
env->xregs[n] = tmp;
57+
return 8;
58+
}
59+
switch (n) {
60+
case 31:
61+
env->xregs[31] = tmp;
62+
return 8;
63+
case 32:
64+
env->pc = tmp;
65+
return 8;
66+
case 33:
67+
/* CPSR */
68+
env->pstate = tmp;
69+
return 4;
70+
}
71+
/* Unknown register. */
72+
return 0;
73+
}

0 commit comments

Comments
 (0)