Skip to content

Commit

Permalink
Call functions for getting linker info
Browse files Browse the repository at this point in the history
  • Loading branch information
pjonsson committed Sep 3, 2023
1 parent 005fcb1 commit dcede4a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 8 deletions.
6 changes: 3 additions & 3 deletions java/org/contikios/cooja/contikimote/ContikiMoteType.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ public boolean loadMoteFirmware(boolean vis) throws MoteTypeCreationException {
logger.info("common1: " + Long.toHexString(commonSecParser.getCommonStartAddr() + secOffset) + " size: " + Integer.toHexString(commonSecParser.getCommonSize()));
initialMemory.addMemorySection("common",
getMemory(commonSecParser.getCommonStartAddr() + secOffset, commonSecParser.getCommonSize(), offsetVariables));
logger.info("common2: " + Long.toHexString(myCoreComm.getCommonStartAddress() + secOffset) + " size: " + Integer.toHexString(myCoreComm.getMacCommonSize()));
logger.info("bss2: " + Long.toHexString(myCoreComm.getBssStartAddress()) + " size: " + Integer.toHexString(myCoreComm.getMacBssSize()));
logger.info("data1: " + Long.toHexString(myCoreComm.getDataStartAddress()) + " size: " + Integer.toHexString(myCoreComm.getMacDataSize()));
logger.info("common2: " + Long.toHexString(myCoreComm.getMacCommonStartAddress() + secOffset) + " size: " + Integer.toHexString(myCoreComm.getMacCommonSize()));
logger.info("bss2: " + Long.toHexString(myCoreComm.getMacBssStartAddress()) + " size: " + Integer.toHexString(myCoreComm.getMacBssSize()));
logger.info("data1: " + Long.toHexString(myCoreComm.getMacDataStartAddress()) + " size: " + Integer.toHexString(myCoreComm.getMacDataSize()));
}
getCoreMemory(initialMemory);
return true;
Expand Down
79 changes: 74 additions & 5 deletions java/org/contikios/cooja/contikimote/CoreComm.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.lang.foreign.Linker;
import java.lang.foreign.SegmentScope;
import java.lang.foreign.SymbolLookup;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandle;

/**
Expand All @@ -44,6 +45,13 @@
class CoreComm {
private final SymbolLookup symbols;
private final MethodHandle coojaTick;

private long dataStart;
private long dataEnd;
private long bssStart;
private long bssEnd;
private long commonStart;
private long commonEnd;
/**
* Loads library libFile with a scope.
*
Expand All @@ -63,6 +71,48 @@ class CoreComm {
} catch (Throwable e) {
throw new RuntimeException("Calling cooja_init failed: " + e.getMessage(), e);
}
var mtype_bssStart = linker.downcallHandle(symbols.find("mtype_bssStart").get(),
FunctionDescriptor.of(ValueLayout.JAVA_LONG));
var mtype_bssEnd = linker.downcallHandle(symbols.find("mtype_bssEnd").get(),
FunctionDescriptor.of(ValueLayout.JAVA_LONG));
var mtype_dataStart = linker.downcallHandle(symbols.find("mtype_dataStart").get(),
FunctionDescriptor.of(ValueLayout.JAVA_LONG));
var mtype_dataEnd = linker.downcallHandle(symbols.find("mtype_dataEnd").get(),
FunctionDescriptor.of(ValueLayout.JAVA_LONG));
var mtype_commonStart = linker.downcallHandle(symbols.find("mtype_commonStart").get(),
FunctionDescriptor.of(ValueLayout.JAVA_LONG));
var mtype_commonEnd = linker.downcallHandle(symbols.find("mtype_commonEnd").get(),
FunctionDescriptor.of(ValueLayout.JAVA_LONG));
try {
bssStart = (long)mtype_bssStart.invokeExact();
} catch (Throwable e) {
throw new RuntimeException("Calling mtype_bssStart failed: " + e.getMessage(), e);
}
try {
bssEnd = (long)mtype_bssEnd.invokeExact();
} catch (Throwable e) {
throw new RuntimeException("Calling mtype_bssEnd failed: " + e.getMessage(), e);
}
try {
dataStart = (long)mtype_dataStart.invokeExact();
} catch (Throwable e) {
throw new RuntimeException("Calling mtype_dataStart failed: " + e.getMessage(), e);
}
try {
dataEnd = (long)mtype_dataEnd.invokeExact();
} catch (Throwable e) {
throw new RuntimeException("Calling mtype_dataEnd failed: " + e.getMessage(), e);
}
try {
commonStart = (long)mtype_commonStart.invokeExact();
} catch (Throwable e) {
throw new RuntimeException("Calling mtype_commonStart failed: " + e.getMessage(), e);
}
try {
commonEnd = (long)mtype_commonEnd.invokeExact();
} catch (Throwable e) {
throw new RuntimeException("Calling mtype_commonEnd failed: " + e.getMessage(), e);
}
}

/**
Expand Down Expand Up @@ -120,21 +170,40 @@ long getCommonStartAddress() {
return symbols.find("cooja_commonStart").get().address();
}

long getMacDataStartAddress() {
return dataStart;
}
long getMacDataEnd() {
return dataEnd;
}
long getMacBssStartAddress() {
return bssStart;
}
long getMacBssEnd() {
return bssEnd;
}
long getMacCommonStartAddress() {
return commonStart;
}
long getMacCommonEnd() {
return commonEnd;
}

int getMacDataSize() {
var start = getDataStartAddress();
var end = symbols.find("cooja_dataEnd").get().address();
var start = getMacDataStartAddress();
var end = getMacDataEnd();
return (int)(end - start);
}

int getMacBssSize() {
var start = getBssStartAddress();
var end = symbols.find("cooja_bssEnd").get().address();
var start = getMacBssStartAddress();
var end = getMacBssEnd();
return (int)(end - start);
}

int getMacCommonSize() {
var start = getCommonStartAddress();
var end = symbols.find("cooja_commonEnd").get().address();
var end = getMacCommonEnd();
return (int)(end - start);
}
}

0 comments on commit dcede4a

Please sign in to comment.