Disk Device
Device Type:
0x96818B9A
Interrupt on completion:0x72(DiskOperationFinish) — read and write only
CLI Name:Disk
The disk device is a command-based serial device that reads and writes fixed-size blocks, and reports its capacity.
Block format
Section titled “Block format”- Block size is 512 bytes.
- Operations are queued and executed serially.
Commands
Section titled “Commands”| Command | ID | Args |
|---|---|---|
| Read | 1 | 3 |
| Write | 2 | 3 |
| Get Size | 3 | 0 |
Read and write both take:
- VM memory address
- start block
- block count
Get size takes no arguments.
Copies block count blocks from disk into VM memory starting at the provided memory address.
Copies block count blocks from VM memory into disk starting at the provided block number.
Get Size
Section titled “Get Size”The next value the device emits from the serial protocol is the disk’s capacity in blocks, so the size in bytes is that value multiplied by 512. A disk whose length is not a whole number of blocks is reported rounded down, since a partial trailing block cannot be addressed.
Unlike read and write this is answered immediately and does not raise 0x72, so read the
reply straight after issuing the command rather than waiting for the completion interrupt. It
may be issued while a read or write is still in flight; it does not queue behind them.
Completion
Section titled “Completion”After each read or write finishes, the device raises hardware interrupt 0x72. Get size is
synchronous and never raises it.
Example
Section titled “Example”; Read 1 block from disk block 4 into memory at 0x200OUT DISK_PORT, 1 ; ReadOUT DISK_PORT, 0x200 ; memory addressOUT DISK_PORT, 4 ; start blockOUT DISK_PORT, 1 ; block count
; Write 1 block from memory 0x200 to disk block 8OUT DISK_PORT, 2 ; WriteOUT DISK_PORT, 0x200OUT DISK_PORT, 8OUT DISK_PORT, 1
; Ask the disk how big it isOUT DISK_PORT, 3 ; Get SizeIN r0, DISK_PORT ; capacity in 512-byte blocks