booting entirely from the bios

This commit is contained in:
minjaesong
2020-10-31 22:23:26 +09:00
parent ca906d8606
commit 055b825cca
7 changed files with 86 additions and 60 deletions

View File

@@ -4,6 +4,7 @@ import net.torvald.UnsafeHelper
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUint
import net.torvald.tsvm.peripheral.BlockTransferInterface.Companion.BLOCK_SIZE
import net.torvald.tsvm.peripheral.BlockTransferInterface.Companion.END_OF_SEND_BLOCK
import net.torvald.tsvm.peripheral.trimNull
import java.io.ByteArrayOutputStream
import kotlin.experimental.and
import kotlin.experimental.or
@@ -95,10 +96,10 @@ object SerialHelper {
fun getStatusCode(vm: VM, portNo: Int) = vm.getIO().mmio_read(4080L + portNo)
private fun checkIfDeviceIsThere(vm: VM, portNo: Int) =
fun checkIfDeviceIsThere(vm: VM, portNo: Int) =
(vm.getIO().mmio_read(4092L + portNo)!! and 1.toByte()) == 1.toByte()
private fun checkIfDeviceIsReady(vm: VM, portNo: Int) =
fun checkIfDeviceIsReady(vm: VM, portNo: Int) =
(vm.getIO().mmio_read(4092L + portNo)!! and 0b111.toByte()) == 0b011.toByte()
private fun initiateWriting(vm: VM, portNo: Int) {
@@ -145,4 +146,5 @@ class SerialHelperDelegate(val vm: VM) {
fun getStatusCode(portNo: Int) = SerialHelper.getStatusCode(vm, portNo)
/** @return Object where { code: <Int>, message: <String> } */
fun getDeviceStatus(portNo: Int) = SerialHelper.getDeviceStatus(vm, portNo)
fun areYouThere(portNo: Int) = SerialHelper.checkIfDeviceIsThere(vm, portNo)
}

View File

@@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import kotlinx.coroutines.*
import net.torvald.tsvm.peripheral.GraphicsAdapter
import java.io.File
import java.io.FileReader
class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter() {
@@ -51,31 +52,10 @@ class VMGUI(val appConfig: LwjglApplicationConfiguration) : ApplicationAdapter()
memvwr = Memvwr(vm)
// TEST PRG
//val fr = FileReader("./assets/tvdos/command.js")
//val fr = FileReader("./assets/jscon.js")
val fr1 = FileReader("./assets/bios1.js")
//val fr1 = FileReader("./assets/phototest.js")
val bios = fr1.readText()
fr1.close()
//val fr = FileReader("./assets/tvdos/command.js")
//val fr = FileReader("./assets/zippytest.js")
//val fr = FileReader("./assets/serialtest.js")
//val fr = FileReader("./assets/tvdos/fsh.js")
//val fr = FileReader("./assets/tvdos/flsh.js")
//val fr = FileReader("./assets/tbas/basic.js")
//val fr = FileReader("./assets/jscon.js")
val fr = FileReader("./assets/!BOOTSEC")
val prg = fr.readText()
fr.close()
// load test bios
vmRunner = VMRunnerFactory(vm, "js")
coroutineJob = GlobalScope.launch {
//vmRunner.evalGlobal("$bios")
//vmRunner.executeCommand(prg)
vmRunner.executeCommand("$bios\n$prg")
vmRunner.executeCommand(File("./assets/bios1.js").readText(VM.CHARSET))
}
}

View File

@@ -86,14 +86,14 @@ abstract class BlockTransferInterface(val isMaster: Boolean, val isSlave: Boolea
const val BAD_NEWS = 0x15.toByte()
const val UNIT_SEP = 0x1F.toByte()
const val END_OF_SEND_BLOCK = 0x17.toByte()
fun trimNull(ba: ByteArray): ByteArray {
var cnt = BLOCK_SIZE - 1
while (cnt >= 0) {
if (ba[cnt] != 0.toByte()) break
cnt -= 1
}
return ba.sliceArray(0..cnt)
}
}
}
fun ByteArray.trimNull(): ByteArray {
var cnt = BlockTransferInterface.BLOCK_SIZE - 1
while (cnt >= 0) {
if (this[cnt] != 0.toByte()) break
cnt -= 1
}
return this.sliceArray(0..cnt)
}

View File

@@ -3,6 +3,7 @@ package net.torvald.tsvm.peripheral
import net.torvald.tsvm.VM
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileInputStream
import java.io.IOException
import java.util.*
@@ -122,7 +123,7 @@ class TestDiskDrive(private val driveNum: Int, theRootPath: File? = null) : Bloc
}
}
else {
val inputString = trimNull(inputData).toString(VM.CHARSET)
val inputString = inputData.trimNull().toString(VM.CHARSET)
if (inputString.startsWith("DEVRST\u0017")) {
println("[TestDiskDrive] Device Reset")
@@ -217,6 +218,37 @@ class TestDiskDrive(private val driveNum: Int, theRootPath: File? = null) : Bloc
return
}
}
else if (inputString.startsWith("LOADBOOT")) {
var commaIndex = 0
while (commaIndex < inputString.length) {
if (inputString[commaIndex] == ',') break
commaIndex += 1
}
val driveNum = if (commaIndex >= inputString.length) null else commaIndex
// TODO driveNum is for disk drives that may have two or more slots built; for testing purposes we'll ignore it
val bootFile = File(rootPath, "!BOOTSEC")
if (!bootFile.exists()) {
statusCode = STATE_CODE_FILE_NOT_FOUND
return
}
val fis = FileInputStream(bootFile)
try {
val retMsg = ByteArray(BLOCK_SIZE)
fis.read(retMsg)
recipient?.writeout(retMsg)
statusCode = STATE_CODE_STANDBY
}
catch (e: IOException) {
statusCode = STATE_CODE_SYSTEM_IO_ERROR
return
}
finally {
fis.close()
}
}
else if (inputString.startsWith("WRITE")) {
if (!fileOpen || fileOpenMode < 0) {
statusCode = STATE_CODE_OPERATION_NOT_PERMITTED
@@ -228,8 +260,10 @@ class TestDiskDrive(private val driveNum: Int, theRootPath: File? = null) : Bloc
}
writeMode = true
writeModeLength = inputString.substring(5, inputString.length).toInt()
statusCode = 0
statusCode = STATE_CODE_STANDBY
}
else
statusCode = STATE_CODE_ILLEGAL_COMMAND
}
}

View File

@@ -149,7 +149,7 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
}
}
else {
val inputString = trimNull(inputData).toString(VM.CHARSET)
val inputString = inputData.trimNull().toString(VM.CHARSET)
if (inputString.startsWith("DEVRST\u0017")) {
fileOpen = false
@@ -171,6 +171,8 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
writeModeLength = inputString.substring(5, inputString.length).toInt()
statusCode = 0
}
else
statusCode = 128
blockSendCount = 0
}