From 27ef63cc8dd0d2dd2d54c65971d6358f44640654 Mon Sep 17 00:00:00 2001 From: lazymio Date: Tue, 15 Feb 2022 22:07:53 +0100 Subject: [PATCH] Add UC_PPC_REG_CR --- include/unicorn/ppc.h | 3 ++- qemu/target/ppc/unicorn.c | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/unicorn/ppc.h b/include/unicorn/ppc.h index 5705ffff..a7ea5725 100644 --- a/include/unicorn/ppc.h +++ b/include/unicorn/ppc.h @@ -417,7 +417,8 @@ typedef enum uc_ppc_reg { UC_PPC_REG_XER, UC_PPC_REG_CTR, UC_PPC_REG_MSR, - UC_PPC_REG_FPSCR + UC_PPC_REG_FPSCR, + UC_PPC_REG_CR } uc_ppc_reg; #ifdef __cplusplus diff --git a/qemu/target/ppc/unicorn.c b/qemu/target/ppc/unicorn.c index 52737f76..06adf132 100644 --- a/qemu/target/ppc/unicorn.c +++ b/qemu/target/ppc/unicorn.c @@ -196,6 +196,13 @@ static void reg_read(CPUPPCState *env, unsigned int regid, void *value) case UC_PPC_REG_CR7: *(uint32_t *)value = env->crf[regid - UC_PPC_REG_CR0]; break; + case UC_PPC_REG_CR: { + uint32_t cr = 0; + for (int i = 0; i < 8; i++) { + cr <<= 4; + cr |= env->crf[i]; + } + } break; case UC_PPC_REG_LR: *(ppcreg_t *)value = env->lr; break; @@ -270,8 +277,15 @@ static void reg_write(CPUPPCState *env, unsigned int regid, const void *value) case UC_PPC_REG_CR5: case UC_PPC_REG_CR6: case UC_PPC_REG_CR7: - env->crf[regid - UC_PPC_REG_CR0] = *(uint32_t *)value; + env->crf[regid - UC_PPC_REG_CR0] = (*(uint32_t *)value) & 0b1111; break; + case UC_PPC_REG_CR: { + uint32_t cr = *(uint32_t *)value; + for (int i = 0; i < 8; i++) { + env->crf[i] = cr & 0b1111; + cr >>= 4; + } + } break; case UC_PPC_REG_LR: env->lr = *(ppcreg_t *)value; break;