Commit 1958f150 authored by Kunshan Wang's avatar Kunshan Wang

WIP: reloc

parent 5cc0978b
......@@ -22,6 +22,7 @@ import uvm.types._
import uvm.utils.WithUtils.tryWithResource
import uvm.ir.textoutput.EntityUtils
import uvm.ir.textoutput.BundleSerializer
import scala.collection.mutable.HashMap
class BootImageBuilder(implicit microVM: MicroVM) {
def makeBootImage(whiteList: Seq[TopLevel], outputFile: String): Unit = {
......@@ -60,8 +61,10 @@ object BootImageWriter {
* @param fileOffset The offset from the beginning of the .data file.
* @param ty The type of the allocation unit.
* @param varLen The length of the variable part if it is a hybrid; otherwise 0.
*
* @param addr The address in the current micro VM instance. Not persisted.
*/
case class UnitAllocRecord(num: Long, fileOffset: Long, ty: Type, varLen: Long)
case class UnitAllocRecord(num: Long, fileOffset: Long, ty: Type, varLen: Long, addr: Word)
/**
* Relocation record. One for each field of ref<T>, iref<T>, weakref<T> or funcref<sig> types.
......@@ -107,6 +110,9 @@ class BootImageWriter(tcb: TransitiveClosureBuilder, outputFile: String)(implici
private val smallObjectSpace: Space = microVM.memoryManager.heap.space
private val largeObjectSpace: Space = microVM.memoryManager.heap.los
private implicit val memorySupport = microVM.memoryManager.memorySupport
val addrToGlobalCell = tcb.globalCellMap
val addrToHeapObjNum = new HashMap[Word, Long]()
def writeFile(): Unit = {
for (addr <- tcb.allocs.set) {
......@@ -122,6 +128,12 @@ class BootImageWriter(tcb: TransitiveClosureBuilder, outputFile: String)(implici
writeAllocRecs(globalGroup)
writeAllocRecs(heapGroup)
scanForRelocs(globalGroup)
scanForRelocs(heapGroup)
writeRelocRecs(globalGroup)
writeRelocRecs(heapGroup)
writeIDNameMap()
writeUIRBundle()
}
......@@ -149,7 +161,7 @@ class BootImageWriter(tcb: TransitiveClosureBuilder, outputFile: String)(implici
val pos = group.dataOS.position
group.dataOS.copy(addr, size)
val rec = UnitAllocRecord(num, pos, ty, varLen)
val rec = UnitAllocRecord(num, pos, ty, varLen, addr)
group.allocRecs += rec
}
......@@ -161,6 +173,16 @@ class BootImageWriter(tcb: TransitiveClosureBuilder, outputFile: String)(implici
}
}
private def scanForRelocs(group: FileGroup): Unit = {
for (alloc <- group.allocRecs) {
???
}
}
private def writeRelocRecs(group: FileGroup): Unit = {
???
}
private def writeIDNameMap(): Unit = {
tryWithResource(Files.newBufferedWriter(idNameMapPath, StandardCharsets.UTF_8)) { writer =>
bundleSerializer.writeIDNameMap(writer)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment