Reading/writing to hard-disk in pmode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
alexbnc
Posts: 14
Joined: Sun Jun 17, 2012 4:37 pm

Reading/writing to hard-disk in pmode

Post by alexbnc »

Hi, OSDev community!
I'm back with this tiny O.S. (I don't give up so easy, even if I take 1-2 months breaks) and I must say that the last time I played with its code I have learnt so much, specially from here. I have understood and managed to create a boot-loader, second boot-loader, load the GDT, open A20 and enter pmode. Now, I suppose I should start to read from the hard-disk. In order to do that I need to organize the data on the disk (create a File System which will hold information about the files and their structure) and, of course, to be able to read/write (and maybe realize other operations, like getting information about the hdd, checking its status, resetting, etc.). In real mode this is quite simple with the BIOS interrupts but in pmode it's not so easy, as I see.
So, my question is: how many and which are they?
As far as I know there's the PIO Mode, an old method compatible with any ATA disk. For example, I have installed Windows XP on a SATA disk. Is Windows XP using PIO in order to interact with the disk? Does that mean that it doesn't take all the advantages of the SATA features by using PIO for it?
In this case, is there a better way of reading/writing to SATA disks?
A more difficult method is to create a driver. In this case you must know the manufacturer and type of the disk or you can create a driver that can be understood by any hard disk's controller? What I'm asking basically is how many types of hard disks do exist on the most common machines and how many methods to i/o them in pmode?
Oh, and related to file systems, I haven't create it yet (in real mode). Is it absolutely necessary or I can do it in pmode, too?
Also, how can you detect the hardware on the computer in pmode? I mean, if I want to find out the name, type and size of the disk, how do I do it? Is there any place in memory storing that info?
Thanks for your answer. Understanding this will help me take the next step.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Reading/writing to hard-disk in pmode

Post by egos »

PIO mode is too slow and is bad suitable for multitasking. As you said this mode is used only if DMA mode is not supported. SATA can work in two modes: IDE-mode and AHCI-mode. So you should write PCI IDE-driver and probably AHCI-driver. I still have no AHCI-driver. I just set up IDE-mode in BIOS Setup. But sometimes it's not possible.
If you have seen bad English in my words, tell me what's wrong, please.
alexbnc
Posts: 14
Joined: Sun Jun 17, 2012 4:37 pm

Re: Reading/writing to hard-disk in pmode

Post by alexbnc »

Thanks, I will start creating an IDE driver, so I can read/write on both ATA and SATA.
Post Reply