From 8fd4d147b6573ef2c0237901cd1691ffee06a14c Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Wed, 25 Mar 2020 15:50:07 -0700 Subject: [PATCH] util: Add missing functions to the java wrapper for m5 ops. Change-Id: I9bdef3cb78cc01b0743ea38eec6f6d28cd2f6765 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27225 Reviewed-by: Bobby R. Bruce Maintainer: Gabe Black Tested-by: kokoro --- util/m5/src/jni/gem5Op.java | 6 +++++ util/m5/src/jni_gem5Op.c | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/util/m5/src/jni/gem5Op.java b/util/m5/src/jni/gem5Op.java index 52c36fff6..11403bfbb 100644 --- a/util/m5/src/jni/gem5Op.java +++ b/util/m5/src/jni/gem5Op.java @@ -57,8 +57,14 @@ public class gem5Op { public native void reset_stats(long ns_delay, long ns_period); public native void dump_stats(long ns_delay, long ns_period); public native void dump_reset_stats(long ns_delay, long ns_period); + public native long read_file(byte[] buffer, long len, long offset); + public native long write_file(byte[] buffer, long len, long offset, + String filename); public native void debug_break(); public native void switch_cpu(); + public native void dist_toggle_sync(); + public native void add_symbol(long addr, String symbol); + public native void load_symbol(); public native void panic(); public native void work_begin(long workid, long threadid); public native void work_end(long workid, long threadid); diff --git a/util/m5/src/jni_gem5Op.c b/util/m5/src/jni_gem5Op.c index 6c3f69657..83a9512e2 100644 --- a/util/m5/src/jni_gem5Op.c +++ b/util/m5/src/jni_gem5Op.c @@ -142,6 +142,33 @@ Java_jni_gem5Op_dump_1reset_1stats(JNIEnv *env, jobject obj, m5_dump_reset_stats(j_ns_delay, j_ns_period); } +JNIEXPORT jlong JNICALL +Java_jni_gem5Op_read_1file(JNIEnv *env, jobject obj, + jbyteArray j_buffer, jlong j_len, jlong j_offset) +{ + jbyte *buffer = (*env)->GetByteArrayElements(env, j_buffer, 0); + + uint64_t result = m5_read_file(buffer, j_len, j_offset); + + (*env)->ReleaseByteArrayElements(env, j_buffer, buffer, JNI_ABORT); + return (result & 0x7FFFFFFFFFFFFFFFULL); +} + +JNIEXPORT jlong JNICALL +Java_jni_gem5Op_write_1file(JNIEnv *env, jobject obj, + jbyteArray j_buffer, jlong j_len, jlong j_offset, + jstring j_filename) +{ + jbyte *buffer = (*env)->GetByteArrayElements(env, j_buffer, 0); + const char *filename = (*env)->GetStringUTFChars(env, j_filename, NULL); + + uint64_t result = m5_write_file(buffer, j_len, j_offset, filename); + + (*env)->ReleaseStringUTFChars(env, j_filename, filename); + (*env)->ReleaseByteArrayElements(env, j_buffer, buffer, JNI_ABORT); + return (result & 0x7FFFFFFFFFFFFFFFULL); +} + JNIEXPORT void JNICALL Java_jni_gem5Op_debug_1break(JNIEnv *env, jobject obj) { @@ -154,6 +181,29 @@ Java_jni_gem5Op_switch_1cpu (JNIEnv *env, jobject obj) m5_switch_cpu(); } +JNIEXPORT void JNICALL +Java_jni_gem5Op_dist_1toggle_1sync(JNIEnv *env, jobject obj) +{ + m5_dist_toggle_sync(); +} + +JNIEXPORT void JNICALL +Java_jni_gem5Op_add_symbol(JNIEnv *env, jobject obj, + jlong j_addr, jstring j_symbol) +{ + const char *symbol = (*env)->GetStringUTFChars(env, j_symbol, NULL); + + m5_add_symbol(j_addr, symbol); + + (*env)->ReleaseStringUTFChars(env, j_symbol, symbol); +} + +JNIEXPORT void JNICALL +Java_jni_gem5Op_load_1symbol(JNIEnv *env, jobject obj) +{ + m5_load_symbol(); +} + JNIEXPORT void JNICALL Java_jni_gem5Op_panic(JNIEnv *env, jobject obj) { -- 2.30.2