LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   I want to learn the linux kernel (https://www.linuxquestions.org/questions/programming-9/i-want-to-learn-the-linux-kernel-901514/)

dspjm 09-06-2011 11:39 PM

I want to learn the linux kernel
 
So, I am a newbie to Linux kernel, and I want to study it.
I am reading a book "Linux Kernel Development". I want to read the source code of the Linux kernel. In my opinion, the book went into detail too much. I want to know how the kernel work first.
When I open the source of kernel, I found myself lost in so much source code, I dont understand what is in those directories, can anybody help me?

theNbomr 09-06-2011 11:53 PM

Who said it was going to be easy? If it was, everyone would be doing it. If the book was too detailed, what could possibly make you think the source code would somehow summarize anything? What is the purpose of your study?

--- rod.

dspjm 09-07-2011 02:24 AM

Quote:

Originally Posted by theNbomr (Post 4463527)
Who said it was going to be easy? If it was, everyone would be doing it. If the book was too detailed, what could possibly make you think the source code would somehow summarize anything? What is the purpose of your study?

--- rod.

Yeah, I know it's not gonna be easy. While, when I learn something else, I sometimes found a book which can lead you step by step, then you can understand the point suddenly. I just prefer that kind of process. So, I am just wondering if there is a book that can help me in this.

Sergei Steshenko 09-07-2011 05:46 AM

Quote:

Originally Posted by dspjm (Post 4463523)
... I found myself lost in so much source code ...

http://www.makelinux.co.il/kernel_map/

easuter 09-07-2011 06:13 AM

Quote:

Originally Posted by dspjm (Post 4463640)
Yeah, I know it's not gonna be easy. While, when I learn something else, I sometimes found a book which can lead you step by step, then you can understand the point suddenly. I just prefer that kind of process. So, I am just wondering if there is a book that can help me in this.

I'm not a kernel developer, so (someone) correct me if I'm wrong, but the problem with that kind of book would probably be 2 connected essential points:

1 - The kernel is *huge*. Any book that would give you a step-by-step walkthrough of the entire kernel would take a long time to write/edit before being ready to publish.
2 - The kernel's development development pace is pretty fast. The latest 2.6 kernel (or 3.x now?...) is quite different from the first release of 2.6.0, so much so that drivers written for the older 2.6 kernels won't compile against the newer ones unless they keep up with the changes.

This kind of makes the effort put into writing such a book a bit of a waste of time since it will become outdated very quickly.

Aquarius_Girl 09-07-2011 06:40 AM

Quote:

Originally Posted by dspjm (Post 4463523)
So, I am a newbie to Linux kernel, and I want to study it.

IMO, studying the kernel without any defined
aims will be difficult and pretty much useless
too.

What EXACTLY do you want to do after studying
the kernel?

http://www.linuxquestions.org/questi...-books-873556/

theNbomr 09-07-2011 08:02 AM

Perhaps a study of OS's in a more general way would be a good place to start. From there, you can apply general principles to specific implementations within Linux. There is an older book 'The Design of the Unix Operating System' which covers the basics with some detail. There are others with similar scope.

--- rod.

dspjm 09-08-2011 09:32 AM

Thank everybody for answering, well, I found myself not very familiar with how an operating system work, I am looking for some information from grub and openbios.

Well, I just don't understand, forgive my ignorance, why there is not a main() function in linux kernel and many other softwares? I was taught there must be one, wired. And when the kernel was boot, where does the code started executing. I think the linux kernel is just like a large program, as the other programs, while it just have some functions of allocating the memory or something.

I thought I may have a wrong concept about the linux kernel...*-*

theNbomr 09-08-2011 09:41 AM

The kernel entry point is not the same as that of a userspace application. It is platform-specific, and is usually invoked by the bootloader. Older x86 kernels were made to load directly from the disk, and included built-in bootloaders. The entry point for those was defined by the PC BIOS. Linux has since been generalized for other architectures. The kernel is also quite modular, and is composed of loadable/un-loadable kernel modules, which also do not require a main() function.
When doing kernel level programming, one needs a very different mindset from the usual userspace software development. Same for bootloaders.

--- rod.

dspjm 09-08-2011 10:19 AM

Quote:

Originally Posted by theNbomr (Post 4466227)
The kernel entry point is not the same as that of a userspace application. It is platform-specific, and is usually invoked by the bootloader. Older x86 kernels were made to load directly from the disk, and included built-in bootloaders. The entry point for those was defined by the PC BIOS. Linux has since been generalized for other architectures. The kernel is also quite modular, and is composed of loadable/un-loadable kernel modules, which also do not require a main() function.
When doing kernel level programming, one needs a very different mindset from the usual userspace software development. Same for bootloaders.

--- rod.

So, can we see this like this, the linux kernel is codes consisted by many functions, and the bootloader just invoke some of them? The main function is the bootloader?

Sergei Steshenko 09-08-2011 12:51 PM

Quote:

Originally Posted by dspjm (Post 4466225)
...forgive my ignorance, why there is not a main() function in linux kernel and many other softwares? I was taught there must be one, wired. ...

And since there is 'main' function in a program, who/what calls that function ?

And who told you there should be a 'main' function and if he/she told you this, were you given any reason ?

And when you boot, say, your PC (or cellphone) is a 'main' function involved ? And if you think it is, who/what calls it ?

At all, do you understand how a computer works ? I.e., more specifically, how a CPU works ? And do you think CPU has anything to do with 'main' function ?

dspjm 09-08-2011 01:47 PM

Quote:

Originally Posted by Sergei Steshenko (Post 4466559)
And since there is 'main' function in a program, who/what calls that function ?

And who told you there should be a 'main' function and if he/she told you this, were you given any reason ?

And when you boot, say, your PC (or cellphone) is a 'main' function involved ? And if you think it is, who/what calls it ?

At all, do you understand how a computer works ? I.e., more specifically, how a CPU works ? And do you think CPU has anything to do with 'main' function ?

When you boot the computer, the computer start executing the first command written in rom, that's what I know... I think that can be a main(). I think main() doesn't have to be named 'main', but it is a function that can be called and links many other functions. So linux consists of many functions, well, I just don't know who call those functions to accomplish their mission? If there is not a main(), who calls those functions?
If grub calls it, or bios calls it, fine, they can be main(). 'Main' is a clue for us to understand the exact process of running a program, maybe there is not a main, but there must be something controlling everything, that's all I know.

SigTerm 09-08-2011 02:26 PM

Quote:

Originally Posted by dspjm (Post 4466596)
If there is not a main(), who calls those functions?

I think it is too early for you to hack kernel. For example, interrupt handler won't be called from within "main"-like function, it will be triggered by external event. Either start with book theNbomr recommended, or read something about cpu architecture.

theNbomr 09-08-2011 03:44 PM

Quote:

Originally Posted by dspjm (Post 4466300)
So, can we see this like this, the linux kernel is codes consisted by many functions, and the bootloader just invoke some of them? The main function is the bootloader?

Not exactly. The bootloader simply launches the kernel (and then usually disappears). There is one entry point (and I don't know off the top of my head how the bootloader establishes what it is). The kernel has numerous internal mechanisms for transferring control to its internal components. In addition, it knows how to launch userspace application code and transfer control to those applications. Further still, it exposes an interface to userspace applications to permit them to access system services which are provided by the kernel (filesystem, interprocess comm's, networking, etc.) The mechanism to provide this too, is architecture dependent, although I think it is common to use a software interrupt to do so, if the architecture provides such a thing. Most, if not all of this is common to all (non trivial) operating systems, not just Linux.

--- rod.

Sergei Steshenko 09-08-2011 03:59 PM

Quote:

Originally Posted by dspjm (Post 4466596)
When you boot the computer, the computer start executing the first command written in rom, that's what I know... I think that can be a main(). I think main() doesn't have to be named 'main', but it is a function that can be called and links many other functions. So linux consists of many functions, well, I just don't know who call those functions to accomplish their mission? If there is not a main(), who calls those functions?
If grub calls it, or bios calls it, fine, they can be main(). 'Main' is a clue for us to understand the exact process of running a program, maybe there is not a main, but there must be something controlling everything, that's all I know.

Not exactly. The CPU knows nothing about ROM, it knows about "reset vector" or something like this. I.e. HW reset causes CPU to start execution from certain address. Typically, but not necessarily, the address resides in ROM.

So, think again about 'main' and realize that CPU knows nothing about 'main'. I.e. 'main' is not part of CPU architecture.

No, there is nothing controlling everything, there is just currently executed code, and there can be causes (interrupts, exceptions) which interfere with currently executed code.


All times are GMT -5. The time now is 02:36 PM.