| Linux - Kernel This forum is for all discussion relating to the Linux kernel. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
07-29-2011, 12:57 AM
|
#1
|
|
LQ Newbie
Registered: Mar 2011
Posts: 23
Rep:
|
Kernel Stack Initialization
Linux Kernel Initialization starts at start_kernel function which is writtern in c.
This function sets up the kernel stack and other stuffs. For this function to run , it needs a stack. Who sets up the stack for this function to run?.
|
|
|
|
07-30-2011, 06:02 AM
|
#2
|
|
Moderator
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,471
Rep: 
|
The first part of the kernel code, written in assembly. The stack must be present when the first function in C gets called.
|
|
|
|
08-03-2011, 08:31 AM
|
#3
|
|
LQ Newbie
Registered: Oct 2009
Posts: 23
Rep:
|
To Mara
hi
when we write a simple c code main function is the one responsible for creating stack ?
please correct me if i am incorect
Thanx in advance
|
|
|
|
08-03-2011, 09:16 AM
|
#4
|
|
Senior Member
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 4,554
|
This is the kernel. When you run an ordinary "C" program in an ordinary environment, the loader and the runtime library do all of the initialization for you. But, in the kernel, there is nothing there (yet).
|
|
|
|
08-04-2011, 06:09 AM
|
#5
|
|
LQ Newbie
Registered: Mar 2011
Posts: 23
Original Poster
Rep:
|
when we write a simple c code main function is the one responsible for creating stack ?
For each and every c program you run , fork system call is called.
This fork() system call is responsible for Creating the memory regions(including stack) of our program.
But when the kernel starts , there is no fork system call.
So , there would be two options.
1. Assembly code in head.s & entry.s setup the stack.
2. Kernel runs without stack.
Correct me if i am wrong.
Regards,
Prabagaran.
|
|
|
|
08-04-2011, 02:38 PM
|
#6
|
|
Moderator
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,471
Rep: 
|
When we run a function in C, it needs a stack. The compiler generates code that uses it. That is the assembly fun before the first C function that sets up the stack. In fact, for most architectures it's easy: just a register that needs to get the right value. As an example, for X86 it's in http://lxr.linux.no/#linux+v3.0/arch/x86/boot/header.S from line 264.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:23 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|