Hard disk access in pm
Posted: Wed Mar 12, 2008 11:15 pm
i wonder how hard disk can be accessed in protected mode?
cause int 13h can't be used
cause int 13h can't be used
The Place to Start for Operating System Developers
http://f.osdev.org/
That's wrong. Hard drive drivers using in/out are extremely simple. All you need is the spec (t13.org) and a spare hard disk image to test with (of course, you should put known values at known sectors so you can try it out).Actually it's not that simple to implement. Most people think it is because they use code that's written by someone else, and that's always simple.
Ever read a network card's spec?zaleschiemilgabriel wrote:I think I burst a bubble... Yup, in concept it's that easy, but wait till you actually read the specs...
Yes, writing an LBA 'driver' that can read/write a sector (or multiple sectors) is very easy actually. Now, writing a driver that can detect installed drives gets to be harder (especially when the hardware doesn't conform to the specs properly like I have witnessed, I spent a good amount of time writing a very by the spec detection routine that just failed to run properly, after extensive debugging, i found the IDE controller was not giving me the proper values it should have according to the specifications, so I reverted back to my not-so-by-the-spec-but-works detection method, which detects all drives it should). Then once you start adding things like PCI config space, DMA, etc things start getting very far outside of the simple window. But to get a basic read primary disk on controller in LBA28 or LBA48 mode is very simple, even following the specs or examples on the web.zaleschiemilgabriel wrote:I think I burst a bubble... Yup, in concept it's that easy, but wait till you actually read the specs...
Yes, like I said, basic PIO is simple, so getting a very basic driver is not to difficult, now turning the device from legacy 'isa ide' mode, to 'pci ide' mode, reading the pci space, enabling the device, programming a dma driver, etc, etc is a lot more difficult. So, depending on what you consider a 'good enough for now' driver, means that writing a HD driver can be easy, or very difficult. I think that a PIO fall-back is a must... unless you plan on supporting only advanced machines, and know that you will never have to revert back to PIO, and can write drivers very well without needing a way to read the hard-drive while in PMODE while testing said drivers). So, I suggest that you, like many others, start with some code that scans the standard locations for devices, and write some code to read/write to them at a specific sector. Then something that can parse and MBR for partitions, then a FS driver so you can read files. Writing isn't important until you get a lot of bugs worked out (and I would suggest leaving it disabled until that point, unless you absolutely know it works, and you need to log something to disk for debugging, in which case I would suggest writing a serial port driver with another machine cnostantly reading inputs).zaleschiemilgabriel wrote:I know. I have implemented reading data from an IDE using PIO mode (without using interrupts), and that, I must agree, was pretty easy.
1. You have to program the DMA. Last time I checked, there were only 3 DMA channels available... who gets them? That means you must write some kind of resource manager for the DMA channels. If they're all busy at the moment, you have to wait...
2. Using interrupts is just weird. What do you do when an interrupt form the IDE you sent a "READ DMA" to interrupts? The processor might have done a lot of things ever since you sent the command, so there are a lot of synchronization issues there...
On the other hand, I found PCI device detection to be a lot easier than everything I just said.
I just gave it to you!anybody has a sample code to access hdd using port instructions like in and out in assembly?