[Pdbg] [PATCH 4/8] libpdbg: Make getcr actually get all of the Condition Register

Alistair Popple alistair at popple.id.au
Mon Jun 25 16:33:23 AEST 2018


> +int ram_getcr(struct pdbg_target *thread, uint32_t *value)
> +{
> +	uint32_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 */

Why not? ram_getcr_field() is an external API and I think it's suprising that it
would return bits not part of the requested field so we should mask off bits
there. Also I would expect the field to be right-justified, which would turn
this:

> +		cr |= cr_field & (0xf << 4*i);

Into this:

		cr |= cr_field << 4*i;

Do you think that makes sense? Or will users expect the _field() APIs to return
fields left-shifted? (The same comments apply to your getxer_fields() series too
;)

- Alistair

> +	}
> +
> +	*value = cr;
> +	return 0;
> +}
> +
>  int ram_putmsr(struct pdbg_target *thread, uint64_t value)
>  {
>  	uint64_t opcodes[] = {mfspr(0, 277), mtmsr(0)};
> @@ -447,12 +463,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, &regs->cr);
>  	printf("CR    : 0x%08" PRIx32 "\n", regs->cr);
>  
>  	ram_getxer(thread, &regs->xer);
> diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
> index 81d6170..28470c3 100644
> --- a/libpdbg/libpdbg.h
> +++ b/libpdbg/libpdbg.h
> @@ -138,6 +138,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,  uint32_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);
> 




More information about the Pdbg mailing list