Hard disk access in pm

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.
User avatar
Philip
Member
Member
Posts: 59
Joined: Thu Mar 06, 2008 11:37 pm
Location: Singapore

Hard disk access in pm

Post by Philip »

i wonder how hard disk can be accessed in protected mode?
cause int 13h can't be used :?
eddyb

Post by eddyb »

hi, Philip
this is pretty simple via in/out ports, like any other peripherals communication. I recommend to get some ATA/SATA documentation, where it is explaneid how u can do this. I saw somewhere some docs, but i'm not remember now...
User avatar
zaleschiemilgabriel
Member
Member
Posts: 232
Joined: Mon Feb 04, 2008 3:58 am

Post by zaleschiemilgabriel »

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. :roll: Any way, if you want simple, find a library and use it. If you want compatibility and performance, write it yourself. :wink:
DeviOuS - what a stupid name
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

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.
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).
User avatar
zaleschiemilgabriel
Member
Member
Posts: 232
Joined: Mon Feb 04, 2008 3:58 am

Post by zaleschiemilgabriel »

I think I burst a bubble... Yup, in concept it's that easy, but wait till you actually read the specs...
DeviOuS - what a stupid name
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

zaleschiemilgabriel wrote:I think I burst a bubble... Yup, in concept it's that easy, but wait till you actually read the specs...
Ever read a network card's spec?

Seriously though, if you read the spec and are still confused, you can still ask. The tutorial on LBA HDD access on osdever.net can help when you've read the spec and still don't get it, because you then get an idea of register offsets and the like.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

I agree hdd is easy compared to most things in OS dev. see my post here to see how easy it is to destroy your main OS :lol:
http://www.osdev.org/phpBB2/viewtopic.p ... hlight=hdd
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Post by piranha »

Check out the LBA access tutorial over at osdever.net.

Thats a good one.

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
Philip
Member
Member
Posts: 59
Joined: Thu Mar 06, 2008 11:37 pm
Location: Singapore

Post by Philip »

sorry a bit off topic but
seems like we have lots of expert here with osdev
i'm glad to be a member
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Post by Ready4Dis »

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.
User avatar
zaleschiemilgabriel
Member
Member
Posts: 232
Joined: Mon Feb 04, 2008 3:58 am

Post by zaleschiemilgabriel »

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. :roll:
DeviOuS - what a stupid name
User avatar
Philip
Member
Member
Posts: 59
Joined: Thu Mar 06, 2008 11:37 pm
Location: Singapore

Post by Philip »

anybody has a sample code to access hdd using port instructions like in and out in assembly?
User avatar
t0xic
Member
Member
Posts: 216
Joined: Sat May 05, 2007 3:16 pm
Location: VA
Contact:

Post by t0xic »

*cough* www.osdever.net *cough*
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Post by Ready4Dis »

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. :roll:
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).
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Post by piranha »

anybody has a sample code to access hdd using port instructions like in and out in assembly?
I just gave it to you!

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
Post Reply