From 3fa1ce6d7289efb485c8d69fe33fd2c47a9f6cfe Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 22 Oct 2020 20:01:08 -0700 Subject: [PATCH] util: Expose addr config mechanisms in the gem5 op java wrapper. These allow you to set the target physical address, and map or unmap the region of physical memory. This is not automatic for two reasons. First, the address needs to be configured before the mapping is done, and there's no way to ensure that ordering when everything is handled automatically. Second, if the user isn't going to use the address based mechanism, then the mapping and access to /dev/mem isn't necessary and may prevent using the other call types. Change-Id: I0f9c32d6bfa402ba59ea1bf5672fb7f11003568d Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/28184 Reviewed-by: Gabe Black Maintainer: Bobby R. Bruce Tested-by: kokoro --- util/m5/README.md | 13 +++++++++++++ util/m5/src/java/gem5/Ops.java | 4 ++++ util/m5/src/java/gem5/ops.cc | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/util/m5/README.md b/util/m5/README.md index b9ccbff55..cbdff1d12 100644 --- a/util/m5/README.md +++ b/util/m5/README.md @@ -362,6 +362,19 @@ gem5.Ops gem5_ops = gem5.Ops.callTypes.get("default"); long sum = gem5_ops.sum(1, 2, 3, 4, 5, 6); ``` +To configure the address based trigger mechanism, you can use these static +methods. + +void setAddr(long addr); +Set the address for the "magic" address region. + +void mapMem(); +Map the "magic" physical address region into the process' address space, likely +by mmapping the "/dev/mem" device file. + +void unmapMem(); +Unmap the "magic" physical address region that was previously mapped. + # lua module diff --git a/util/m5/src/java/gem5/Ops.java b/util/m5/src/java/gem5/Ops.java index f6ab178db..ab2541947 100644 --- a/util/m5/src/java/gem5/Ops.java +++ b/util/m5/src/java/gem5/Ops.java @@ -53,6 +53,10 @@ public class Ops { private static Map _callTypes; public static final Map callTypes; + public static native void setAddr(long addr); + public static native void mapMem(); + public static native void unmapMem(); + static { try { File temp_lib = File.createTempFile("gem5Ops", ".so"); diff --git a/util/m5/src/java/gem5/ops.cc b/util/m5/src/java/gem5/ops.cc index c1f36e483..da2184076 100644 --- a/util/m5/src/java/gem5/ops.cc +++ b/util/m5/src/java/gem5/ops.cc @@ -44,6 +44,7 @@ #include "call_type/semi_dt.hh" #include "gem5/m5ops.h" #include "java/gem5_Ops.h" +#include "m5_mmap.h" #define _stringify(x) #x #define stringify(x) _stringify(x) @@ -108,6 +109,24 @@ Java_gem5_Ops_setupCallTypes(JNIEnv *env, jclass clazz) env->DeleteLocalRef(map); } +JNIEXPORT void JNICALL +Java_gem5_Ops_setAddr(JNIEnv *env, jclass clazz, jlong addr) +{ + m5op_addr = addr; +} + +JNIEXPORT void JNICALL +Java_gem5_Ops_mapMem(JNIEnv *env, jclass clazz) +{ + map_m5_mem(); +} + +JNIEXPORT void JNICALL +Java_gem5_Ops_unmapMem(JNIEnv *env, jclass clazz) +{ + unmap_m5_mem(); +} + static DispatchTable * getDispatchTable(JNIEnv *env, jobject obj) { -- 2.30.2