[Pdbg] [PATCH 09/29] main: Pull memory accessors out of main.c
Cyril Bur
cyrilbur at gmail.com
Fri Feb 9 15:38:37 AEDT 2018
Signed-off-by: Cyril Bur <cyrilbur at gmail.com>
---
Makefile.am | 2 +-
src/main.c | 27 +--------------------------
src/mem.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
src/mem.h | 18 ++++++++++++++++++
4 files changed, 68 insertions(+), 27 deletions(-)
create mode 100644 src/mem.c
create mode 100644 src/mem.h
diff --git a/Makefile.am b/Makefile.am
index 1e9f1e5..b01ff0f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,7 +11,7 @@ ACLOCAL_AMFLAGS = -Im4
AM_CFLAGS = -I$(top_srcdir)/ccan/array_size -Wall -Werror
pdbg_SOURCES = \
- src/main.c src/cfam.c src/scom.c src/reg.c
+ src/main.c src/cfam.c src/scom.c src/reg.c src/mem.c
pdbg_LDADD = fake.dtb.o p8-fsi.dtb.o p8-i2c.dtb.o p9w-fsi.dtb.o p8-host.dtb.o \
p9z-fsi.dtb.o p9r-fsi.dtb.o p9-kernel.dtb.o libpdbg.la libfdt.la \
p9-host.dtb.o \
diff --git a/src/main.c b/src/main.c
index e7599bc..3d6a5e7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -34,6 +34,7 @@
#include "cfam.h"
#include "scom.h"
#include "reg.h"
+#include "mem.h"
#undef PR_DEBUG
#define PR_DEBUG(...)
@@ -487,32 +488,6 @@ static int print_proc_thread_status(struct pdbg_target *pib_target, uint32_t ind
return for_each_child_target("core", pib_target, print_core_thread_status, NULL, NULL);
};
-#define PUTMEM_BUF_SIZE 1024
-static int putmem(uint64_t addr)
-{
- uint8_t *buf;
- int read_size, rc = 0;
- struct pdbg_target *adu_target;
-
- pdbg_for_each_class_target("adu", adu_target)
- break;
-
- buf = malloc(PUTMEM_BUF_SIZE);
- assert(buf);
- do {
- read_size = read(STDIN_FILENO, buf, PUTMEM_BUF_SIZE);
- if (adu_putmem(adu_target, addr, buf, read_size)) {
- rc = 0;
- PR_ERROR("Unable to write memory.\n");
- break;
- }
- rc += read_size;
- } while (read_size > 0);
-
- free(buf);
- return rc;
-}
-
static int start_thread(struct pdbg_target *thread_target, uint32_t index, uint64_t *unused, uint64_t *unused1)
{
return ram_start_thread(thread_target) ? 0 : 1;
diff --git a/src/mem.c b/src/mem.c
new file mode 100644
index 0000000..b036f12
--- /dev/null
+++ b/src/mem.c
@@ -0,0 +1,48 @@
+/* Copyright 2017 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <operations.h>
+#include <target.h>
+
+#define PUTMEM_BUF_SIZE 1024
+int putmem(uint64_t addr)
+{
+ uint8_t *buf;
+ int read_size, rc = 0;
+ struct pdbg_target *adu_target;
+
+ pdbg_for_each_class_target("adu", adu_target)
+ break;
+
+ buf = malloc(PUTMEM_BUF_SIZE);
+ assert(buf);
+ do {
+ read_size = read(STDIN_FILENO, buf, PUTMEM_BUF_SIZE);
+ if (adu_putmem(adu_target, addr, buf, read_size)) {
+ rc = 0;
+ printf("Unable to write memory.\n");
+ break;
+ }
+ rc += read_size;
+ } while (read_size > 0);
+
+ free(buf);
+ return rc;
+}
diff --git a/src/mem.h b/src/mem.h
new file mode 100644
index 0000000..27312a2
--- /dev/null
+++ b/src/mem.h
@@ -0,0 +1,18 @@
+/* Copyright 2017 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <inttypes.h>
+
+int putmem(uint64_t addr);
--
2.16.1
More information about the Pdbg
mailing list