[Pdbg] [PATCH 03/10] pdbg: Add getxer & putxer commands

Rashmica Gupta rashmica.g at gmail.com
Thu May 31 15:29:08 AEST 2018


Signed-off-by: Rashmica Gupta <rashmica.g at gmail.com>
---
 src/main.c |  2 ++
 src/reg.c  | 37 +++++++++++++++++++++++++++++++++++++
 src/reg.h  |  1 +
 3 files changed, 40 insertions(+)

diff --git a/src/main.c b/src/main.c
index 07c3677..90fb729 100644
--- a/src/main.c
+++ b/src/main.c
@@ -96,6 +96,8 @@ static struct action expert_actions[] = {
 	{ "putspr",  "<spr> <value>", "Write Special Purpose Register (SPR)", &handle_spr },
 	{ "getmsr",  "", "Get Machine State Register (MSR)", &handle_msr },
 	{ "putmsr",  "<value>", "Write Machine State Register (MSR)", &handle_msr },
+	{ "getxer",  "", "Get Fixed Point Exception Register (XER)", &handle_xer },
+	{ "putxer",  "<value>", "Write Fixed Point Exception Register (XER)", &handle_xer },
 	{ "getring", "<addr> <len>", "Read a ring. Length must be correct", &handle_getring },
 	{ "start",   "", "Start thread", &thread_start },
 	{ "step",    "<count>", "Set a thread <count> instructions", &thread_step },
diff --git a/src/reg.c b/src/reg.c
index 002cfe9..416236b 100644
--- a/src/reg.c
+++ b/src/reg.c
@@ -18,11 +18,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <debug.h>
 
 #include <libpdbg.h>
 
 #include "main.h"
 
+#define REG_XER -4
 #define REG_MEM -3
 #define REG_MSR -2
 #define REG_NIA -1
@@ -41,6 +43,8 @@ static void print_proc_reg(struct pdbg_target *target, uint64_t reg, uint64_t va
 		printf("msr: ");
 	else if (reg == REG_NIA)
 		printf("nia: ");
+	else if (reg == REG_XER)
+		printf("xer: ");
 	else if (reg > REG_R31)
 		printf("spr%03" PRIu64 ": ", reg - REG_R31);
 	else if (reg >= 0 && reg <= 31)
@@ -62,6 +66,8 @@ static int putprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg,
 		rc = ram_putmsr(target, *value);
 	else if (*reg == REG_NIA)
 		rc = ram_putnia(target, *value);
+	else if (*reg == REG_XER)
+		rc = ram_putxer(target, *value);
 	else if (*reg > REG_R31)
 		rc = ram_putspr(target, *reg - REG_R31, *value);
 	else if (*reg >= 0 && *reg <= 31)
@@ -81,6 +87,8 @@ static int getprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg,
 		rc = ram_getmsr(target, &value);
 	else if (*reg == REG_NIA)
 		rc = ram_getnia(target, &value);
+	else if (*reg == REG_XER)
+		rc = ram_getxer(target, &value);
 	else if (*reg > REG_R31)
 		rc = ram_getspr(target, *reg - REG_R31, &value);
 	else if (*reg >= 0 && *reg <= 31)
@@ -231,3 +239,32 @@ int handle_msr(int optind, int argc, char *argv[])
 
 	return for_each_target("thread", getprocreg, &msr, NULL);
 }
+
+int handle_xer(int optind, int argc, char *argv[])
+{
+	uint64_t xer = REG_XER;
+	char *endptr;
+
+	if (strcmp(argv[optind], "putxer") == 0) {
+		uint64_t data;
+
+		if (optind + 1 >= argc) {
+			printf("%s: command '%s' requires data\n", argv[0], argv[optind]);
+			return -1;
+		}
+
+		errno = 0;
+		data = strtoull(argv[optind + 1], &endptr, 0);
+		if (errno || *endptr != '\0') {
+			printf("%s: command '%s' couldn't parse data '%s'\n",
+				argv[0], argv[optind], argv[optind + 1]);
+			return -1;
+		}
+
+		PR_WARNING("We can only set part of the XER register.\n");
+		return for_each_target("thread", putprocreg, &xer, &data);
+	}
+
+	PR_WARNING("We can only get part of the XER register.\n");
+	return for_each_target("thread", getprocreg, &xer, NULL);
+}
diff --git a/src/reg.h b/src/reg.h
index ad41d9d..ca548a6 100644
--- a/src/reg.h
+++ b/src/reg.h
@@ -18,3 +18,4 @@ int handle_gpr(int optind, int argc, char *argv[]);
 int handle_nia(int optind, int argc, char *argv[]);
 int handle_spr(int optind, int argc, char *argv[]);
 int handle_msr(int optind, int argc, char *argv[]);
+int handle_xer(int optind, int argc, char *argv[]);
-- 
2.14.3



More information about the Pdbg mailing list