Disk device driver: floppy disk or USB key?
Disk device driver: floppy disk or USB key?
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.
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?
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 ?
Are you using Grub or your own boot loader ?
If a trainstation is where trains stop, what is a workstation ?
Re: Disk device driver: floppy disk or USB key?
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.
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?
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?
By IDE I mean a driver for a hard disk like this
http://wiki.osdev.org/ATA_PIO_Mode
http://wiki.osdev.org/ATA_PIO_Mode
If a trainstation is where trains stop, what is a workstation ?
Re: Disk device driver: floppy disk or USB key?
OK, I will look at that. Thank you very much for the suggestion.
Re: Disk device driver: floppy disk or USB key?
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?
Hi,
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.
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).
Cheers,
Brendan
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).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.
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.
For modern devices (not floppy) you need to start with PCI enumeration and resource detection/assignment.lpoulain wrote:However, it looks like reading from a USB key seems even more nightmarish. Or am I imagining things?
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).
PIO mode is a very bad idea, even if it does work properly.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.
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.
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: Disk device driver: floppy disk or USB key?
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.
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
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
- Combuster
- 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?
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)
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'm using Grub.
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: Disk device driver: floppy disk or USB key?
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.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)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'm using Grub.
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
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Re: Disk device driver: floppy disk or USB key?
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.
@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?
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?
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?
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.
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
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