[Pdbg] [PATCH 08/29] main: Pull register accessors out of main.c

Cyril Bur cyrilbur at gmail.com
Fri Feb 9 15:38:36 AEDT 2018


Signed-off-by: Cyril Bur <cyrilbur at gmail.com>
---
 Makefile.am |  2 +-
 src/main.c  | 68 +------------------------------------------------
 src/main.h  | 23 +++++++++++++++++
 src/reg.c   | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/reg.h   | 24 +++++++++++++++++
 5 files changed, 134 insertions(+), 68 deletions(-)
 create mode 100644 src/main.h
 create mode 100644 src/reg.c
 create mode 100644 src/reg.h

diff --git a/Makefile.am b/Makefile.am
index 1e645b7..1e9f1e5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,7 +11,7 @@ ACLOCAL_AMFLAGS = -Im4
 AM_CFLAGS = -I$(top_srcdir)/ccan/array_size -Wall -Werror
 
 pdbg_SOURCES = \
-	src/main.c src/cfam.c src/scom.c
+	src/main.c src/cfam.c src/scom.c src/reg.c
 pdbg_LDADD = fake.dtb.o p8-fsi.dtb.o p8-i2c.dtb.o p9w-fsi.dtb.o	p8-host.dtb.o \
 	p9z-fsi.dtb.o p9r-fsi.dtb.o p9-kernel.dtb.o libpdbg.la libfdt.la \
 	p9-host.dtb.o \
diff --git a/src/main.c b/src/main.c
index 33ebda3..e7599bc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,6 +33,7 @@
 #include "bitutils.h"
 #include "cfam.h"
 #include "scom.h"
+#include "reg.h"
 
 #undef PR_DEBUG
 #define PR_DEBUG(...)
@@ -486,73 +487,6 @@ static int print_proc_thread_status(struct pdbg_target *pib_target, uint32_t ind
 	return for_each_child_target("core", pib_target, print_core_thread_status, NULL, NULL);
 };
 
