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?. |
The first part of the kernel code, written in assembly. The stack must be present when the first function in C gets called.
|
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 |
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).
|
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. |
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.
|
All times are GMT -5. The time now is 08:52 AM. |