LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-06-2011, 11:39 PM   #1
dspjm
Member
 
Registered: Dec 2010
Distribution: Scientific Linux Slackware
Posts: 91

Rep: Reputation: 2
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?
 
Old 09-06-2011, 11:53 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
Old 09-07-2011, 02:24 AM   #3
dspjm
Member
 
Registered: Dec 2010
Distribution: Scientific Linux Slackware
Posts: 91

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by theNbomr View Post
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.
 
Old 09-07-2011, 05:46 AM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by dspjm View Post
... I found myself lost in so much source code ...
http://www.makelinux.co.il/kernel_map/
 
1 members found this post helpful.
Old 09-07-2011, 06:13 AM   #5
easuter
Member
 
Registered: Dec 2005
Location: Portugal
Distribution: Slackware64 13.0, Slackware64 13.1
Posts: 538

Rep: Reputation: 62
Quote:
Originally Posted by dspjm View Post
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.

Last edited by easuter; 09-07-2011 at 06:14 AM.
 
Old 09-07-2011, 06:40 AM   #6
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by dspjm View Post
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/
 
Old 09-07-2011, 08:02 AM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
Old 09-08-2011, 09:32 AM   #8
dspjm
Member
 
Registered: Dec 2010
Distribution: Scientific Linux Slackware
Posts: 91

Original Poster
Rep: Reputation: 2
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...*-*
 
Old 09-08-2011, 09:41 AM   #9
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
2 members found this post helpful.
Old 09-08-2011, 10:19 AM   #10
dspjm
Member
 
Registered: Dec 2010
Distribution: Scientific Linux Slackware
Posts: 91

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by theNbomr View Post
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?
 
Old 09-08-2011, 12:51 PM   #11
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by dspjm View Post
...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 ?
 
Old 09-08-2011, 01:47 PM   #12
dspjm
Member
 
Registered: Dec 2010
Distribution: Scientific Linux Slackware
Posts: 91

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by Sergei Steshenko View Post
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.
 
Old 09-08-2011, 02:26 PM   #13
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by dspjm View Post
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.
 
Old 09-08-2011, 03:44 PM   #14
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by dspjm View Post
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.

Last edited by theNbomr; 09-08-2011 at 04:13 PM.
 
2 members found this post helpful.
Old 09-08-2011, 03:59 PM   #15
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by dspjm View Post
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.
 
2 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I get to learn linux kernel gschen2010 Programming 9 01-13-2011 05:20 AM
LXer: Learn how to invoke Linux kernel function system calls LXer Syndicated Linux News 0 04-07-2010 09:10 PM
Learn How To Compile The Linux Kernel AwesomeMachine Linux - Newbie 18 02-13-2010 02:12 PM
How to learn kernel programming? vrishankaryan Linux - Newbie 6 08-16-2007 02:49 AM
How to learn kernel ? yangwuking Linux - Newbie 1 12-27-2004 07:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration