Disk device driver: floppy disk or USB key?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
lpoulain
Member
Member
Posts: 38
Joined: Mon Dec 21, 2015 7:09 pm

Disk device driver: floppy disk or USB key?

Post 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.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

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

Post 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 ?
If a trainstation is where trains stop, what is a workstation ?
lpoulain
Member
Member
Posts: 38
Joined: Mon Dec 21, 2015 7:09 pm

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

Post 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.
lpoulain
Member
Member
Posts: 38
Joined: Mon Dec 21, 2015 7:09 pm

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

Post 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 ?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

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

Post by gerryg400 »

By IDE I mean a driver for a hard disk like this
http://wiki.osdev.org/ATA_PIO_Mode
If a trainstation is where trains stop, what is a workstation ?
lpoulain
Member
Member
Posts: 38
Joined: Mon Dec 21, 2015 7:09 pm

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

Post by lpoulain »

OK, I will look at that. Thank you very much for the suggestion.
User avatar
Quaker763
Posts: 17
Joined: Sun Mar 08, 2015 5:32 am
Location: Straya

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

Post 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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

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

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

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

Post 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.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

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

Post 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.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
lpoulain
Member
Member
Posts: 38
Joined: Mon Dec 21, 2015 7:09 pm

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

Post 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.
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

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

Post 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.
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post 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).
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

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

Post 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.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Post Reply