-#define REG_MEM -3
-#define REG_MSR -2
-#define REG_NIA -1
-#define REG_R31 31
-static void print_proc_reg(struct pdbg_target *target, uint64_t reg, uint64_t value, int rc)
-{
-	int proc_index, chip_index, thread_index;
-
-	thread_index = pdbg_target_index(target);
-	chip_index = pdbg_parent_index(target, "core");
-	proc_index = pdbg_parent_index(target, "pib");
-	printf("p%d:c%d:t%d:", proc_index, chip_index, thread_index);
-
-	if (reg == REG_MSR)
-		printf("msr: ");
-	else if (reg == REG_NIA)
-		printf("nia: ");
-	else if (reg > REG_R31)
-		printf("spr%03" PRIu64 ": ", reg - REG_R31);
-	else if (reg >= 0 && reg <= 31)
-		printf("gpr%02" PRIu64 ": ", reg);
-
-	if (rc == 1) {
-		printf("Check threadstatus - not all threads on this core are quiesced\n");
-	} else if (rc == 2)
-		printf("Thread in incorrect state\n");
-	else
-		printf("0x%016" PRIx64 "\n", value);
-}
-
-static int putprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg, uint64_t *value)
-{
-	int rc;
-
-	if (*reg == REG_MSR)
-		rc = ram_putmsr(target, *value);
-	else if (*reg == REG_NIA)
-		rc = ram_putnia(target, *value);
-	else if (*reg > REG_R31)
-		rc = ram_putspr(target, *reg - REG_R31, *value);
-	else if (*reg >= 0 && *reg <= 31)
-		rc = ram_putgpr(target, *reg, *value);
-
-	print_proc_reg(target, *reg, *value, rc);
-
-	return 0;
-}
-
-static int getprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg, uint64_t *unused)
-{
-	int rc;
-	uint64_t value;
-
-	if (*reg == REG_MSR)
-		rc = ram_getmsr(target, &value);
-	else if (*reg == REG_NIA)
-		rc = ram_getnia(target, &value);
-	else if (*reg > REG_R31)
-		rc = ram_getspr(target, *reg - REG_R31, &value);
-	else if (*reg >= 0 && *reg <= 31)
-		rc = ram_getgpr(target, *reg, &value);
-
-	print_proc_reg(target, *reg, value, rc);
-
-	return !rc;
-}
-
 #define PUTMEM_BUF_SIZE 1024
 static int putmem(uint64_t addr)
 {
diff --git a/src/main.h b/src/main.h
new file mode 100644
index 0000000..bfa8c37
--- /dev/null
+++ b/src/main.h
@@ -0,0 +1,23 @@
+/* Copyright 2017 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 	http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <inttypes.h>
+
+#include <target.h>
+
+/* Returns the sum of return codes. This can be used to count how many targets the callback was run on. */
+int for_each_child_target(char *class, struct target *parent,
+				 int (*cb)(struct target *, uint32_t, uint64_t *, uint64_t *),
+				 uint64_t *arg1, uint64_t *arg2);
diff --git a/src/reg.c b/src/reg.c
new file mode 100644
index 0000000..02835c7
--- /dev/null
+++ b/src/reg.c
@@ -0,0 +1,85 @@
+/* Copyright 2017 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 	http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <inttypes.h>
+#include <stdio.h>
+
+#include <target.h>
+#include <operations.h>
+
+#include "reg.h"
+
+static void print_proc_reg(struct pdbg_target *target, uint64_t reg, uint64_t value, int rc)
+{
+	int proc_index, chip_index, thread_index;
+
+	thread_index = pdbg_target_index(target);
+	chip_index = pdbg_parent_index(target, "core");
+	proc_index = pdbg_parent_index(target, "pib");
+	printf("p%d:c%d:t%d:", proc_index, chip_index, thread_index);
+
+	if (reg == REG_MSR)
+		printf("msr: ");
+	else if (reg == REG_NIA)
+		printf("nia: ");
+	else if (reg > REG_R31)
+		printf("spr%03" PRIu64 ": ", reg - REG_R31);
+	else if (reg >= 0 && reg <= 31)
+		printf("gpr%02" PRIu64 ": ", reg);
+
+	if (rc == 1) {
+		printf("Check threadstatus - not all threads on this chiplet are quiesced\n");
+	} else if (rc == 2)
+		printf("Thread in incorrect state\n");
+	else
+		printf("0x%016" PRIx64 "\n", value);
+}
+
+int putprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg, uint64_t *value)
+{
+	int rc;
+
+	if (*reg == REG_MSR)
+		rc = ram_putmsr(target, *value);
+	else if (*reg == REG_NIA)
+		rc = ram_putnia(target, *value);
+	else if (*reg > REG_R31)
+		rc = ram_putspr(target, *reg - REG_R31, *value);
+	else if (*reg >= 0 && *reg <= 31)
+		rc = ram_putgpr(target, *reg, *value);
+
+	print_proc_reg(target, *reg, *value, rc);
+
+	return 0;
+}
+
+int getprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg, uint64_t *unused)
+{
+	int rc;
+	uint64_t value;
+
+	if (*reg == REG_MSR)
+		rc = ram_getmsr(target, &value);
+	else if (*reg == REG_NIA)
+		rc = ram_getnia(target, &value);
+	else if (*reg > REG_R31)
+		rc = ram_getspr(target, *reg - REG_R31, &value);
+	else if (*reg >= 0 && *reg <= 31)
+		rc = ram_getgpr(target, *reg, &value);
+
+	print_proc_reg(target, *reg, value, rc);
+
+	return !rc;
+}
diff --git a/src/reg.h b/src/reg.h
new file mode 100644
index 0000000..c80df57
--- /dev/null
+++ b/src/reg.h
@@ -0,0 +1,24 @@
+/* Copyright 2017 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 	http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <inttypes.h>
+
+#define REG_MEM -3
+#define REG_MSR -2
+#define REG_NIA -1
+#define REG_R31 31
+
+int putprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg, uint64_t *value);
+int getprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg, uint64_t *unused);
-- 
2.16.1



More information about the Pdbg mailing list