Skip to content

Commit 74de0eb

Browse files
rivos-eblotloiclefort
authored andcommitted
[ot] hw/riscv: add a monitor helper function to track CPU PC
Signed-off-by: Emmanuel Blot <eblot@rivosinc.com>
1 parent 03e5dbb commit 74de0eb

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

hmp-commands-info.hx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,3 +1007,15 @@ SRST
10071007
``info cryptodev``
10081008
Show the crypto devices.
10091009
ERST
1010+
1011+
{
1012+
.name = "ibex",
1013+
.args_type = "",
1014+
.params = "",
1015+
.help = "Show Ibex vCPU info",
1016+
},
1017+
1018+
SRST
1019+
``info ibex``
1020+
Show Ibex vCPU information.
1021+
ERST

hw/riscv/ibex_common.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "qemu/error-report.h"
2525
#include "qemu/log.h"
2626
#include "cpu.h"
27+
#include "disas/disas.h"
2728
#include "elf.h"
2829
#include "exec/hwaddr.h"
2930
#include "hw/boards.h"
@@ -33,6 +34,7 @@
3334
#include "hw/qdev-properties.h"
3435
#include "hw/riscv/ibex_common.h"
3536
#include "hw/sysbus.h"
37+
#include "monitor/monitor.h"
3638

3739

3840
static void ibex_mmio_map_device(SysBusDevice *dev, MemoryRegion *mr,
@@ -293,3 +295,32 @@ void ibex_log_vcpu_registers(uint64_t regbm)
293295
}
294296
}
295297
}
298+
299+
/*
300+
* Note: this is not specific to Ibex, and might apply to any vCPU.
301+
*/
302+
static void hmp_info_ibex(Monitor *mon, const QDict *qdict)
303+
{
304+
CPUState *cpu;
305+
306+
CPU_FOREACH(cpu) {
307+
vaddr pc;
308+
const char *symbol;
309+
if (cpu->cc->get_pc) {
310+
pc = cpu->cc->get_pc(cpu);
311+
symbol = lookup_symbol(pc);
312+
} else {
313+
pc = -1;
314+
symbol = "?";
315+
}
316+
monitor_printf(mon, "* CPU #%d: 0x%" PRIx64 " in '%s'\n",
317+
cpu->cpu_index, (uint64_t)pc, symbol);
318+
}
319+
}
320+
321+
static void ibex_register_types(void)
322+
{
323+
monitor_register_hmp("ibex", true, &hmp_info_ibex);
324+
}
325+
326+
type_init(ibex_register_types)

0 commit comments

Comments
 (0)