Page 1 of 1

ATA/HDD driver for x86_64

Posted: Thu Jan 28, 2021 12:27 pm
by monarrk
Hello there!!

I have reached the point with my OS where I am interested in making an HDD/ATA driver so I can read from the disk. I know there is a tutorial on here for that, but my issue is that it is for x86 (32 bits), whereas my kernel is written for x86_64. My question is this: are there any good tutorials/resources/examples of an HDD driver for x86_64 that I could use?

You can find the code for my kernel here if it matters: https://gitlab.com/monarrk/untrust

Thank you,
Skylar Bleed

Re: ATA/HDD driver for x86_64

Posted: Thu Jan 28, 2021 2:04 pm
by pvc
It is all exactly the same for 32 and 64 bits.

Re: ATA/HDD driver for x86_64

Posted: Sat Jan 30, 2021 10:25 pm
by foliagecanine
You're probably going to want to have a look at >>AHCI<< if you're developing for x86_64.
Technically you could use IDE mode even in x86_64 (it looks like you have some code for that), but it's pretty old and practically all x86_64 computers have support for AHCI.

I've got some AHCI code in my OS (written in C though). However, my AHCI code isn't up to spec and I sort of just hacked it together.
I'd recommend taking a look at other people's OSes and see how they manage AHCI.

This took me a while to figure out, but to add an AHCI disk in QEMU:

Code: Select all

qemu-system-x86_64 -device ahci,id=ahci -drive file=hard_disk_image_here.img,id=disk,if=none,format=raw -device ide-hd,drive=disk,bus=ahci.0 [other options...]
Good luck!

Re: ATA/HDD driver for x86_64

Posted: Sun Jan 31, 2021 11:52 am
by monarrk
thank you! I will look at using ahci