On 8/28/2014 12:15 PM, Paolo Bonzini wrote:
> Match the idiom used by linux-user/signal.c and
> linux-user/elfload.c.
> 
> Signed-off-by: Paolo Bonzini <pbonz...@redhat.com>
> ---
>  target-ppc/gdbstub.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/target-ppc/gdbstub.c b/target-ppc/gdbstub.c
> index 14675f4..bad49ae 100644
> --- a/target-ppc/gdbstub.c
> +++ b/target-ppc/gdbstub.c
> @@ -138,7 +138,7 @@ int ppc_cpu_gdb_read_register(CPUState *cs, uint8_t 
> *mem_buf, int n)
>              {
>                  uint32_t cr = 0;
>                  int i;
> -                for (i = 0; i < 8; i++) {
> +                for (i = 0; i < ARRAY_SIZE(env->crf); i++) {
>                      cr |= env->crf[i] << (32 - ((i + 1) * 4));
>                  }
>                  gdb_get_reg32(mem_buf, cr);
> @@ -246,7 +246,7 @@ int ppc_cpu_gdb_write_register(CPUState *cs, uint8_t 
> *mem_buf, int n)
>              {
>                  uint32_t cr = ldl_p(mem_buf);
>                  int i;
> -                for (i = 0; i < 8; i++) {
> +                for (i = 0; i < ARRAY_SIZE(env->crf); i++) {
>                      env->crf[i] = (cr >> (32 - ((i + 1) * 4))) & 0xF;
>                  }
>                  break;
> 

Since the same code appears in 3 different places, would it be better to 
implement a reusable function in target-ppc/cpu.h?

I.e.:

static inline uint32_t ppc_get_cr(const CPUPPCState *env) {
    uint32_t cr = 0;
    for (i = 0; i < ARRAY_SIZE(env->crf); i++) {
        cr |= ppc_get_crf(env, i) << (32 - ((i + 1) * 4));
    }
    return cr;
}


Reply via email to