This commit is contained in:
minjaesong
2022-03-06 13:53:40 +09:00
parent 8d1f6fccf3
commit f992713e85
7 changed files with 116 additions and 43 deletions

View File

@@ -53,6 +53,7 @@ class VM(
var resetDown = false
var stopDown = false
var sysrqDown = false
var romMapping = 255
internal set

View File

@@ -144,6 +144,11 @@ class VMJSR223Delegate(val vm: VM) {
fun waitForMemChg(addr: Int, andMask: Int) = waitForMemChg(addr, andMask, 0)
fun getUsedMem() = vm.allocatedBlockCount * vm.MALLOC_UNIT
fun getSysrq() = vm.sysrqDown
fun unsetSysrq() {
vm.sysrqDown = false
}
}
class VMSerialDebugger(val vm: VM) {
@@ -156,8 +161,8 @@ class Parallel(val vm: VM) {
fun spawnNewContext(): VMRunner {
return VMRunnerFactory(vm.assetsDir, vm, "js")
}
fun attachProgram(context: VMRunner, program: String): Thread {
Thread { context.eval(program) }.let {
fun attachProgram(name: String, context: VMRunner, program: String): Thread {
Thread({ context.eval(program) }, name).let {
vm.contexts.add(it)
return it
}
@@ -171,4 +176,11 @@ class Parallel(val vm: VM) {
fun resume(thread: Thread) {
thread.resume()
}
}
fun kill(thread: Thread) {
thread.interrupt()
vm.contexts.remove(thread)
}
fun getThreadPool() = vm.contexts
}
class ParallelDummy()

View File

@@ -6,9 +6,9 @@ import java.io.FileReader
import javax.script.ScriptEngineManager
abstract class VMRunner(val extension: String) {
abstract suspend fun executeCommand(command: String)
abstract suspend fun evalGlobal(command: String)
abstract fun eval(command: String)
abstract suspend fun evalGlobal(command: String) // Ring 0
abstract suspend fun executeCommand(command: String) // Ring 1
abstract fun eval(command: String) // Ring 2 (for child processes spawned using Parallel API)
abstract fun close()
}
@@ -47,6 +47,9 @@ object VMRunnerFactory {
}*/
"js" -> {
object : VMRunner(extension) {
private val ringOneParallel = Parallel(vm)
private val ringTwoParallel = ParallelDummy()
private val context = Context.newBuilder("js")
.allowHostAccess(HostAccess.ALL)
.allowHostClassLookup { false }
@@ -66,7 +69,7 @@ object VMRunnerFactory {
bind.putMember("base64", Base64Delegate)
bind.putMember("com", SerialHelperDelegate(vm))
bind.putMember("dma", DMADelegate(vm))
bind.putMember("parallel", Parallel(vm))
bind.putMember("parallel", ringOneParallel)
val fr = FileReader("$assetsRoot/JS_INIT.js")
val prg = fr.readText()
@@ -76,6 +79,7 @@ object VMRunnerFactory {
override suspend fun executeCommand(command: String) {
try {
bind.putMember("parallel", ringOneParallel)
context.eval("js", encapsulateJS(sanitiseJS(command)))
}
catch (e: javax.script.ScriptException) {
@@ -87,6 +91,7 @@ object VMRunnerFactory {
override fun eval(command: String) {
try {
bind.putMember("parallel", ringTwoParallel)
context.eval("js", encapsulateJS(sanitiseJS(command)))
}
catch (e: javax.script.ScriptException) {
@@ -96,6 +101,7 @@ object VMRunnerFactory {
} }
override suspend fun evalGlobal(command: String) {
bind.putMember("parallel", ringOneParallel)
context.eval("js", "\"use strict\";" + sanitiseJS(command))
}

View File

@@ -255,10 +255,10 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
}
// SIGTERM key combination: Ctrl+Shift+T+R
vm.stopDown = Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT) &&
vm.stopDown = (Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT) &&
Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT) &&
Gdx.input.isKeyPressed(Input.Keys.T) &&
Gdx.input.isKeyPressed(Input.Keys.R)
Gdx.input.isKeyPressed(Input.Keys.R)) || Gdx.input.isKeyPressed(Input.Keys.PAUSE)
if (vm.stopDown) println("[VM-${vm.id}] SIGTERM requested")
// RESET key combination: Ctrl+Shift+R+S
@@ -267,6 +267,13 @@ class IOSpace(val vm: VM) : PeriBase, InputProcessor {
Gdx.input.isKeyPressed(Input.Keys.R) &&
Gdx.input.isKeyPressed(Input.Keys.S)
if (vm.resetDown) println("[VM-${vm.id}] RESET requested")
// SYSRQ key combination: Ctrl+Shift+S+Q
vm.sysrqDown = (Gdx.input.isKeyPressed(Input.Keys.SHIFT_LEFT) &&
Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT) &&
Gdx.input.isKeyPressed(Input.Keys.Q) &&
Gdx.input.isKeyPressed(Input.Keys.S)) || Gdx.input.isKeyPressed(Input.Keys.PRINT_SCREEN)
if (vm.sysrqDown) println("[VM-${vm.id}] SYSRQ requested")
}
override fun touchUp(p0: Int, p1: Int, p2: Int, p3: Int): Boolean {