Originally Published: Thursday, 19 July 2001 Author: Subhasish Ghosh
Published to: learn_articles_firststep/General Page: 4/6 - [Printable]

Bootstrapping a Linux system - An Analysis

Ever wonder what happens between powering on your system and the logon prompt? You see all the screen messages, but what do they mean? Linux.com writer Subhasish Ghosh wondered the same thing, and went to find out in Bootstrapping a Linux System.

Setup Function  << Page 4 of 6  >>

The setup( ) function. What does it do?

Now the time has come to take a deeper look into some of the essential assembly language functions that are indispensable for the bootstrapping process.

The setup( ) function can be found in the file /usr/src/linux-2.4.2/arch/i386/boot/setup.S. The code of the setup( ) assembly language function is placed by the linker immediately after the integrated boot loader of the Kernel, that is, at offset 0x200 of the Kernel Image file. This allows the boot loader to locate the code easily and copy it onto the RAM starting from the physical address 0x00090200.

Now the question that comes up is: What does this setup( ) function do? As its name suggests, it's supposed to set up something. But what? And how?

As we all know for the Kernel to operate properly all the hardware devices in the computer must be detected and then initialized in an orderly fashion. The setup( ) function initializes all the hardware devices and thus creates an environment for the Kernel to operate in.

But, hang on a second. Didn't we see a few minutes earlier that the BIOS was supposed to do all this stuff? Yeah, you are right. Although the BIOS already initialized most hardware, the Linux Kernel does NOT rely on it and initializes all of the hardware in its own fashion. But, if someone asks, well, why does Linux operate in such a way? The answer to this question is both very easy yet extremely difficult to explain. The Linux Kernel had been so designed to enhance portability and robustness. This is one of the many features that makes the Linux Kernel the best out of all the Unix and Unix-like Kernels available and makes it unique in so many ways. A proper understanding of why and exactly how the Linux Kernel implements this feature is beyond the scope of this article and would require an extremely detailed coverage of the essential features of the Linux Kernel Architecture.

The setup( ) code mainly performs the following tasks:

  1. First, total amount of physical RAM available to the system is detected. It invokes a BIOS procedure for detecting the RAM.
  2. Sets the Keyboard repeat delay and rate.
  3. The Video adapter card is detected.
  4. The Disk Controller is reinitialized and hard disk parameters are determined.
  5. Checks for an IBM Micro Channel bus (MCA).
  6. Checks for a PS/2 pointing device (bus mouse).
  7. Checks for Advanced Power Management (APM) BIOS support.
  8. Checks the position of the Kernel Image loaded in RAM. If loaded "low" in RAM (when using zImage, at physical address 0x00010000) it is moved to "high" in RAM (at physical address 0x00001000). But, if the Kernel image is a "bzImage" loaded in "high" of RAM already, then it's not moved anywhere.
  9. Sets up the Interrupt Descriptor Table (IDT) and a Global Descriptor Table (GDT).
  10. If a floating-point unit (FPU) is present, it's now reset.
  11. The PIC (Programmable Interrupt Controller) is reprogrammed at this step.
  12. The CPU is switched from "Real mode" to "Protected mode" by setting the PE bit in the cr0 status register.
  13. Jumps to the stratup_32( ) assembly language function.

From here on the going gets a bit tougher as the bootstrap process gets a bit more complicated.





Setup Function  << Page 4 of 6  >>