summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyril Bur <cyrilbur@gmail.com>2018-02-09 15:38:36 +1100
committerAlistair Popple <alistair@popple.id.au>2018-02-12 14:50:47 +1100
commit1de4af7a2907f2377ad2b4123cd25a3a40c0122f (patch)
treef3f61920eba70f78d4b911343687817f0b52f491
parentbe19a48a31d8ed0350e880374fb0e4fe30905f36 (diff)
downloadpdbg-1de4af7a2907f2377ad2b4123cd25a3a40c0122f.tar.gz
pdbg-1de4af7a2907f2377ad2b4123cd25a3a40c0122f.zip
main: Pull register accessors out of main.c
Signed-off-by: Cyril Bur <cyrilbur@gmail.com>
-rw-r--r--Makefile.am2
-rw-r--r--src/main.c68
-rw-r--r--src/main.h23
-rw-r--r--src/reg.c85
-rw-r--r--src/reg.h24
5 files changed, 134 insertions, 68 deletions
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);
OpenPOWER on IntegriCloud