[Pdbg] [PATCH 3/3] libpdbg: Wrappers for cache inhibited adu_getmem and adu_putmem

Joel Stanley joel at jms.id.au
Fri May 18 17:02:02 AEST 2018


Tacking a boolean parameter onto the end of the a function makes it hard
to read the code at call sites and know what is going on.

See Rusty's API levels, point 6 and 7:

 7. The obvious use is (probably) the correct one.
 6. The name tells you how to use it.

 From http://ozlabs.org/~rusty/index.cgi/tech/2008-03-30.html

Cache inhibited is probably not what you're after, unless you know that
you're after it. These wrappers remove the boolean from the user
callable API.

Signed-off-by: Joel Stanley <joel at jms.id.au>
---
 libpdbg/adu.c     | 30 ++++++++++++++++++++++++++++--
 libpdbg/libpdbg.h |  8 ++++++--
 src/mem.c         |  6 +++---
 3 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/libpdbg/adu.c b/libpdbg/adu.c
index 4b9e8cea739d..5d736aefee65 100644
--- a/libpdbg/adu.c
+++ b/libpdbg/adu.c
@@ -83,7 +83,20 @@
 #define FBC_ALTD_DATA_DONE	PPC_BIT(3)
 #define FBC_ALTD_PBINIT_MISSING PPC_BIT(18)
 
-int adu_getmem(struct pdbg_target *adu_target, uint64_t start_addr, uint8_t *output, uint64_t size, bool ci)
+int adu_getmem(struct pdbg_target *adu_target, uint64_t start_addr,
+	       uint8_t *output, uint64_t size)
+{
+	return __adu_getmem(adu_target, start_addr, output, size, false);
+}
+
+int adu_getmem_ci(struct pdbg_target *adu_target, uint64_t start_addr,
+		  uint8_t *output, uint64_t size)
+{
+	return __adu_getmem(adu_target, start_addr, output, size, true);
+}
+
+int __adu_getmem(struct pdbg_target *adu_target, uint64_t start_addr,
+		 uint8_t *output, uint64_t size, bool ci)
 {
 	struct adu *adu;
 	int rc = 0;
@@ -120,7 +133,20 @@ int adu_getmem(struct pdbg_target *adu_target, uint64_t start_addr, uint8_t *out
 	return rc;
 }
 
-int adu_putmem(struct pdbg_target *adu_target, uint64_t start_addr, uint8_t *input, uint64_t size, bool ci)
+int adu_putmem(struct pdbg_target *adu_target, uint64_t start_addr,
+	       uint8_t *output, uint64_t size)
+{
+	return __adu_putmem(adu_target, start_addr, output, size, false);
+}
+
+int adu_putmem_ci(struct pdbg_target *adu_target, uint64_t start_addr,
+		  uint8_t *output, uint64_t size)
+{
+	return __adu_putmem(adu_target, start_addr, output, size, true);
+}
+
+int __adu_putmem(struct pdbg_target *adu_target, uint64_t start_addr,
+		 uint8_t *input, uint64_t size, bool ci)
 {
 	struct adu *adu;
 	int rc = 0, tsize;
diff --git a/libpdbg/libpdbg.h b/libpdbg/libpdbg.h
index 97d2e131ce51..1aa851ab1c72 100644
--- a/libpdbg/libpdbg.h
+++ b/libpdbg/libpdbg.h
@@ -171,8 +171,12 @@ int htm_status(struct pdbg_target *target);
 int htm_reset(struct pdbg_target *target, uint64_t *base, uint64_t *size);
 int htm_dump(struct pdbg_target *target, uint64_t size, const char *filename);
 
-int adu_getmem(struct pdbg_target *target, uint64_t addr, uint8_t *ouput, uint64_t size, bool ci);
-int adu_putmem(struct pdbg_target *target, uint64_t addr, uint8_t *input, uint64_t size, bool ci);
+int adu_getmem(struct pdbg_target *target, uint64_t addr, uint8_t *ouput, uint64_t size);
+int adu_putmem(struct pdbg_target *target, uint64_t addr, uint8_t *input, uint64_t size);
+int adu_getmem_ci(struct pdbg_target *target, uint64_t addr, uint8_t *ouput, uint64_t size);
+int adu_putmem_ci(struct pdbg_target *target, uint64_t addr, uint8_t *input, uint64_t size);
+int __adu_getmem(struct pdbg_target *target, uint64_t addr, uint8_t *ouput, uint64_t size, bool ci);
+int __adu_putmem(struct pdbg_target *target, uint64_t addr, uint8_t *input, uint64_t size, bool ci);
 
 int opb_read(struct pdbg_target *target, uint32_t addr, uint32_t *data);
 int opb_write(struct pdbg_target *target, uint32_t addr, uint32_t data);
diff --git a/src/mem.c b/src/mem.c
index 9c2c09687b53..22680b6a99f4 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -40,7 +40,7 @@ static int getmem(uint64_t addr, uint64_t size, bool ci)
 
 		pdbg_set_progress_tick(progress_tick);
 		progress_init();
-		if (!adu_getmem(target, addr, buf, size, ci)) {
+		if (!__adu_getmem(target, addr, buf, size, ci)) {
 			if (write(STDOUT_FILENO, buf, size) < 0)
 				PR_ERROR("Unable to write stdout.\n");
 			else
@@ -73,7 +73,7 @@ static int putmem(uint64_t addr, bool ci)
 	progress_init();
 	do {
 		read_size = read(STDIN_FILENO, buf, PUTMEM_BUF_SIZE);
-		if (adu_putmem(adu_target, addr, buf, read_size, ci)) {
+		if (__adu_putmem(adu_target, addr, buf, read_size, ci)) {
 			rc = 0;
 			printf("Unable to write memory.\n");
 			break;
@@ -97,7 +97,7 @@ static bool is_real_address(struct thread_regs *regs, uint64_t addr)
 
 static int load8(struct pdbg_target *target, uint64_t addr, uint64_t *value)
 {
-	if (adu_getmem(target, addr, (uint8_t *)value, 8, false)) {
+	if (adu_getmem(target, addr, (uint8_t *)value, 8)) {
 		PR_ERROR("Unable to read memory address=%016" PRIx64 ".\n", addr);
 		return 0;
 	}
-- 
2.17.0



More information about the Pdbg mailing list