Hi,
lpoulain wrote:
I am at a point where I'm trying to write a disk device driver. As my OS currently resides on a floppy disk image, I've been trying to write a driver to read from the floppy disk (in protected mode). I've however been banging my head against the wall for some time now (the code doesn't crash but doesn't read anything)
So I am wondering if I shouldn't move the OS to an USB key and try to read from there.
You should fix your floppy driver, partly because it's easier to do it now when all the information is still fresh in your mind (and harder to try again later when you've forgotten the information).
Also don't forget that if you start writing a completely different device driver there's no guarantee that it'll work the first time either.
lpoulain wrote:
However, it looks like reading from a USB key seems even more nightmarish. Or am I imagining things?
For modern devices (not floppy) you need to start with PCI enumeration and resource detection/assignment.
USB is a minimum of 2 drivers (one for the controller and another for the device) where there's multiple controllers to worry about (UHCI, OHCI, EHCI, xHCI), and then possibly USB hubs too.
For ATA there's variations between different controllers (with/without bus mastering, "legacy ISA mode" or "native PCI mode"), plus multiple variations for the disk drives themselves (LBA24, LBA48, different PIO and DMA transfer modes, 4 KiB sectors, power management, secure erase, etc). Most people who think this is "easier than floppy" haven't written code that copes with all the possible variations and/or supports all the hardware's features properly.
For floppy, there's no need for PCI bus enumeration, etc; and (assuming you don't care about tape drives) there's very little variation between different versions of the controller or drive that makes any significant difference. The only part that makes it a little complicated is auto-detecting the disk's media type (1440 KiB, 1680 KiB, 1200 KiB, etc); but it's not that hard (just a "trial and error" sequence that narrows down the possibilities until there's only one possible media type left) and it's also completely optional (you can just use end-user config and/or rely on BPB and/or just assume all floppies are 1440 KiB).
Quaker763 wrote:
Are you trying to read the floppy in PIO mode or DMA mode? I've read that some emulators struggle or flat out refuse non-DMA requests.
PIO mode is a very bad idea, even if it does work properly.
Cheers,
Brendan