diff mbox series

[6/8] pdbg: Add getcr and putcr options

Message ID 20180622045116.12059-7-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  | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/main.c b/src/main.c
index ce218d5..33f7edb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -84,7 +84,8 @@  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_getxer, optcmd_putxer;
+	optcmd_getmem, optcmd_putmem, optcmd_getxer, optcmd_putxer,
+	optcmd_getcr, optcmd_putcr;
 
 static struct optcmd_cmd *cmds[] = {
 	&optcmd_getscom, &optcmd_putscom, &optcmd_getcfam, &optcmd_putcfam,
@@ -93,6 +94,7 @@  static struct optcmd_cmd *cmds[] = {
 	&optcmd_getring, &optcmd_start, &optcmd_stop, &optcmd_step,
 	&optcmd_threadstatus, &optcmd_sreset, &optcmd_regs, &optcmd_probe,
 	&optcmd_getmem, &optcmd_putmem, &optcmd_getxer, &optcmd_putxer,
+	&optcmd_getcr, &optcmd_putcr,
 };
 
 /* Purely for printing usage text. We could integrate printing argument and flag
@@ -112,6 +114,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)" },
+	{ "getcr",  "", "Get Condition Register (CR)" },
+	{ "putcr",  "<value>", "Write Condition Register (CR)" },
 	{ "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" },
diff --git a/src/reg.c b/src/reg.c
index 65e8eb4..60705f1 100644
--- a/src/reg.c
+++ b/src/reg.c
@@ -25,6 +25,7 @@ 
 #include "main.h"
 #include "optcmd.h"
 
+#define REG_CR -5
 #define REG_XER -4
 #define REG_MEM -3
 #define REG_MSR -2
@@ -46,6 +47,8 @@  static void print_proc_reg(struct pdbg_target *target, uint64_t reg, uint64_t va
 		printf("nia: ");
 	else if (reg == REG_XER)
 		printf("xer: ");
+	else if (reg == REG_CR)
+		printf("cr: ");
 	else if (reg > REG_R31)
 		printf("spr%03" PRIu64 ": ", reg - REG_R31);
 	else if (reg >= 0 && reg <= 31)
@@ -69,6 +72,8 @@  static int putprocreg(struct pdbg_target *target, uint32_t index, uint64_t *reg,
 		rc = ram_putnia(target, *value);
 	else if (*reg == REG_XER)
 		rc = ram_putxer(target, *value);
+	else if (*reg == REG_CR)
+		rc = ram_putcr(target, *value);
 	else if (*reg > REG_R31)
 		rc = ram_putspr(target, *reg - REG_R31, *value);
 	else if (*reg >= 0 && *reg <= 31)
@@ -172,3 +177,18 @@  static int putxer(uint32_t data)
 	return for_each_target("thread", putprocreg, &reg, &d);
 }
 OPTCMD_DEFINE_CMD_WITH_ARGS(putxer, putxer, (DATA32));
+
+static int getcr(void)
+{
+	uint64_t cr = REG_CR;
+	return for_each_target("thread", getprocreg, &cr, NULL);
+}
+OPTCMD_DEFINE_CMD(getcr, getcr);
+
+static int putcr(uint32_t data)
+{
+	uint64_t cr = REG_CR;
+	uint64_t d = data;
+	return for_each_target("thread", putprocreg, &cr, &d);
+}
+OPTCMD_DEFINE_CMD_WITH_ARGS(putcr, putcr, (DATA32));