mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-17 00:16:04 +09:00
nvm fixed it
This commit is contained in:
@@ -42,6 +42,7 @@ object SerialHelper {
|
|||||||
fun fetchResponse(vm: VM, portNo: Int): ByteArray {
|
fun fetchResponse(vm: VM, portNo: Int): ByteArray {
|
||||||
val incomingMsg = ByteArray(BLOCK_SIZE)
|
val incomingMsg = ByteArray(BLOCK_SIZE)
|
||||||
|
|
||||||
|
// incoming message is always 4K long and unused bytes are zero-filled. THIS IS INTENTIONAL
|
||||||
UnsafeHelper.memcpyRaw(
|
UnsafeHelper.memcpyRaw(
|
||||||
null, vm.getIO().blockTransferRx[portNo].ptr,
|
null, vm.getIO().blockTransferRx[portNo].ptr,
|
||||||
incomingMsg, UnsafeHelper.getArrayOffset(incomingMsg),
|
incomingMsg, UnsafeHelper.getArrayOffset(incomingMsg),
|
||||||
@@ -61,9 +62,10 @@ object SerialHelper {
|
|||||||
waitUntilReady(vm, portNo)
|
waitUntilReady(vm, portNo)
|
||||||
|
|
||||||
val transStat = getBlockTransferStatus(vm, portNo)
|
val transStat = getBlockTransferStatus(vm, portNo)
|
||||||
println("[SerialHelper.pullMessage()] received length: ${transStat.first}")
|
val receivedLen = transStat.first//vm.getIO().blockTransferPorts[portNo].yourBlockSize()
|
||||||
|
//println("[SerialHelper.pullMessage()] received length: $receivedLen")
|
||||||
|
|
||||||
for (k in 0 until minOf(BLOCK_SIZE, transStat.first)) {
|
for (k in 0 until minOf(BLOCK_SIZE, receivedLen)) {
|
||||||
msgBuffer.write(vm.getIO().blockTransferRx[portNo][k.toLong()].toInt())
|
msgBuffer.write(vm.getIO().blockTransferRx[portNo][k.toLong()].toInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,15 +21,19 @@ abstract class BlockTransferInterface(val isMaster: Boolean, val isSlave: Boolea
|
|||||||
open fun areYouBusy(): Boolean = recipient?.busy ?: false
|
open fun areYouBusy(): Boolean = recipient?.busy ?: false
|
||||||
|
|
||||||
/** Writes a thing to the recipient.
|
/** Writes a thing to the recipient.
|
||||||
* A method exposed to outside of the box */
|
* A method exposed to outside of the box
|
||||||
abstract fun startSendImpl(recipient: BlockTransferInterface)
|
* @return number of bytes actually sent over*/
|
||||||
|
abstract fun startSendImpl(recipient: BlockTransferInterface): Int
|
||||||
/** The actual implementation */
|
/** The actual implementation */
|
||||||
fun startSend() {
|
fun startSend() {
|
||||||
//if (areYouReady()) {
|
//if (areYouReady()) {
|
||||||
busy = true
|
busy = true
|
||||||
ready = false
|
ready = false
|
||||||
|
|
||||||
recipient?.let { startSendImpl(it) }
|
recipient?.let {
|
||||||
|
this.blockSize = startSendImpl(it)
|
||||||
|
//println("[BlockTransferInterface.startSend()] recipients blocksize = ${this.blockSize}")
|
||||||
|
}
|
||||||
|
|
||||||
busy = false
|
busy = false
|
||||||
ready = true
|
ready = true
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ class BlockTransferPort(val vm: VM, val portno: Int) : BlockTransferInterface(tr
|
|||||||
|
|
||||||
internal var hasNext = false
|
internal var hasNext = false
|
||||||
|
|
||||||
override fun startSendImpl(recipient: BlockTransferInterface) {
|
override fun startSendImpl(recipient: BlockTransferInterface): Int {
|
||||||
recipient.writeout(ByteArray(BLOCK_SIZE) { vm.getIO().blockTransferTx[portno][it.toLong()] })
|
recipient.writeout(ByteArray(BLOCK_SIZE) { vm.getIO().blockTransferTx[portno][it.toLong()] })
|
||||||
|
return blockSize // use MMIO to modify this variable
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hasNext(): Boolean = hasNext
|
override fun hasNext(): Boolean = hasNext
|
||||||
@@ -22,9 +23,9 @@ class BlockTransferPort(val vm: VM, val portno: Int) : BlockTransferInterface(tr
|
|||||||
//UnsafeHelper.memcpyRaw(inputData, arrayOffset, null, vm.getIO().blockTransferRx[portno].ptr, copySize)
|
//UnsafeHelper.memcpyRaw(inputData, arrayOffset, null, vm.getIO().blockTransferRx[portno].ptr, copySize)
|
||||||
|
|
||||||
// not exposing raw memory to block probable security hole
|
// not exposing raw memory to block probable security hole
|
||||||
println("[BlockTranferPort] writeout size: ${inputData.size}")
|
//println("[BlockTranferPort] writeout size: ${inputData.size}")
|
||||||
for (k in 0 until BLOCK_SIZE) {
|
for (k in 0 until BLOCK_SIZE) {
|
||||||
vm.getIO().blockTransferRx[portno][k.toLong()] = if (k >= inputData.size) 0x5F else inputData[k]
|
vm.getIO().blockTransferRx[portno][k.toLong()] = if (k >= inputData.size) 0 else inputData[k]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
*
|
*
|
||||||
* Disk drive must send prepared message (or file transfer packet) to the computer.
|
* Disk drive must send prepared message (or file transfer packet) to the computer.
|
||||||
*/
|
*/
|
||||||
override fun startSendImpl(recipient: BlockTransferInterface) {
|
override fun startSendImpl(recipient: BlockTransferInterface): Int {
|
||||||
if (blockSendCount == 0) {
|
if (blockSendCount == 0) {
|
||||||
blockSendBuffer = messageComposeBuffer.toByteArray()
|
blockSendBuffer = messageComposeBuffer.toByteArray()
|
||||||
}
|
}
|
||||||
@@ -102,6 +102,8 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
})
|
})
|
||||||
|
|
||||||
blockSendCount += 1
|
blockSendCount += 1
|
||||||
|
|
||||||
|
return sendSize
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Computer's attempt to startSend() will result in calling this very function.
|
/** Computer's attempt to startSend() will result in calling this very function.
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
|||||||
return sb.toByteArray()
|
return sb.toByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startSendImpl(recipient: BlockTransferInterface) {
|
override fun startSendImpl(recipient: BlockTransferInterface): Int {
|
||||||
if (blockSendCount == 0) {
|
if (blockSendCount == 0) {
|
||||||
//blockSendBuffer = messageComposeBuffer.toByteArray()
|
//blockSendBuffer = messageComposeBuffer.toByteArray()
|
||||||
blockSendBuffer = fileContent_multiblocks
|
blockSendBuffer = fileContent_multiblocks
|
||||||
@@ -115,6 +115,8 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
|||||||
})
|
})
|
||||||
|
|
||||||
blockSendCount += 1
|
blockSendCount += 1
|
||||||
|
|
||||||
|
return sendSize
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hasNext(): Boolean {
|
override fun hasNext(): Boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user