LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 07-29-2011, 12:57 AM   #1
prabagaranvt
LQ Newbie
 
Registered: Mar 2011
Posts: 23

Rep: Reputation: 0
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?.
 
Old 07-30-2011, 06:02 AM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
The first part of the kernel code, written in assembly. The stack must be present when the first function in C gets called.
 
Old 08-03-2011, 08:31 AM   #3
ashish anand
LQ Newbie
 
Registered: Oct 2009
Posts: 23

Rep: Reputation: 0
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
 
Old 08-03-2011, 09:16 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939Reputation: 3939
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).
 
Old 08-04-2011, 06:09 AM   #5
prabagaranvt
LQ Newbie
 
Registered: Mar 2011
Posts: 23

Original Poster
Rep: Reputation: 0
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.
 
Old 08-04-2011, 02:38 PM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
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.
 
  


Reply

Tags
kernel



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
Difference b/t Kernel stack and User stack hazzyb Linux - Software 2 09-29-2008 07:40 PM
Increasing Kernel stack size to 8k without recompiling the Kernel deathman Linux - Software 2 04-08-2006 04:39 AM
Where to find a Kernel/Kernel Patch with support for stack sizes >8K Valhalla Linux - Software 2 05-24-2005 05:39 PM
Compaq WL110 initialization problem after kernel upgrade LrdChaos Linux - Wireless Networking 0 07-24-2004 05:59 PM
Virtual Machine kernel stack fault in kernel mode virtical Linux - Software 0 07-14-2003 08:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 04:59 AM.

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