diff mbox series

[1/4] libpdbg: Use spr specific procedures if defined

Message ID 20200723052641.561009-2-amitay@ozlabs.org
State Accepted
Headers show
Series Improve getspr/putspr command | expand

Commit Message

Amitay Isaacs July 23, 2020, 5:26 a.m. UTC
Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 libpdbg/thread.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
diff mbox series

Patch

diff --git a/libpdbg/thread.c b/libpdbg/thread.c
index e8fb0c0..7ef0bf8 100644
--- a/libpdbg/thread.c
+++ b/libpdbg/thread.c
@@ -18,6 +18,7 @@ 
 #include "libpdbg.h"
 #include "hwunit.h"
 #include "debug.h"
+#include "sprs.h"
 
 struct thread_state thread_status(struct pdbg_target *target)
 {
@@ -334,6 +335,28 @@  int thread_getspr(struct pdbg_target *target, int spr, uint64_t *value)
 
 	thread = target_to_thread(target);
 
+	if (spr == SPR_MSR) {
+		if (thread->getmsr)
+			return thread->getmsr(thread, value);
+	} else if (spr == SPR_NIA) {
+		if (thread->getnia)
+			return thread->getnia(thread, value);
+	} else if (spr == SPR_XER) {
+		if (thread->getxer)
+			return thread->getxer(thread, value);
+	} else if (spr == SPR_CR) {
+		if (thread->getcr) {
+			uint32_t u32;
+			int rc;
+
+			rc  = thread->getcr(thread, &u32);
+			if (rc == 0)
+				*value = u32;
+
+			return rc;
+		}
+	}
+
 	if (!thread->getspr) {
 		PR_ERROR("getspr() not imeplemented for the target\n");
 		return -1;
@@ -353,6 +376,20 @@  int thread_putspr(struct pdbg_target *target, int spr, uint64_t value)
 
 	thread = target_to_thread(target);
 
+	if (spr == SPR_MSR) {
+		if (thread->putmsr)
+			return thread->putmsr(thread, value);
+	} else if (spr == SPR_NIA) {
+		if (thread->putnia)
+			return thread->putnia(thread, value);
+	} else if (spr == SPR_XER) {
+		if (thread->putxer)
+			return thread->putxer(thread, value);
+	} else if (spr == SPR_CR) {
+		if (thread->putcr)
+			return thread->putcr(thread, (uint32_t)value);
+	}
+
 	if (!thread->putspr) {
 		PR_ERROR("putspr() not imeplemented for the target\n");
 		return -1;