summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyril Bur <cyrilbur@gmail.com>2018-02-09 15:38:37 +1100
committerAlistair Popple <alistair@popple.id.au>2018-02-12 14:50:47 +1100
commit856c44984dfd8fcb7a08e7b416cf7b457427974b (patch)
treeff7178d9d31593dccd74060f71c87fac72860428
parent1de4af7a2907f2377ad2b4123cd25a3a40c0122f (diff)
downloadpdbg-856c44984dfd8fcb7a08e7b416cf7b457427974b.tar.gz
pdbg-856c44984dfd8fcb7a08e7b416cf7b457427974b.zip
main: Pull memory accessors out of main.c
Signed-off-by: Cyril Bur <cyrilbur@gmail.com>
-rw-r--r--Makefile.am2
-rw-r--r--src/main.c27
-rw-r--r--src/mem.c48
-rw-r--r--src/mem.h18
4 files changed, 68 insertions, 27 deletions
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);
OpenPOWER on IntegriCloud