From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: pierrick.bouvier@linaro.org, alex.bennee@linaro.org
Subject: [PATCH v2 9/9] target/arm: Implement TCGCPUOps for plugin register reads
Date: Wed, 5 Jun 2024 20:29:26 -0700 [thread overview]
Message-ID: <20240606032926.83599-10-richard.henderson@linaro.org> (raw)
In-Reply-To: <20240606032926.83599-1-richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/arm/internals.h | 7 +++++--
target/arm/cpu.c | 38 ++++++++++++++++++++++++++++++++++++++
target/arm/cpu64.c | 25 +++++++++++++++++++++++++
target/arm/tcg/cpu-v7m.c | 2 ++
4 files changed, 70 insertions(+), 2 deletions(-)
diff --git a/target/arm/internals.h b/target/arm/internals.h
index dc53d86249..fe28937515 100644
--- a/target/arm/internals.h
+++ b/target/arm/internals.h
@@ -358,11 +358,14 @@ void init_cpreg_list(ARMCPU *cpu);
void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu);
void arm_translate_init(void);
+#ifdef CONFIG_TCG
void arm_restore_state_to_opc(CPUState *cs,
const TranslationBlock *tb,
const uint64_t *data);
-
-#ifdef CONFIG_TCG
+bool arm_plugin_need_unwind_for_reg(CPUState *cs, int reg);
+int arm_plugin_unwind_read_reg(CPUState *cs, GByteArray *buf, int reg,
+ const TranslationBlock *tb,
+ const uint64_t *data);
void arm_cpu_synchronize_from_tb(CPUState *cs, const TranslationBlock *tb);
bool arm_cpu_exec_interrupt(CPUState *cs, int interrupt_request);
#endif /* CONFIG_TCG */
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 3cd4711064..e8ac3da351 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -29,6 +29,7 @@
#include "cpu.h"
#ifdef CONFIG_TCG
#include "hw/core/tcg-cpu-ops.h"
+#include "gdbstub/helpers.h"
#endif /* CONFIG_TCG */
#include "internals.h"
#include "cpu-features.h"
@@ -120,6 +121,41 @@ void arm_restore_state_to_opc(CPUState *cs,
env->exception.syndrome = data[2] << ARM_INSN_START_WORD2_SHIFT;
}
}
+
+bool arm_plugin_need_unwind_for_reg(CPUState *cs, int reg)
+{
+ return reg == 15 || reg == 25; /* pc (r15) or cpsr */
+}
+
+int arm_plugin_unwind_read_reg(CPUState *cs, GByteArray *buf, int reg,
+ const TranslationBlock *tb,
+ const uint64_t *data)
+{
+ CPUARMState *env = cpu_env(cs);
+ uint32_t val, condexec;
+
+ switch (reg) {
+ case 15: /* PC */
+ val = data[0];
+ if (tb_cflags(tb) & CF_PCREL) {
+ val |= env->regs[15] & TARGET_PAGE_MASK;
+ }
+ break;
+ case 25: /* CPSR, or XPSR for M-profile */
+ if (arm_feature(env, ARM_FEATURE_M)) {
+ val = xpsr_read(env);
+ } else {
+ val = cpsr_read(env);
+ }
+ condexec = data[1] & 0xff;
+ val = (val & ~(3 << 25)) | ((condexec & 3) << 25);
+ val = (val & ~(0xfc << 8)) | ((condexec & 0xfc) << 8);
+ break;
+ default:
+ g_assert_not_reached();
+ }
+ return gdb_get_reg32(buf, val);
+}
#endif /* CONFIG_TCG */
/*
@@ -2657,6 +2693,8 @@ static const TCGCPUOps arm_tcg_ops = {
.synchronize_from_tb = arm_cpu_synchronize_from_tb,
.debug_excp_handler = arm_debug_excp_handler,
.restore_state_to_opc = arm_restore_state_to_opc,
+ .plugin_need_unwind_for_reg = arm_plugin_need_unwind_for_reg,
+ .plugin_unwind_read_reg = arm_plugin_unwind_read_reg,
#ifdef CONFIG_USER_ONLY
.record_sigsegv = arm_cpu_record_sigsegv,
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
index 7ba80099af..1595be5d8f 100644
--- a/target/arm/cpu64.c
+++ b/target/arm/cpu64.c
@@ -33,6 +33,8 @@
#include "hw/qdev-properties.h"
#ifdef CONFIG_TCG
#include "hw/core/tcg-cpu-ops.h"
+#include "exec/translation-block.h"
+#include "gdbstub/helpers.h"
#endif
#include "internals.h"
#include "cpu-features.h"
@@ -797,11 +799,34 @@ static const gchar *aarch64_gdb_arch_name(CPUState *cs)
}
#ifdef CONFIG_TCG
+static bool aarch64_plugin_need_unwind_for_reg(CPUState *cs, int reg)
+{
+ return reg == 32; /* pc */
+}
+
+static int aarch64_plugin_unwind_read_reg(CPUState *cs, GByteArray *buf,
+ int reg, const TranslationBlock *tb,
+ const uint64_t *data)
+{
+ CPUARMState *env = cpu_env(cs);
+ uint64_t val;
+
+ assert(reg == 32);
+
+ val = data[0];
+ if (tb_cflags(tb) & CF_PCREL) {
+ val |= env->pc & TARGET_PAGE_MASK;
+ }
+ return gdb_get_reg64(buf, val);
+}
+
static const TCGCPUOps aarch64_tcg_ops = {
.initialize = arm_translate_init,
.synchronize_from_tb = arm_cpu_synchronize_from_tb,
.debug_excp_handler = arm_debug_excp_handler,
.restore_state_to_opc = arm_restore_state_to_opc,
+ .plugin_need_unwind_for_reg = aarch64_plugin_need_unwind_for_reg,
+ .plugin_unwind_read_reg = aarch64_plugin_unwind_read_reg,
#ifdef CONFIG_USER_ONLY
.record_sigsegv = arm_cpu_record_sigsegv,
diff --git a/target/arm/tcg/cpu-v7m.c b/target/arm/tcg/cpu-v7m.c
index c059c681e9..47e44f70c7 100644
--- a/target/arm/tcg/cpu-v7m.c
+++ b/target/arm/tcg/cpu-v7m.c
@@ -237,6 +237,8 @@ static const TCGCPUOps arm_v7m_tcg_ops = {
.synchronize_from_tb = arm_cpu_synchronize_from_tb,
.debug_excp_handler = arm_debug_excp_handler,
.restore_state_to_opc = arm_restore_state_to_opc,
+ .plugin_need_unwind_for_reg = arm_plugin_need_unwind_for_reg,
+ .plugin_unwind_read_reg = arm_plugin_unwind_read_reg,
#ifdef CONFIG_USER_ONLY
.record_sigsegv = arm_cpu_record_sigsegv,
--
2.34.1
next prev parent reply other threads:[~2024-06-06 3:30 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-06 3:29 [PATCH v2 0/9] plugins: Use unwind info for special gdb registers Richard Henderson
2024-06-06 3:29 ` [PATCH v2 1/9] tcg: Introduce INDEX_op_plugin_pc Richard Henderson
2024-06-06 9:40 ` Alex Bennée
2024-06-06 3:29 ` [PATCH v2 2/9] accel/tcg: Set CPUState.plugin_ra before all plugin callbacks Richard Henderson
2024-06-06 9:44 ` Alex Bennée
2024-06-06 3:29 ` [PATCH v2 3/9] accel/tcg: Return the TranslationBlock from cpu_unwind_state_data Richard Henderson
2024-06-06 9:45 ` Alex Bennée
2024-06-06 3:29 ` [PATCH v2 4/9] plugins: Introduce TCGCPUOps callbacks for mid-tb register reads Richard Henderson
2024-06-06 9:47 ` Alex Bennée
2024-06-06 10:22 ` Alex Bennée
2024-06-06 3:29 ` [PATCH v2 5/9] target/i386: Split out gdb-internal.h Richard Henderson
2024-06-06 6:51 ` Philippe Mathieu-Daudé
2024-06-06 15:27 ` Richard Henderson
2024-06-06 3:29 ` [PATCH v2 6/9] target/i386: Introduce cpu_compute_eflags_ccop Richard Henderson
2024-06-06 3:29 ` [PATCH v2 7/9] target/i386: Implement TCGCPUOps for plugin register reads Richard Henderson
2024-06-06 9:52 ` Alex Bennée
2024-06-06 3:29 ` [PATCH v2 8/9] target/arm: Add aarch64_tcg_ops Richard Henderson
2024-06-12 14:36 ` Alex Bennée
2024-06-12 15:45 ` Richard Henderson
2024-06-13 12:35 ` Alex Bennée
2024-06-06 3:29 ` Richard Henderson [this message]
2024-06-06 6:55 ` [PATCH v2 0/9] plugins: Use unwind info for special gdb registers Philippe Mathieu-Daudé
2024-06-12 14:39 ` Alex Bennée
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240606032926.83599-10-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).