mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-23 01:29:33 +00:00
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
@ -26,7 +26,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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.
|
||||
* (this must not be static due to memory locations)
|
||||
*/
|
||||
int referenceVar;
|
||||
long referenceVar;
|
||||
|
||||
/*
|
||||
* process_run() infinite loop.
|
||||
@ -118,10 +118,10 @@ start_process_run_loop(void *data)
|
||||
|
||||
/* Initialize communication stack */
|
||||
init_net();
|
||||
|
||||
|
||||
/* Start user applications */
|
||||
autostart_start(autostart_processes);
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
/* 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.
|
||||
@ -179,9 +177,15 @@ Java_se_sics_cooja_corecomm_[CLASS_NAME]_init(JNIEnv *env, jobject obj)
|
||||
* responsible Java part (MoteType.java).
|
||||
*/
|
||||
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).
|
||||
*/
|
||||
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);
|
||||
memcpy((void *) start, mem, length);
|
||||
memcpy(
|
||||
(char*) (((long)rel_addr) + referenceVar),
|
||||
mem,
|
||||
length);
|
||||
(*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).
|
||||
*/
|
||||
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 init();
|
||||
public native int getReferenceAbsAddr();
|
||||
public native void getMemory(int start, int length, byte[] mem);
|
||||
public native void setMemory(int start, int length, byte[] mem);
|
||||
public native void setReferenceAddress(int addr);
|
||||
public native void getMemory(int rel_addr, 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
|
||||
* 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;
|
||||
@ -361,35 +361,29 @@ public abstract class CoreComm {
|
||||
protected abstract void init();
|
||||
|
||||
/**
|
||||
* Returns absolute memory location of the core variable referenceVar. Used to
|
||||
* get offset between relative and absolute memory addresses.
|
||||
* Sets the relative memory address of the reference variable.
|
||||
* 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.
|
||||
*
|
||||
* @param start
|
||||
* Start address of segment
|
||||
* @param length
|
||||
* Length of segment
|
||||
* @param mem
|
||||
* Array to fill with memory segment
|
||||
* @param relAddr Relative memory start address
|
||||
* @param length 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.
|
||||
*
|
||||
* @param start
|
||||
* Start address of segment
|
||||
* @param length
|
||||
* Length of segment
|
||||
* @param mem
|
||||
* New memory segment data
|
||||
* @param relAddr Relative memory start address
|
||||
* @param length 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
|
||||
* 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;
|
||||
@ -172,7 +172,7 @@ public class ContikiMoteType implements MoteType {
|
||||
// Core communication variables
|
||||
private String libraryClassName = null;
|
||||
|
||||
private int offsetRelToAbs = 0;
|
||||
private int relAddressOfRefenceVariable = 0;
|
||||
|
||||
private CoreComm myCoreComm = null;
|
||||
|
||||
@ -385,7 +385,7 @@ public class ContikiMoteType implements MoteType {
|
||||
|
||||
try {
|
||||
// Get offset between relative and absolute addresses
|
||||
offsetRelToAbs = getReferenceAbsAddr() - (Integer) varAddresses.get("referenceVar");
|
||||
relAddressOfRefenceVariable = (Integer) varAddresses.get("referenceVar");
|
||||
} catch (Exception e) {
|
||||
throw (MoteTypeCreationException) new MoteTypeCreationException(
|
||||
"JNI call error: " + e.getMessage()).initCause(e);
|
||||
@ -397,12 +397,14 @@ public class ContikiMoteType implements MoteType {
|
||||
"Could not parse section addresses correctly");
|
||||
}
|
||||
|
||||
myCoreComm.setReferenceAddress(relAddressOfRefenceVariable);
|
||||
|
||||
// Create initial memory
|
||||
byte[] initialDataSection = new byte[dataSectionSize];
|
||||
getCoreMemory(relDataSectionAddr + offsetRelToAbs, dataSectionSize,
|
||||
getCoreMemory(relDataSectionAddr, dataSectionSize,
|
||||
initialDataSection);
|
||||
byte[] initialBssSection = new byte[bssSectionSize];
|
||||
getCoreMemory(relBssSectionAddr + offsetRelToAbs, bssSectionSize,
|
||||
getCoreMemory(relBssSectionAddr, bssSectionSize,
|
||||
initialBssSection);
|
||||
initialMemory = new SectionMoteMemory(varAddresses);
|
||||
initialMemory.setMemorySegment(relDataSectionAddr, initialDataSection);
|
||||
@ -437,8 +439,9 @@ public class ContikiMoteType implements MoteType {
|
||||
*/
|
||||
public void setCoreMemory(SectionMoteMemory mem) {
|
||||
for (int i = 0; i < mem.getNumberOfSections(); i++) {
|
||||
setCoreMemory(mem.getStartAddrOfSection(i) + offsetRelToAbs, mem
|
||||
.getSizeOfSection(i), mem.getDataOfSection(i));
|
||||
setCoreMemory(
|
||||
mem.getStartAddrOfSection(i),
|
||||
mem.getSizeOfSection(i), mem.getDataOfSection(i));
|
||||
}
|
||||
}
|
||||
|
||||
@ -501,8 +504,8 @@ public class ContikiMoteType implements MoteType {
|
||||
} else {
|
||||
int oldAddress = (Integer) varAddresses.get(varName);
|
||||
if (oldAddress != varAddress) {
|
||||
logger.warn("Warning, command response not matching previous entry of: "
|
||||
+ varName);
|
||||
/*logger.warn("Warning, command response not matching previous entry of: "
|
||||
+ varName);*/
|
||||
nrMismatch++;
|
||||
}
|
||||
|
||||
@ -514,7 +517,7 @@ public class ContikiMoteType implements MoteType {
|
||||
if (nrMismatch > 0) {
|
||||
logger.debug("Command response parsing summary: Added " + nrNew
|
||||
+ " variables. Found " + nrOld
|
||||
+ " old variables. MISMATCHING ADDRESSES: " + nrMismatch);
|
||||
+ " old variables. Mismatching addresses: " + nrMismatch);
|
||||
} else {
|
||||
logger.debug("Command response parsing summary: Added " + nrNew
|
||||
+ " variables. Found " + nrOld + " old variables");
|
||||
@ -536,7 +539,7 @@ public class ContikiMoteType implements MoteType {
|
||||
int size = mem.getSizeOfSection(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() {
|
||||
return myCoreComm.getReferenceAbsAddr();
|
||||
private void getCoreMemory(int relAddr, int length, byte[] data) {
|
||||
myCoreComm.getMemory(relAddr, length, data);
|
||||
}
|
||||
|
||||
private void getCoreMemory(int start, int length, byte[] data) {
|
||||
myCoreComm.getMemory(start, length, data);
|
||||
}
|
||||
|
||||
private void setCoreMemory(int start, int length, byte[] mem) {
|
||||
myCoreComm.setMemory(start, length, mem);
|
||||
private void setCoreMemory(int relAddr, int length, byte[] mem) {
|
||||
myCoreComm.setMemory(relAddr, length, mem);
|
||||
}
|
||||
|
||||
private static String getFirstMatchGroup(Vector<String> lines, String regexp,
|
||||
|
Loading…
Reference in New Issue
Block a user