WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.2% of users enabled 2FA.

Commit 7f3709b2 authored by Kunshan Wang's avatar Kunshan Wang
Browse files

Hello world case with HAIL and native iface.

No C code written.
parent 878c45f0
package uvm.refimpl.hail
import org.scalatest._
import java.io.FileReader
import uvm._
import uvm.types._
import uvm.ssavariables._
import uvm.refimpl._
import uvm.refimpl.itpr._
import uvm.refimpl.mem._
import MemoryOrder._
import AtomicRMWOptr._
import uvm.refimpl.mem.TypeSizes.Word
import uvm.refimpl.TrapHandlerResult.{ ThreadExit, Rebind }
import uvm.refimpl.HowToResume.{ PassValues, ThrowExc }
import ch.qos.logback.classic.Level._
import uvm.refimpl.RichMuCtx._
import com.kenai.jffi.Library
class UvmHailHelloWorldTest extends UvmHailTesterBase {
setLogLevels(ROOT_LOGGER_NAME -> INFO,
"uvm.refimpl.hail" -> DEBUG //"uvm.refimpl.mem" -> DEBUG,
//"uvm.refimpl.itpr" -> DEBUG
)
preloadBundles("tests/uvm-refimpl-test/primitives.uir",
"tests/uvm-hail-test/hello-world-test.uir")
behavior of "The HAIL reader and the unsafe native interface"
it should "create string constants and print it using the 'write' syscall" in {
val mc = microVM.newContext()
loadHailFromFile(mc, "tests/uvm-hail-test/hello-world-test.hail")
// Resolve the function address for 'write'
val lib = Library.getDefault()
val funcAddr = lib.getSymbolAddress("write")
val hFuncAddr = mc.handleFromFP("@write.fp", funcAddr)
val hWrite = mc.handleFromGlobal("@write")
mc.store(NOT_ATOMIC, hWrite, hFuncAddr)
val func = mc.handleFromFunc("@main")
testFunc(mc, func, Seq()) { (ctx, th, st, wp) =>
val Seq(rv: MuIntValue) = ctx.dumpKeepalives(st, 0)
val rvInt = ctx.handleToSInt(rv).toLong
printf("[trap handler] %d bytes written\n", rvInt)
rvInt shouldBe 13
returnFromTrap(st)
}
mc.closeContext()
}
}
\ No newline at end of file
// hail
.newhybrid $hw <@string> 13
// "Hello world!\n"
.init $hw = {13 {72 101 108 108 111 32 119 111 114 108 100 33 10}}
.init @conststr_helloworld = $hw
// uir
// require "../uvm-refimpl-test/primitives.uir"
.typedef @size_t = int<64>
.funcsig @write.sig = (@i32 @ptrvoid @size_t) -> (@size_t)
.typedef @write.fp = ufuncptr<@write.sig>
.global @write <@write.fp>
.typedef @string = hybrid<@i64 @i8>
.typedef @string.r = ref<@string>
.global @conststr_helloworld <@string.r>
.const @STDOUT <@i32> = 1
.funcsig @main.sig = () -> ()
.funcdef @main VERSION %1 <@main.sig> {
%entry():
%str = LOAD <@string.r> @conststr_helloworld
%str.ir = GETIREF <@string> %str
%str.l = GETFIELDIREF <@string 0> %str.ir
%len = LOAD <@i64> %str.l // @i64 is the same as @size_t
%str.v = GETVARPARTIREF <@string> %str.ir
%write = LOAD <@write.fp> @write
%buf = COMMINST @uvm.native.pin <@irefi8> (%str.v)
%rv = CCALL #DEFAULT <@write.fp @write.sig> %write (@STDOUT %buf %len)
COMMINST @uvm.native.unpin <@irefi8> (%str.v)
[%trap] TRAP <> KEEPALIVE(%rv)
COMMINST @uvm.thread_exit
}
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