Kernel Entry Point and Linker Script
KERNEL ENTRY POINT :
Kernel Entry point is the piece of code that will be executed first when the bootloader calls the kernel. This chunk of code is mainly written in assembly language as things like new stack or loading a new Global Descriptor Table, (GDT is type of data structure used by Intel x86 family processors, in order to define the characteristics of the various memory used during program execution), Interrupt Descriptor Table (IDT is also a data structure used by the x86 architecture to implement an interrupt vector table. IDT is used by the processor to determine the correct response to interrupts and exceptions), or segment registers are things that cannot be done using C codes. In many kernels will put all their assembler code in this one file. and put all the rest of the sources in several C source files.
As far as code is concerned, all this file does is load a new 8KB stack, and then jump into an infinite loop. The stack is a very small amount of memory and is used to store or pass arguments to functions in C. It can also be used to hold local variables that is declared and used inside the functions. All other global variables are stored in the data and BSS sections. A BSS (Block Started by Symbol) section typically includes all uninitialized variables declared outside any function as well as uninitialized local variables declared with the static keyword. The program loader initializes the memory allocated for the BSS section when it loads the program. Operating System may use a technique called zero-filled on demand to efficiently implement the bss segment.
LINKER SCRIPT :
The Linker is a tool that takes all the compiler and assembler output files and links them together into one binary file. A binary file can have many formats, most common ones are FLAT, AOUT, COFF, PE and ELF. Regardless of which ever format we choose there are always 3 sections in the outout file. ‘Text’ or ‘Code’ which are executable itself. The ‘Data’ section is for hard coded vales used in the code. eg: suppose you declare a variable and set its vales to 5. The value 5 would get stored in ‘Data’ section. The third section is calles the ‘BSS’ section. It is a virtual section and doesn’t exist in the binary image, but exist in memory when your binary is loaded.
For more details on Linker Scripts click here
Combine The Two :
Now we must combine the two to create our kernel’s binary for GRUB to load. The Simplest way to do this in Unix is to create a makefle script to do the assembling, compiling and linking for us. However if you are using windows, you can create a batch file. A batch file is simply a collection of DOS commands that can be executed with one command.
Reference : Bran’s Kernel Development Tutorial
Recent Comments