-
Notifications
You must be signed in to change notification settings - Fork 154
Add gdb xml register support. #160
Changes from 1 commit
59a2a11
67110fb
458d08e
0461550
dabcc50
970b95b
e0bc582
0bf5716
31aa0b4
5fe21a8
3737960
24ece65
0a656f3
b379f5a
c2901dd
f4399d2
ad21000
8812433
bea8bb0
764aa94
fc5d882
2ad9b10
eec015a
e8ae79c
e8b5944
25571ed
fc4d86d
34f9902
9d4473b
6338416
3e20277
27016af
c7b1e00
884c701
0a13267
0b22435
d7e5d78
577f7aa
cf5f50f
63801b3
077d5e6
d621573
79fe4f4
2f70fed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0"?> | ||
<!-- Copyright (C) 2018 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.riscv.cpu"> | ||
<reg name="x0" bitsize="64"/> | ||
<reg name="x1" bitsize="64"/> | ||
<reg name="x2" bitsize="64"/> | ||
<reg name="x3" bitsize="64"/> | ||
<reg name="x4" bitsize="64"/> | ||
<reg name="x5" bitsize="64"/> | ||
<reg name="x6" bitsize="64"/> | ||
<reg name="x7" bitsize="64"/> | ||
<reg name="x8" bitsize="64"/> | ||
<reg name="x9" bitsize="64"/> | ||
<reg name="x10" bitsize="64"/> | ||
<reg name="x11" bitsize="64"/> | ||
<reg name="x12" bitsize="64"/> | ||
<reg name="x13" bitsize="64"/> | ||
<reg name="x14" bitsize="64"/> | ||
<reg name="x15" bitsize="64"/> | ||
<reg name="x16" bitsize="64"/> | ||
<reg name="x17" bitsize="64"/> | ||
<reg name="x18" bitsize="64"/> | ||
<reg name="x19" bitsize="64"/> | ||
<reg name="x20" bitsize="64"/> | ||
<reg name="x21" bitsize="64"/> | ||
<reg name="x22" bitsize="64"/> | ||
<reg name="x23" bitsize="64"/> | ||
<reg name="x24" bitsize="64"/> | ||
<reg name="x25" bitsize="64"/> | ||
<reg name="x26" bitsize="64"/> | ||
<reg name="x27" bitsize="64"/> | ||
<reg name="x28" bitsize="64"/> | ||
<reg name="x29" bitsize="64"/> | ||
<reg name="x30" bitsize="64"/> | ||
<reg name="x31" bitsize="64"/> | ||
<reg name="pc" bitsize="64"/> | ||
</feature> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0"?> | ||
<!-- Copyright (C) 2018 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.riscv.csr"> | ||
<reg name="misa" bitsize="64" regnum="0x342"/> | ||
</feature> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0"?> | ||
<!-- Copyright (C) 2018 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.riscv.fpu"> | ||
<reg name="f0" bitsize="64"/> | ||
<reg name="f1" bitsize="64"/> | ||
<reg name="f2" bitsize="64"/> | ||
<reg name="f3" bitsize="64"/> | ||
<reg name="f4" bitsize="64"/> | ||
<reg name="f5" bitsize="64"/> | ||
<reg name="f6" bitsize="64"/> | ||
<reg name="f7" bitsize="64"/> | ||
<reg name="f8" bitsize="64"/> | ||
<reg name="f9" bitsize="64"/> | ||
<reg name="f10" bitsize="64"/> | ||
<reg name="f11" bitsize="64"/> | ||
<reg name="f12" bitsize="64"/> | ||
<reg name="f13" bitsize="64"/> | ||
<reg name="f14" bitsize="64"/> | ||
<reg name="f15" bitsize="64"/> | ||
<reg name="f16" bitsize="64"/> | ||
<reg name="f17" bitsize="64"/> | ||
<reg name="f18" bitsize="64"/> | ||
<reg name="f19" bitsize="64"/> | ||
<reg name="f20" bitsize="64"/> | ||
<reg name="f21" bitsize="64"/> | ||
<reg name="f22" bitsize="64"/> | ||
<reg name="f23" bitsize="64"/> | ||
<reg name="f24" bitsize="64"/> | ||
<reg name="f25" bitsize="64"/> | ||
<reg name="f26" bitsize="64"/> | ||
<reg name="f27" bitsize="64"/> | ||
<reg name="f28" bitsize="64"/> | ||
<reg name="f29" bitsize="64"/> | ||
<reg name="f30" bitsize="64"/> | ||
<reg name="f31" bitsize="64"/> | ||
<reg name="f32" bitsize="64"/> | ||
</feature> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,13 +30,6 @@ int riscv_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n) | |
return gdb_get_regl(mem_buf, env->gpr[n]); | ||
} else if (n == 32) { | ||
return gdb_get_regl(mem_buf, env->pc); | ||
} else if (n < 65) { | ||
return gdb_get_reg64(mem_buf, env->fpr[n - 33]); | ||
} else if (n < 4096 + 65) { | ||
target_ulong val = 0; | ||
if (riscv_csrrw(env, n - 65, &val, 0, 0) == 0) { | ||
return gdb_get_regl(mem_buf, val); | ||
} | ||
} | ||
return 0; | ||
} | ||
|
@@ -55,14 +48,55 @@ int riscv_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) | |
} else if (n == 32) { | ||
env->pc = ldtul_p(mem_buf); | ||
return sizeof(target_ulong); | ||
} else if (n < 65) { | ||
env->fpr[n - 33] = ldq_p(mem_buf); /* always 64-bit */ | ||
} | ||
return 0; | ||
} | ||
|
||
static int riscv_gdb_get_fpu(CPURISCVState *env, uint8_t *mem_buf, int n) | ||
{ | ||
if (n < 32) { | ||
return gdb_get_reg64(mem_buf, env->fpr[n]); | ||
} | ||
return 0; | ||
} | ||
|
||
static int riscv_gdb_set_fpu(CPURISCVState *env, uint8_t *mem_buf, int n) | ||
{ | ||
if (n < 32) { | ||
env->fpr[n] = ldq_p(mem_buf); /* always 64-bit */ | ||
return sizeof(uint64_t); | ||
} else if (n < 4096 + 65) { | ||
} | ||
return 0; | ||
} | ||
|
||
static int riscv_gdb_get_csr(CPURISCVState *env, uint8_t *mem_buf, int n) | ||
{ | ||
if (n < 4096) { | ||
target_ulong val = 0; | ||
if (riscv_csrrw(env, n, &val, 0, 0) == 0) { | ||
return gdb_get_regl(mem_buf, val); | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
static int riscv_gdb_set_csr(CPURISCVState *env, uint8_t *mem_buf, int n) | ||
{ | ||
if (n < 4096) { | ||
target_ulong val = ldtul_p(mem_buf); | ||
if (riscv_csrrw(env, n - 65, NULL, val, -1) == 0) { | ||
if (riscv_csrrw(env, n, NULL, val, -1) == 0) { | ||
return sizeof(target_ulong); | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) | ||
{ | ||
/* ??? Assume all targets have FPU regs for now. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can get look at
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Register numbers have to match gdb, and gdb always makes the FP regs 33 to 64. I think that we will always have to register the FP regs for now, even if they aren't enabled. I will check this when I have a chance. Ideally we only register FP regs if enabled, but I suspect this will require a gdb patch, which in turn will also require a OpenOCD patch. So if we change this, we will need coordinated qemu/gdb/OpenOCD patches which will be inconvenient. It appears that this is how the ARM port works, but then they have 4 different kinds of FP registers to support, so they probably don't have a choice. |
||
gdb_register_coprocessor(cs, riscv_gdb_get_fpu, riscv_gdb_set_fpu, | ||
32, "riscv-fpu.xml", 0); | ||
|
||
gdb_register_coprocessor(cs, riscv_gdb_get_csr, riscv_gdb_set_csr, | ||
4096, "riscv-csr.xml", 0); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spotting. I vaguely remember this one. CSR 0xfff is out of bounds. We should roll this fragment into 0bf5716 RISC-V: Implement modular CSR helper interface When I merge the commit I can rebase and move this fragment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With an earlier version of the patch, I got a core dump when gdb tried to read CSR4095, because of the out-of-bounds array access.