diff mbox series

[04/10] libpdbg: Make getcr actually get all of the Condition Register

Message ID 20180531052915.31171-4-rashmica.g@gmail.com
State Changes Requested
Headers show
Series [01/10] libpdbg: Print the name of the instruction when erroring | expand

Commit Message

Rashmica Gupta May 31, 2018, 5:29 a.m. UTC
Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com>
---
 libpdbg/chip.c    | 25 ++++++++++++++++++-------
 libpdbg/libpdbg.h |  1 +
 2 files changed, 19 insertions(+), 7 deletions(-)

Comments

Alistair Popple June 15, 2018, 1:17 a.m. UTC | #1
Reviewed-by: Alistair Popple <alistair@popple.id.au>

On Thursday, 31 May 2018 3:29:09 PM AEST Rashmica Gupta wrote:
> Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com>
> ---
>  libpdbg/chip.c    | 25 ++++++++++++++++++-------
>  libpdbg/libpdbg.h |  1 +
>  2 files changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/libpdbg/chip.c b/libpdbg/chip.c
> index e91d775..f478526 100644
> --- a/libpdbg/chip.c
> +++ b/libpdbg/chip.c
> @@ -318,7 +318,7 @@ int ram_getmsr(struct pdbg_target *thread, uint64_t *value)
>  	return 0;
>  }
>  
> -int ram_getcr(struct pdbg_target *thread, int cr, uint64_t *value)
> +int ram_getcr_field(struct pdbg_target *thread, int cr, uint64_t *value)
>  {
>  	uint64_t opcodes[] = {mfocrf(0, cr), mtspr(277, 0)};
>  	uint64_t results[] = {0, 0};
> @@ -328,6 +328,22 @@ int ram_getcr(struct pdbg_target *thread, int cr, uint64_t *value)
>  	return 0;
>  }
>  
> +int ram_getcr(struct pdbg_target *thread, uint64_t *value)
> +{
> +	uint64_t cr_field, cr = 0;
> +	int i;
> +
> +	for (i = 0; i < 8; i++){
> +		cr_field = 0;
> +		ram_getcr_field(thread, i, &cr_field);
> +		/* We are not guarenteed that the other bits will be zeroed out */
> +		cr |= cr_field & (0xf << 4*i);
> +	}
> +
> +	*value = cr;
> +	return 0;
> +}
> +
>  int ram_putmsr(struct pdbg_target *thread, uint64_t value)
>  {
>  	uint64_t opcodes[] = {mfspr(0, 277), mtmsr(0)};
> @@ -472,12 +488,7 @@ int ram_state_thread(struct pdbg_target *thread, struct thread_regs *regs)
>  	ram_getspr(thread, 815, &regs->tar);
>  	printf("TAR   : 0x%016" PRIx64 "\n", regs->tar);
>  
> -	regs->cr = 0;
> -	for (i = 0; i < 8; i++) {
> -		uint64_t cr;
> -		ram_getcr(thread, i, &cr);
> -		regs->cr |= cr;
> -	}
> +	ram_getcr(thread, (uint64_t *)&regs->cr);
>  	printf("CR    : 0x%08" PRIx32 "\n", regs->cr);
>  
>  	ram_getxer(thread, (uint64_t *)&regs->xer);
> diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
> index 2a3a337..7f09caa 100644
> --- a/libpdbg/libpdbg.h
> +++ b/libpdbg/libpdbg.h
> @@ -140,6 +140,7 @@ int ram_putnia(struct pdbg_target *target, uint64_t val);
>  int ram_putspr(struct pdbg_target *target, int spr, uint64_t val);
>  int ram_putgpr(struct pdbg_target *target, int spr, uint64_t val);
>  int ram_getmsr(struct pdbg_target *target, uint64_t *val);
> +int ram_getcr(struct pdbg_target *thread,  uint64_t *value);
>  int ram_getnia(struct pdbg_target *target, uint64_t *val);
>  int ram_getspr(struct pdbg_target *target, int spr, uint64_t *val);
>  int ram_getgpr(struct pdbg_target *target, int gpr, uint64_t *val);
>
diff mbox series

Patch

diff --git a/libpdbg/chip.c b/libpdbg/chip.c
index e91d775..f478526 100644
--- a/libpdbg/chip.c
+++ b/libpdbg/chip.c
@@ -318,7 +318,7 @@  int ram_getmsr(struct pdbg_target *thread, uint64_t *value)
 	return 0;
 }
 
-int ram_getcr(struct pdbg_target *thread, int cr, uint64_t *value)
+int ram_getcr_field(struct pdbg_target *thread, int cr, uint64_t *value)
 {
 	uint64_t opcodes[] = {mfocrf(0, cr), mtspr(277, 0)};
 	uint64_t results[] = {0, 0};
@@ -328,6 +328,22 @@  int ram_getcr(struct pdbg_target *thread, int cr, uint64_t *value)
 	return 0;
 }
 
+int ram_getcr(struct pdbg_target *thread, uint64_t *value)
+{
+	uint64_t cr_field, cr = 0;
+	int i;
+
+	for (i = 0; i < 8; i++){
+		cr_field = 0;
+		ram_getcr_field(thread, i, &cr_field);
+		/* We are not guarenteed that the other bits will be zeroed out */
+		cr |= cr_field & (0xf << 4*i);
+	}
+
+	*value = cr;
+	return 0;
+}
+
 int ram_putmsr(struct pdbg_target *thread, uint64_t value)
 {
 	uint64_t opcodes[] = {mfspr(0, 277), mtmsr(0)};
@@ -472,12 +488,7 @@  int ram_state_thread(struct pdbg_target *thread, struct thread_regs *regs)
 	ram_getspr(thread, 815, &regs->tar);
 	printf("TAR   : 0x%016" PRIx64 "\n", regs->tar);
 
-	regs->cr = 0;
-	for (i = 0; i < 8; i++) {
-		uint64_t cr;
-		ram_getcr(thread, i, &cr);
-		regs->cr |= cr;
-	}
+	ram_getcr(thread, (uint64_t *)&regs->cr);
 	printf("CR    : 0x%08" PRIx32 "\n", regs->cr);
 
 	ram_getxer(thread, (uint64_t *)&regs->xer);
diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
index 2a3a337..7f09caa 100644
--- a/libpdbg/libpdbg.h
+++ b/libpdbg/libpdbg.h
@@ -140,6 +140,7 @@  int ram_putnia(struct pdbg_target *target, uint64_t val);
 int ram_putspr(struct pdbg_target *target, int spr, uint64_t val);
 int ram_putgpr(struct pdbg_target *target, int spr, uint64_t val);
 int ram_getmsr(struct pdbg_target *target, uint64_t *val);
+int ram_getcr(struct pdbg_target *thread,  uint64_t *value);
 int ram_getnia(struct pdbg_target *target, uint64_t *val);
 int ram_getspr(struct pdbg_target *target, int spr, uint64_t *val);
 int ram_getgpr(struct pdbg_target *target, int gpr, uint64_t *val);