How to read from SATA HDD (AHCI) on low level?

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.
natiiix
Member
Member
Posts: 44
Joined: Thu Mar 23, 2017 5:21 pm

Re: How to read from SATA HDD (AHCI) on low level?

Post by natiiix »

Korona wrote:What in particular is so bad about the Linux kernel if you just want to build a user-space? What features does it lack? It only seems overcomplicated if you refuse to study it.
It's probably the most complicated open source code on the Internet, how is it not overcomplicated for someone making a very basic OS? So yeah, that's bad about it. It's completely unusable for what I want. It would be more than a gigabyte of redundant code.
iansjack wrote:This thread sure makes me chuckle every time it gets sillier and sillier.
It won't get smarter unless the replies become more helpful.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to read from SATA HDD (AHCI) on low level?

Post by iansjack »

natiiix wrote:
Korona wrote:What in particular is so bad about the Linux kernel if you just want to build a user-space? What features does it lack? It only seems overcomplicated if you refuse to study it.
It's probably the most complicated open source code on the Internet, how is it not overcomplicated for someone making a very basic OS?
How complicated the source code is shouldn't matter to you. You just want to use the kernel, not write drivers for it or anything like that. It provides a straightforward, easily used set of system calls.
natiiix
Member
Member
Posts: 44
Joined: Thu Mar 23, 2017 5:21 pm

Re: How to read from SATA HDD (AHCI) on low level?

Post by natiiix »

iansjack wrote:How complicated the source code is shouldn't matter to you. You just want to use the kernel, not write drivers for it or anything like that. It provides a straightforward, easily used set of system calls.
I guess that's why Linux From Scratch book has only 359 pages, right?
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to read from SATA HDD (AHCI) on low level?

Post by iansjack »

You expect a book describing in detail how to build an operating system to have less than 359 pages? Once again an example of your naively inflated expectations I'm afraid.
natiiix
Member
Member
Posts: 44
Joined: Thu Mar 23, 2017 5:21 pm

Re: How to read from SATA HDD (AHCI) on low level?

Post by natiiix »

iansjack wrote:You expect a book describing in detail how to build an operating system to have less than 359 pages? Once again an example of your naively inflated expectations I'm afraid.
I don't remember mentioning anything about a detailed book. It's just the best known book regarding that topic.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to read from SATA HDD (AHCI) on low level?

Post by iansjack »

Certainly most books describing an operating system are considerably longer than that. The reason for that, as you are discovering (but refuse to accept) is that a useful operating system is a moderately complicated project.
natiiix
Member
Member
Posts: 44
Joined: Thu Mar 23, 2017 5:21 pm

Re: How to read from SATA HDD (AHCI) on low level?

Post by natiiix »

iansjack wrote:Certainly most books describing an operating system are considerably longer than that. The reason for that, as you are discovering (but refuse to accept) is that a useful operating system is a moderately complicated project.
You've just made a very good counter-argument to your statement about Linux kernel having easy to use system calls, because that would certainly make OS development pretty easy. Obviously that assume you don't necessarily want to start from an absolute scratch.
If it were as easy as you said I would have found a guide on how to build an OS on top of it and never started making my own kernel to begin with.
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: How to read from SATA HDD (AHCI) on low level?

Post by SpyderTL »

Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: How to read from SATA HDD (AHCI) on low level?

Post by Schol-R-LEA »

Actually, SpyderTL, the Linux From Scratch project was mentioned already, and was in fact what Natilix was talking about. And the point is a valid one, it really isn't a very approachable text; the problem is in expecting that an approachable text on this topic exists, or can exist.

I will also admit that I hadn't used the AHCI page as anything other than reference until now, and now that I have read it, I have to agree that it is severely lacking in detailed explanations and usable information - the information is there, but it will only make sense to someone who already knows enough about AHCI to implement it on their own. The fact that the code exists at all is extremely misleading, because, well, as people keep telling Natilix, it doesn't actually work and a working example can't be given without relying on knowledge of the OS it is being written for. We really have been falling down on the job, though part of it is that we still aren't being clear enough on just how high the bar is. Even with all the warnings we've got in the Beginner's pages, we haven't been getting through to people about what the limitations of our information, and the requirements of a working OS project, really are.

In the case of AHCI, part of the problem is copyright - we're already pushing Fair Use as far as it will go by including diagrams and direct quotes from the specification, and we'd need a lot more specialized knowledge than anyone here actually has in order to do a better job of explaining it without infringing on the spec IP.

