fix: disk drive-explicitly writing 0 bytes would write 4096 bytes instead

This commit is contained in:
minjaesong
2023-06-16 13:31:38 +09:00
parent 974be9dda6
commit a83cdc1a02
5 changed files with 41 additions and 12 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -115,12 +115,12 @@ MMIO
n-read: size of the block from the other device, LSB (4096-full block size is zero) n-read: size of the block from the other device, LSB (4096-full block size is zero)
m-read: size of the block from the other device, MSB (4096-full block size is zero) m-read: size of the block from the other device, MSB (4096-full block size is zero)
a-read: if the other device hasNext (doYouHaveNext), false if device not present a-read: if the other device hasNext (doYouHaveNext), false if device not present
z-read: set if the size is actually 0 instead of 4096 z-read: set if the size is actually 0 instead of 4096 (overrides n and m parameters)
n-write: size of the block I'm sending, LSB (4096-full block size is zero) n-write: size of the block I'm sending, LSB (4096-full block size is zero)
m-write: size of the block I'm sending, MSB (4096-full block size is zero) m-write: size of the block I'm sending, MSB (4096-full block size is zero)
a-write: if there's more to send (hasNext) a-write: if there's more to send (hasNext)
z-write: set if the size is actually 0 instead of 4096 z-write: set if the size is actually 0 instead of 4096 (overrides n and m parameters)
4092..4095 RW: Block transfer control for Port 1 through 4 4092..4095 RW: Block transfer control for Port 1 through 4
0b 00ms abcd 0b 00ms abcd

View File

@@ -121,6 +121,8 @@ class TestDiskDrive(private val vm: VM, private val driveNum: Int, theRootPath:
val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE) val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
blockSendBuffer.size % BLOCK_SIZE blockSendBuffer.size % BLOCK_SIZE
else if (blockSendBuffer.size <= BLOCK_SIZE)
blockSendBuffer.size
else BLOCK_SIZE else BLOCK_SIZE
// println("blockSendCount = ${blockSendCount}; sendSize = $sendSize; blockSendBuffer.size = ${blockSendBuffer.size}") // println("blockSendCount = ${blockSendCount}; sendSize = $sendSize; blockSendBuffer.size = ${blockSendBuffer.size}")
@@ -147,9 +149,28 @@ class TestDiskDrive(private val vm: VM, private val driveNum: Int, theRootPath:
//println("[DiskDrive] writeout with inputdata length of ${inputData.size}") //println("[DiskDrive] writeout with inputdata length of ${inputData.size}")
//println("[DiskDriveMsg] ${inputData.toString(Charsets.UTF_8)}") //println("[DiskDriveMsg] ${inputData.toString(Charsets.UTF_8)}")
// println("[TestDiskDrive] (write-payload of ${inputData.size} bytes; $writeBufferUsage out of $writeModeLength bytes has been written so far)")
if (!fileOpen) throw InternalError("File is not open but the drive is in write mode") if (!fileOpen) throw InternalError("File is not open but the drive is in write mode")
System.arraycopy(inputData, 0, writeBuffer, writeBufferUsage, minOf(writeModeLength - writeBufferUsage, inputData.size, BLOCK_SIZE)) if (writeModeLength == 0) {
// println("[TestDiskDrive] write mode was initiated with zero-byte writing; closing immediately")
if (writeMode)
file.writeBytes(ByteArray(0))
writeMode = false
appendMode = false
}
else {
System.arraycopy(
inputData,
0,
writeBuffer,
writeBufferUsage,
minOf(writeModeLength - writeBufferUsage, inputData.size, BLOCK_SIZE)
)
writeBufferUsage += inputData.size writeBufferUsage += inputData.size
if (writeBufferUsage >= writeModeLength) { if (writeBufferUsage >= writeModeLength) {
@@ -163,6 +184,7 @@ class TestDiskDrive(private val vm: VM, private val driveNum: Int, theRootPath:
appendMode = false appendMode = false
} }
} }
}
else if (fileOpenMode == 17) { else if (fileOpenMode == 17) {
if (!fileOpen) throw InternalError("Bootloader file is not open but the drive is in boot write mode") if (!fileOpen) throw InternalError("Bootloader file is not open but the drive is in boot write mode")

View File

@@ -117,6 +117,8 @@ class TevdDiskDrive(private val vm: VM, private val driveNum: Int, theTevdPath:
val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE) val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
blockSendBuffer.size % BLOCK_SIZE blockSendBuffer.size % BLOCK_SIZE
else if (blockSendBuffer.size <= BLOCK_SIZE)
blockSendBuffer.size
else BLOCK_SIZE else BLOCK_SIZE
// println("blockSendCount = ${blockSendCount}; sendSize = $sendSize; blockSendBuffer.size = ${blockSendBuffer.size}") // println("blockSendCount = ${blockSendCount}; sendSize = $sendSize; blockSendBuffer.size = ${blockSendBuffer.size}")
@@ -143,12 +145,17 @@ class TevdDiskDrive(private val vm: VM, private val driveNum: Int, theTevdPath:
//println("[DiskDrive] writeout with inputdata length of ${inputData.size}") //println("[DiskDrive] writeout with inputdata length of ${inputData.size}")
//println("[DiskDriveMsg] ${inputData.toString(Charsets.UTF_8)}") //println("[DiskDriveMsg] ${inputData.toString(Charsets.UTF_8)}")
println("[TevDiskDrive] write-payload (${inputData.size} bytes)") // println("[TevDiskDrive] (write-payload of ${inputData.size} bytes; $writeBufferUsage out of $writeModeLength bytes has been written so far)")
if (!fileOpen) throw InternalError("File is not open but the drive is in write mode") if (!fileOpen) throw InternalError("File is not open but the drive is in write mode")
if (writeBuffer.isEmpty()) { if (writeModeLength == 0) {
// println("[TevDiskDrive] write mode was initiated with zero-byte writing; closing immediately")
if (writeMode)
file.overwrite(ByteArray(0))
writeMode = false writeMode = false
appendMode = false appendMode = false
} }