towards adding support for 64-bit architectures: registering relative memory addresses with contiki instead of fetching absolute addresses to java
This commit is contained in:
parent
11fa5a9a6b
commit
42c3b0fc19
4 changed files with 53 additions and 53 deletions
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: contiki_template.c,v 1.7 2008/02/10 22:36:36 oliverschmidt Exp $
|
* $Id: contiki_template.c,v 1.8 2008/11/20 16:36:27 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,7 +96,7 @@
|
||||||
* referenceVar is used for comparing absolute and process relative memory.
|
* referenceVar is used for comparing absolute and process relative memory.
|
||||||
* (this must not be static due to memory locations)
|
* (this must not be static due to memory locations)
|
||||||
*/
|
*/
|
||||||
int referenceVar;
|
long referenceVar;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* process_run() infinite loop.
|
* process_run() infinite loop.
|
||||||
|
@ -118,10 +118,10 @@ start_process_run_loop(void *data)
|
||||||
|
|
||||||
/* Initialize communication stack */
|
/* Initialize communication stack */
|
||||||
init_net();
|
init_net();
|
||||||
|
|
||||||
/* Start user applications */
|
/* Start user applications */
|
||||||
autostart_start(autostart_processes);
|
autostart_start(autostart_processes);
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
/* Always pretend we have processes left while inside process_run() */
|
/* Always pretend we have processes left while inside process_run() */
|
||||||
|
@ -145,8 +145,6 @@ start_process_run_loop(void *data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern unsigned long _end;
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* \brief Initialize a mote by starting processes etc.
|
* \brief Initialize a mote by starting processes etc.
|
||||||
|
@ -179,9 +177,15 @@ Java_se_sics_cooja_corecomm_[CLASS_NAME]_init(JNIEnv *env, jobject obj)
|
||||||
* responsible Java part (MoteType.java).
|
* responsible Java part (MoteType.java).
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_se_sics_cooja_corecomm_[CLASS_NAME]_getMemory(JNIEnv *env, jobject obj, jint start, jint length, jbyteArray mem_arr)
|
Java_se_sics_cooja_corecomm_[CLASS_NAME]_getMemory(JNIEnv *env, jobject obj, jint rel_addr, jint length, jbyteArray mem_arr)
|
||||||
{
|
{
|
||||||
(*env)->SetByteArrayRegion(env, mem_arr, 0, (size_t) length, (jbyte *) start);
|
(*env)->SetByteArrayRegion(
|
||||||
|
env,
|
||||||
|
mem_arr,
|
||||||
|
0,
|
||||||
|
(size_t) length,
|
||||||
|
(jbyte *) (((long)rel_addr) + referenceVar)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -198,10 +202,13 @@ Java_se_sics_cooja_corecomm_[CLASS_NAME]_getMemory(JNIEnv *env, jobject obj, jin
|
||||||
* responsible Java part (MoteType.java).
|
* responsible Java part (MoteType.java).
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
Java_se_sics_cooja_corecomm_[CLASS_NAME]_setMemory(JNIEnv *env, jobject obj, jint start, jint length, jbyteArray mem_arr)
|
Java_se_sics_cooja_corecomm_[CLASS_NAME]_setMemory(JNIEnv *env, jobject obj, jint rel_addr, jint length, jbyteArray mem_arr)
|
||||||
{
|
{
|
||||||
jbyte *mem = (*env)->GetByteArrayElements(env, mem_arr, 0);
|
jbyte *mem = (*env)->GetByteArrayElements(env, mem_arr, 0);
|
||||||
memcpy((void *) start, mem, length);
|
memcpy(
|
||||||
|
(char*) (((long)rel_addr) + referenceVar),
|
||||||
|
mem,
|
||||||
|
length);
|
||||||
(*env)->ReleaseByteArrayElements(env, mem_arr, mem, 0);
|
(*env)->ReleaseByteArrayElements(env, mem_arr, mem, 0);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
@ -272,9 +279,9 @@ Java_se_sics_cooja_corecomm_[CLASS_NAME]_tick(JNIEnv *env, jobject obj)
|
||||||
* responsible Java part (MoteType.java).
|
* responsible Java part (MoteType.java).
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jint JNICALL
|
JNIEXPORT jint JNICALL
|
||||||
Java_se_sics_cooja_corecomm_[CLASS_NAME]_getReferenceAbsAddr(JNIEnv *env, jobject obj)
|
Java_se_sics_cooja_corecomm_[CLASS_NAME]_setReferenceAddress(JNIEnv *env, jobject obj, jint addr)
|
||||||
{
|
{
|
||||||
return (jint) &referenceVar;
|
referenceVar = (((long)&referenceVar) - ((long)addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class [CLASSNAME] extends CoreComm {
|
||||||
|
|
||||||
public native void tick();
|
public native void tick();
|
||||||
public native void init();
|
public native void init();
|
||||||
public native int getReferenceAbsAddr();
|
public native void setReferenceAddress(int addr);
|
||||||
public native void getMemory(int start, int length, byte[] mem);
|
public native void getMemory(int rel_addr, int length, byte[] mem);
|
||||||
public native void setMemory(int start, int length, byte[] mem);
|
public native void setMemory(int rel_addr, int length, byte[] mem);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: CoreComm.java,v 1.11 2008/02/12 15:03:02 fros4943 Exp $
|
* $Id: CoreComm.java,v 1.12 2008/11/20 16:34:45 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja;
|
package se.sics.cooja;
|
||||||
|
@ -361,35 +361,29 @@ public abstract class CoreComm {
|
||||||
protected abstract void init();
|
protected abstract void init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns absolute memory location of the core variable referenceVar. Used to
|
* Sets the relative memory address of the reference variable.
|
||||||
* get offset between relative and absolute memory addresses.
|
* Is used by Contiki to map between absolute and relative memory addresses.
|
||||||
*
|
*
|
||||||
* @return Absolute memory address
|
* @param addr Relative address
|
||||||
*/
|
*/
|
||||||
public abstract int getReferenceAbsAddr();
|
public abstract void setReferenceAddress(int addr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills an byte array with memory segment identified by start and length.
|
* Fills an byte array with memory segment identified by start and length.
|
||||||
*
|
*
|
||||||
* @param start
|
* @param relAddr Relative memory start address
|
||||||
* Start address of segment
|
* @param length Length of segment
|
||||||
* @param length
|
* @param mem Array to fill with memory segment
|
||||||
* Length of segment
|
|
||||||
* @param mem
|
|
||||||
* Array to fill with memory segment
|
|
||||||
*/
|
*/
|
||||||
public abstract void getMemory(int start, int length, byte[] mem);
|
public abstract void getMemory(int relAddr, int length, byte[] mem);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrites a memory segment identified by start and length.
|
* Overwrites a memory segment identified by start and length.
|
||||||
*
|
*
|
||||||
* @param start
|
* @param relAddr Relative memory start address
|
||||||
* Start address of segment
|
* @param length Length of segment
|
||||||
* @param length
|
* @param mem New memory segment data
|
||||||
* Length of segment
|
|
||||||
* @param mem
|
|
||||||
* New memory segment data
|
|
||||||
*/
|
*/
|
||||||
public abstract void setMemory(int start, int length, byte[] mem);
|
public abstract void setMemory(int relAddr, int length, byte[] mem);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: ContikiMoteType.java,v 1.27 2008/05/02 05:47:22 fros4943 Exp $
|
* $Id: ContikiMoteType.java,v 1.28 2008/11/20 16:35:44 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.contikimote;
|
package se.sics.cooja.contikimote;
|
||||||
|
@ -172,7 +172,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
// Core communication variables
|
// Core communication variables
|
||||||
private String libraryClassName = null;
|
private String libraryClassName = null;
|
||||||
|
|
||||||
private int offsetRelToAbs = 0;
|
private int relAddressOfRefenceVariable = 0;
|
||||||
|
|
||||||
private CoreComm myCoreComm = null;
|
private CoreComm myCoreComm = null;
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get offset between relative and absolute addresses
|
// Get offset between relative and absolute addresses
|
||||||
offsetRelToAbs = getReferenceAbsAddr() - (Integer) varAddresses.get("referenceVar");
|
relAddressOfRefenceVariable = (Integer) varAddresses.get("referenceVar");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw (MoteTypeCreationException) new MoteTypeCreationException(
|
throw (MoteTypeCreationException) new MoteTypeCreationException(
|
||||||
"JNI call error: " + e.getMessage()).initCause(e);
|
"JNI call error: " + e.getMessage()).initCause(e);
|
||||||
|
@ -397,12 +397,14 @@ public class ContikiMoteType implements MoteType {
|
||||||
"Could not parse section addresses correctly");
|
"Could not parse section addresses correctly");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
myCoreComm.setReferenceAddress(relAddressOfRefenceVariable);
|
||||||
|
|
||||||
// Create initial memory
|
// Create initial memory
|
||||||
byte[] initialDataSection = new byte[dataSectionSize];
|
byte[] initialDataSection = new byte[dataSectionSize];
|
||||||
getCoreMemory(relDataSectionAddr + offsetRelToAbs, dataSectionSize,
|
getCoreMemory(relDataSectionAddr, dataSectionSize,
|
||||||
initialDataSection);
|
initialDataSection);
|
||||||
byte[] initialBssSection = new byte[bssSectionSize];
|
byte[] initialBssSection = new byte[bssSectionSize];
|
||||||
getCoreMemory(relBssSectionAddr + offsetRelToAbs, bssSectionSize,
|
getCoreMemory(relBssSectionAddr, bssSectionSize,
|
||||||
initialBssSection);
|
initialBssSection);
|
||||||
initialMemory = new SectionMoteMemory(varAddresses);
|
initialMemory = new SectionMoteMemory(varAddresses);
|
||||||
initialMemory.setMemorySegment(relDataSectionAddr, initialDataSection);
|
initialMemory.setMemorySegment(relDataSectionAddr, initialDataSection);
|
||||||
|
@ -437,8 +439,9 @@ public class ContikiMoteType implements MoteType {
|
||||||
*/
|
*/
|
||||||
public void setCoreMemory(SectionMoteMemory mem) {
|
public void setCoreMemory(SectionMoteMemory mem) {
|
||||||
for (int i = 0; i < mem.getNumberOfSections(); i++) {
|
for (int i = 0; i < mem.getNumberOfSections(); i++) {
|
||||||
setCoreMemory(mem.getStartAddrOfSection(i) + offsetRelToAbs, mem
|
setCoreMemory(
|
||||||
.getSizeOfSection(i), mem.getDataOfSection(i));
|
mem.getStartAddrOfSection(i),
|
||||||
|
mem.getSizeOfSection(i), mem.getDataOfSection(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -501,8 +504,8 @@ public class ContikiMoteType implements MoteType {
|
||||||
} else {
|
} else {
|
||||||
int oldAddress = (Integer) varAddresses.get(varName);
|
int oldAddress = (Integer) varAddresses.get(varName);
|
||||||
if (oldAddress != varAddress) {
|
if (oldAddress != varAddress) {
|
||||||
logger.warn("Warning, command response not matching previous entry of: "
|
/*logger.warn("Warning, command response not matching previous entry of: "
|
||||||
+ varName);
|
+ varName);*/
|
||||||
nrMismatch++;
|
nrMismatch++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -514,7 +517,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
if (nrMismatch > 0) {
|
if (nrMismatch > 0) {
|
||||||
logger.debug("Command response parsing summary: Added " + nrNew
|
logger.debug("Command response parsing summary: Added " + nrNew
|
||||||
+ " variables. Found " + nrOld
|
+ " variables. Found " + nrOld
|
||||||
+ " old variables. MISMATCHING ADDRESSES: " + nrMismatch);
|
+ " old variables. Mismatching addresses: " + nrMismatch);
|
||||||
} else {
|
} else {
|
||||||
logger.debug("Command response parsing summary: Added " + nrNew
|
logger.debug("Command response parsing summary: Added " + nrNew
|
||||||
+ " variables. Found " + nrOld + " old variables");
|
+ " variables. Found " + nrOld + " old variables");
|
||||||
|
@ -536,7 +539,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
int size = mem.getSizeOfSection(i);
|
int size = mem.getSizeOfSection(i);
|
||||||
byte[] data = mem.getDataOfSection(i);
|
byte[] data = mem.getDataOfSection(i);
|
||||||
|
|
||||||
getCoreMemory(startAddr + offsetRelToAbs, size, data);
|
getCoreMemory(startAddr, size, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,16 +616,12 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getReferenceAbsAddr() {
|
private void getCoreMemory(int relAddr, int length, byte[] data) {
|
||||||
return myCoreComm.getReferenceAbsAddr();
|
myCoreComm.getMemory(relAddr, length, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCoreMemory(int start, int length, byte[] data) {
|
private void setCoreMemory(int relAddr, int length, byte[] mem) {
|
||||||
myCoreComm.getMemory(start, length, data);
|
myCoreComm.setMemory(relAddr, length, mem);
|
||||||
}
|
|
||||||
|
|
||||||
private void setCoreMemory(int start, int length, byte[] mem) {
|
|
||||||
myCoreComm.setMemory(start, length, mem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getFirstMatchGroup(Vector<String> lines, String regexp,
|
private static String getFirstMatchGroup(Vector<String> lines, String regexp,
|
||||||
|
|
Loading…
Reference in a new issue