diff mbox series

[08/10] libpdbg: add fused-core thread id

Message ID 20220531091457.2208488-9-npiggin@gmail.com
State New
Headers show
Series [01/10] sbefifo: correct typo in thread target name | expand

Commit Message

Nicholas Piggin May 31, 2022, 9:14 a.m. UTC
libpdbg thread id is in small-core units because pervasive tends to be
addressed by small core. However some PC registers contain fused-core
thread ID fields, which need fused core indexing.

Add thread->fc_id.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 libpdbg/hwunit.h  |  1 +
 libpdbg/p10chip.c | 19 +++++++++++++++++++
 libpdbg/p8chip.c  |  1 +
 libpdbg/p9chip.c  | 18 ++++++++++++++++++
 libpdbg/sbefifo.c | 10 ++++++++++
 5 files changed, 49 insertions(+)
diff mbox series

Patch

diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h
index 4f27e34c..23053b31 100644
--- a/libpdbg/hwunit.h
+++ b/libpdbg/hwunit.h
@@ -143,6 +143,7 @@  struct thread {
 	struct thread_state status;
 	void *gdbserver_priv;
 	int id;
+	int fc_id;
 	struct thread_state (*state)(struct thread *);
 	int (*step)(struct thread *, int);
 	int (*start)(struct thread *);
diff --git a/libpdbg/p10chip.c b/libpdbg/p10chip.c
index fc661d34..c0358ebc 100644
--- a/libpdbg/p10chip.c
+++ b/libpdbg/p10chip.c
@@ -90,13 +90,32 @@  struct thread_state p10_thread_state(struct thread *thread)
 	return thread_state;
 }
 
+static uint8_t p10_core_id(struct pdbg_target *core)
+{
+	return pdbg_target_index(core) & 0xff;
+}
+
 static int p10_thread_probe(struct pdbg_target *target)
 {
+	struct core *core = target_to_core(pdbg_target_require_parent("core", target));
 	struct thread *thread = target_to_thread(target);
 
 	thread->id = pdbg_target_index(target);
 	thread->status = thread->state(thread);
 
+	if (core->status.fused_core_mode) {
+		struct pdbg_target *parent;
+		uint8_t core_id;
+
+		/* P10 uses core id as core-id */
+		parent = pdbg_target_require_parent("core", target);
+		core_id = p10_core_id(parent);
+
+		thread->fc_id = thread->id * 2 + (core_id % 2);
+	} else {
+		thread->fc_id = thread->id;
+	}
+
 	return 0;
 }
 
diff --git a/libpdbg/p8chip.c b/libpdbg/p8chip.c
index 1863af74..798db6c6 100644
--- a/libpdbg/p8chip.c
+++ b/libpdbg/p8chip.c
@@ -611,6 +611,7 @@  static int p8_thread_probe(struct pdbg_target *target)
 	struct thread *thread = target_to_thread(target);
 
 	thread->id = (pdbg_target_address(target, NULL) >> 4) & 0xf;
+	thread->fc_id = thread->id;
 	thread->status = thread->state(thread);
 
 	return 0;
diff --git a/libpdbg/p9chip.c b/libpdbg/p9chip.c
index 1167dac8..28e98762 100644
--- a/libpdbg/p9chip.c
+++ b/libpdbg/p9chip.c
@@ -111,13 +111,31 @@  struct thread_state p9_thread_state(struct thread *thread)
 	return thread_state;
 }
 
+static uint8_t p9_core_id(struct pdbg_target *core)
+{
+	return pdbg_target_index(core) & 0xff;
+}
+
 static int p9_thread_probe(struct pdbg_target *target)
 {
+	struct core *core = target_to_core(pdbg_target_require_parent("core", target));
 	struct thread *thread = target_to_thread(target);
 
 	thread->id = pdbg_target_index(target);
 	thread->status = thread->state(thread);
 
+	if (core->status.fused_core_mode) {
+		struct pdbg_target *parent;
+		uint8_t core_id;
+
+		parent = pdbg_target_require_parent("core", target);
+		core_id = p9_core_id(parent);
+
+		thread->fc_id = thread->id * 2 + (core_id % 2);
+	} else {
+		thread->fc_id = thread->id;
+	}
+
 	return 0;
 }
 
diff --git a/libpdbg/sbefifo.c b/libpdbg/sbefifo.c
index 3be19b80..7a9f614a 100644
--- a/libpdbg/sbefifo.c
+++ b/libpdbg/sbefifo.c
@@ -375,11 +375,21 @@  static uint8_t sbefifo_core_id(struct sbefifo_context *sctx, struct thread *thre
 
 static int sbefifo_thread_probe(struct pdbg_target *target)
 {
+	struct pdbg_target *parent = pdbg_target_require_parent("core", target);
+	struct core *core = target_to_core(parent);
 	struct thread *thread = target_to_thread(target);
 
 	thread->id = pdbg_target_index(target);
 	thread->status = thread->state(thread);
 
+	if (core->status.fused_core_mode) {
+		uint8_t core_id = pdbg_target_index(parent) & 0xff;
+
+		thread->fc_id = thread->id * 2 + (core_id % 2);
+	} else {
+		thread->fc_id = thread->id;
+	}
+
 	return 0;
 }