Commit 7cdb32c6 authored by Kunshan Wang's avatar Kunshan Wang

Fixed runmu.sh and bootimg loader

parent eac74cd8
......@@ -327,9 +327,13 @@ class BootImageLoader(file: String, maybeAppArgs: Option[Seq[String]])(implicit
logger.info("Thread local obj address: %d 0x%x".format(threadLocalAddr, threadLocalAddr))
logger.info {
val tag = HeaderUtils.getTag(threadLocalAddr)
val ty = HeaderUtils.getType(microVM, tag)
"Thread-local obj type: %s %s".format(ty.repr, ty)
if (threadLocalAddr == 0L) {
"The thread-local obj ref is NULL"
} else {
val tag = HeaderUtils.getTag(threadLocalAddr)
val ty = HeaderUtils.getType(microVM, tag)
"Thread-local obj type: %s %s".format(ty.repr, ty)
}
}
val stack = microVM.threadStackManager.newStack(func, mutator)
......
......@@ -66,43 +66,10 @@ object RunMu {
}
props("bootImg") = bootImg
val microVM = MicroVM(VMConf(props.toMap))
val entryPoint: Either[MuID, MuName] = {
tryWithResource(new ZipFile(bootImg)) { zipFile =>
val entryPointEntry = Option(zipFile.getEntry(ENTRYPOINT_FILE)).getOrElse {
throw new UvmRuntimeException("Boot image has no entry point. Use tools/mar.py to set entry point. Image: " + bootImg)
}
val line = tryWithResource(new BufferedReader(new InputStreamReader(zipFile.getInputStream(entryPointEntry), StandardCharsets.UTF_8))) { br =>
br.readLine()
}
val Array(kind, value) = line.split(" ")
kind match {
case "id" => Left(value.toInt)
case "name" => Right(value)
}
}
}
val allArgs = bootImg :: appArgs
val nativeArgv = new NativeArgv(allArgs)
val (argc, argv) = (nativeArgv.argc, nativeArgv.argv)
tryWithResource(microVM.newContext()) { ctx =>
val id = entryPoint match {
case Left(id) => id
case Right(name) => ctx.idOf(name)
}
val func = ctx.handleFromFunc(id)
val stack = ctx.newStack(func)
val hArgc = ctx.handleFromInt(argc, 32)
val hArgv = ctx.handleFromPtr(InternalTypes.C_CHARPP.id, argv)
val thread = ctx.newThread(stack, None, PassValues(Seq(hArgc, hArgv)))
}
val microVM = MicroVM(VMConf(props.toMap), allArgs)
microVM.execute()
}
......
......@@ -6,6 +6,7 @@ import uvm.ir.textinput.TestingBundlesValidators.MagicalOur
import uvm.refimpl.MicroVM
import uvm.refimpl.UvmBundleTesterBase
import uvm.refimpl.VMConf
import uvm.utils.WithUtils._
class BootImageEchoExample extends UvmBundleTesterBase with ExtraMatchers {
preloadBundles("tests/uvm-refimpl-test/boot-image-echo.uir")
......@@ -19,6 +20,10 @@ class BootImageEchoExample extends UvmBundleTesterBase with ExtraMatchers {
val filename = "target/boot-image-echo.muref"
val everything = Seq("@main", "@charpp").map(idOf)
microVM.makeBootImage(everything, filename)
tryWithResource(microVM.newContext()) { ctx =>
val func = ctx.handleFromFunc("@main")
ctx.makeBootImage(everything, Some(func), None, None, Seq(), Seq(), Seq(), Seq(), filename)
}
}
}
\ No newline at end of file
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