From e3dd8d6114ca49101905002ccb2a1a4836171917 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sun, 5 Apr 2020 02:39:33 -0700 Subject: [PATCH] util: Make the device file name used by map_m5_mem overridable. The name this function uses is now exposed as a global variable called m5_mmap_dev which can be changed at run time. This would be useful if using a non-standard location for /dev/mem, or for testing where we might want to use a totally different device. Change-Id: I5e7ac106c3e4e0555c99af2a7a0aca8171534451 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27556 Reviewed-by: Jason Lowe-Power Reviewed-by: Pouya Fotouhi Maintainer: Jason Lowe-Power Tested-by: kokoro --- util/m5/src/m5_mmap.c | 10 +++++++--- util/m5/src/m5_mmap.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/util/m5/src/m5_mmap.c b/util/m5/src/m5_mmap.c index 4a5aa0f55..d3413031d 100644 --- a/util/m5/src/m5_mmap.c +++ b/util/m5/src/m5_mmap.c @@ -38,9 +38,11 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include +#include #include #include #include @@ -54,21 +56,23 @@ void *m5_mem = NULL; #endif uint64_t m5op_addr = M5OP_ADDR; +const char *m5_mmap_dev = "/dev/mem"; + void map_m5_mem() { int fd; - fd = open("/dev/mem", O_RDWR | O_SYNC); + fd = open(m5_mmap_dev, O_RDWR | O_SYNC); if (fd == -1) { - perror("Can't open /dev/mem"); + fprintf(stderr, "Can't open %s: %s\n", m5_mmap_dev, strerror(errno)); exit(1); } m5_mem = mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, m5op_addr); if (!m5_mem) { - perror("Can't mmap /dev/mem"); + fprintf(stderr, "Can't map %s: %s\n", m5_mmap_dev, strerror(errno)); exit(1); } } diff --git a/util/m5/src/m5_mmap.h b/util/m5/src/m5_mmap.h index d7fe19b3d..09cddb29c 100644 --- a/util/m5/src/m5_mmap.h +++ b/util/m5/src/m5_mmap.h @@ -49,7 +49,7 @@ extern "C" { extern void *m5_mem; extern uint64_t m5op_addr; - +extern const char *m5_mmap_dev; void map_m5_mem(); #ifdef __cplusplus -- 2.30.2