You have to recall, too, that were are doing this as volunteers, most of us as a hobby; there aren't many actual professional OS devs in the world, and only maybe four are on this forum. Those who are, generally have focused on other parts of the wiki. There are simply too many different variables, too many options and approaches, to give a walkthrough for OS design beyond the very basic material already there.

Finally, while people such as Lee Felsenstein, Steve Wozniak, and Tim Pittman may have written their own operating systems in relatively short time spans, you have to keep in mind that they were working on hardware they designed themselves and knew intimately, hardware much simpler than what is used today, and they had no standards to try and implement or legacy cruft to remain compatible with. They only managed it because things like AHCI didn't exist to get in their way.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
natiiix
Member
Member
Posts: 44
Joined: Thu Mar 23, 2017 5:21 pm

Re: How to read from SATA HDD (AHCI) on low level?

Post by natiiix »

SpyderTL wrote:Something like this?

http://www.makeuseof.com/tag/create-ope ... -linux-si/
Seen that page, seemed and still seems completely useless to me.
Mentions LFS, which is quite complicatedm, and simply modifying which packages to install in an already existing distro, which is ridiculous and is nothing like OS development.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to read from SATA HDD (AHCI) on low level?

Post by iansjack »

natiiix wrote:
iansjack wrote:Certainly most books describing an operating system are considerably longer than that. The reason for that, as you are discovering (but refuse to accept) is that a useful operating system is a moderately complicated project.
You've just made a very good counter-argument to your statement about Linux kernel having easy to use system calls, because that would certainly make OS development pretty easy. Obviously that assume you don't necessarily want to start from an absolute scratch.
If it were as easy as you said I would have found a guide on how to build an OS on top of it and never started making my own kernel to begin with.
You really don't understand what an operating system is, do you. Which explains this train-wreck of a thread.

There is a big difference between a kernel that provides system calls and user programs that make use of those system calls. The former is a complicated business; the latter, if you did your work right with the former, is much simpler.
User avatar
IanSeyler
Member
Member
Posts: 326
Joined: Mon Jul 28, 2008 9:46 am
Location: Ontario, Canada
Contact:

Re: How to read from SATA HDD (AHCI) on low level?

Post by IanSeyler »

@natiiix Here is the AHCI driver I wrote for my OS:

https://github.com/ReturnInfinity/BareM ... e/ahci.asm

It shows how to initialize the hardware and command slots as well as reading/writing sectors. It's written in x86-64 assembly (but is fairly well commented) so you can't get much lower level than that.

-Ian
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
natiiix
Member
Member
Posts: 44
Joined: Thu Mar 23, 2017 5:21 pm

Re: How to read from SATA HDD (AHCI) on low level?

Post by natiiix »

iansjack wrote:There is a big difference between a kernel that provides system calls and user programs that make use of those system calls. The former is a complicated business; the latter, if you did your work right with the former, is much simpler.
You don't really understand what I'm talking about. I've never said anything about user programs.
IanSeyler wrote:@natiiix Here is the AHCI driver I wrote for my OS:

https://github.com/ReturnInfinity/BareM ... e/ahci.asm

It shows how to initialize the hardware and command slots as well as reading/writing sectors. It's written in x86-64 assembly (but is fairly well commented) so you can't get much lower level than that.

-Ian
I've seen it quite some time ago, but it doesn't appear anywhere near possible to me to get a C code out of that.
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Re: How to read from SATA HDD (AHCI) on low level?

Post by MollenOS »

I've seen it quite some time ago, but it doesn't appear anywhere near possible to me to get a C code out of that.
It's a good thing it's not that hard to convert assembly to C code.

Otherwise, just as a mind-experiment, my AHCI driver is here:
https://github.com/Fadekraft/MollenOS/t ... orage/ahci
User avatar
IanSeyler
Member
Member
Posts: 326
Joined: Mon Jul 28, 2008 9:46 am
Location: Ontario, Canada
Contact:

Re: How to read from SATA HDD (AHCI) on low level?

Post by IanSeyler »

MollenOS wrote:It's a good thing it's not that hard to convert assembly to C code.
=D>
Even with the Assembly driver I linked you should be able to follow along with what is happening (along with the official documentation). For the most part its just moving/setting values in memory.
BareMetal OS - http://www.returninfinity.com/
Mono-tasking 64-bit OS for x86-64 based computers, written entirely in Assembly
Post Reply