ATA/HDD driver for x86_64

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
monarrk
Posts: 20
Joined: Mon Nov 02, 2020 4:53 pm
Libera.chat IRC: monarrk

ATA/HDD driver for x86_64

Post 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
User avatar
pvc
Member
Member
Posts: 201
Joined: Mon Jan 15, 2018 2:27 pm

Re: ATA/HDD driver for x86_64

Post by pvc »

It is all exactly the same for 32 and 64 bits.
foliagecanine
Member
Member
Posts: 148
Joined: Sun Aug 23, 2020 4:35 pm

Re: ATA/HDD driver for x86_64

Post 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!
My OS: TritiumOS
https://github.com/foliagecanine/tritium-os
void warranty(laptop_t laptop) { if (laptop.broken) return laptop; }
I don't get it: Why's the warranty void?
monarrk
Posts: 20
Joined: Mon Nov 02, 2020 4:53 pm
Libera.chat IRC: monarrk

Re: ATA/HDD driver for x86_64

Post by monarrk »

thank you! I will look at using ahci
Post Reply