Disk controller should honor img_readonly (write-protect gate) #24

Open
opened 2026-04-10 02:04:32 +00:00 by bcox · 0 comments
Owner

The MiSTer hps_io module provides an img_readonly signal that indicates when a mounted disk image should be treated as read-only. Currently disk.sv does not check this flag -- write commands are accepted unconditionally, and the WRPROT bit in DSK_STAT (bit 5) is never set.

What should happen:

  1. SBC7.sv and sbc7_top.sv should wire img_readonly through to the disk controller.
  2. disk.sv should latch the read-only flag per drive (alongside disk_present) on img_mounted events.
  3. When a write command is issued to a read-only drive, the controller should refuse the write, set the ERROR and WRPROT status bits, and complete immediately without issuing sd_wr.
  4. The DSK_STAT register already reserves bit 5 for WRPROT -- it just needs to be driven.

Risk: Without the gate, writing to a read-only-mounted image silently writes through to the SD card, which could corrupt images the user intended to protect.

The MiSTer `hps_io` module provides an `img_readonly` signal that indicates when a mounted disk image should be treated as read-only. Currently `disk.sv` does not check this flag -- write commands are accepted unconditionally, and the `WRPROT` bit in `DSK_STAT` (bit 5) is never set. **What should happen:** 1. `SBC7.sv` and `sbc7_top.sv` should wire `img_readonly` through to the disk controller. 2. `disk.sv` should latch the read-only flag per drive (alongside `disk_present`) on `img_mounted` events. 3. When a write command is issued to a read-only drive, the controller should refuse the write, set the `ERROR` and `WRPROT` status bits, and complete immediately without issuing `sd_wr`. 4. The `DSK_STAT` register already reserves bit 5 for `WRPROT` -- it just needs to be driven. **Risk:** Without the gate, writing to a read-only-mounted image silently writes through to the SD card, which could corrupt images the user intended to protect.
bcox changed title from Disk controller should honour img_readonly (write-protect gate) to Disk controller should honor img_readonly (write-protect gate) 2026-04-10 02:06:02 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
bcox/sbc7#24
No description provided.