diff mbox series

[3/8] pdbg: Add getxer & putxer commands

Message ID 20180622045116.12059-4-rashmica.g@gmail.com
State Superseded
Headers show
Series Pre gdbserver additions | expand

Commit Message

Rashmica Gupta June 22, 2018, 4:51 a.m. UTC
Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com>
---
 src/main.c |  6 ++++--
 src/reg.c  | 23 +++++++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/main.c b/src/main.c
index 1cfaca7..ce218d5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -84,7 +84,7 @@  extern struct optcmd_cmd
 	optcmd_getnia, optcmd_putnia, optcmd_getmsr, optcmd_putmsr,
 	optcmd_getring, optcmd_start, optcmd_stop, optcmd_step,
 	optcmd_threadstatus, optcmd_sreset, optcmd_regs, optcmd_probe,
-	optcmd_getmem, optcmd_putmem;
+	optcmd_getmem, optcmd_putmem, optcmd_getxer, optcmd_putxer;
 
 static struct optcmd_cmd *cmds[] = {
 	&optcmd_getscom, &optcmd_putscom, &optcmd_getcfam, &optcmd_putcfam,
@@ -92,7 +92,7 @@  static struct optcmd_cmd *cmds[] = {
 	&optcmd_getnia, &optcmd_putnia, &optcmd_getmsr, &optcmd_putmsr,
 	&optcmd_getring, &optcmd_start, &optcmd_stop, &optcmd_step,
 	&optcmd_threadstatus, &optcmd_sreset, &optcmd_regs, &optcmd_probe,
-	&optcmd_getmem, &optcmd_putmem,
+	&optcmd_getmem, &optcmd_putmem, &optcmd_getxer, &optcmd_putxer,
 };
 
 /* Purely for printing usage text. We could integrate printing argument and flag
@@ -112,6 +112,8 @@  static struct action actions[] = {
 	{ "putspr",  "<spr> <value>", "Write Special Purpose Register (SPR)" },
 	{ "getmsr",  "", "Get Machine State Register (MSR)" },
 	{ "putmsr",  "<value>", "Write Machine State Register (MSR)" },
+	{ "getxer",  "", "Get Fixed Point Exception Register (XER)" },
+	{ "putxer",  "<value>", "Write Fixed Point Exception Register (XER)" },
 	{ "getring", "<addr> <len>", "Read a ring. Length must be correct" },
 	{ "start",   "", "Start thread" },
 	{ "step",    "<count>", "Set a thread <count> instructions" },
diff --git a/src/reg.c b/src/reg.c
index aa77a8a..dbef0ef 100644
--- a/src/reg.c
+++ b/src/reg.c
@@ -18,12 +18,14 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <debug.h>
 
 #include <libpdbg.h>
 
 #include "main.h"
 #include "optcmd.h"
 
+#define REG_XER -4
 #define REG_MEM -3
 #define REG_MSR -2
 #define REG_NIA -1
@@ -42,6 +44,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)
@@ -63,6 +67,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)
@@ -82,6 +88,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, (uint32_t *)&value);
 	else if (*reg > REG_R31)
 		rc = ram_getspr(target, *reg - REG_R31, &value);
 	else if (*reg >= 0 && *reg <= 31)
@@ -147,3 +155,18 @@  static int putmsr(uint64_t data)
 	return for_each_target("thread", putprocreg, &reg, &data);
 }
 OPTCMD_DEFINE_CMD_WITH_ARGS(putmsr, putmsr, (DATA));
+
+static int getxer(void)
+{
+	uint64_t reg = REG_XER;
+	return for_each_target("thread", getprocreg, &reg, NULL);
+}
+OPTCMD_DEFINE_CMD(getxer, getxer);
+
+static int putxer(uint32_t data)
+{
+	uint64_t reg = REG_XER;
+	uint64_t d = data;
+	return for_each_target("thread", putprocreg, &reg, &d);
+}
+OPTCMD_DEFINE_CMD_WITH_ARGS(putxer, putxer, (DATA32));