diff options
-rw-r--r-- | libpdbg/chip.c | 27 | ||||
-rw-r--r-- | libpdbg/libpdbg.h | 1 |
2 files changed, 18 insertions, 10 deletions
diff --git a/libpdbg/chip.c b/libpdbg/chip.c index 01c9b58..31c8c80 100644 --- a/libpdbg/chip.c +++ b/libpdbg/chip.c @@ -281,13 +281,25 @@ 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(struct pdbg_target *thread, uint32_t *value) { - uint64_t opcodes[] = {mfocrf(0, cr), mtspr(277, 0)}; - uint64_t results[] = {0, 0}; + + uint64_t opcodes[] = {mfocrf(0, 0), mtspr(277, 0), mfocrf(0, 1), mtspr(277, 0), + mfocrf(0, 2), mtspr(277, 0), mfocrf(0, 3), mtspr(277, 0), + mfocrf(0, 4), mtspr(277, 0), mfocrf(0, 5), mtspr(277, 0), + mfocrf(0, 6), mtspr(277, 0), mfocrf(0, 7), mtspr(277, 0)}; + uint64_t results[16] = {0}; + uint32_t cr_field, cr = 0; + int i; CHECK_ERR(ram_instructions(thread, opcodes, results, ARRAY_SIZE(opcodes), 0)); - *value = results[1]; + for (i = 1; i < 16; i += 2) { + cr_field = results[i]; + /* We are not guaranteed that the other bits will be zeroed out */ + cr |= cr_field & (0xf << 2*(i-1)); + } + + *value = cr; return 0; } @@ -386,12 +398,7 @@ int ram_state_thread(struct pdbg_target *thread, struct thread_regs *regs) ram_getspr(thread, 815, ®s->tar); printf("TAR : 0x%016" PRIx64 "\n", regs->tar); - regs->cr = 0; - for (i = 0; i < 8; i++) { - uint64_t cr = 0; - ram_getcr(thread, i, &cr); - regs->cr |= cr; - } + ram_getcr(thread, ®s->cr); printf("CR : 0x%08" PRIx32 "\n", regs->cr); ram_getxer(thread, ®s->xer); diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h index 68d158c..9c29ecc 100644 --- a/libpdbg/libpdbg.h +++ b/libpdbg/libpdbg.h @@ -141,6 +141,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); |