From 20cad17ce3306072ac948e54737a1abad97ecd85 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Mon, 2 Oct 2017 11:28:38 +1300 Subject: [PATCH] target: Implement generic multi-register read/write --- src/target/target.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index 85c5198..09cdc61 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -347,8 +347,26 @@ ssize_t target_reg_write(target *t, int reg, const void *data, size_t size) return t->reg_write(t, reg, data, size); } -void target_regs_read(target *t, void *data) { t->regs_read(t, data); } -void target_regs_write(target *t, const void *data) { t->regs_write(t, data); } +void target_regs_read(target *t, void *data) +{ + if (t->regs_read) { + t->regs_read(t, data); + return; + } + for (size_t x = 0, i = 0; x < t->regs_size; ) { + x += t->reg_read(t, i++, data + x, t->regs_size - x); + } +} +void target_regs_write(target *t, const void *data) +{ + if (t->regs_write) { + t->regs_write(t, data); + return; + } + for (size_t x = 0, i = 0; x < t->regs_size; ) { + x += t->reg_write(t, i++, data + x, t->regs_size - x); + } +} /* Halt/resume functions */ void target_reset(target *t) { t->reset(t); }