Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
target/loongarch: Add GDB support for loongarch32 mode
GPRs and PC are 32-bit wide in loongarch32 mode.

Signed-off-by: Jiajie Chen <c@jia.je>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Song Gao <gaosong@loongson.cn>
Message-ID: <20230817093121.1053890-4-gaosong@loongson.cn>
[PMD: Rebased, set gdb_num_core_regs]
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20230821125959.28666-9-philmd@linaro.org>
  • Loading branch information
jiegec authored and gaosong-loongson committed Aug 24, 2023
1 parent 6cbba3e commit ebda303
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 8 deletions.
2 changes: 1 addition & 1 deletion configs/targets/loongarch64-softmmu.mak
@@ -1,5 +1,5 @@
TARGET_ARCH=loongarch64
TARGET_BASE_ARCH=loongarch
TARGET_SUPPORTS_MTTCG=y
TARGET_XML_FILES= gdb-xml/loongarch-base64.xml gdb-xml/loongarch-fpu.xml
TARGET_XML_FILES= gdb-xml/loongarch-base32.xml gdb-xml/loongarch-base64.xml gdb-xml/loongarch-fpu.xml
TARGET_NEED_FDT=y
45 changes: 45 additions & 0 deletions gdb-xml/loongarch-base32.xml
@@ -0,0 +1,45 @@
<?xml version="1.0"?>
<!-- Copyright (C) 2022 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. -->

<!DOCTYPE feature SYSTEM "gdb-target.dtd">
<feature name="org.gnu.gdb.loongarch.base">
<reg name="r0" bitsize="32" type="uint32" group="general"/>
<reg name="r1" bitsize="32" type="code_ptr" group="general"/>
<reg name="r2" bitsize="32" type="data_ptr" group="general"/>
<reg name="r3" bitsize="32" type="data_ptr" group="general"/>
<reg name="r4" bitsize="32" type="uint32" group="general"/>
<reg name="r5" bitsize="32" type="uint32" group="general"/>
<reg name="r6" bitsize="32" type="uint32" group="general"/>
<reg name="r7" bitsize="32" type="uint32" group="general"/>
<reg name="r8" bitsize="32" type="uint32" group="general"/>
<reg name="r9" bitsize="32" type="uint32" group="general"/>
<reg name="r10" bitsize="32" type="uint32" group="general"/>
<reg name="r11" bitsize="32" type="uint32" group="general"/>
<reg name="r12" bitsize="32" type="uint32" group="general"/>
<reg name="r13" bitsize="32" type="uint32" group="general"/>
<reg name="r14" bitsize="32" type="uint32" group="general"/>
<reg name="r15" bitsize="32" type="uint32" group="general"/>
<reg name="r16" bitsize="32" type="uint32" group="general"/>
<reg name="r17" bitsize="32" type="uint32" group="general"/>
<reg name="r18" bitsize="32" type="uint32" group="general"/>
<reg name="r19" bitsize="32" type="uint32" group="general"/>
<reg name="r20" bitsize="32" type="uint32" group="general"/>
<reg name="r21" bitsize="32" type="uint32" group="general"/>
<reg name="r22" bitsize="32" type="data_ptr" group="general"/>
<reg name="r23" bitsize="32" type="uint32" group="general"/>
<reg name="r24" bitsize="32" type="uint32" group="general"/>
<reg name="r25" bitsize="32" type="uint32" group="general"/>
<reg name="r26" bitsize="32" type="uint32" group="general"/>
<reg name="r27" bitsize="32" type="uint32" group="general"/>
<reg name="r28" bitsize="32" type="uint32" group="general"/>
<reg name="r29" bitsize="32" type="uint32" group="general"/>
<reg name="r30" bitsize="32" type="uint32" group="general"/>
<reg name="r31" bitsize="32" type="uint32" group="general"/>
<reg name="orig_a0" bitsize="32" type="uint32" group="general"/>
<reg name="pc" bitsize="32" type="code_ptr" group="general"/>
<reg name="badv" bitsize="32" type="code_ptr" group="general"/>
</feature>
10 changes: 10 additions & 0 deletions target/loongarch/cpu.c
Expand Up @@ -726,8 +726,18 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data)
#endif
}

static gchar *loongarch32_gdb_arch_name(CPUState *cs)
{
return g_strdup("loongarch32");
}

static void loongarch32_cpu_class_init(ObjectClass *c, void *data)
{
CPUClass *cc = CPU_CLASS(c);

cc->gdb_num_core_regs = 35;
cc->gdb_core_xml_file = "loongarch-base32.xml";
cc->gdb_arch_name = loongarch32_gdb_arch_name;
}

static gchar *loongarch64_gdb_arch_name(CPUState *cs)
Expand Down
32 changes: 25 additions & 7 deletions target/loongarch/gdbstub.c
Expand Up @@ -34,16 +34,25 @@ int loongarch_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
{
LoongArchCPU *cpu = LOONGARCH_CPU(cs);
CPULoongArchState *env = &cpu->env;
uint64_t val;

if (0 <= n && n < 32) {
return gdb_get_regl(mem_buf, env->gpr[n]);
val = env->gpr[n];
} else if (n == 32) {
/* orig_a0 */
return gdb_get_regl(mem_buf, 0);
val = 0;
} else if (n == 33) {
return gdb_get_regl(mem_buf, env->pc);
val = env->pc;
} else if (n == 34) {
return gdb_get_regl(mem_buf, env->CSR_BADV);
val = env->CSR_BADV;
}

if (0 <= n && n <= 34) {
if (is_la64(env)) {
return gdb_get_reg64(mem_buf, val);
} else {
return gdb_get_reg32(mem_buf, val);
}
}
return 0;
}
Expand All @@ -52,15 +61,24 @@ int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
{
LoongArchCPU *cpu = LOONGARCH_CPU(cs);
CPULoongArchState *env = &cpu->env;
target_ulong tmp = ldtul_p(mem_buf);
target_ulong tmp;
int read_length;
int length = 0;

if (is_la64(env)) {
tmp = ldq_p(mem_buf);
read_length = 8;
} else {
tmp = ldl_p(mem_buf);
read_length = 4;
}

if (0 <= n && n < 32) {
env->gpr[n] = tmp;
length = sizeof(target_ulong);
length = read_length;
} else if (n == 33) {
env->pc = tmp;
length = sizeof(target_ulong);
length = read_length;
}
return length;
}
Expand Down

0 comments on commit ebda303

Please sign in to comment.