Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer app04.tex V1 - 09/04/2008 6:12pm Page 1224

Appendix D: System Startup................................................


D.1 Architecture-Specific Setup on IA-32


Systems


Once the kernel has been loaded into physical memory using the bootloader (LILO, GRUB, etc.), the
setupassembler ‘‘function‘‘ inarch/x86/boot/header.Sis invoked by switching the control flow to the
appropriate point in memory by means of a jump statement. This is possible because thesetupfunction
is always at the same place in the object file.

The code performs the following tasks, which require a great deal of assembly code:


  1. It checks whether the kernel was loaded to the correct position in memory. To do this, it
    uses a 4-byte signature that is integrated in the kernel image and that must be located,
    unchanged, at the correct position in RAM.

  2. It determines how big system memory is.

  3. It initializes the graphics card.

  4. It moves the kernel image to a position in memory where it does not get in its own way dur-
    ing subsequent decompression.

  5. It switches the CPU to protected mode.


On completion of these tasks, the code branches to thestartup_32function (inarch/x86/boot/
compressed/head_32.S), which does the following:


  1. It creates a provisional kernel stack.

  2. It fills uninitialized kernel data with null bytes. The relevant area is between the_edataand
    _endconstants. When the kernel is linked, these constants are automatically supplied with
    the correct values as generated for the kernel binary.

  3. It calls the C routinedecompress_kernelinarch/x86/boot/compressed/misc_32.c.This
    decompresses the kernel and writes the uncompressed machine code to position 0x100000,^1
    directly after the first MiB of memory. Uncompressing is the first operation performed by
    the kernel, as indicated by the screen messagesUncompressing Linux...andOk, booting
    the kernel.


The final part of processor-specific initialization is started by redirecting control flow tostartup_32in
arch/x86/kernel/head_32.S.

This is adifferentroutine from the previously describedstartup_32function and is
defined in a different file. The kernel need not concern itself with the fact that both
‘‘functions‘‘ have the same label because it branches directly to the appropriate
address, which is patched in by the assembler and is not associated with the
symbolic labels used in the source code.

(^1) The address can differ if the kernel was built as a relocatable kernel, but this scenario is not relevant here.

Free download pdf