mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-10 23:04:04 +09:00
duh duh duh duh
This commit is contained in:
@@ -61,6 +61,7 @@ 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}")
|
||||||
|
|
||||||
for (k in 0 until minOf(BLOCK_SIZE, transStat.first)) {
|
for (k in 0 until minOf(BLOCK_SIZE, transStat.first)) {
|
||||||
msgBuffer.write(vm.getIO().blockTransferRx[portNo][k.toLong()].toInt())
|
msgBuffer.write(vm.getIO().blockTransferRx[portNo][k.toLong()].toInt())
|
||||||
|
|||||||
@@ -22,16 +22,14 @@ abstract class BlockTransferInterface(val isMaster: Boolean, val isSlave: Boolea
|
|||||||
|
|
||||||
/** 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 startSend()
|
abstract fun startSendImpl(recipient: BlockTransferInterface)
|
||||||
/** The actual implementation */
|
/** The actual implementation */
|
||||||
protected fun startSend(sendfun: ((BlockTransferInterface) -> Unit)? = null) {
|
fun startSend() {
|
||||||
//if (areYouReady()) {
|
//if (areYouReady()) {
|
||||||
busy = true
|
busy = true
|
||||||
ready = false
|
ready = false
|
||||||
|
|
||||||
recipient?.let { recipient ->
|
recipient?.let { startSendImpl(it) }
|
||||||
sendfun?.invoke(recipient)
|
|
||||||
}
|
|
||||||
|
|
||||||
busy = false
|
busy = false
|
||||||
ready = true
|
ready = true
|
||||||
@@ -48,13 +46,13 @@ abstract class BlockTransferInterface(val isMaster: Boolean, val isSlave: Boolea
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** A method called by the sender so it can ACTUALLY write its thing onto me. */
|
/** A method called by the sender so it can ACTUALLY write its thing onto me. */
|
||||||
abstract fun writeout(inputData: ByteArray)
|
abstract fun writeoutImpl(inputData: ByteArray)
|
||||||
/** The actual implementation; must be called by a sender class */
|
/** The actual implementation; must be called by a sender class */
|
||||||
protected fun writeout(inputData: ByteArray, writeoutfun: (() -> Unit)? = null) {
|
fun writeout(inputData: ByteArray) {
|
||||||
busy = true
|
busy = true
|
||||||
ready = false
|
ready = false
|
||||||
blockSize = minOf(inputData.size, BLOCK_SIZE)
|
blockSize = minOf(inputData.size, BLOCK_SIZE)
|
||||||
writeoutfun?.invoke()
|
writeoutImpl(inputData)
|
||||||
busy = false
|
busy = false
|
||||||
ready = true
|
ready = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,32 +10,22 @@ class BlockTransferPort(val vm: VM, val portno: Int) : BlockTransferInterface(tr
|
|||||||
|
|
||||||
internal var hasNext = false
|
internal var hasNext = false
|
||||||
|
|
||||||
override fun startSend() {
|
override fun startSendImpl(recipient: BlockTransferInterface) {
|
||||||
startSend { recipient ->
|
recipient.writeout(ByteArray(BLOCK_SIZE) { vm.getIO().blockTransferTx[portno][it.toLong()] })
|
||||||
val ba = ByteArray(BLOCK_SIZE) { vm.getIO().blockTransferTx[portno][it.toLong()] }
|
|
||||||
recipient.writeout(ba)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.ready = true
|
|
||||||
this.busy = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hasNext(): Boolean = hasNext
|
override fun hasNext(): Boolean = hasNext
|
||||||
|
|
||||||
override fun writeout(inputData: ByteArray) {
|
override fun writeoutImpl(inputData: ByteArray) {
|
||||||
writeout(inputData) {
|
//val copySize = minOf(BLOCK_SIZE, inputData.size).toLong()
|
||||||
//val copySize = minOf(BLOCK_SIZE, inputData.size).toLong()
|
//val arrayOffset = UnsafeHelper.getArrayOffset(inputData)
|
||||||
//val arrayOffset = UnsafeHelper.getArrayOffset(inputData)
|
//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
|
||||||
for (k in 0 until BLOCK_SIZE) {
|
println("[BlockTranferPort] writeout size: ${inputData.size}")
|
||||||
vm.getIO().blockTransferRx[portno][k.toLong()] = if (k >= inputData.size) 0 else inputData[k]
|
for (k in 0 until BLOCK_SIZE) {
|
||||||
}
|
vm.getIO().blockTransferRx[portno][k.toLong()] = if (k >= inputData.size) 0x5F else inputData[k]
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ready = true
|
|
||||||
this.busy = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -88,22 +88,20 @@ 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 startSend() {
|
override fun startSendImpl(recipient: BlockTransferInterface) {
|
||||||
recipient?.let { recipient ->
|
if (blockSendCount == 0) {
|
||||||
if (blockSendCount == 0) {
|
blockSendBuffer = messageComposeBuffer.toByteArray()
|
||||||
blockSendBuffer = messageComposeBuffer.toByteArray()
|
|
||||||
}
|
|
||||||
|
|
||||||
val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
|
|
||||||
blockSendBuffer.size % BLOCK_SIZE
|
|
||||||
else BLOCK_SIZE
|
|
||||||
|
|
||||||
recipient.writeout(ByteArray(sendSize) {
|
|
||||||
blockSendBuffer[blockSendCount * BLOCK_SIZE + it]
|
|
||||||
})
|
|
||||||
|
|
||||||
blockSendCount += 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
|
||||||
|
blockSendBuffer.size % BLOCK_SIZE
|
||||||
|
else BLOCK_SIZE
|
||||||
|
|
||||||
|
recipient.writeout(ByteArray(sendSize) {
|
||||||
|
blockSendBuffer[blockSendCount * BLOCK_SIZE + it]
|
||||||
|
})
|
||||||
|
|
||||||
|
blockSendCount += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Computer's attempt to startSend() will result in calling this very function.
|
/** Computer's attempt to startSend() will result in calling this very function.
|
||||||
@@ -111,11 +109,7 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
*
|
*
|
||||||
* Disk drive must create desired side effects in accordance with the input message.
|
* Disk drive must create desired side effects in accordance with the input message.
|
||||||
*/
|
*/
|
||||||
override fun writeout(inputData: ByteArray) {
|
override fun writeoutImpl(inputData: ByteArray) {
|
||||||
ready = false
|
|
||||||
busy = true
|
|
||||||
|
|
||||||
|
|
||||||
val inputString = inputData.toString()
|
val inputString = inputData.toString()
|
||||||
|
|
||||||
if (inputString.startsWith("DEVRST$END_OF_SEND_BLOCK")) {
|
if (inputString.startsWith("DEVRST$END_OF_SEND_BLOCK")) {
|
||||||
@@ -190,10 +184,6 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ready = true
|
|
||||||
busy = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val diskID: UUID = UUID(0, 0)
|
val diskID: UUID = UUID(0, 0)
|
||||||
|
|||||||
@@ -100,24 +100,21 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
|||||||
return sb.toByteArray()
|
return sb.toByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startSend() {
|
override fun startSendImpl(recipient: BlockTransferInterface) {
|
||||||
recipient?.let { recipient ->
|
if (blockSendCount == 0) {
|
||||||
if (blockSendCount == 0) {
|
//blockSendBuffer = messageComposeBuffer.toByteArray()
|
||||||
//blockSendBuffer = messageComposeBuffer.toByteArray()
|
blockSendBuffer = fileContent_multiblocks
|
||||||
blockSendBuffer = fileContent_multiblocks
|
|
||||||
}
|
|
||||||
|
|
||||||
val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
|
|
||||||
blockSendBuffer.size % BLOCK_SIZE
|
|
||||||
else BLOCK_SIZE
|
|
||||||
|
|
||||||
recipient.writeout(ByteArray(sendSize) {
|
|
||||||
blockSendBuffer[blockSendCount * BLOCK_SIZE + it]
|
|
||||||
})
|
|
||||||
|
|
||||||
blockSendCount += 1
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
|
||||||
|
blockSendBuffer.size % BLOCK_SIZE
|
||||||
|
else BLOCK_SIZE
|
||||||
|
|
||||||
|
recipient.writeout(ByteArray(sendSize) {
|
||||||
|
blockSendBuffer[blockSendCount * BLOCK_SIZE + it]
|
||||||
|
})
|
||||||
|
|
||||||
|
blockSendCount += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hasNext(): Boolean {
|
override fun hasNext(): Boolean {
|
||||||
@@ -125,7 +122,7 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
|||||||
|
|
||||||
return (blockSendCount * BLOCK_SIZE < blockSendBuffer.size)
|
return (blockSendCount * BLOCK_SIZE < blockSendBuffer.size)
|
||||||
}
|
}
|
||||||
override fun writeout(inputData: ByteArray) {
|
override fun writeoutImpl(inputData: ByteArray) {
|
||||||
val inputString = inputData.toString(VM.CHARSET)
|
val inputString = inputData.toString(VM.CHARSET)
|
||||||
|
|
||||||
if (inputString.startsWith("DEVRST\u0017")) {
|
if (inputString.startsWith("DEVRST\u0017")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user