[5/5] main: Use new api to read/write memory

Message ID 20190107043020.145107-6-amitay@ozlabs.org
State New
Headers show
Series
  • Introduce new api mem_read/mem_write
Related show

Checks

Context Check Description
snowpatch_ozlabs/build-multiarch success Test build-multiarch on branch master
snowpatch_ozlabs/apply_patch success master/apply_patch Successfully applied

Commit Message

Amitay Isaacs Jan. 7, 2019, 4:30 a.m.
Signed-off-by: Amitay Isaacs <amitay@ozlabs.org>
---
 src/mem.c       | 28 ++++++++++------------------
 src/pdbgproxy.c |  6 +++---
 src/thread.c    |  2 +-
 3 files changed, 14 insertions(+), 22 deletions(-)

Patch

diff --git a/src/mem.c b/src/mem.c
index 6454739..408ff11 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -41,7 +41,7 @@  struct mem_flags {
 #define MEM_CI_FLAG ("--ci", ci, parse_flag_noarg, false)
 #define BLOCK_SIZE (parse_number8_pow2, NULL)
 
-static int _getmem(uint64_t addr, uint64_t size, uint8_t block_size)
+static int _getmem(uint64_t addr, uint64_t size, uint8_t block_size, bool ci)
 {
 	struct pdbg_target *target;
 	uint8_t *buf;
@@ -60,11 +60,7 @@  static int _getmem(uint64_t addr, uint64_t size, uint8_t block_size)
 
 		pdbg_set_progress_tick(progress_tick);
 		progress_init();
-		if (block_size)
-			rc = adu_getmem_io(target, addr, buf, size, block_size);
-		else
-			rc = adu_getmem(target, addr, buf, size);
-
+		rc = mem_read(target, addr, buf, size, block_size, ci);
 		if (rc)
 			PR_ERROR("Unable to read memory.\n");
 
@@ -84,20 +80,20 @@  static int _getmem(uint64_t addr, uint64_t size, uint8_t block_size)
 static int getmem(uint64_t addr, uint64_t size, struct mem_flags flags)
 {
 	if (flags.ci)
-		return _getmem(addr, size, 8);
+		return _getmem(addr, size, 8, true);
 	else
-		return _getmem(addr, size, 0);
+		return _getmem(addr, size, 0, false);
 }
 OPTCMD_DEFINE_CMD_WITH_FLAGS(getmem, getmem, (ADDRESS, DATA),
 			     mem_flags, (MEM_CI_FLAG));
 
 static int getmemio(uint64_t addr, uint64_t size, uint8_t block_size)
 {
-	return _getmem(addr, size, block_size);
+	return _getmem(addr, size, block_size, true);
 }
 OPTCMD_DEFINE_CMD_WITH_ARGS(getmemio, getmemio, (ADDRESS, DATA, BLOCK_SIZE));
 
-static int _putmem(uint64_t addr, uint8_t block_size)
+static int _putmem(uint64_t addr, uint8_t block_size, bool ci)
 {
 	uint8_t *buf;
 	int read_size, rc = 0;
@@ -118,11 +114,7 @@  static int _putmem(uint64_t addr, uint8_t block_size)
 		if (read_size <= 0)
 			break;
 
-		if (block_size)
-			rc = adu_putmem_io(adu_target, addr, buf, read_size, block_size);
-		else
-			rc = adu_putmem(adu_target, addr, buf, read_size);
-
+		rc = mem_write(adu_target, addr, buf, read_size, block_size, ci);
 		if (rc) {
 			rc = 0;
 			printf("Unable to write memory.\n");
@@ -141,14 +133,14 @@  static int _putmem(uint64_t addr, uint8_t block_size)
 static int putmem(uint64_t addr, struct mem_flags flags)
 {
 	if (flags.ci)
-		return _putmem(addr, 8);
+		return _putmem(addr, 8, true);
 	else
-		return _putmem(addr, 0);
+		return _putmem(addr, 0, false);
 }
 OPTCMD_DEFINE_CMD_WITH_FLAGS(putmem, putmem, (ADDRESS), mem_flags, (MEM_CI_FLAG));
 
 static int putmemio(uint64_t addr, uint8_t block_size)
 {
-	return _putmem(addr, block_size);
+	return _putmem(addr, block_size, true);
 }
 OPTCMD_DEFINE_CMD_WITH_ARGS(putmemio, putmemio, (ADDRESS, BLOCK_SIZE));
diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c
index dedea7a..572af01 100644
--- a/src/pdbgproxy.c
+++ b/src/pdbgproxy.c
@@ -183,7 +183,7 @@  static void get_spr(uint64_t *stack, void *priv)
 
 #define MAX_DATA 0x1000
 
-/* Returns a real address to use with adu_getmem or -1UL if we
+/* Returns a real address to use with mem_read or -1UL if we
  * couldn't determine a real address. At the moment we only deal with
  * kernel linear mapping but in future we could walk that page
  * tables. */
@@ -223,7 +223,7 @@  static void get_mem(uint64_t *stack, void *priv)
 
 	linear_map = get_real_addr(addr);
 	if (linear_map != -1UL) {
-		if (adu_getmem(adu_target, linear_map, (uint8_t *) data, len)) {
+		if (mem_read(adu_target, linear_map, (uint8_t *) data, len, 0, false)) {
 			PR_ERROR("Unable to read memory\n");
 			err = 1;
 		}
@@ -293,7 +293,7 @@  static void put_mem(uint64_t *stack, void *priv)
 
 	PR_INFO("put_mem 0x%016" PRIx64 " = 0x%016" PRIx64 "\n", addr, stack[2]);
 
-	if (adu_putmem(adu_target, addr, data, len)) {
+	if (mem_write(adu_target, addr, data, len, 0, false)) {
 		PR_ERROR("Unable to write memory\n");
 		err = 3;
 	}
diff --git a/src/thread.c b/src/thread.c
index 1fd448d..8f34233 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -35,7 +35,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)) {
+	if (mem_read(target, addr, (uint8_t *)value, 8, 0, false)) {
 		pdbg_log(PDBG_ERROR, "Unable to read memory address=%016" PRIx64 ".\n", addr);
 		return 0;
 	}