[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 08/11] mos6522: add "info via" HMP command for debugging
|
From: |
Mark Cave-Ayland |
|
Subject: |
[PATCH 08/11] mos6522: add "info via" HMP command for debugging |
|
Date: |
Thu, 27 Jan 2022 20:54:02 +0000 |
This displays detailed information about the device registers and timers to aid
debugging problems with timers and interrupts.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
hmp-commands-info.hx | 12 ++++++
hw/misc/mos6522.c | 92 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 104 insertions(+)
diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index e90f20a107..4e714e79a2 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -879,3 +879,15 @@ SRST
``info sgx``
Show intel SGX information.
ERST
+
+ {
+ .name = "via",
+ .args_type = "",
+ .params = "",
+ .help = "show guest 6522 VIA devices",
+ },
+
+SRST
+ ``info via``
+ Show guest 6522 VIA devices.
+ERST
diff --git a/hw/misc/mos6522.c b/hw/misc/mos6522.c
index aaae195d63..cfa6a9c44b 100644
--- a/hw/misc/mos6522.c
+++ b/hw/misc/mos6522.c
@@ -30,6 +30,8 @@
#include "hw/misc/mos6522.h"
#include "hw/qdev-properties.h"
#include "migration/vmstate.h"
+#include "monitor/monitor.h"
+#include "qapi/type-helpers.h"
#include "qemu/timer.h"
#include "qemu/cutils.h"
#include "qemu/log.h"
@@ -415,6 +417,95 @@ void mos6522_write(void *opaque, hwaddr addr, uint64_t
val, unsigned size)
}
}
+static int qmp_x_query_via_foreach(Object *obj, void *opaque)
+{
+ GString *buf = opaque;
+
+ if (object_dynamic_cast(obj, TYPE_MOS6522)) {
+ MOS6522State *s = MOS6522(obj);
+ int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+ uint16_t t1counter = get_counter(s, &s->timers[0]);
+ uint16_t t2counter = get_counter(s, &s->timers[1]);
+
+ g_string_append_printf(buf, "%s:\n", object_get_typename(obj));
+
+ g_string_append_printf(buf, " Registers:\n");
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[0], s->b);
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[1], s->a);
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[2], s->dirb);
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[3], s->dira);
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[4], t1counter & 0xff);
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[5], t1counter >> 8);
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[6],
+ s->timers[0].latch & 0xff);
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[7],
+ s->timers[0].latch >> 8);
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[8], t2counter & 0xff);
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[9], t2counter >> 8);
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[10], s->sr);
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[11], s->acr);
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[12], s->pcr);
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[13], s->ifr);
+ g_string_append_printf(buf, " %-*s: 0x%x\n", 4,
+ mos6522_reg_names[14], s->ier);
+
+ g_string_append_printf(buf, " Timers:\n");
+ g_string_append_printf(buf, " Using current time now(ns)=%"PRId64
+ "\n", now);
+ g_string_append_printf(buf, " T1 freq(hz)=%"PRId64
+ " mode=%s"
+ " counter=0x%x"
+ " latch=0x%x\n"
+ " load_time(ns)=%"PRId64
+ " next_irq_time(ns)=%"PRId64 "\n",
+ s->timers[0].frequency,
+ ((s->acr & T1MODE) == T1MODE_CONT) ?
"continuous"
+ : "one-shot",
+ t1counter,
+ s->timers[0].latch,
+ s->timers[0].load_time,
+ get_next_irq_time(s, &s->timers[0], now));
+ g_string_append_printf(buf, " T2 freq(hz)=%"PRId64
+ " mode=%s"
+ " counter=0x%x"
+ " latch=0x%x\n"
+ " load_time(ns)=%"PRId64
+ " next_irq_time(ns)=%"PRId64 "\n",
+ s->timers[1].frequency,
+ "one-shot",
+ t2counter,
+ s->timers[1].latch,
+ s->timers[1].load_time,
+ get_next_irq_time(s, &s->timers[1], now));
+ }
+
+ return 0;
+}
+
+static HumanReadableText *qmp_x_query_via(Error **errp)
+{
+ g_autoptr(GString) buf = g_string_new("");
+
+ object_child_foreach_recursive(object_get_root(),
+ qmp_x_query_via_foreach, buf);
+
+ return human_readable_text_from_str(buf);
+}
+
static const MemoryRegionOps mos6522_ops = {
.read = mos6522_read,
.write = mos6522_write,
@@ -547,6 +638,7 @@ static const TypeInfo mos6522_type_info = {
static void mos6522_register_types(void)
{
type_register_static(&mos6522_type_info);
+ monitor_register_hmp_info_hrt("via", qmp_x_query_via);
}
type_init(mos6522_register_types)
--
2.20.1
- [PATCH 00/11] mos6522: switch to gpios, add control line edge-triggering and extra debugging, Mark Cave-Ayland, 2022/01/27
- [PATCH 01/11] mos6522: add defines for IFR bit flags, Mark Cave-Ayland, 2022/01/27
- [PATCH 02/11] mac_via: use IFR bit flag constants for VIA1 IRQs, Mark Cave-Ayland, 2022/01/27
- [PATCH 03/11] mac_via: use IFR bit flag constants for VIA2 IRQs, Mark Cave-Ayland, 2022/01/27
- [PATCH 04/11] mos6522: switch over to use qdev gpios for IRQs, Mark Cave-Ayland, 2022/01/27
- [PATCH 05/11] mos6522: remove update_irq() and set_sr_int() methods from MOS6522DeviceClass, Mark Cave-Ayland, 2022/01/27
- [PATCH 06/11] mos6522: use device_class_set_parent_reset() to propagate reset to parent, Mark Cave-Ayland, 2022/01/27
- [PATCH 07/11] mos6522: add register names to register read/write trace events, Mark Cave-Ayland, 2022/01/27
- [PATCH 09/11] mos6522: record last_irq_levels in mos6522_set_irq(), Mark Cave-Ayland, 2022/01/27
- [PATCH 08/11] mos6522: add "info via" HMP command for debugging,
Mark Cave-Ayland <=
- [PATCH 10/11] mos6522: implement edge-triggering for CA1/2 and CB1/2 control line IRQs, Mark Cave-Ayland, 2022/01/27
- [PATCH 11/11] macio/pmu.c: remove redundant code, Mark Cave-Ayland, 2022/01/27