OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:37 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Disk device driver: floppy disk or USB key?
PostPosted: Sun Jan 10, 2016 3:31 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: Disk device driver: floppy disk or USB key?
PostPosted: Sun Jan 10, 2016 3:38 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: Disk device driver: floppy disk or USB key?
PostPosted: Sun Jan 10, 2016 3:45 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: Disk device driver: floppy disk or USB key?
PostPosted: Sun Jan 10, 2016 3:54 pm 
Offline
Member
Member

Joined: Mon Dec 21, 2015 7:09 pm
Posts: 38
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 ?


Top
 Profile  
 
 Post subject: Re: Disk device driver: floppy disk or USB key?
PostPosted: Sun Jan 10, 2016 5:02 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: Disk device driver: floppy disk or USB key?
PostPosted: Sun Jan 10, 2016 7:39 pm 
Offline
Member
Member

Joined: Mon Dec 21, 2015 7:09 pm
Posts: 38
OK, I will look at that. Thank you very much for the suggestion.


Top
 Profile  
 
 Post subject: Re: Disk device driver: floppy disk or USB key?
PostPosted: Sun Jan 10, 2016 11:45 pm 
Offline
User avatar

Joined: Sun Mar 08, 2015 5:32 am
Posts: 17
Location: Straya
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.


Top
 Profile  
 
 Post subject: Re: Disk device driver: floppy disk or USB key?
PostPosted: Mon Jan 11, 2016 12:55 am 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject: Re: Disk device driver: floppy disk or USB key?
PostPosted: Mon Jan 11, 2016 2:35 am 
Offline
Member
Member

Joined: Sat Mar 01, 2014 2:59 pm
Posts: 1146
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


Top
 Profile  
 
 Post subject: Re: Disk device driver: floppy disk or USB key?
PostPosted: Mon Jan 11, 2016 2:45 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
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)
Quote:
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 ]


Top
 Profile  
 
 Post subject: Re: Disk device driver: floppy disk or USB key?
PostPosted: Mon Jan 11, 2016 10:04 am 
Offline
Member
Member

Joined: Sat Mar 01, 2014 2:59 pm
Posts: 1146
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)
Quote:
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


Top
 Profile  
 
 Post subject: Re: Disk device driver: floppy disk or USB key?
PostPosted: Mon Jan 11, 2016 11:57 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: Disk device driver: floppy disk or USB key?
PostPosted: Mon Jan 11, 2016 12:10 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: Disk device driver: floppy disk or USB key?
PostPosted: Mon Jan 11, 2016 1:21 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
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).


Top
 Profile  
 
 Post subject: Re: Disk device driver: floppy disk or USB key?
PostPosted: Mon Jan 11, 2016 2:32 pm 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group