LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Kernel Stack Initialization (https://www.linuxquestions.org/questions/linux-kernel-70/kernel-stack-initialization-894413/)

prabagaranvt 07-29-2011 12:57 AM

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?.

Mara 07-30-2011 06:02 AM

The first part of the kernel code, written in assembly. The stack must be present when the first function in C gets called.

ashish anand 08-03-2011 08:31 AM

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

sundialsvcs 08-03-2011 09:16 AM

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).

prabagaranvt 08-04-2011 06:09 AM

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.

Mara 08-04-2011 02:38 PM

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.