mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 11:51:49 +09:00
nvm fixed it
This commit is contained in:
@@ -42,6 +42,7 @@ object SerialHelper {
|
||||
fun fetchResponse(vm: VM, portNo: Int): ByteArray {
|
||||
val incomingMsg = ByteArray(BLOCK_SIZE)
|
||||
|
||||
// incoming message is always 4K long and unused bytes are zero-filled. THIS IS INTENTIONAL
|
||||
UnsafeHelper.memcpyRaw(
|
||||
null, vm.getIO().blockTransferRx[portNo].ptr,
|
||||
incomingMsg, UnsafeHelper.getArrayOffset(incomingMsg),
|
||||
@@ -61,9 +62,10 @@ object SerialHelper {
|
||||
waitUntilReady(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())
|
||||
}
|
||||
|
||||
|
||||
@@ -21,15 +21,19 @@ abstract class BlockTransferInterface(val isMaster: Boolean, val isSlave: Boolea
|
||||
open fun areYouBusy(): Boolean = recipient?.busy ?: false
|
||||
|
||||
/** Writes a thing to the recipient.
|
||||
* A method exposed to outside of the box */
|
||||
abstract fun startSendImpl(recipient: BlockTransferInterface)
|
||||
* A method exposed to outside of the box
|
||||
* @return number of bytes actually sent over*/
|
||||
abstract fun startSendImpl(recipient: BlockTransferInterface): Int
|
||||
/** The actual implementation */
|
||||
fun startSend() {
|
||||
//if (areYouReady()) {
|
||||
busy = true
|
||||
ready = false
|
||||
|
||||
recipient?.let { startSendImpl(it) }
|
||||
recipient?.let {
|
||||
this.blockSize = startSendImpl(it)
|
||||
//println("[BlockTransferInterface.startSend()] recipients blocksize = ${this.blockSize}")
|
||||
}
|
||||
|
||||
busy = false
|
||||
ready = true
|
||||
|
||||
@@ -10,8 +10,9 @@ class BlockTransferPort(val vm: VM, val portno: Int) : BlockTransferInterface(tr
|
||||
|
||||
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()] })
|
||||
return blockSize // use MMIO to modify this variable
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
// 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) {
|
||||
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.
|
||||
*/
|
||||
override fun startSendImpl(recipient: BlockTransferInterface) {
|
||||
override fun startSendImpl(recipient: BlockTransferInterface): Int {
|
||||
if (blockSendCount == 0) {
|
||||
blockSendBuffer = messageComposeBuffer.toByteArray()
|
||||
}
|
||||
@@ -102,6 +102,8 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
||||
})
|
||||
|
||||
blockSendCount += 1
|
||||
|
||||
return sendSize
|
||||
}
|
||||
|
||||
/** 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()
|
||||
}
|
||||
|
||||
override fun startSendImpl(recipient: BlockTransferInterface) {
|
||||
override fun startSendImpl(recipient: BlockTransferInterface): Int {
|
||||
if (blockSendCount == 0) {
|
||||
//blockSendBuffer = messageComposeBuffer.toByteArray()
|
||||
blockSendBuffer = fileContent_multiblocks
|
||||
@@ -115,6 +115,8 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
||||
})
|
||||
|
||||
blockSendCount += 1
|
||||
|
||||
return sendSize
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user