Page 1 of 2

Disk device driver: floppy disk or USB key?

Posted: Sun Jan 10, 2016 3:31 pm
by lpoulain
All,

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. However, it looks like reading from a USB key seems even more nightmarish. Or am I imagining things?

Thanks in advance for your thoughts and advise on the matter.

Re: Disk device driver: floppy disk or USB key?

Posted: Sun Jan 10, 2016 3:38 pm
by gerryg400
Generally speaking, a USB driver is considerably more work than a floppy driver. An IDE driver is much simpler than both and may be the best place to start.

Are you using Grub or your own boot loader ?

Re: Disk device driver: floppy disk or USB key?

Posted: Sun Jan 10, 2016 3:45 pm
by lpoulain
That's what it looked like. Thanks for confirming.

And I'm using Grub. So the issue is not the bootloader read, but the OS kernel itself.

Re: Disk device driver: floppy disk or USB key?

Posted: Sun Jan 10, 2016 3:54 pm
by lpoulain
By the way, when you say an IDE driver, do you mean something else than what is described on http://wiki.osdev.org/Floppy_Disk_Controller ?

Re: Disk device driver: floppy disk or USB key?

Posted: Sun Jan 10, 2016 5:02 pm
by gerryg400
By IDE I mean a driver for a hard disk like this
http://wiki.osdev.org/ATA_PIO_Mode

Re: Disk device driver: floppy disk or USB key?

Posted: Sun Jan 10, 2016 7:39 pm
by lpoulain
OK, I will look at that. Thank you very much for the suggestion.

Re: Disk device driver: floppy disk or USB key?

Posted: Sun Jan 10, 2016 11:45 pm
by Quaker763
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.

Re: Disk device driver: floppy disk or USB key?

Posted: Mon Jan 11, 2016 12:55 am
by Brendan
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

Re: Disk device driver: floppy disk or USB key?

Posted: Mon Jan 11, 2016 2:35 am
by onlyonemac
Regarding the lack of output from your floppy driver, I'd like to add that I initially had some confusion about reading floppy disks and didn't realise that it's necessary to calibrate the controller before first use. For some reason, after entering from the BIOS, the controller assumes that the heads are at track 0 even if they are not, and a calibration is necessary to position the heads back in the correct place. It doesn't "crash" as such if you don't do this, but it doesn't return any data and if you check for errors it does return an error (saying something like "index mark not found" or something like that - it's been a while since I did this).

Obviously, make sure you're not using a USB floppy drive as those are USB devices and must be used as such; do not try to operate a USB floppy drive like a normal FDC-controlled floppy drive.

Re: Disk device driver: floppy disk or USB key?

Posted: Mon Jan 11, 2016 2:45 am
by Combuster
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)
I'm using Grub.
If what you want is a device driver, by all means go ahead and pick your choice. If you want to read files, know that you can just ask GRUB to load files (including tars and filesystem images) into memory at boot time and be saved from deciding which medium you want to use.

Re: Disk device driver: floppy disk or USB key?

Posted: Mon Jan 11, 2016 10:04 am
by onlyonemac
Combuster wrote:
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)
I'm using Grub.
If what you want is a device driver, by all means go ahead and pick your choice. If you want to read files, know that you can just ask GRUB to load files (including tars and filesystem images) into memory at boot time and be saved from deciding which medium you want to use.
I think he's wanting to access the rest of the disk after his OS has booted. Just because you're an admin and (apparently) have more experience with OSdev than the rest of us doesn't mean that the rest of us never know what we're talking about.

Re: Disk device driver: floppy disk or USB key?

Posted: Mon Jan 11, 2016 11:57 am
by lpoulain
Thank you all for your responses.

@Quaker763: I am using DMA mode.

@Brendan: I don't expect anything to work the first time ;-) Developing your own OS is about perseverance (it took me weeks to get multitasking properly working). Sometimes though you're looking for the path which is likely to be the less painful.

@onlyonemac: I will check calibrating the controller. And I believe I am using a standard floppy disk controller (I'm using Bochs and VirtualBox to test)

@Combuster: having Grub loading a file is useful, but I also want the OS to be able to access the filesystem, i.e. read and write files. But before I write my FAT driver I need to be able to read sectors from the disk.

Re: Disk device driver: floppy disk or USB key?

Posted: Mon Jan 11, 2016 12:10 pm
by Techel
I started with simple ata drives. USB is not easy and the buddies over from prettyos needed months to get it working properly; nevertheless it's an awesome thing when it is implemented. Floppy disk are out of date, at least at my point of view, and are not implemented in my own operating system.

Re: Disk device driver: floppy disk or USB key?

Posted: Mon Jan 11, 2016 1:21 pm
by iansjack
I'd agree with that. A simple hard disk driver is simpler than a floppy driver and is going to be more useful in real life. It's unlikely that 1.44 MB is going to suffice once your OS achieves a reasonable level of complexity. You'll need a hard disk driver sooner or later, so why not make it sooner (and save yourself the grief of a floppy driver and a brain dead file system).

Re: Disk device driver: floppy disk or USB key?

Posted: Mon Jan 11, 2016 2:32 pm
by SpyderTL
It's pretty difficult to test out your OS on real hardware if all you have is IDE hard drive support... It's also difficult to test on real hardware if it doesn't have a floppy drive.

The next best approach would be IDE CD-ROM, but that is also getting pretty hard to find, nowadays. You may have to go to AHCI CD-ROM if you want your OS to run on a modern PC.